import { defineStore } from 'pinia'
export const UserStore = defineStore('user', () => {
  const user = ref({})
  const menus = ref([])
  /**
   * 将用户信息存起来;用户信息是在路由变更时,路由前置守卫去服务进行兑换而来
   * @param {String} payload token串
   */
  const setUser = (payload) => {
    user.value = payload
  }
  /**
   * 清除用户信息并删除token
   */
  const logOut = () => {
    user.value = {}
    localStorage.removeItem('token')
  }
  const setMenus = (payload) => {
    menus.value = payload
  }
  return { user, setUser, logOut, menus, setMenus }
})
