main.js 2.0 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 "./styles/index.css";
  8. import Uploader from "./components/Uploader.vue";
  9. import IdUploader from "./components/IdUploader.vue";
  10. import ShipInfo from "./components/ShipInfo.vue";
  11. import RemoteSearch from "./components/RemoteSearch.vue";
  12. import RemoteSelect from "./components/RemoteSelect.vue";
  13. import zhCn from "element-plus/dist/locale/zh-cn.mjs";
  14. import Layout from "./layout/Layout.vue";
  15. import { createPinia } from "pinia";
  16. const pinia = createPinia();
  17. const app = createApp(App);
  18. app.use(ElementPlus, {
  19. locale: zhCn,
  20. });
  21. app.use(pinia);
  22. app.component("Layout", Layout);
  23. app.component("ShipInfo", ShipInfo);
  24. app.component("Uploader", Uploader);
  25. app.component("IdUploader", IdUploader);
  26. app.component("RemoteSearch", RemoteSearch);
  27. app.component("RemoteSelect", RemoteSelect);
  28. import * as ElementPlusIconsVue from "@element-plus/icons-vue";
  29. for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  30. app.component(key, component);
  31. }
  32. router.beforeEach(async (to, from, next) => {
  33. let id = localStorage.loginAccountId;
  34. if (id) {
  35. store.commit("changeLogin", true);
  36. if (0 === to.matched.length) {
  37. next("/index");
  38. } else if (to.path == "/login" || to.path == "/") {
  39. next("/index");
  40. } else {
  41. next();
  42. }
  43. } else {
  44. localStorage.removeItem("loginAccountId");
  45. localStorage.removeItem("loginName");
  46. localStorage.removeItem("loginPhone");
  47. localStorage.removeItem("shippingCompany");
  48. localStorage.removeItem("shippingId");
  49. store.commit("changeLogin", false);
  50. if (to.path == "/login") {
  51. next();
  52. } else {
  53. next("/login");
  54. }
  55. }
  56. });
  57. router.afterEach((to, from) => {
  58. let { title } = to.meta;
  59. document.title = "船务公司 - " + title;
  60. store.commit("setCurrentMenuItem", to.path);
  61. store.commit("changefirstTitle", title);
  62. });
  63. app.use(router).use(store).mount("#app");