import { createStore } from "vuex"
// 引入持久化
import createPersistedState from 'vuex-persistedstate';

const store = createStore({
    state: {
        currentPath: '',
        userInfo: {},
        selectDate: 0,
        selectTab: 'old',
        modelName: ''
    },
    mutations: {
        updateCurrentPath(state, path) {
            state.currentPath = path
        },
        setUserInfo(state, data) {
            state.userInfo = data;
        },
        changeSelectDate(state, data) {
            state.selectDate = data;
        },
        changeSelectTab(state, data) {
            state.selectTab = data;
        },
        setModelName(state, data) {
            state.modelName = data;
        }
    },
    actions: {
        updateCurrentPath({ commit }, path) {
            commit('updateCurrentPath', path)
        }
    },
    modules: {},
    getters: {
        getCurrentPath(state) {
            return state.currentPath;
        }
    },
    plugins: [
        createPersistedState({
            key: 'vuex', 
            storage: window.localStorage
        })
    ]
})
export default store