text: // import { login, getInfo } from '@/api/user'
  import { getToken, setToken, removeToken } from '@/utils/auth'
  import router, { resetRouter } from '@/router'
  
  const state = {
    token: getToken(),
    name: '',
    roles: []
  }
  
  const mutations = {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_NAME: (state, name) => {
      state.name = name
    },
    SET_ROLES: (state, roles) => {
      state.roles = roles
    }
  }
  
  const actions = {
    // user login
    login({ commit }, userInfo) {
      // const { username, password } = userInfo
      // return new Promise((resolve, reject) => {
      //   login({ username: username.trim(), password: password }).then(response => {
      //     const { data } = response
      //
      //     // videoPort 端口
      //     commit('SET_TOKEN', data.token)
      //     setToken(data.token)
      //     resolve()
      //   }).catch(error => {
      //     reject(error)
      //   })
      // })
  
      return new Promise((resolve, reject) => {
        commit('SET_TOKEN', '123456')
        setToken('123456')
        resolve()
      })
    },
  
    // get user info
    getInfo({ commit }) {
      // return new Promise((resolve, reject) => {
      //   getInfo().then(response => {
      //     const { data } = response
      //     if (!data) {
      //       reject('Verification failed, please Login again.')
      //     }
      //     data.roles = ['admin']
      //     const { roles, realname } = data
      //     commit('SET_ROLES', roles)
      //     commit('SET_NAME', realname)
      //     resolve(data)
      //   }).catch(error => {
      //     reject(error)
      //   })
      // })
  
      return new Promise((resolve, reject) => {
        const oUserData = {
          account: {
            url: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            name: 'Super Admin',
            token: '123456'
          },
          roles: ['admin']
        }
        const { roles, account } = oUserData
  
        commit('SET_ROLES', roles)
        commit('SET_NAME', account.name)
        resolve(oUserData)
      })
    },
  
    // user logout
    logout({ commit, state, dispatch }) {
      return new Promise((resolve, reject) => {
        commit('SET_TOKEN', '')
        commit('SET_ROLES', [])
        removeToken()
        resetRouter()
  
        // reset visited views and cached views
        dispatch('tagsView/delAllViews', null, { root: true })
  
        resolve()
      })
    },
  
    // remove token
    resetToken({ commit }) {
      return new Promise(resolve => {
        commit('SET_TOKEN', '')
        commit('SET_ROLES', [])
        removeToken()
        resolve()
      })
    },
  
    // dynamically modify permissions
    changeRoles({ commit, dispatch }, role) {
      return new Promise(async resolve => {
        const token = role + '-token'
  
        commit('SET_TOKEN', token)
        setToken(token)
  
        const { roles } = await dispatch('getInfo')
  
        resetRouter()
  
        // generate accessible routes map based on roles
        const accessRoutes = await dispatch('permission/generateRoutes', roles, { root: true })
  
        // dynamically add accessible routes
        router.addRoutes(accessRoutes)
  
        // reset visited views and cached views
        dispatch('tagsView/delAllViews', null, { root: true })
  
        resolve()
      })
    }
  }
  
  export default {
    namespaced: true,
    state,
    mutations,
    actions
  }
  