123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- import login from '@/apis/login'
- import order from '@/apis/order'
- import user from '@/apis/user'
- import common from '@/apis/common'
- import tools from '@/common/tools'
- import axios from 'axios'
- Vue.use(Vuex);
- export default new Vuex.Store({
- //所有的数据都放在state中
- state: {
- TENANT_NANE: "",
- msgCount: 0,
- cartCount: 0,
- applyData: {}, //预约考试数据存放
- currentRouter: {},
- token: '',
- user_account: '',
- userInfo: null,
- examResult: {},
- dictList: {},//字典数据
- sysTime: 0,
- businessItem: null,
- educationType: null,
- businessList_t: null,
- businessList: [],
- packPageStatus: true,
- isDesktop: !navigator.userAgent.match(
- /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i
- ),
- //--------------------------------
- header: {},//页头配置
- footer: {},//页尾配置
- nav: [],//底部说明
- links: [],//友情链接
- consultPc: {},//移动端设置
- consultMobile: {},//移动端设置
- other: {},//移动端设置
- //--------------------------------
- },
- getters: {
- educationType(state) {
- if (!state.educationType) {
- common.educationTypeList({ status: 1 }).then(res => {
- state.educationType = res.rows
- })
- }
- return state.educationType
- },
- businessList_t(state) {
- if (!state.businessList_t) {
- common.businessList({ status: 1 }).then(res => {
- state.businessList_t = res.rows
- })
- }
- return state.businessList_t
- },
- businessList: state => state.businessList,
- businessItem: state => state.businessItem,
- sysTime: state => state.sysTime,
- userInfo: state => state.userInfo,
- token: state => state.token,
- header: state => state.header,
- footer: state => state.footer,
- nav: state => state.nav,
- links: state => state.links,
- consultPc: state => state.consultPc,
- other: state => state.other,
- getApplyData: state => state.applyData,
- examResult: state => state.examResult,
- currentRouter: state => state.currentRouter,
- cartCount: state => state.cartCount,
- msgCount: state => state.msgCount
- },
- //操作数据,唯一的通道是mutations
- mutations: {
- setDictList(state, data) {
- state.dictList = data;
- },
- setTENANT_NANE(state, id) {
- state.TENANT_NANE = id
- },
- setBusinessList(state, list) {
- state.businessList = list
- },
- setBusinessItem(state, item) {
- state.businessItem = item
- },
- commonSystemTime(state, time) {
- state.sysTime = time;
- },
- setCurrentRouter(state, data) {
- state.currentRouter = data;
- },
- setExamResult(state, data) {
- state.examResult = data;
- },
- updateApplyData(state, data) {
- state.applyData = data;
- },
- setUserInfo(state, data) {
- state.userInfo = data;
- },
- setHomeSetList(state, data) {
- console.log(data,'data')
- data.forEach(item => {
- // if (item.configKey === 'home.header') {
- // state.header = JSON.parse(item.configValue)
- // }
- // if (item.configKey === 'home.footer') {
- // state.footer = JSON.parse(item.configValue)
- // }
- // if (item.configKey === 'home.footer.record') {
- // state.footerRecord = JSON.parse(item.configValue) || {}
- // }
- // if (item.configKey === 'home.links') {
- // state.links = JSON.parse(item.configValue)
- // }
- // if (item.configKey === 'home.mobile') {
- // state.mobile = JSON.parse(item.configValue)
- // }
- if (item.configKey === 'client.config') {
- let configValue = JSON.parse(item.configValue) || {}
- for(let k in configValue){
- state[k] = configValue[k]
- console.log(k,configValue[k],'k')
- }
- }
- })
- },
- getCartCount(state) {
- user.cartList().then((res) => {
- state.cartCount = res.total;
- });
- },
- getMsgCount(state) {
- user.appinformUsercount({
- systemStatusList: '1,2',
- receiptStatus: 0,
- }).then(res => {
- state.msgCount = res.data
- })
- }
- },
- //actions,可以来做异步操作,然后提交给mutations,而后再对state(数据)进行操作
- actions: {
- findTenantId({
- commit
- }) {
- return new Promise(resolve => {
- var urlReg = /[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/;
- var urls = location.origin.includes("localhost") ? '' : urlReg.exec(location.origin)[0];
- if (location.origin.includes("192.168.1") || location.origin.includes("localhost") || location.origin.includes("120.79.166.78")) {
- urls = "120.79.166.78:19012"
- }
- axios.get(process.env.BASE_URL + '/app/common/findTenantId?hostPc=' + urls)
- .then(function (response) {
- let favicon = document.querySelector('link[rel="icon"]')
- favicon = document.createElement('link')
- favicon.rel = 'icon'
- favicon.href = response.data.data == '867735392558919680' ? '/static/favicon.ico' : '/static/favicons.ico'
- document.head.appendChild(favicon)
- commit('setTENANT_NANE', response.data.data)
- resolve()
- })
- .catch(function (error) {
- console.log("TenantIDerror:", error);
- });
- })
- },
- /**
- * 设置系统时间
- */
- setSystemTime({
- commit
- }) {
- return new Promise(resolve => {
- common.commonSystemTime().then(res => {
- if (res.code == 200) {
- commit('commonSystemTime', res.data)
- resolve()
- }
- })
- })
- },
- getbusinessList({
- commit
- }) {
- return new Promise(resolve => {
- order.orderUserAllBusinessList().then(res => {
- if (res.code == 200) {
- commit('setBusinessList', res.rows)
- if (res.rows && res.rows.length) {
- commit('setBusinessItem', res.rows[0])
- }
- resolve()
- }
- })
- })
- },
- /**
- *
- * @param {*} context
- * @returns
- * 获取用户信息
- */
- getUserInfo(context) {
- return new Promise(resolve => {
- login.getInfo({ fromPlat: 2 }).then(res => {
- context.commit('setUserInfo', res.data)
- if (!tools.getUuid()) {
- tools.setUuid(new Date().valueOf() + "")
- }
- resolve()
- }).catch(err => { })
- })
- },
- /**
- *
- * @param {*} context
- * @returns
- * 获取首页配置
- */
- getCommonBaseHomeList(context) {
- return new Promise(resolve => {
- common.getCommonBaseHomeList().then(res => {
- context.commit('setHomeSetList', res.rows)
- resolve()
- })
- })
- },
- /**
- *
- * @param {*} context
- * @returns
- * 获取字典配置
- */
- getCommonBaseDictList(context) {
- return new Promise(resolve => {
- common.dictList({status:1}).then(res => {
- if (res.code === 200) {
- let dictList = {};
- let list = res.data;
- for (let i = 0; i < list.length; i++) {
- let item = list[i];
- if (dictList.hasOwnProperty(item.dictType)) {
- dictList[item.dictType].push(item.dictLabel);
- } else {
- dictList[item.dictType] = [item.dictLabel];
- }
- }
- context.commit('setDictList', dictList)
- resolve()
- }
- })
- })
- },
- }
- })
|