reloaded 4 سال پیش
والد
کامیت
a34f3e61ea
3فایلهای تغییر یافته به همراه24 افزوده شده و 3 حذف شده
  1. 1 0
      src/router/index.js
  2. 6 1
      src/store/index.js
  3. 17 2
      src/views/index.vue

+ 1 - 0
src/router/index.js

@@ -95,6 +95,7 @@ const router = new VueRouter({
 router.beforeEach((to, form, next) => {
   store.commit('setUser');
   store.commit('setClass');
+  store.dispatch('setting/checkCache');
   let user = store.state.user;
   if (user) {
     console.log('已登录');

+ 6 - 1
src/store/index.js

@@ -22,18 +22,22 @@ import util from '@frame/store/util';
 import attendance from '@frame/store/attendance';
 import leave from '@frame/store/leave';
 import uploadtask from '@frame/store/uploadtask';
+import setting from '@frame/store/setting';
 import * as ustate from '@frame/store/user/state';
 import * as umutations from '@frame/store/user/mutations';
+import * as dostate from '@frame/store/setting/state';
+import * as domutations from '@frame/store/setting/mutations';
 Vue.use(Vuex);
 
 export default new Vuex.Store({
-  state: { ...ustate, classid: undefined },
+  state: { ...ustate, classid: undefined, ...dostate },
   mutations: {
     ...umutations,
     setClass(state) {
       let classid = sessionStorage.getItem('classid');
       if (classid) state.classid = classid;
     },
+    ...domutations,
   },
   actions: {},
   modules: {
@@ -59,5 +63,6 @@ export default new Vuex.Store({
     attendance,
     leave,
     uploadtask,
+    setting,
   },
 });

+ 17 - 2
src/views/index.vue

@@ -30,9 +30,11 @@
 <script>
 import NavBar from '@/layout/common/topInfo.vue';
 import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
+var moment = require('moment');
 const { mapActions: lesson } = createNamespacedHelpers('lesson');
 const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
 const { mapActions: classes } = createNamespacedHelpers('classes');
+const { mapActions: setting } = createNamespacedHelpers('setting');
 export default {
   name: 'index',
   props: {},
@@ -59,15 +61,28 @@ export default {
     ...lesson({ lessionInfo: 'fetch', lessionlist: 'query' }),
     ...trainplan(['query']),
     ...classes({ classQuery: 'query' }),
+    ...setting({ settingFetch: 'fetch' }),
     async search() {
-      const planList = await this.query();
-      this.$set(this, `planList`, planList.data);
+      const setting = await this.settingFetch();
+      if (setting.data.planid) {
+        this.toClass(setting.data.planid);
+      } else {
+        const planList = await this.query();
+        this.$set(this, `planList`, planList.data);
+      }
     },
     async toClass(planid) {
       // index:计划id
       this.display = false;
       this.$set(this, `planId`, planid);
       const classList = await this.classQuery({ planid: planid, headteacherid: this.user.userid });
+      const today = moment().format('YYYY-MM-DD');
+      for (const classes of classList.data) {
+        const isclass = moment(today).isBetween(classes.startdate, classes.enddate, null, '[]');
+        if (isclass) {
+          this.classBtn(classes.id);
+        }
+      }
       this.$set(this, `classList`, classList.data);
     },
     classBtn(index) {