main.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. const app = createApp(App);
  14. app.component("RemoteSearch", RemoteSearch);
  15. app.component("Certs", Certs);
  16. app.component("Uploader", Uploader);
  17. let userId = localStorage.userId;
  18. if (userId) {
  19. store.dispatch("GetBasePermissionData", localStorage.loginAccountId);
  20. store.dispatch("GetUserPermission", localStorage.loginAccountId);
  21. }
  22. router.beforeEach(async (to, from, next) => {
  23. if (localStorage.userId) {
  24. store.commit("changeLogin", true);
  25. let rolePermission = localStorage.rolePermission?.split(",") || [];
  26. if (store.state.menuData.length) {
  27. let path = store.state?.menuData[0]?.items[0].path;
  28. if (0 === to.matched.length) {
  29. next(path);
  30. } else if (to.path == "/login" || to.path == "/") {
  31. next(path);
  32. } else if (rolePermission?.indexOf(to.meta.code) == -1) {
  33. next(path);
  34. } else {
  35. next();
  36. }
  37. } else {
  38. if (to.path == "/") {
  39. next("/voyage/voyageList");
  40. } else {
  41. next();
  42. }
  43. }
  44. } else {
  45. store.commit("changeLogin", false);
  46. if (to.path == "/login") {
  47. next();
  48. } else {
  49. next("/login");
  50. }
  51. }
  52. });
  53. router.afterEach((to, from) => {
  54. let { title } = to.meta;
  55. document.title = title;
  56. store.commit("setCurrentMenuItem", to.path);
  57. store.commit("changefirstTitle", title);
  58. });
  59. app.directive("auth", {
  60. mounted(el, bind) {
  61. let permissions = localStorage.rolePermission?.split(",") || [];
  62. if (permissions.indexOf(bind.value) == -1) {
  63. el.parentNode.removeChild(el);
  64. }
  65. },
  66. });
  67. app
  68. .use(router)
  69. .use(ElementPlus, {
  70. locale: zhCn,
  71. })
  72. .use(store)
  73. .mount("#app");