123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import Vue from "vue";
- import Vuex from "vuex";
- import other from "./modules/other";
- import login from "./modules/login";
- import dictionary from "./modules/dictionary";
- import system from "./modules/system";
- Vue.use(Vuex);
- const myPlugin = (store) => {
-
- const customModules = [{
- name: 'other',
- aliasName: 'Other',
- isLocalstorage: true
- },
- {
- name: 'login',
- aliasName: 'Login',
- isLocalstorage: true
- },
- {
- name: 'dictionary',
- aliasName: 'Dictionary',
- isLocalstorage: false
- },
- {
- name: 'system',
- aliasName: 'System',
- isLocalstorage: false
- },
- ];
-
- const localstorageModules = customModules.filter(v => v.isLocalstorage);
-
- let vuexStorage = uni.getStorageSync("vuexStorage");
- if (vuexStorage) {
- customModules.forEach(v => {
- if (v.isLocalstorage) {
- store.commit(`${v.name}/resetVx${v.aliasName}`, vuexStorage[v.name]);
- } else {
- store.commit(`${v.name}/resetVx${v.aliasName}`);
- }
- })
- }
- store.subscribe((mutation, state) => {
- const isLocalstorageFlag = localstorageModules.some(v => mutation.type.startsWith(`${v.name}/`));
- if (isLocalstorageFlag) {
- const obj = {};
- localstorageModules.forEach(v => {
- obj[v.name] = state[v.name];
- })
- uni.setStorageSync("vuexStorage", obj);
- }
- });
- };
- export default new Vuex.Store({
- modules: {
- login,
- dictionary,
- system,
- other,
- },
- plugins: [myPlugin],
- });
|