index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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:true, //是否隐藏购买流程和订单列表
  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. },
  26. getters: {
  27. userInfo: state => {
  28. // if (state.userInfo == null) {
  29. // if (uni.getStorageSync('user_account')) {
  30. // getUserInfo(state)
  31. // }
  32. // }
  33. return state.userInfo
  34. },
  35. dictObj: state => {
  36. if (state.dictObj == null) {
  37. api.dictList().then(res => {
  38. if (res.data.code === 200) {
  39. let newList = {}
  40. let list = res.data.data
  41. for (let i = 0; i < list.length; i++) {
  42. let item = list[i]
  43. if (newList.hasOwnProperty(item.dictType)) {
  44. newList[item.dictType].push(item.dictLabel)
  45. } else {
  46. newList[item.dictType] = [item.dictLabel]
  47. }
  48. }
  49. state.dictObj = newList;
  50. }
  51. });
  52. }
  53. return state.dictObj
  54. },
  55. allowLoading: state => {
  56. return state.allowLoading
  57. },
  58. playNextId: state => {
  59. return state.playNextId
  60. },
  61. chapterOpen: state => {
  62. return state.chapterOpen
  63. },
  64. goodsAuditionConfigIdList: state => {
  65. return state.goodsAuditionConfigIdList
  66. },
  67. hideBuyState: state => {
  68. return state.hideBuyState
  69. },
  70. shoppingCartList: state => {
  71. return state.shoppingCartList
  72. },
  73. getApplyData: state => {
  74. return state.applyData
  75. },
  76. getBackPageApplyData: state => {
  77. return state.backPageApplyData
  78. },
  79. playSectionId: state => {
  80. return state.playSectionId
  81. },
  82. getCopyData: state => state.copyData,
  83. playChannelId: state => state.playChannelId,
  84. playVID: state => state.playVID,
  85. },
  86. mutations: {
  87. tabNum(state, nums) {
  88. if (nums) {
  89. uni.setTabBarBadge({
  90. index: 3,
  91. text: nums + ''
  92. })
  93. } else {
  94. uni.removeTabBarBadge({
  95. index: 3
  96. })
  97. }
  98. },
  99. updateAllowLoading(state,isShowloading) {
  100. state.allowLoading = isShowloading
  101. },
  102. updatePlayNextId(state,str) {
  103. console.log(str,'str')
  104. state.playNextId = str
  105. },
  106. updateChapterOpen(state,boolean) {
  107. state.chapterOpen = boolean
  108. },
  109. updataCopyData(state, objs) {
  110. state.copyData = objs
  111. },
  112. updateApplyData(state, arrays) {
  113. state.applyData = arrays;
  114. },
  115. updateBackApplyData(state, arrays) {
  116. state.backPageApplyData = arrays;
  117. },
  118. updateUserInfo(state, provider) {
  119. state.userInfo = provider.userInfo;
  120. },
  121. setGoodsAuditionConfigIdList(state, provider) {
  122. state.goodsAuditionConfigIdList = provider.goodsAuditionConfigIdList;
  123. },
  124. setShoppingCartList(state, provider) {
  125. state.shoppingCartList = provider.shoppingCartList;
  126. },
  127. setPlaySectionId(state, provider) {
  128. state.playSectionId = provider.playSectionId;
  129. },
  130. setPlayChannelId(state, provider) {
  131. state.playChannelId = provider.playChannelId;
  132. },
  133. setPlayVID(state, provider) {
  134. state.playVID = provider.playVID;
  135. },
  136. },
  137. actions: {
  138. changeTabsNum({
  139. commit
  140. }) {
  141. api.getinfoAttached().then(res => {
  142. if (res.data.code === 200) {
  143. const nums = res.data.data.informSum + res.data.data.orderSum + res.data.data
  144. .periodSum + res.data.data.planSum + res.data.data.subscribeSum
  145. commit('tabNum', nums)
  146. }
  147. })
  148. },
  149. getUserInfo(context) {
  150. return new Promise(async resolve => {
  151. const resdata = await api.getInfo()
  152. if (resdata.data.code == 200) {
  153. context.state.userInfo = resdata.data.data;
  154. resolve()
  155. }
  156. })
  157. },
  158. async appCommonConfig(context) {
  159. const resdata = await api.appCommonConfig()
  160. if (resdata.data.code == 200) {
  161. context.state.hideBuyState = resdata.data.data.hide;
  162. }
  163. }
  164. }
  165. })
  166. async function getUserInfo(state) {
  167. const resdata = await api.getInfo()
  168. if (resdata.data.code == 200) {
  169. state.userInfo = resdata.data.data;
  170. }
  171. }
  172. export default store