1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- import login from '@/apis/login'
- import common from '@/apis/common'
- Vue.use(Vuex);
- export default new Vuex.Store({
- //所有的数据都放在state中
- state: {
- applyData: {}, //预约考试数据存放
- token: '',
- user_account: '',
- userInfo: null,
- checkGoodsList: [],
- examResult:{},
- header: {
- serviceTel: {}
- },//页头配置
- footer: [],//页尾配置
- links: null,//友情链接
- },
- getters: {
- userInfo: state => state.userInfo,
- token: state => state.token,
- checkGoodsList: state => state.checkGoodsList,
- header: state => state.header,
- footer: state => state.footer,
- links: state => state.links,
- getApplyData: state => state.applyData,
- examResult: state => state.examResult,
- },
- //操作数据,唯一的通道是mutations
- mutations: {
- setExamResult(state,data) {
- state.examResult = data;
- },
- updateApplyData(state, data) {
- state.applyData = data;
- },
- setUserInfo(state, data) {
- state.userInfo = data;
- },
- setCheckGoodsList(state, data) {
- state.checkGoodsList = data;
- },
- setHomeSetList(state, data) {
- data.forEach(item => {
- if (item.configKey === 'home.header') {
- state.header = JSON.parse(item.configValue)
- console.log(state.header)
- }
- if (item.configKey === 'home.footer') {
- state.footer = JSON.parse(item.configValue)
- console.log(state.footer)
- }
- if (item.configKey === 'home.links') {
- state.links = JSON.parse(item.configValue)
- console.log(state.links)
- }
- })
- }
- },
- //actions,可以来做异步操作,然后提交给mutations,而后再对state(数据)进行操作
- actions: {
- /**
- *
- * @param {*} context
- * @returns
- * 获取用户信息
- */
- getUserInfo(context) {
- return new Promise(resolve => {
- login.getInfo().then(res => {
- context.commit('setUserInfo', res.data)
- resolve()
- })
- })
- },
- /**
- *
- * @param {*} context
- * @returns
- * 获取首页配置
- */
- getCommonBaseHomeList(context) {
- return new Promise(resolve => {
- common.getCommonBaseHomeList().then(res => {
- context.commit('setHomeSetList', res.rows)
- resolve()
- })
- })
- }
- }
- })
|