| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { createApp } from "vue";
- import ElementPlus from "element-plus";
- import "element-plus/dist/index.css";
- import App from "./App.vue";
- import router from "./router";
- import store from "./store";
- import md5 from "md5";
- import "./styles/index.css";
- import Uploader from "./components/Uploader.vue";
- import Certs from "./components/Certs.vue";
- const app = createApp(App);
- app.component("Certs", Certs);
- app.component("Uploader", Uploader);
- let userId = localStorage.userId;
- if (userId) {
- store.dispatch("GetBasePermissionData", localStorage.loginAccountId);
- store.dispatch("GetUserPermission", localStorage.loginAccountId);
- }
- router.beforeEach(async (to, from, next) => {
- if (localStorage.userId) {
- store.commit("changeLogin", true);
- let rolePermission = localStorage.rolePermission?.split(",") || [];
- if (store.state.menuData.length) {
- let path = store.state?.menuData[0]?.items[0].path;
- if (0 === to.matched.length) {
- next(path);
- } else if (to.path == "/login" || to.path == "/") {
- next(path);
- } else if (rolePermission?.indexOf(to.meta.code) == -1) {
- next(path);
- } else {
- next();
- }
- } else {
- next();
- }
- } else {
- store.commit("changeLogin", false);
- if (to.path == "/login") {
- next();
- } else {
- next("/login");
- }
- }
- });
- router.afterEach((to, from) => {
- let { title } = to.meta;
- document.title = title;
- store.commit("setCurrentMenuItem", to.path);
- store.commit("changefirstTitle", title);
- });
- app.directive("auth", {
- mounted(el, bind) {
- let permissions = localStorage.rolePermission?.split(",") || [];
- if (permissions.indexOf(bind.value) == -1) {
- el.parentNode.removeChild(el);
- }
- },
- });
- app.use(router).use(ElementPlus).use(store).mount("#app");
|