// import {getToken,setToken,removeToken} from '@/utils/auth'
// import { Message } from 'element-plus';
const state = {
  authToken: '', //
  username: '',
}
const mutations = {
  REMOVE_TOKEN(state) {
    localStorage.removeItem('authToken');
    localStorage.removeItem('username');
    state.authToken = "";
    state.username = "";
    Message({
      message: '退出成功',
      type: 'success'
    });
    setTimeout(() => {
      window.location.reload();
    }, 1000);

  },
  SET_TOKEN: (state, token_name) => {
    state.authToken = token_name.token;
    state.username = token_name.username;
    localStorage.setItem('authToken', token_name.token);
    localStorage.setItem('username', token_name.username);
  },
  SET_NAME: (state, name) => {
    state.username = name;
  },
}
const actions = {
  async login(context, data) {
    const result = await login(data)
    if (result.data.sucess) {
      //调用vuex中setToken方法
      context.commit('setToken', result.data.data)
    }
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
}