index.js 5.1 KB

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