index.js 4.9 KB

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