lrf402788946 5 年之前
父节点
当前提交
2a26236cd0
共有 4 个文件被更改,包括 18 次插入24 次删除
  1. 1 0
      .env
  2. 4 1
      src/App.vue
  3. 9 3
      src/router/index.js
  4. 4 20
      src/store/index.js

+ 1 - 0
.env

@@ -1,4 +1,5 @@
 VUE_APP_AXIOS_BASE_URL = ''
 VUE_APP_AXIOS_BASE_URL = ''
 VUE_APP_ROOT_URL=/admin/
 VUE_APP_ROOT_URL=/admin/
 VUE_APP_MODULE='school'
 VUE_APP_MODULE='school'
+VUE_APP_USER_TYPE = '2'
 VUE_APP_LIMIT = 10
 VUE_APP_LIMIT = 10

+ 4 - 1
src/App.vue

@@ -4,7 +4,7 @@
   </div>
   </div>
 </template>
 </template>
 <script>
 <script>
-import { createNamespacedHelpers } from 'vuex';
+import { mapState, createNamespacedHelpers } from 'vuex';
 import _ from 'lodash';
 import _ from 'lodash';
 const { mapActions } = createNamespacedHelpers('login');
 const { mapActions } = createNamespacedHelpers('login');
 export default {
 export default {
@@ -13,6 +13,9 @@ export default {
   created() {
   created() {
     this.toLogin();
     this.toLogin();
   },
   },
+  computed: {
+    ...mapState(['user']),
+  },
   methods: {
   methods: {
     ...mapActions(['login']),
     ...mapActions(['login']),
     async toLogin() {
     async toLogin() {

+ 9 - 3
src/router/index.js

@@ -92,9 +92,15 @@ router.beforeEach((to, form, next) => {
     if (to.path === '/school/info') {
     if (to.path === '/school/info') {
       next();
       next();
     } else {
     } else {
-      let { status } = user;
-      if (status === '0') next('/school/info');
-      else next();
+      if (user.type == process.env.VUE_APP_USER_TYPE) {
+        console.log('缓存登陆');
+        let { status } = user;
+        if (status === '0') next('/school/info');
+        else next();
+      } else {
+        console.error('非当前端用户,需要重新登陆');
+        // next('/login'); //TODO 跳转至登陆页
+      }
     }
     }
   }
   }
   //下面是没登录的情况,需要跳转页面到用户未登录页
   //下面是没登录的情况,需要跳转页面到用户未登录页

+ 4 - 20
src/store/index.js

@@ -7,29 +7,13 @@ import classes from '@frame/store/classes';
 import schPlan from '@frame/store/sch-plan';
 import schPlan from '@frame/store/sch-plan';
 import schimport from '@frame/store/sch-import';
 import schimport from '@frame/store/sch-import';
 import login from '@frame/store/login';
 import login from '@frame/store/login';
-
+import * as ustate from '@frame/store/user/state';
+import * as umutations from '@frame/store/user/mutations';
 Vue.use(Vuex);
 Vue.use(Vuex);
 
 
 export default new Vuex.Store({
 export default new Vuex.Store({
   modules: { student, teacher, trainplan, schPlan, schimport, classes, login },
   modules: { student, teacher, trainplan, schPlan, schimport, classes, login },
-  state: { user: {} },
-  mutations: {
-    setUser(state, payload) {
-      let res = true;
-      //登陆时
-      if (payload) state.user = payload;
-      else {
-        //已经登陆,切换路由时取出用户信息放在总store中
-        let user = sessionStorage.getItem('user');
-        if (user) state.user = JSON.parse(user);
-        else {
-          res = false;
-          state.user = undefined;
-          console.warn('用户未登录');
-        }
-      }
-      return res;
-    },
-  },
+  state: { ...ustate },
+  mutations: { ...umutations },
   actions: {},
   actions: {},
 });
 });