展品维保小程序前端代码接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.9 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import * as api from '@/api'
  4. Vue.use(Vuex)
  5. const store = new Vuex.Store({
  6. state: {
  7. // 存放状态
  8. configList: [],
  9. departmentList: [],
  10. },
  11. mutations: {
  12. // 分类列表
  13. setCategoryList(state, data) {
  14. state.categoryList = data
  15. },
  16. setConfigList(state, data) {
  17. state.configList = data
  18. },
  19. setDepartmentList(state, data) {
  20. state.departmentList = data
  21. },
  22. },
  23. actions: {
  24. // 查询配置列表
  25. async getConfig({ commit }) {
  26. const res = await api.config.queryConfigList()
  27. // 要求变成键值对的样子
  28. const config = res.result.records.reduce((acc, item) => {
  29. if (!item.paramCode) {
  30. console.log('paramCode为空', item);
  31. return acc
  32. }
  33. acc[item.paramCode] = item
  34. return acc
  35. }, {})
  36. commit('setConfigList', config)
  37. },
  38. // 查询部门列表
  39. async getDepartment({ commit }) {
  40. const res = await api.config.queryDepartmentList()
  41. commit('setDepartmentList', res.result.records)
  42. },
  43. // 获取分类列表
  44. async getCategory({ commit }) {
  45. const res = await api.config.queryCategoryList()
  46. commit('setCategoryList', res.result.records)
  47. },
  48. // 初始化数据
  49. async initData({ dispatch, state }) {
  50. // 检查是否已初始化
  51. if (state.configList.length > 0 && state.departmentList.length > 0 && state.categoryList.length > 0) {
  52. console.log('配置数据已初始化,无需重复初始化')
  53. return
  54. }
  55. try {
  56. await Promise.all([
  57. dispatch('getConfig'),
  58. dispatch('getDepartment'),
  59. // dispatch('getCategory'),
  60. ])
  61. console.log('所有配置数据初始化完成')
  62. } catch (error) {
  63. console.error('配置数据初始化失败:', error)
  64. }
  65. },
  66. }
  67. })
  68. export default store