h5
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

180 lines
4.3 KiB

import { createStore } from 'vuex';
import deliver from './deliver/index.js';
import finance from './finance/index.js';
import project from './project/index.js';
import role from './role/index.js';
import socket from './socket/index.js';
import task from './task/index.js';
import user from './user/index.js';
import Config from '@/common/js/config.js';
// 不属于具体模块的 应用级的 store内容
const state = {
theme: 'theme-default',
networkConnected: true, // 网络是否连接
forceUseStorage: true, // 强制启用storage
systemInfo: null, // 系统设备信息
count: 3, // 后台出错,多次返回错误的token信息导致的死循环,用count来阻止死循环
domain: `${Config.apiUrl}/defaultwbs`, // 项目跳转域名
guide: '', // 引导页图片json
advs: '', // 广告图片json
businessPlugin: '', // 所有服务
allPlugin: '', // 所有插件
firstOpenApp: false, // 是否是第一次打开APP或者引导页有更新,false表示从未打开过,true表示打开过
isOpenApp: true, // 是否打开APP
longitude: '', // 经度
latitude: '', // 纬度
};
const getters = {
// 是否启用本地存储
// 设置了强制启用本地存储 或者 没有网络连接的时候
useStorage({ networkConnected, forceUseStorage }) {
return forceUseStorage || !networkConnected;
},
};
const mutations = {
/**
* 设置网络是否连接的变量
* @param {*} state
* @param {boolean} networkConnected
*/
setNetworkConnected(state, networkConnected) {
state.networkConnected = networkConnected;
},
/**
* 设置系统信息的数据
* @param {object} state
* @param {object | null} data 获取到的数据
*/
setSystemInfo(state, data) {
state.systemInfo = data;
},
/**
* 设置当前位置经度
* @param {object} state
* @param {object | null} data 获取到的数据
*/
setLongitude(state, data) {
state.longitude = data;
},
/**
* 设置当前位置纬度
* @param {object} state
* @param {object | null} data 获取到的数据
*/
setLatitude(state, data) {
state.latitude = data;
},
/**
* 设置主题
* @param {object} state
* @param {string} theme 主题名称 默认theme-default
*/
setTheme(state, theme) {
state.theme = theme || 'theme-default';
},
/**
* 设置count
* 后台出错,多次返回错误的token信息导致的死循环,用count来阻止死循环
* @param {Object} state
* @param {Object} data
*/
setCount(state, data) {
state.count = data;
},
/**
* 设置域名
* @param {Object} state
* @param {Object} data
*/
setDomain(state, data) {
state.domain = data;
uni.$storage.setStorageSync('domain', data);
},
/**
* 设置引导页图片
* @param {Object} state
* @param {Object} data
*/
setGuide(state, data) {
state.guide = data;
},
/**
* 设置广告页图片
* @param {Object} state
* @param {Object} data
*/
setAdvs(state, data) {
state.advs = data;
},
/**
* 设置服务列表
* @param {Object} state
* @param {Object} data
*/
setBusinessPlugin(state, data) {
state.businessPlugin = data;
},
/**
* 设置插件列表
* @param {Object} state
* @param {Object} data
*/
setAllPlugin(state, data) {
state.allPlugin = data;
},
setFirstOpenApp(state, data) {
state.firstOpenApp = uni.$storage.getStorageSync('firstOpenApp');
},
setIsOpenApp(state, data) {
state.isOpenApp = data;
}
};
const actions = {
async getBusinessPlugin({ commit }, param) {
try {
const res = await uni.$u.api.getBusinessPlugin();
uni.$storage.setStorageSync('businessPlugin', JSON.stringify(res) || '');
commit('setBusinessPlugin', JSON.stringify(res) || '');
return res;
} catch (error) {
uni.$ui.showToast(error.msg);
throw error;
}
},
async getAllPlugin({ commit }, param) {
try {
const res = await uni.$u.api.getAllPlugin();
uni.$storage.setStorageSync('allPlugin', JSON.stringify(res) || '');
commit('setAllPlugin', JSON.stringify(res) || '');
return res;
} catch (error) {
uni.$ui.showToast(error.msg);
throw error;
}
}
};
export default createStore({
state,
getters,
mutations,
actions,
modules: { user, socket, project, role, task, deliver, finance },
});