index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. tabNum(state, nums) {
  68. if (nums) {
  69. uni.setTabBarBadge({
  70. index: 3,
  71. text: nums + ''
  72. })
  73. } else {
  74. uni.removeTabBarBadge({
  75. index: 3
  76. })
  77. }
  78. },
  79. updataCopyData(state, objs) {
  80. state.copyData = objs
  81. },
  82. updateApplyData(state, arrays) {
  83. state.applyData = arrays;
  84. },
  85. updateUserInfo(state, provider) {
  86. state.userInfo = provider.userInfo;
  87. },
  88. setGoodsAuditionConfigIdList(state, provider) {
  89. state.goodsAuditionConfigIdList = provider.goodsAuditionConfigIdList;
  90. },
  91. setShoppingCartList(state, provider) {
  92. state.shoppingCartList = provider.shoppingCartList;
  93. },
  94. setPlaySectionId(state, provider) {
  95. state.playSectionId = provider.playSectionId;
  96. },
  97. },
  98. actions: {
  99. changeTabsNum({
  100. commit
  101. }) {
  102. api.getinfoAttached().then(res => {
  103. if (res.data.code === 200) {
  104. const nums = res.data.data.informSum + res.data.data.orderSum + res.data.data
  105. .periodSum + res.data.data.planSum + res.data.data.subscribeSum
  106. commit('tabNum', nums)
  107. }
  108. })
  109. }
  110. }
  111. })
  112. async function getUserInfo(state) {
  113. const resdata = await api.getInfo()
  114. if (resdata.data.code == 200) {
  115. state.userInfo = resdata.data.data;
  116. }
  117. }
  118. export default store