index.js 4.4 KB

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