import { btnAuthFilter,setToken, getToken } from '@/libs/util'
import userinfo from  "./metainfo/userinfo"

export default {
  state: {
      user_info:userinfo,
      dict_info:import("./metainfo/dict")
  },
  mutations: {
    setAvatar (state, avatarPath) {
      state.avatarImgPath = avatarPath
    },
  },
  getters: {
    user_info: (state, getters, {user}) => btnAuthFilter(state.user_info,user),//定义一个函数添加权限控制逻辑
    dict_info:state=>state.dict_info
  },
  actions: {
    // 登录
    handleLogin ({ commit }, { userName, password }) {
      userName = userName.trim()
      return new Promise((resolve, reject) => {
        login({
          userName,
          password
        }).then(res => {
          const data = res.data
          commit('setToken', data.token)
          resolve()
        }).catch(err => {
          reject(err)
        })
      })
    }
  }
}
