selects.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* eslint-disable no-empty */
  2. import { branchQueryPage } from '@/api/specialSetting'
  3. import { getSubject } from '@/api/buildTeam'
  4. /**
  5. *
  6. * 为避免重复请求全局参数,将需要使用的全局参数放到vuex中缓存
  7. *
  8. * 使用:
  9. *
  10. * 按照需要直接使用 this.$store.dispatch('action', force: Bool 是否强制刷新)
  11. *
  12. * 直接从this.$store.state.name 中获取数据
  13. */
  14. export default {
  15. state: {
  16. branchs: [],
  17. subjects: [],
  18. },
  19. mutations: {
  20. commit_branchs: (state, branchs) => {
  21. state.branchs = branchs
  22. },
  23. commit_subjects: (state, subjects) => {
  24. state.subjects = subjects
  25. },
  26. },
  27. actions: {
  28. async setBranchs({ commit, state }, force) {
  29. if (!state.branchs.length || force === true) {
  30. try {
  31. const res = await branchQueryPage({rows: 9999})
  32. commit('commit_branchs', res.data.rows)
  33. } catch (error) {}
  34. }
  35. },
  36. async setSubject({ commit, state }, force) {
  37. if (!state.subjects.length || force === true) {
  38. try {
  39. const res = await getSubject({rows: 9999})
  40. commit('commit_subjects', res.data.rows)
  41. } catch (error) {}
  42. }
  43. }
  44. }
  45. }