lrf402788946 5 vuotta sitten
vanhempi
commit
921eb89c25
5 muutettua tiedostoa jossa 8 lisäystä ja 18 poistoa
  1. 2 1
      .env
  2. 3 14
      src/layout/layout-part/heads.vue
  3. 1 1
      src/router.js
  4. 1 1
      src/views/login/login.vue
  5. 1 1
      vue.config.js

+ 2 - 1
.env

@@ -1 +1,2 @@
-VUE_APP_AXIOS_BASE_URL = ''
+VUE_APP_AXIOS_BASE_URL = ''
+VUE_APP_ROUTER="/www/student"

+ 3 - 14
src/layout/layout-part/heads.vue

@@ -65,8 +65,8 @@ export default {
     },
   }),
   created() {
-    this.checkUrl();
     this.setUser();
+    this.check();
   },
   computed: {
     ...mapState(['user']),
@@ -74,19 +74,8 @@ export default {
   methods: {
     ...mapMutations(['setUser']),
     ...mapActions(['userOperation']),
-    checkUrl() {
-      if (location.search.length > 0) {
-        let params = location.search.replace('?', '').split('=');
-        let key = params[0];
-        if (key.includes(`token`)) {
-          let token = params[1];
-          sessionStorage.setItem('token', token);
-          let info = jwt.decode(token);
-          this.setUser(info);
-          let turnTo = window.location.href.replace(window.location.search, '');
-          window.location.href = turnTo;
-        }
-      }
+    check() {
+      if (!this.user.id) this.$router.push({ path: '/login' });
     },
     toClose() {
       this.$refs.form.resetFields();

+ 1 - 1
src/router.js

@@ -5,7 +5,7 @@ Vue.use(Router);
 
 export default new Router({
   mode: 'history',
-  base: process.env.BASE_URL,
+  base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROUTER,
   routes: [
     {
       path: '/',

+ 1 - 1
src/views/login/login.vue

@@ -125,7 +125,7 @@ export default {
         message: `${result.errcode}` === '0' ? '登录成功' : result.errmsg,
       });
       if (`${result.errcode}` === '0') {
-        sessionStorage.setItem('token', JSON.stringify(result.data));
+        sessionStorage.setItem('token', result.data);
         let info = jwt.decode(result.data);
         sessionStorage.setItem('user', JSON.stringify(info));
         this.$router.push({ path: '/' });

+ 1 - 1
vue.config.js

@@ -1,7 +1,7 @@
 const path = require('path');
 const resumeSrc = path.resolve(__dirname, '../web-common');
 module.exports = {
-  publicPath: '/',
+  publicPath: process.env.NODE_ENV === 'development' ? '/' : '/www/student',
   configureWebpack: config => {
     Object.assign(config, {
       // 开发生产共同配置