index.js 6.8 KB

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