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: "",
    loginWay: "std",//std 标准,qujing:曲靖定制登录,admin:G端小程序登录
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    },
    setLoginWay(state, way) {
      state.loginWay = way
    },
    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
