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

94 lines
2.5 KiB

3 months ago
3 months ago
3 months ago
3 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. // if (res.code === 0) {
  36. commit('setConfigList', res.result.records)
  37. // } else {
  38. // uni.showToast({ title: res.msg, icon: 'error' })
  39. // }
  40. },
  41. // 查询职业列表
  42. async getCareer({ commit }) {
  43. const res = await api.config.queryCareerList()
  44. // if (res.code === 0) {
  45. commit('setCareerList', res.result.records)
  46. // } else {
  47. // uni.showToast({ title: res.msg, icon: 'error' })
  48. // }
  49. },
  50. // 查询学历列表
  51. async getQualification({ commit }) {
  52. const res = await api.config.queryQualificationList()
  53. // if (res.code === 0) {
  54. commit('setQualificationList', res.result.records)
  55. // } else {
  56. // uni.showToast({ title: res.msg, icon: 'error' })
  57. // }
  58. },
  59. // 查询商品分类列表
  60. async getCategoryGoodsList({ commit }) {
  61. const res = await api.config.queryCategoryGoodsList()
  62. commit('setCategoryGoodsList', res.result.records)
  63. },
  64. // 查询活动分类列表
  65. async getCategoryActivityList({ commit }) {
  66. const res = await api.config.queryCategoryActivityList()
  67. commit('setCategoryActivityList', res.result.records)
  68. },
  69. // 初始化数据
  70. async initData({ dispatch }) {
  71. try {
  72. await Promise.all([
  73. dispatch('getConfig'),
  74. dispatch('getCareer'),
  75. dispatch('getQualification'),
  76. dispatch('getCategoryGoodsList'),
  77. dispatch('getCategoryActivityList')
  78. ])
  79. console.log('所有配置数据初始化完成')
  80. } catch (error) {
  81. console.error('配置数据初始化失败:', error)
  82. }
  83. }
  84. }
  85. })
  86. export default store