|
|
import Vue from 'vue';
|
|
|
import Vuex, { createLogger } from 'vuex';
|
|
|
import createPersistedState from 'vuex-persistedstate';
|
|
|
import { config } from 'vuex-module-decorators';
|
|
|
import { createVueWait } from '@/utils/wait';
|
|
|
import configAxios from './plugins/axios';
|
|
|
|
|
|
Vue.use(Vuex);
|
|
|
|
|
|
const debug = process.env.NODE_ENV !== 'production';
|
|
|
|
|
|
// 全局设置 rawError = true,省去 @Action({ rawError: true }) 配置
|
|
|
config.rawError = true;
|
|
|
|
|
|
// 循环引入Modules
|
|
|
// const files = require.context('./modules', true, /\.(ts|js)$/);
|
|
|
// const modules: ModuleTree<RootState> = {};
|
|
|
//
|
|
|
// files.keys().forEach((key) => {
|
|
|
// modules[key.replace(/(\.\/|\.(ts|js))/g, '')] = files(key).default;
|
|
|
// });
|
|
|
|
|
|
// 循环引入views目录下的Modules
|
|
|
// 规则为 model.js 或 model目录下的js文件
|
|
|
// const viewModules = require.context('../pages/', true, /model.*\.(ts|js)$/);
|
|
|
// viewModules.keys().forEach((key) => {
|
|
|
// const module = viewModules(key).default;
|
|
|
// modules[key.replace(/(\.\/|\/model|\.(ts|js))/g, '')] = module;
|
|
|
// });
|
|
|
|
|
|
const plugins = [];
|
|
|
debug && plugins.push(createLogger());
|
|
|
plugins.push(createVueWait());
|
|
|
plugins.push(configAxios());
|
|
|
export const persistedKey = '__GWMS_APP_STATE_DATA__';
|
|
|
plugins.push(
|
|
|
createPersistedState({
|
|
|
key: persistedKey, // 状态保存到本地的 key
|
|
|
paths: ['session', 'server'], // 要持久化的状态,在state里面取,如果有嵌套,可以 a.b.c
|
|
|
storage: {
|
|
|
// 存储方式定义
|
|
|
getItem: (key) => uni.getStorageSync(key), // 获取
|
|
|
setItem: (key, value) => uni.setStorageSync(key, value), // 存储
|
|
|
removeItem: (key) => uni.removeStorageSync(key), // 删除
|
|
|
},
|
|
|
}),
|
|
|
);
|
|
|
|
|
|
export default new Vuex.Store({
|
|
|
state: {},
|
|
|
mutations: {},
|
|
|
actions: {},
|
|
|
// modules,
|
|
|
plugins,
|
|
|
});
|
|
|
|
|
|
export declare class RootState {}
|