lrf402788946 5 tahun lalu
induk
melakukan
59ea6094e2

+ 1 - 0
.env

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

+ 1 - 0
package.json

@@ -15,6 +15,7 @@
     "axios": "^0.19.2",
     "core-js": "^3.4.4",
     "element-ui": "^2.13.0",
+    "jsonwebtoken": "^8.5.1",
     "lodash": "^4.17.15",
     "naf-core": "^0.1.2",
     "vue": "^2.6.10",

+ 15 - 0
src/App.vue

@@ -4,9 +4,24 @@
   </div>
 </template>
 <script>
+import { createNamespacedHelpers } from 'vuex';
+import _ from 'lodash';
+const { mapActions } = createNamespacedHelpers('login');
 export default {
   name: 'App',
   components: {},
+  created() {
+    this.toLogin();
+  },
+  methods: {
+    ...mapActions(['login']),
+    async toLogin() {
+      let object = { mobile: '13089419811', passwd: '12345678' };
+      let res = await this.login(object);
+      if (_.isBoolean(res)) console.log('登陆成功');
+      else this.$message.warning(res.errmsg);
+    },
+  },
 };
 </script>
 

+ 17 - 1
src/router/index.js

@@ -1,5 +1,6 @@
 import Vue from 'vue';
 import VueRouter from 'vue-router';
+import store from '@/store/index';
 
 Vue.use(VueRouter);
 
@@ -29,7 +30,7 @@ const routes = [
       },
       {
         path: '/classes/name/list',
-        name: 'classes_list',
+        name: 'classes_name_list',
         meta: { title: '班级', sub: '名单' },
         component: () => import('@/views/classes/name-list.vue'),
       },
@@ -55,5 +56,20 @@ const router = new VueRouter({
   base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROOT_URL + 'school',
   routes,
 });
+router.beforeEach((to, form, next) => {
+  store.commit('setUser');
+  let user = store.state.user;
+  if (user) {
+    if (user.type == process.env.VUE_APP_USER_TYPE) {
+      console.log('缓存登陆');
+      next();
+    } else {
+      console.error('非当前端用户,需要重新登陆');
+      // next('/login'); //TODO 跳转至登陆页
+    }
+  }
+  //下面是没登录的情况,需要跳转页面到用户未登录页
+  else next();
+});
 
 export default router;

+ 7 - 3
src/store/index.js

@@ -9,12 +9,12 @@ import nation from '@frame/store/nation';
 import school from '@frame/store/school';
 import termquest from '@frame/store/termquest';
 import questionnaire from '@frame/store/questionnaire';
+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);
 
 export default new Vuex.Store({
-  state: {},
-  mutations: {},
-  actions: {},
   modules: {
     trainplan,
     dirPlan,
@@ -25,5 +25,9 @@ export default new Vuex.Store({
     school,
     termquest,
     questionnaire,
+    login,
   },
+  state: { ...ustate },
+  mutations: { ...umutations },
+  actions: {},
 });

+ 5 - 3
src/views/classes/index.vue

@@ -9,7 +9,7 @@
 <script>
 import listFrame from '@frame/layout/admin/list-frame';
 import dataTable from '@frame/components/data-table';
-import { createNamespacedHelpers } from 'vuex';
+import { mapState, createNamespacedHelpers } from 'vuex';
 const { mapActions: classes } = createNamespacedHelpers('classes');
 export default {
   metaInfo: { title: '班级管理' },
@@ -44,12 +44,14 @@ export default {
   created() {
     this.search();
   },
-  computed: {},
+  computed: {
+    ...mapState(['user']),
+  },
   methods: {
     ...classes(['query', 'delete']),
     async search({ skip = 0, limit = 10, ...info } = {}) {
       //TODO 将headteacherid替换成用户的id
-      const res = await this.query({ skip, limit, ...info, headteacherid: '5e4f35c86a90e861b0f30868' });
+      const res = await this.query({ skip, limit, ...info, headteacherid: this.user.userid || '' });
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);
         this.$set(this, `total`, res.total);

+ 5 - 5
src/views/classes/name-list.vue

@@ -50,11 +50,11 @@ export default {
         method: 'delete',
         confirm: true,
       },
-      {
-        label: '管理任职',
-        icon: 'el-icon-check',
-        method: 'post',
-      },
+      // {
+      //   label: '管理任职',
+      //   icon: 'el-icon-check',
+      //   method: 'post',
+      // },
     ],
     fields: [
       { label: '姓名', prop: 'name' },

+ 4 - 4
src/views/plan/detail.vue

@@ -45,7 +45,7 @@ import detailFrame from '@frame/layout/admin/detail-frame';
 import calendar from '@frame/components/calendar';
 import dataTable from '@frame/components/data-table';
 import _ from 'lodash';
-import { createNamespacedHelpers } from 'vuex';
+import { mapState, createNamespacedHelpers } from 'vuex';
 const { mapActions } = createNamespacedHelpers('trainplan');
 const { mapActions: dirPlan } = createNamespacedHelpers('dirPlan');
 export default {
@@ -76,7 +76,6 @@ export default {
   }),
   created() {
     this.search();
-    //TODO 正常来说:我是根据计划进来的,我需要查的不仅是计划的信息,还需要根据计划id和用户id查询出我曾经添加过的信息做回显及修改
     this.searchDir();
   },
   mounted() {},
@@ -88,7 +87,7 @@ export default {
       dirUpdatePlan: 'update',
     }),
     async searchDir() {
-      let res = await this.dirQuery({ trainplanid: this.info.id, headteacherid: 'headerTeacherTest 99991' });
+      let res = await this.dirQuery({ trainplanid: this.info.id, headteacherid: this.user.userid });
       if (this.$checkRes(res)) {
         let data = JSON.parse(JSON.stringify(res.data));
         if (res.data.length > 0) {
@@ -176,7 +175,7 @@ export default {
       let object = { trainplanid: _id };
       object.nobatchid = arr.map(i => i.id || i._id);
       //TODO修改班主任id为登录用户的id
-      object.headteacherid = 'headerTeacherTest 99991';
+      object.headteacherid = this.user.userid;
       let res;
       let msg;
       if (!teaplanid) {
@@ -216,6 +215,7 @@ export default {
     },
   },
   computed: {
+    ...mapState(['user']),
     widths() {
       let width = (document.body.clientWidth - 200) * 0.5;
       return width > 400 ? width : 400;

+ 1 - 12
src/views/plan/index.vue

@@ -1,7 +1,7 @@
 <template>
   <div id="index">
     <list-frame :title="mainTitle" @query="search" :total="total" :needFilter="false" :needAdd="false">
-      <data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" @update="toUpdate"></data-table>
+      <data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit"></data-table>
     </list-frame>
   </div>
 </template>
@@ -24,11 +24,6 @@ export default {
         icon: 'el-icon-date',
         method: 'edit',
       },
-      {
-        label: '上报时间',
-        icon: 'el-icon-document',
-        method: 'update',
-      },
     ],
     fields: [
       { label: '计划标题', prop: 'title' },
@@ -67,12 +62,6 @@ export default {
       //TODO 该把详情做成什么样的比较好,是和大日历在一起选择还是其他形式
       this.$router.push({ path: '/plan/detail', query: { id: data.id } });
     },
-
-    async toUpdate({ data }) {
-      // const res = await this.delete(data.id);
-      // this.$checkRes(res, '删除成功', '删除失败');
-      // this.search();
-    },
   },
 };
 </script>