123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- import Vue from "vue";
- import Vuex from "vuex";
- import api from "@/common/api.js";
- import method from "@/common/methodTool";
- import ipconfig from "../common/config";
- import {
- tenantId
- } from "@/common/request.js";
- Vue.use(Vuex);
- const store = new Vuex.Store({
- state: {
- current: 0, //tab选中
- hideBuyState: false, //是否隐藏购买流程和订单列表
- login: true,
- token: "",
- avatarUrl: "",
- userName: "",
- playNextId: "", //正在播放的节id
- userInfo: null,
- dictObj: null,
- chapterOpen: true,
- allowLoading: true,
- goodsAuditionConfigIdList: [], //当前访问页面的试听节ID
- shoppingCartList: [], //购物车支付商品
- applyData: {}, //预约考试数据存放
- backPageApplyData: {}, //预约考试返回页面的数据存放
- playSectionId: 0, //正在播放的录播节ID
- copyData: null, //存放审核资料数据
- playChannelId: 0, //正在播放的直播频道号
- playVID: 0, //正在播放的保利威视频ID
- liveLast: null,
- tabNums: 0, // '我的'右上角的数字
- sysTime: 0, //系统时间
- scene: 0, //进入小程序的场景值
- sac: "",
- educationType: null,
- businessLevel: null,
- sujectType: null,
- tenantId: "",
- //---------------
- consultPc: {},
- consultMobile: {},
- header: {},
- nav: {},
- other: {},
- shoppingNum: 0,
- //---------------
- config: {},
- },
- getters: {
- tenantId(state) {
- return tenantId || ''
- },
- current(state) {
- return state.current || 0
- },
- educationType(state) {
- if (!state.educationType) {
- api.educationTypeList({
- status: 1
- }).then(res => {
- state.educationType = res.data.rows
- })
- }
- return state.educationType
- },
- businessLevel(state) {
- if (!state.businessLevel) {
- api.businessList({
- status: 1
- }).then(res => {
- state.businessLevel = res.data.rows
- })
- }
- return state.businessLevel
- },
- sujectType(state) {
- if (!state.sujectType) {
- api.subjectList({
- status: 1
- }).then(res => {
- res.data.rows.forEach(i => {
- i.projectList = i.courseProjectTypes && i.courseProjectTypes.map(k => k
- .id) || []
- })
- state.sujectType = res.data.rows
- })
- }
- return state.sujectType
- },
- sysTime: (state) => {
- return state.sysTime;
- },
- userInfo: (state) => {
- if (state.userInfo == null) {
- if (uni.getStorageSync('user_account')) {
- getUserInfo(state)
- }
- }
- return state.userInfo;
- },
- dictObj: (state) => {
- if (state.dictObj == null) {
- api.dictList().then((res) => {
- if (res.data.code === 200) {
- let newList = {};
- let list = res.data.data;
- for (let i = 0; i < list.length; i++) {
- let item = list[i];
- if (newList.hasOwnProperty(item.dictType)) {
- newList[item.dictType].push(item.dictLabel);
- } else {
- newList[item.dictType] = [item.dictLabel];
- }
- }
- state.dictObj = newList;
- }
- });
- }
- return state.dictObj;
- },
- allowLoading: (state) => {
- return state.allowLoading;
- },
- playNextId: (state) => {
- return state.playNextId;
- },
- chapterOpen: (state) => {
- return state.chapterOpen;
- },
- goodsAuditionConfigIdList: (state) => {
- return state.goodsAuditionConfigIdList;
- },
- hideBuyState: (state) => {
- return state.hideBuyState;
- },
- shoppingCartList: (state) => {
- return state.shoppingCartList;
- },
- getApplyData: (state) => {
- return state.applyData;
- },
- getBackPageApplyData: (state) => {
- return state.backPageApplyData;
- },
- playSectionId: (state) => {
- return state.playSectionId;
- },
- getCopyData: (state) => state.copyData,
- playChannelId: (state) => state.playChannelId,
- playVID: (state) => state.playVID,
- liveLast: (state) => state.liveLast,
- sac: (state) => state.sac,
- consultMobile: (state) => state.consultMobile,
- consultPc: (state) => state.consultPc,
- header: (state) => state.header,
- nav: (state) => state.nav,
- other: (state) => state.other,
- shoppingNum: (state) => state.shoppingNum || 0,
- config: (state) => state.config,
- },
- mutations: {
- commonSystemTime(state, time) {
- state.sysTime = time;
- },
- tabNum(state, nums) {
- // state.tabLists[4].count = nums
- // if (nums) {
- // uni.setTabBarBadge({
- // index: 4,
- // text: nums + ''
- // })
- // } else {
- // uni.removeTabBarBadge({
- // index: 4
- // })
- // }
- },
- updateLiveLast(state, liveLast) {
- state.liveLast = liveLast;
- },
- updateAllowLoading(state, isShowloading) {
- state.allowLoading = isShowloading;
- },
- updatePlayNextId(state, str) {
- state.playNextId = str;
- },
- updateChapterOpen(state, boolean) {
- state.chapterOpen = boolean;
- },
- updataCopyData(state, objs) {
- state.copyData = objs;
- },
- updateApplyData(state, arrays) {
- state.applyData = arrays;
- },
- updateBackApplyData(state, arrays) {
- state.backPageApplyData = arrays;
- },
- updateUserInfo(state, provider) {
- state.userInfo = provider.userInfo;
- },
- setGoodsAuditionConfigIdList(state, provider) {
- state.goodsAuditionConfigIdList = provider.goodsAuditionConfigIdList;
- },
- setShoppingCartList(state, provider) {
- state.shoppingCartList = provider.shoppingCartList;
- },
- setPlaySectionId(state, provider) {
- state.playSectionId = provider.playSectionId;
- },
- setPlayChannelId(state, provider) {
- state.playChannelId = provider.playChannelId;
- },
- setPlayVID(state, provider) {
- state.playVID = provider.playVID;
- },
- setScene(state, scene) {
- state.scene = scene;
- },
- setSac(state, sac) {
- state.sac = sac;
- },
- setConfig(state, config) {
- console.log(config, 'config')
- for (let k in config) {
- state[k] = config[k]
- }
- },
- setConfigs(state, config) {
- state.config = config;
- },
- },
- actions: {
- /**
- * 设置系统时间
- */
- setSystemTime({
- commit
- }) {
- return new Promise((resolve) => {
- api.commonSystemTime().then((res) => {
- if (res.data.code == 200) {
- commit("commonSystemTime", res.data.data);
- resolve();
- }
- });
- });
- },
- changeTabsNum({
- commit
- }) {
- api.getinfoAttached().then((res) => {
- if (res.data.code === 200) {
- const nums =
- res.data.data.informSum +
- res.data.data.orderSum +
- res.data.data.periodSum +
- res.data.data.planSum +
- res.data.data.subscribeSum;
- commit("tabNum", nums);
- }
- });
- },
- getUserInfo(context) {
- return new Promise(async (resolve) => {
- const resdata = await api.getInfo();
- if (resdata.data.code == 200) {
- context.dispatch('getShoppingNum')
- context.state.userInfo = resdata.data.data;
- method.setUuid(new Date().valueOf() + "");
- resolve();
- }
- });
- },
- async appCommonConfig(context, data) {
- const resdata = await api.appCommonConfig(data);
- if (resdata.data.code == 200) {
- context.state.hideBuyState = resdata.data.data.hide;
- }
- },
- getConfig({
- commit
- }) {
- return new Promise(async (resolve) => {
- let config = {};
- let configs = {};
- api.mobileConfig().then((res) => {
- let data = res.data.rows.find((e) => e.configKey == "client.config");
- if (data) {
- config = JSON.parse(data.configValue) || {}
- }
- commit("setConfig", config);
- let datas = res.data.rows.find((e) => e.configKey == "home.mobile");
- if (datas) {
- configs = {
- ...configs,
- ...JSON.parse(datas.configValue)
- };
- }
- let header = res.data.rows.find((e) => e.configKey == "home.header");
- if (header) {
- configs = {
- ...configs,
- companyName: JSON.parse(header.configValue).companyName,
- };
- }
- let foot = res.data.rows.find(
- (e) => e.configKey == "home.footer.record"
- );
- if (foot) {
- configs = {
- ...configs,
- ...JSON.parse(foot.configValue)
- };
- }
- commit("setConfigs", configs);
- resolve(config);
- });
- });
- },
- getShoppingNum(context) {
- return new Promise(async (resolve) => {
- api.cartList().then((res) => {
- let total = res.data.total || 0
- context.state.shoppingNum = total
- resolve(total);
- });
- });
- },
- },
- });
- async function getUserInfo(state) {
- const resdata = await api.getInfo();
- if (resdata.data.code == 200) {
- state.userInfo = resdata.data.data;
- }
- }
- export default store;
|