index.js 3.3 KB

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