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

110 lines
2.9 KiB

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. careerList: [],
  10. qualificationList: [],
  11. categoryGoodsList: [],
  12. categoryActivityList: []
  13. },
  14. mutations: {
  15. setConfigList(state, data) {
  16. state.configList = data
  17. },
  18. setCareerList(state, data) {
  19. state.careerList = data
  20. },
  21. setQualificationList(state, data) {
  22. state.qualificationList = data
  23. },
  24. setCategoryGoodsList(state, data) {
  25. state.categoryGoodsList = data
  26. },
  27. setCategoryActivityList(state, data) {
  28. state.categoryActivityList = data
  29. }
  30. },
  31. actions: {
  32. // 查询配置列表
  33. async getConfig({ commit }) {
  34. const res = await api.config.queryConfigList()
  35. // 要求变成键值对的样子
  36. const config = res.result.records.reduce((acc, item) => {
  37. if (!item.paramCode) {
  38. console.log('paramCode为空', item);
  39. return acc
  40. }
  41. acc[item.paramCode] = item
  42. return acc
  43. }, {})
  44. commit('setConfigList', config)
  45. },
  46. // 查询职业列表
  47. async getCareer({ commit }) {
  48. const res = await api.config.queryCareerList()
  49. // if (res.code === 0) {
  50. commit('setCareerList', res.result.records)
  51. // } else {
  52. // uni.showToast({ title: res.msg, icon: 'error' })
  53. // }
  54. },
  55. // 查询学历列表
  56. async getQualification({ commit }) {
  57. const res = await api.config.queryQualificationList()
  58. // if (res.code === 0) {
  59. commit('setQualificationList', res.result.records)
  60. // } else {
  61. // uni.showToast({ title: res.msg, icon: 'error' })
  62. // }
  63. },
  64. // 查询商品分类列表
  65. async getCategoryGoodsList({ commit }) {
  66. const res = await api.config.queryCategoryGoodsList()
  67. commit('setCategoryGoodsList', res.result.records)
  68. },
  69. // 查询活动分类列表
  70. async getCategoryActivityList({ commit }) {
  71. const res = await api.config.queryCategoryActivityList()
  72. commit('setCategoryActivityList', res.result.records)
  73. },
  74. // 初始化数据
  75. async initData({ dispatch, state }) {
  76. // 检查是否已初始化
  77. if (state.configList.length > 0 && state.careerList.length > 0 && state.qualificationList.length > 0 && state.categoryGoodsList.length > 0 && state.categoryActivityList.length > 0) {
  78. console.log('配置数据已初始化,无需重复初始化')
  79. return
  80. }
  81. try {
  82. await Promise.all([
  83. dispatch('getConfig'),
  84. dispatch('getCareer'),
  85. dispatch('getQualification'),
  86. dispatch('getCategoryGoodsList'),
  87. dispatch('getCategoryActivityList')
  88. ])
  89. console.log('所有配置数据初始化完成')
  90. } catch (error) {
  91. console.error('配置数据初始化失败:', error)
  92. }
  93. },
  94. }
  95. })
  96. export default store