展品维保小程序前端代码接口
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.

61 lines
1.2 KiB

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. },
  10. mutations: {
  11. setConfigList(state, data) {
  12. state.configList = data
  13. },
  14. },
  15. actions: {
  16. // 查询配置列表
  17. async getConfig({ commit }) {
  18. const res = await api.config.queryConfigList()
  19. // 要求变成键值对的样子
  20. const config = res.result.records.reduce((acc, item) => {
  21. if (!item.paramCode) {
  22. console.log('paramCode为空', item);
  23. return acc
  24. }
  25. acc[item.paramCode] = item
  26. return acc
  27. }, {})
  28. commit('setConfigList', config)
  29. },
  30. // 初始化数据
  31. async initData({ dispatch, state }) {
  32. // 检查是否已初始化
  33. if (state.configList.length > 0) {
  34. console.log('配置数据已初始化,无需重复初始化')
  35. return
  36. }
  37. try {
  38. await Promise.all([
  39. dispatch('getConfig'),
  40. ])
  41. console.log('所有配置数据初始化完成')
  42. } catch (error) {
  43. console.error('配置数据初始化失败:', error)
  44. }
  45. },
  46. }
  47. })
  48. export default store