index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. backPageApplyData: {}, //预约考试返回页面的数据存放
  18. playSectionId: 0,
  19. copyData: null, //存放审核资料数据
  20. },
  21. getters: {
  22. userInfo: state => {
  23. if (state.userInfo == null) {
  24. if (uni.getStorageSync('user_account')) {
  25. getUserInfo(state)
  26. }
  27. }
  28. return state.userInfo
  29. },
  30. dictObj: state => {
  31. if (state.dictObj == null) {
  32. api.dictList().then(res => {
  33. if (res.data.code === 200) {
  34. let newList = {}
  35. let list = res.data.data
  36. for (let i = 0; i < list.length; i++) {
  37. let item = list[i]
  38. if (newList.hasOwnProperty(item.dictType)) {
  39. newList[item.dictType].push(item.dictLabel)
  40. } else {
  41. newList[item.dictType] = [item.dictLabel]
  42. }
  43. }
  44. state.dictObj = newList;
  45. }
  46. });
  47. }
  48. return state.dictObj
  49. },
  50. allowLoading: state => {
  51. return state.allowLoading
  52. },
  53. goodsAuditionConfigIdList: state => {
  54. return state.goodsAuditionConfigIdList
  55. },
  56. shoppingCartList: state => {
  57. return state.shoppingCartList
  58. },
  59. getApplyData: state => {
  60. return state.applyData
  61. },
  62. getBackPageApplyData: state => {
  63. return state.backPageApplyData
  64. },
  65. playSectionId: state => {
  66. return state.playSectionId
  67. },
  68. getCopyData: state => state.copyData,
  69. },
  70. mutations: {
  71. tabNum(state, nums) {
  72. if (nums) {
  73. uni.setTabBarBadge({
  74. index: 3,
  75. text: nums + ''
  76. })
  77. } else {
  78. uni.removeTabBarBadge({
  79. index: 3
  80. })
  81. }
  82. },
  83. updataCopyData(state, objs) {
  84. state.copyData = objs
  85. },
  86. updateApplyData(state, arrays) {
  87. state.applyData = arrays;
  88. },
  89. updateBackApplyData(state, arrays) {
  90. state.backPageApplyData = arrays;
  91. },
  92. updateUserInfo(state, provider) {
  93. state.userInfo = provider.userInfo;
  94. },
  95. setGoodsAuditionConfigIdList(state, provider) {
  96. state.goodsAuditionConfigIdList = provider.goodsAuditionConfigIdList;
  97. },
  98. setShoppingCartList(state, provider) {
  99. state.shoppingCartList = provider.shoppingCartList;
  100. },
  101. setPlaySectionId(state, provider) {
  102. state.playSectionId = provider.playSectionId;
  103. },
  104. },
  105. actions: {
  106. changeTabsNum({
  107. commit
  108. }) {
  109. api.getinfoAttached().then(res => {
  110. if (res.data.code === 200) {
  111. const nums = res.data.data.informSum + res.data.data.orderSum + res.data.data
  112. .periodSum + res.data.data.planSum + res.data.data.subscribeSum
  113. commit('tabNum', nums)
  114. }
  115. })
  116. }
  117. }
  118. })
  119. async function getUserInfo(state) {
  120. const resdata = await api.getInfo()
  121. if (resdata.data.code == 200) {
  122. state.userInfo = resdata.data.data;
  123. }
  124. }
  125. export default store