import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        userInfo: {
            DEPARTMENT_NAME: "",
            JOB: "",
            JOB_LEVEL: "",
            BASICINFO_ID:"",
            DEPARTMENT_ID:"",
            CORPINFO_ID:"",
            NAME:"",
            PRECINCT_ID:"",
            ROLEID:"",
            ROLE_NAME:"",
            USERBZ:"",
            USERNAME:"",
            USER_ID:"",
        },
        filePath: 'https://skqhdg.porthebei.com:9004/file/', // 附件地址
		// filePath: 'https://qgqy.qhdsafety.com/file/', // 附件地址
    },
    getters: {
        getUserInfo: state => state.userInfo,
    },
    mutations: {
        setUserInfo(state, userInfo) {
            state.userInfo = userInfo
        } ,
        setfilePath(state, filePath) {
            state.filePath = 'https://skqhdg.porthebei.com:9004/file/'
            // state.filePath = 'https://wwag.qhdsafety.com/file/'
        }
    },
    actions: {
        setUserInfo({commit}, userInfo) {
            commit('setUserInfo', userInfo)
        },
        setfilePath({commit}, filePath) {
            commit('setfilePath', filePath)
        }
    },
    plugins: [
        createPersistedState({
            storage: {
                getItem: (key) => uni.getStorageSync(key), // 获取
                setItem: (key, value) => uni.setStorageSync(key, value), // 存储
                removeItem: (key) => uni.removeStorageSync(key) // 删除
            }
        })
    ]
})
export default store
