main.js 2.2 KB

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