index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. sac: ''
  31. },
  32. getters: {
  33. sysTime: state => {
  34. return state.sysTime
  35. },
  36. userInfo: state => {
  37. // if (state.userInfo == null) {
  38. // if (uni.getStorageSync('user_account')) {
  39. // getUserInfo(state)
  40. // }
  41. // }
  42. return state.userInfo
  43. },
  44. dictObj: state => {
  45. if (state.dictObj == null) {
  46. api.dictList().then(res => {
  47. if (res.data.code === 200) {
  48. let newList = {}
  49. let list = res.data.data
  50. for (let i = 0; i < list.length; i++) {
  51. let item = list[i]
  52. if (newList.hasOwnProperty(item.dictType)) {
  53. newList[item.dictType].push(item.dictLabel)
  54. } else {
  55. newList[item.dictType] = [item.dictLabel]
  56. }
  57. }
  58. state.dictObj = newList;
  59. }
  60. });
  61. }
  62. return state.dictObj
  63. },
  64. allowLoading: state => {
  65. return state.allowLoading
  66. },
  67. playNextId: state => {
  68. return state.playNextId
  69. },
  70. chapterOpen: state => {
  71. return state.chapterOpen
  72. },
  73. goodsAuditionConfigIdList: state => {
  74. return state.goodsAuditionConfigIdList
  75. },
  76. hideBuyState: state => {
  77. return state.hideBuyState
  78. },
  79. shoppingCartList: state => {
  80. return state.shoppingCartList
  81. },
  82. getApplyData: state => {
  83. return state.applyData
  84. },
  85. getBackPageApplyData: state => {
  86. return state.backPageApplyData
  87. },
  88. playSectionId: state => {
  89. return state.playSectionId
  90. },
  91. getCopyData: state => state.copyData,
  92. playChannelId: state => state.playChannelId,
  93. playVID: state => state.playVID,
  94. liveLast: state => state.liveLast,
  95. sac: state => state.sac
  96. },
  97. mutations: {
  98. commonSystemTime(state, time) {
  99. state.sysTime = time;
  100. },
  101. tabNum(state, nums) {
  102. // state.tabLists[4].count = nums
  103. // if (nums) {
  104. // uni.setTabBarBadge({
  105. // index: 4,
  106. // text: nums + ''
  107. // })
  108. // } else {
  109. // uni.removeTabBarBadge({
  110. // index: 4
  111. // })
  112. // }
  113. },
  114. updateLiveLast(state, liveLast) {
  115. state.liveLast = liveLast
  116. },
  117. updateAllowLoading(state, isShowloading) {
  118. state.allowLoading = isShowloading
  119. },
  120. updatePlayNextId(state, str) {
  121. console.log(str, 'str')
  122. state.playNextId = str
  123. },
  124. updateChapterOpen(state, boolean) {
  125. state.chapterOpen = boolean
  126. },
  127. updataCopyData(state, objs) {
  128. state.copyData = objs
  129. },
  130. updateApplyData(state, arrays) {
  131. state.applyData = arrays;
  132. },
  133. updateBackApplyData(state, arrays) {
  134. state.backPageApplyData = arrays;
  135. },
  136. updateUserInfo(state, provider) {
  137. state.userInfo = provider.userInfo;
  138. },
  139. setGoodsAuditionConfigIdList(state, provider) {
  140. state.goodsAuditionConfigIdList = provider.goodsAuditionConfigIdList;
  141. },
  142. setShoppingCartList(state, provider) {
  143. state.shoppingCartList = provider.shoppingCartList;
  144. },
  145. setPlaySectionId(state, provider) {
  146. state.playSectionId = provider.playSectionId;
  147. },
  148. setPlayChannelId(state, provider) {
  149. state.playChannelId = provider.playChannelId;
  150. },
  151. setPlayVID(state, provider) {
  152. state.playVID = provider.playVID;
  153. },
  154. setScene(state, scene) {
  155. state.scene = scene
  156. },
  157. setSac(state, sac) {
  158. state.sac = sac
  159. },
  160. },
  161. actions: {
  162. /**
  163. * 设置系统时间
  164. */
  165. setSystemTime({
  166. commit
  167. }) {
  168. return new Promise(resolve => {
  169. api.commonSystemTime().then(res => {
  170. if (res.data.code == 200) {
  171. commit('commonSystemTime', res.data.data)
  172. resolve()
  173. }
  174. })
  175. })
  176. },
  177. changeTabsNum({
  178. commit
  179. }) {
  180. api.getinfoAttached().then(res => {
  181. if (res.data.code === 200) {
  182. const nums = res.data.data.informSum + res.data.data.orderSum + res.data.data
  183. .periodSum + res.data.data.planSum + res.data.data.subscribeSum
  184. commit('tabNum', nums)
  185. }
  186. })
  187. },
  188. getUserInfo(context) {
  189. return new Promise(async resolve => {
  190. const resdata = await api.getInfo()
  191. if (resdata.data.code == 200) {
  192. context.state.userInfo = resdata.data.data;
  193. method.setUuid(new Date().valueOf() + "")
  194. resolve()
  195. }
  196. })
  197. },
  198. async appCommonConfig(context, data) {
  199. const resdata = await api.appCommonConfig(data)
  200. if (resdata.data.code == 200) {
  201. context.state.hideBuyState = resdata.data.data.hide;
  202. }
  203. }
  204. }
  205. })
  206. async function getUserInfo(state) {
  207. const resdata = await api.getInfo()
  208. if (resdata.data.code == 200) {
  209. state.userInfo = resdata.data.data;
  210. }
  211. }
  212. export default store