index.js 5.8 KB

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