index.js 3.5 KB

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