import Vue from 'vue'
import Vuex from 'vuex'
import perState from 'vuex-persistedstate'
import * as modules from "dvcp-wui/utils/modules"

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    token: ""
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    },
    logout(state, showToast) {
      state.token = ""
      state.user = {}
      showToast && uni.showToast({title: `登录失效，请重新登录`, duration: 2000, icon: 'none'})
    },
  },
  modules,
  plugins: [perState({
    storage: {
      getItem: key => uni.getStorageSync(key),
      setItem: (key, value) => uni.setStorageSync(key, value),
      removeItem: key => uni.removeStorageSync(key)
    }
  })]
})

export default store
