木邻有你前端代码仓库
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.

102 lines
2.6 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months 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 }) {
  76. try {
  77. await Promise.all([
  78. dispatch('getConfig'),
  79. dispatch('getCareer'),
  80. dispatch('getQualification'),
  81. dispatch('getCategoryGoodsList'),
  82. dispatch('getCategoryActivityList')
  83. ])
  84. console.log('所有配置数据初始化完成')
  85. } catch (error) {
  86. console.error('配置数据初始化失败:', error)
  87. }
  88. }
  89. }
  90. })
  91. export default store