index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. educationType: null,
  37. businessLevel: null,
  38. sujectType: null,
  39. tenantId: "",
  40. //---------------
  41. consultPc: {},
  42. consultMobile: {},
  43. header: {},
  44. nav: {},
  45. other: {},
  46. shoppingNum: 0,
  47. //---------------
  48. config: {},
  49. },
  50. getters: {
  51. tenantId(state) {
  52. return tenantId || ''
  53. },
  54. current(state) {
  55. return state.current || 0
  56. },
  57. educationType(state) {
  58. if (!state.educationType) {
  59. api.educationTypeList({
  60. status: 1
  61. }).then(res => {
  62. state.educationType = res.data.rows
  63. })
  64. }
  65. return state.educationType
  66. },
  67. businessLevel(state) {
  68. if (!state.businessLevel) {
  69. api.businessList({
  70. status: 1
  71. }).then(res => {
  72. state.businessLevel = res.data.rows
  73. })
  74. }
  75. return state.businessLevel
  76. },
  77. sujectType(state) {
  78. if (!state.sujectType) {
  79. api.subjectList({
  80. status: 1
  81. }).then(res => {
  82. res.data.rows.forEach(i => {
  83. i.projectList = i.courseProjectTypes && i.courseProjectTypes.map(k => k
  84. .id) || []
  85. })
  86. state.sujectType = res.data.rows
  87. })
  88. }
  89. return state.sujectType
  90. },
  91. sysTime: (state) => {
  92. return state.sysTime;
  93. },
  94. userInfo: (state) => {
  95. if (state.userInfo == null) {
  96. if (uni.getStorageSync('user_account')) {
  97. getUserInfo(state)
  98. }
  99. }
  100. return state.userInfo;
  101. },
  102. dictObj: (state) => {
  103. if (state.dictObj == null) {
  104. api.dictList().then((res) => {
  105. if (res.data.code === 200) {
  106. let newList = {};
  107. let list = res.data.data;
  108. for (let i = 0; i < list.length; i++) {
  109. let item = list[i];
  110. if (newList.hasOwnProperty(item.dictType)) {
  111. newList[item.dictType].push(item.dictLabel);
  112. } else {
  113. newList[item.dictType] = [item.dictLabel];
  114. }
  115. }
  116. state.dictObj = newList;
  117. }
  118. });
  119. }
  120. return state.dictObj;
  121. },
  122. allowLoading: (state) => {
  123. return state.allowLoading;
  124. },
  125. playNextId: (state) => {
  126. return state.playNextId;
  127. },
  128. chapterOpen: (state) => {
  129. return state.chapterOpen;
  130. },
  131. goodsAuditionConfigIdList: (state) => {
  132. return state.goodsAuditionConfigIdList;
  133. },
  134. hideBuyState: (state) => {
  135. return state.hideBuyState;
  136. },
  137. shoppingCartList: (state) => {
  138. return state.shoppingCartList;
  139. },
  140. getApplyData: (state) => {
  141. return state.applyData;
  142. },
  143. getBackPageApplyData: (state) => {
  144. return state.backPageApplyData;
  145. },
  146. playSectionId: (state) => {
  147. return state.playSectionId;
  148. },
  149. getCopyData: (state) => state.copyData,
  150. playChannelId: (state) => state.playChannelId,
  151. playVID: (state) => state.playVID,
  152. liveLast: (state) => state.liveLast,
  153. sac: (state) => state.sac,
  154. consultMobile: (state) => state.consultMobile,
  155. consultPc: (state) => state.consultPc,
  156. header: (state) => state.header,
  157. nav: (state) => state.nav,
  158. other: (state) => state.other,
  159. shoppingNum: (state) => state.shoppingNum || 0,
  160. config: (state) => state.config,
  161. },
  162. mutations: {
  163. commonSystemTime(state, time) {
  164. state.sysTime = time;
  165. },
  166. tabNum(state, nums) {
  167. // state.tabLists[4].count = nums
  168. // if (nums) {
  169. // uni.setTabBarBadge({
  170. // index: 4,
  171. // text: nums + ''
  172. // })
  173. // } else {
  174. // uni.removeTabBarBadge({
  175. // index: 4
  176. // })
  177. // }
  178. },
  179. updateLiveLast(state, liveLast) {
  180. state.liveLast = liveLast;
  181. },
  182. updateAllowLoading(state, isShowloading) {
  183. state.allowLoading = isShowloading;
  184. },
  185. updatePlayNextId(state, str) {
  186. state.playNextId = str;
  187. },
  188. updateChapterOpen(state, boolean) {
  189. state.chapterOpen = boolean;
  190. },
  191. updataCopyData(state, objs) {
  192. state.copyData = objs;
  193. },
  194. updateApplyData(state, arrays) {
  195. state.applyData = arrays;
  196. },
  197. updateBackApplyData(state, arrays) {
  198. state.backPageApplyData = arrays;
  199. },
  200. updateUserInfo(state, provider) {
  201. state.userInfo = provider.userInfo;
  202. },
  203. setGoodsAuditionConfigIdList(state, provider) {
  204. state.goodsAuditionConfigIdList = provider.goodsAuditionConfigIdList;
  205. },
  206. setShoppingCartList(state, provider) {
  207. state.shoppingCartList = provider.shoppingCartList;
  208. },
  209. setPlaySectionId(state, provider) {
  210. state.playSectionId = provider.playSectionId;
  211. },
  212. setPlayChannelId(state, provider) {
  213. state.playChannelId = provider.playChannelId;
  214. },
  215. setPlayVID(state, provider) {
  216. state.playVID = provider.playVID;
  217. },
  218. setScene(state, scene) {
  219. state.scene = scene;
  220. },
  221. setSac(state, sac) {
  222. state.sac = sac;
  223. },
  224. setConfig(state, config) {
  225. console.log(config, 'config')
  226. for (let k in config) {
  227. state[k] = config[k]
  228. }
  229. },
  230. setConfigs(state, config) {
  231. state.config = config;
  232. },
  233. },
  234. actions: {
  235. /**
  236. * 设置系统时间
  237. */
  238. setSystemTime({
  239. commit
  240. }) {
  241. return new Promise((resolve) => {
  242. api.commonSystemTime().then((res) => {
  243. if (res.data.code == 200) {
  244. commit("commonSystemTime", res.data.data);
  245. resolve();
  246. }
  247. });
  248. });
  249. },
  250. changeTabsNum({
  251. commit
  252. }) {
  253. api.getinfoAttached().then((res) => {
  254. if (res.data.code === 200) {
  255. const nums =
  256. res.data.data.informSum +
  257. res.data.data.orderSum +
  258. res.data.data.periodSum +
  259. res.data.data.planSum +
  260. res.data.data.subscribeSum;
  261. commit("tabNum", nums);
  262. }
  263. });
  264. },
  265. getUserInfo(context) {
  266. return new Promise(async (resolve) => {
  267. const resdata = await api.getInfo();
  268. if (resdata.data.code == 200) {
  269. context.dispatch('getShoppingNum')
  270. context.state.userInfo = resdata.data.data;
  271. method.setUuid(new Date().valueOf() + "");
  272. resolve();
  273. }
  274. });
  275. },
  276. async appCommonConfig(context, data) {
  277. const resdata = await api.appCommonConfig(data);
  278. if (resdata.data.code == 200) {
  279. context.state.hideBuyState = resdata.data.data.hide;
  280. }
  281. },
  282. getConfig({
  283. commit
  284. }) {
  285. return new Promise(async (resolve) => {
  286. let config = {};
  287. let configs = {};
  288. api.mobileConfig().then((res) => {
  289. let data = res.data.rows.find((e) => e.configKey == "client.config");
  290. if (data) {
  291. config = JSON.parse(data.configValue) || {}
  292. }
  293. commit("setConfig", config);
  294. let datas = res.data.rows.find((e) => e.configKey == "home.mobile");
  295. if (datas) {
  296. configs = {
  297. ...configs,
  298. ...JSON.parse(datas.configValue)
  299. };
  300. }
  301. let header = res.data.rows.find((e) => e.configKey == "home.header");
  302. if (header) {
  303. configs = {
  304. ...configs,
  305. companyName: JSON.parse(header.configValue).companyName,
  306. };
  307. }
  308. let foot = res.data.rows.find(
  309. (e) => e.configKey == "home.footer.record"
  310. );
  311. if (foot) {
  312. configs = {
  313. ...configs,
  314. ...JSON.parse(foot.configValue)
  315. };
  316. }
  317. commit("setConfigs", configs);
  318. resolve(config);
  319. });
  320. });
  321. },
  322. getShoppingNum(context) {
  323. return new Promise(async (resolve) => {
  324. api.cartList().then((res) => {
  325. let total = res.data.total || 0
  326. context.state.shoppingNum = total
  327. resolve(total);
  328. });
  329. });
  330. },
  331. },
  332. });
  333. async function getUserInfo(state) {
  334. const resdata = await api.getInfo();
  335. if (resdata.data.code == 200) {
  336. state.userInfo = resdata.data.data;
  337. }
  338. }
  339. export default store;