index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import api from '@/common/api.js'
  4. Vue.use(Vuex);
  5. const store = new Vuex.Store({
  6. state: {
  7. login: true,
  8. token: '',
  9. avatarUrl: '',
  10. userName: '',
  11. userInfo: null,
  12. dictObj: null,
  13. allowLoading: true,
  14. goodsAuditionConfigIdList: [], //当前访问页面的试听节ID
  15. shoppingCartList: [], //购物车支付商品
  16. applyData: {}, //预约考试数据存放
  17. playSectionId: 0,
  18. copyData: null, //存放审核资料数据
  19. },
  20. getters: {
  21. userInfo: state => {
  22. if (state.userInfo == null) {
  23. if (uni.getStorageSync('user_account')) {
  24. getUserInfo(state)
  25. }
  26. }
  27. return state.userInfo
  28. },
  29. dictObj: state => {
  30. if (state.dictObj == null) {
  31. api.dictList().then(res => {
  32. if (res.data.code === 200) {
  33. let newList = {}
  34. let list = res.data.data
  35. for (let i = 0; i < list.length; i++) {
  36. let item = list[i]
  37. if (newList.hasOwnProperty(item.dictType)) {
  38. newList[item.dictType].push(item.dictLabel)
  39. } else {
  40. newList[item.dictType] = [item.dictLabel]
  41. }
  42. }
  43. state.dictObj = newList;
  44. }
  45. });
  46. }
  47. return state.dictObj
  48. },
  49. allowLoading: state => {
  50. return state.allowLoading
  51. },
  52. goodsAuditionConfigIdList: state => {
  53. return state.goodsAuditionConfigIdList
  54. },
  55. shoppingCartList: state => {
  56. return state.shoppingCartList
  57. },
  58. getApplyData: state => {
  59. return state.applyData
  60. },
  61. playSectionId: state => {
  62. return state.playSectionId
  63. },
  64. getCopyData: state => state.copyData
  65. },
  66. mutations: {
  67. updataCopyData(state, objs) {
  68. state.copyData = objs
  69. },
  70. updateApplyData(state, arrays) {
  71. state.applyData = arrays;
  72. },
  73. updateUserInfo(state, provider) {
  74. state.userInfo = provider.userInfo;
  75. },
  76. setGoodsAuditionConfigIdList(state, provider) {
  77. state.goodsAuditionConfigIdList = provider.goodsAuditionConfigIdList;
  78. },
  79. setShoppingCartList(state, provider) {
  80. state.shoppingCartList = provider.shoppingCartList;
  81. },
  82. setPlaySectionId(state, provider) {
  83. state.playSectionId = provider.playSectionId;
  84. },
  85. }
  86. })
  87. async function getUserInfo(state) {
  88. const resdata = await api.getInfo()
  89. if (resdata.data.code == 200) {
  90. state.userInfo = resdata.data.data;
  91. }
  92. }
  93. export default store