main.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { createApp } from "vue";
  2. import ElementPlus from "element-plus";
  3. import "element-plus/dist/index.css";
  4. import App from "./App.vue";
  5. import router from "./router";
  6. import store from "./store";
  7. import md5 from "md5";
  8. import "./styles/index.css";
  9. import Uploader from "./components/Uploader.vue";
  10. import Certs from "./components/Certs.vue";
  11. const app = createApp(App);
  12. app.component("Certs", Certs);
  13. app.component("Uploader", Uploader);
  14. let userId = localStorage.userId;
  15. if (userId) {
  16. store.dispatch("GetBasePermissionData", localStorage.loginAccountId);
  17. store.dispatch("GetUserPermission", localStorage.loginAccountId);
  18. }
  19. router.beforeEach(async (to, from, next) => {
  20. if (localStorage.userId) {
  21. store.commit("changeLogin", true);
  22. let rolePermission = localStorage.rolePermission?.split(",") || [];
  23. if (store.state.menuData.length) {
  24. let path = store.state?.menuData[0]?.items[0].path;
  25. if (0 === to.matched.length) {
  26. next(path);
  27. } else if (to.path == "/login" || to.path == "/") {
  28. next(path);
  29. } else if (rolePermission?.indexOf(to.meta.code) == -1) {
  30. next(path);
  31. } else {
  32. next();
  33. }
  34. } else {
  35. next();
  36. }
  37. } else {
  38. store.commit("changeLogin", false);
  39. if (to.path == "/login") {
  40. next();
  41. } else {
  42. next("/login");
  43. }
  44. }
  45. });
  46. router.afterEach((to, from) => {
  47. let { title } = to.meta;
  48. document.title = title;
  49. store.commit("setCurrentMenuItem", to.path);
  50. store.commit("changefirstTitle", title);
  51. });
  52. app.directive("auth", {
  53. mounted(el, bind) {
  54. let permissions = localStorage.rolePermission?.split(",") || [];
  55. if (permissions.indexOf(bind.value) == -1) {
  56. el.parentNode.removeChild(el);
  57. }
  58. },
  59. });
  60. app.use(router).use(ElementPlus).use(store).mount("#app");