index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. console.log(str, "str");
  125. state.playNextId = str;
  126. },
  127. updateChapterOpen(state, boolean) {
  128. state.chapterOpen = boolean;
  129. },
  130. updataCopyData(state, objs) {
  131. state.copyData = objs;
  132. },
  133. updateApplyData(state, arrays) {
  134. state.applyData = arrays;
  135. },
  136. updateBackApplyData(state, arrays) {
  137. state.backPageApplyData = arrays;
  138. },
  139. updateUserInfo(state, provider) {
  140. state.userInfo = provider.userInfo;
  141. },
  142. setGoodsAuditionConfigIdList(state, provider) {
  143. state.goodsAuditionConfigIdList = provider.goodsAuditionConfigIdList;
  144. },
  145. setShoppingCartList(state, provider) {
  146. state.shoppingCartList = provider.shoppingCartList;
  147. },
  148. setPlaySectionId(state, provider) {
  149. state.playSectionId = provider.playSectionId;
  150. },
  151. setPlayChannelId(state, provider) {
  152. state.playChannelId = provider.playChannelId;
  153. },
  154. setPlayVID(state, provider) {
  155. state.playVID = provider.playVID;
  156. },
  157. setScene(state, scene) {
  158. state.scene = scene;
  159. },
  160. setSac(state, sac) {
  161. state.sac = sac;
  162. },
  163. setConfig(state, config) {
  164. state.config = config;
  165. },
  166. },
  167. actions: {
  168. /**
  169. * 设置系统时间
  170. */
  171. setSystemTime({ commit }) {
  172. return new Promise((resolve) => {
  173. api.commonSystemTime().then((res) => {
  174. if (res.data.code == 200) {
  175. commit("commonSystemTime", res.data.data);
  176. resolve();
  177. }
  178. });
  179. });
  180. },
  181. changeTabsNum({ commit }) {
  182. api.getinfoAttached().then((res) => {
  183. if (res.data.code === 200) {
  184. const nums =
  185. res.data.data.informSum +
  186. res.data.data.orderSum +
  187. res.data.data.periodSum +
  188. res.data.data.planSum +
  189. res.data.data.subscribeSum;
  190. commit("tabNum", nums);
  191. }
  192. });
  193. },
  194. getUserInfo(context) {
  195. return new Promise(async (resolve) => {
  196. const resdata = await api.getInfo();
  197. if (resdata.data.code == 200) {
  198. context.state.userInfo = resdata.data.data;
  199. method.setUuid(new Date().valueOf() + "");
  200. resolve();
  201. }
  202. });
  203. },
  204. async appCommonConfig(context, data) {
  205. const resdata = await api.appCommonConfig(data);
  206. if (resdata.data.code == 200) {
  207. context.state.hideBuyState = resdata.data.data.hide;
  208. }
  209. },
  210. getConfig({ commit }) {
  211. return new Promise(async (resolve) => {
  212. let config = {};
  213. api.mobileConfig().then((res) => {
  214. let data = res.data.rows.find((e) => e.configKey == "home.mobile");
  215. if (data) {
  216. config = { ...config, ...JSON.parse(data.configValue) };
  217. }
  218. let header = res.data.rows.find((e) => e.configKey == "home.header");
  219. if (header) {
  220. config = {
  221. ...config,
  222. companyName: JSON.parse(header.configValue).companyName,
  223. };
  224. }
  225. let foot = res.data.rows.find(
  226. (e) => e.configKey == "home.footer.record"
  227. );
  228. if (foot) {
  229. config = { ...config, ...JSON.parse(foot.configValue) };
  230. }
  231. commit("setConfig", config);
  232. resolve(config);
  233. });
  234. });
  235. },
  236. },
  237. });
  238. async function getUserInfo(state) {
  239. const resdata = await api.getInfo();
  240. if (resdata.data.code == 200) {
  241. state.userInfo = resdata.data.data;
  242. }
  243. }
  244. export default store;