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

58 lines
1.8 KiB
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 {}