index.js 7.1 KB

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