session.js 617 B

12345678910111213141516171819202122
  1. import { STORAGE } from '@/core/constants/storage-keys'
  2. export function clearSession({ commit, rootState }) {
  3. const user = rootState.user
  4. Object.keys(user).forEach((k) => {
  5. if (typeof user[k] === 'boolean') user[k] = false
  6. else if (typeof user[k] === 'number') user[k] = 0
  7. else user[k] = ''
  8. })
  9. user.isLogin = false
  10. const stats = rootState.stats
  11. ;['order', 'dynamic', 'notice'].forEach((block) => {
  12. Object.keys(stats[block] || {}).forEach((k) => {
  13. stats[block][k] = 0
  14. })
  15. })
  16. uni.removeStorageSync(STORAGE.user)
  17. uni.removeStorageSync(STORAGE.stats)
  18. commit('user/reset', null, { root: true })
  19. }