main.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. router.beforeEach(async (to, from, next) => {
  15. let userId = localStorage.userId;
  16. if (userId) {
  17. store.commit("changeLogin", true);
  18. if (0 === to.matched.length) {
  19. next("/voyage/voyageList");
  20. } else if (to.path == "/login" || to.path == "/") {
  21. next("/voyage/voyageList");
  22. } else {
  23. next();
  24. }
  25. } else {
  26. store.commit("changeLogin", false);
  27. if (to.path == "/login") {
  28. next();
  29. } else {
  30. next("/login");
  31. }
  32. }
  33. });
  34. router.afterEach((to, from) => {
  35. let { title } = to.meta;
  36. document.title = title;
  37. store.commit("setCurrentMenuItem", to.path);
  38. store.commit("changefirstTitle", title);
  39. });
  40. app.config.globalProperties.check = () => {
  41. console.log("check");
  42. };
  43. app.use(router).use(ElementPlus).use(store).mount("#app");