index.js 5.7 KB

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