index.js 3.9 KB

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