Ver código fonte

添加路由守卫

xiaodai2022 1 ano atrás
pai
commit
2f77925a3c

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/index.html


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/static/js/app.abc023a1.js


BIN
dist/static/js/app.abc023a1.js.gz


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/static/js/app.c9842629.js


BIN
dist/static/js/app.c9842629.js.gz


+ 42 - 34
src/main.js

@@ -1,24 +1,22 @@
 import router from "./router";
-import 'normalize.css/normalize.css' // a modern alternative to CSS resets
-import 'element-ui/lib/theme-chalk/display.css';
-import Viewer from 'v-viewer';
-import {
-  getToken,  removeToken
-} from '@/utils/auth'
-import ElementUI from 'element-ui'
-import 'viewerjs/dist/viewer.css'
+import "normalize.css/normalize.css"; // a modern alternative to CSS resets
+import "element-ui/lib/theme-chalk/display.css";
+import Viewer from "v-viewer";
+import { getToken, removeToken } from "@/utils/auth";
+import ElementUI from "element-ui";
+import "viewerjs/dist/viewer.css";
 
 import "element-ui/lib/theme-chalk/display.css";
 import "./styles/element-variables.scss";
 
-import './styles/index.scss' // global css
-import globalComponents from './components/globalComponents'
-import App from './App'
-import store from './store'
-import base from './assets/utils/prototype/index'
+import "./styles/index.scss"; // global css
+import globalComponents from "./components/globalComponents";
+import App from "./App";
+import store from "./store";
+import base from "./assets/utils/prototype/index";
 // require('./mock')
 
-import * as filters from './filters' // global filters
+import * as filters from "./filters"; // global filters
 
 Array.prototype.remove = function (val) {
   var index = this.indexOf(val);
@@ -33,33 +31,43 @@ if (typeof String.prototype.startsWith != "function") {
   };
 }
 
-Vue.use(globalComponents)
+Vue.use(globalComponents);
 Vue.use(Viewer, {
   defaultOptions: {
-    zIndex: 9999
-  }
-})
-Vue.use(base)
-import PuzzleVerification from 'vue-puzzle-verification'
-Vue.use(PuzzleVerification)
-
+    zIndex: 9999,
+  },
+});
+Vue.use(base);
+import PuzzleVerification from "vue-puzzle-verification";
+Vue.use(PuzzleVerification);
 
 // register global utility filters
-Object.keys(filters).forEach(key => {
-  Vue.filter(key, filters[key])
-})
+Object.keys(filters).forEach((key) => {
+  Vue.filter(key, filters[key]);
+});
 
-Vue.config.productionTip = false
-Vue.use(ElementUI)
+Vue.config.productionTip = false;
+Vue.use(ElementUI);
+router.beforeEach((to, from, next) => {
+  const token = getToken() ?? "";
+  console.log(from.path + "----" + to.path);
+  if (to.path === "/login" || to.path === "/demand/index") {
+    console.log('111');
+    next();
+  } else if (token === "") {
+    removeToken();
+    next("/login");
+  } else {
+    next();
+  }
+});
 window.vm = new Vue({
   router,
   store,
-  render: h => h(App)
+  render: (h) => h(App),
 }).$mount("#app");
 
-
-
-if (getToken() === null || getToken() === undefined || getToken() === '') {
-  removeToken()
-  router.replace({ name: 'login' });
-}
+// if (getToken() === null || getToken() === undefined || getToken() === '') {
+//   removeToken()
+//   router.replace({ name: 'login' });
+// }

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff