main.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. console.log(to, from);
  26. let { token } = to.query;
  27. localStorage.setItem("token", token);
  28. if (token && to.matched.length) {
  29. store.commit("changeLogin", true);
  30. next();
  31. // let rolePermission = localStorage.rolePermission?.split(",") || [];
  32. // if (store.state.menuData.length) {
  33. // let path = store.state?.menuData[0]?.items[0].path;
  34. // if (0 === to.matched.length) {
  35. // next("/index");
  36. // } else if (to.path == "/login") {
  37. // next("/index");
  38. // } else if (rolePermission?.indexOf(to.meta.code) == -1) {
  39. // if (to.path == "/index") {
  40. // next();
  41. // } else {
  42. // next("/index");
  43. // }
  44. // } else {
  45. // if (to.path == "/") {
  46. // next("/index");
  47. // } else {
  48. // next();
  49. // }
  50. // }
  51. // } else {
  52. // if (to.path == "/" || to.path == "/login") {
  53. // next("/index");
  54. // } else {
  55. // next();
  56. // }
  57. // }
  58. } else {
  59. store.commit("changeLogin", false);
  60. if (to.path == "/notFound") {
  61. next();
  62. } else {
  63. next("/notFound");
  64. }
  65. }
  66. });
  67. router.afterEach((to, from) => {
  68. let { title } = to.meta;
  69. document.title = title;
  70. store.commit("setCurrentMenuItem", to.path);
  71. store.commit("changefirstTitle", title);
  72. });
  73. app.directive("auth", {
  74. mounted(el, bind) {
  75. // let permissions = localStorage.rolePermission?.split(",") || [];
  76. // if (permissions.indexOf(bind.value) == -1) {
  77. // el.parentNode.removeChild(el);
  78. // }
  79. },
  80. });
  81. app
  82. .use(router)
  83. .use(ElementPlus, {
  84. locale: zhCn,
  85. })
  86. .use(store)
  87. .mount("#app");