wolyshaw 4 лет назад
Родитель
Сommit
fd531c8e55
2 измененных файлов с 50 добавлено и 1 удалено
  1. 3 1
      src/store/index.js
  2. 47 0
      src/store/modules/selects.js

+ 3 - 1
src/store/index.js

@@ -7,6 +7,7 @@ import user from './modules/user'
 import permission from './modules/permission'
 import buildTeam from './modules/buildTeam'
 import tagsView from './modules/tagsView'
+import selects from './modules/selects'
 
 Vue.use(Vuex)
 
@@ -17,7 +18,8 @@ const store = new Vuex.Store({
     user,
     permission,
     buildTeam,
-    tagsView
+    tagsView,
+    selects
   },
   getters
 })

+ 47 - 0
src/store/modules/selects.js

@@ -0,0 +1,47 @@
+/* eslint-disable no-empty */
+import { branchQueryPage } from '@/api/specialSetting'
+import { getSubject } from '@/api/buildTeam'
+
+/**
+ *
+ * 为避免重复请求全局参数,将需要使用的全局参数放到vuex中缓存
+ *
+ * 使用:
+ *
+ * 按照需要直接使用 this.$store.dispatch('action', force: Bool 是否强制刷新)
+ *
+ * 直接从this.$store.state.name 中获取数据
+ */
+
+export default {
+  state: {
+    branchs: [],
+    subjects: [],
+  },
+  mutations: {
+    commit_branchs: (state, branchs) => {
+      state.branchs = branchs
+    },
+    commit_subjects: (state, subjects) => {
+      state.subjects = subjects
+    },
+  },
+  actions: {
+    async setBranchs({ commit, state }, force) {
+      if (!state.branchs.length || force === true) {
+        try {
+          const res = await branchQueryPage({rows: 9999})
+          commit('commit_branchs', res.data.rows)
+        } catch (error) {}
+      }
+    },
+    async setSubject({ commit, state }, force) {
+      if (!state.subjects.length || force === true) {
+        try {
+          const res = await getSubject({rows: 9999})
+          commit('commit_subjects', res.data.rows)
+        } catch (error) {}
+      }
+    }
+  }
+}