user.js 705 B

12345678910111213141516171819202122232425262728
  1. import { defineStore } from 'pinia'
  2. export const useUserStore = defineStore('user',() => {
  3. const token = ref('')
  4. const userInfo = reactive({
  5. userId: 0,
  6. userName: '',
  7. roleId: 0,
  8. roleName: ''
  9. })
  10. const expiresAt = ref(0)
  11. const updateInfo = (data) => {
  12. token.value = data.token
  13. expiresAt.value = data.expiresAt
  14. Object.assign(userInfo, {
  15. userId: data.user.ID,
  16. userName: data.user.nickName,
  17. roleId: data.user.authority.authorityId,
  18. roleName: data.user.authority.authorityName
  19. })
  20. }
  21. return {
  22. token,
  23. userInfo,
  24. expiresAt,
  25. updateInfo
  26. }
  27. })