user.js 920 B

12345678910111213141516171819202122232425262728293031323334353637
  1. export default {
  2. namespaced: true,
  3. state: () => ({
  4. token: uni.getStorageSync('token') || '',
  5. userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
  6. lastLoginPhone: uni.getStorageSync('lastLoginPhone') || '',
  7. }),
  8. mutations: {
  9. updateUserInfo(state, userInfo) {
  10. state.userInfo = userInfo
  11. this.commit('m_user/saveUserInfoToStorage')
  12. },
  13. saveUserInfoToStorage(state) {
  14. uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
  15. },
  16. updateToken(state, token) {
  17. state.token = token
  18. this.commit('m_user/saveTokenToStorage')
  19. },
  20. saveTokenToStorage(state) {
  21. uni.setStorageSync('token', state.token)
  22. },
  23. updateLastLoginPhone(state, lastLoginPhone) {
  24. state.lastLoginPhone = lastLoginPhone
  25. this.commit('m_user/saveLastLoginPhoneToStorage')
  26. },
  27. saveLastLoginPhoneToStorage(state) {
  28. uni.setStorageSync('lastLoginPhone', state.lastLoginPhone)
  29. }
  30. },
  31. getters: {},
  32. }