123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- import api from '@/common/api.js'
- import method from '@/common/methodTool'
- Vue.use(Vuex);
- const store = new Vuex.Store({
- state: {
- 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, //进入小程序的场景值
- tabLists: [{
- iconPath: "/static/nav1.png",
- selectedIconPath: "/static/nav1_on.png",
- text: '首页',
- pagePath: "/pages/index/index"
- },
- {
- iconPath: "/static/nav2.png",
- selectedIconPath: "/static/nav2_on.png",
- text: '选课',
- pagePath: "/pages/course/index"
- },
- {
- iconPath: "/static/nav6.png",
- selectedIconPath: "/static/nav6_on.png",
- text: '学习',
- midButton: true,
- pagePath: "/pages/learn/index"
- },
- {
- iconPath: "/static/nav3.png",
- selectedIconPath: "/static/nav3_on.png",
- text: '购物车',
- pagePath: "/pages/shopping/shoppingCart"
- },
- {
- iconPath: "/static/nav5.png",
- selectedIconPath: "/static/nav5_on.png",
- text: '我的',
- count: 0,
- pagePath: "/pages/wd/index"
- }]
- },
- getters: {
- 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,
- },
- 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) {
- console.log(str,'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
- }
- },
- 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.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;
- }
- }
- }
- })
- async function getUserInfo(state) {
- const resdata = await api.getInfo()
- if (resdata.data.code == 200) {
- state.userInfo = resdata.data.data;
- }
- }
- export default store
|