stats.js 961 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { STORAGE } from '@/core/constants/storage-keys'
  2. const emptyStats = () => ({
  3. order: { pay: 0, delive: 0, receiving: 0, evaluate: 0, customer: 0, whole: 0, groups: 0 },
  4. dynamic: { collection: 0, concern: 0, footprint: 0, coupon: 0, accountbank: 0 },
  5. notice: { order: 0, notice: 0, chat: 0 },
  6. logistics: []
  7. })
  8. export default {
  9. namespaced: true,
  10. state: emptyStats(),
  11. mutations: {
  12. replace(state, payload) {
  13. Object.assign(state, payload || emptyStats())
  14. uni.setStorageSync(STORAGE.stats, state)
  15. },
  16. merge(state, patch) {
  17. Object.keys(patch || {}).forEach((block) => {
  18. if (state[block] && typeof state[block] === 'object') {
  19. Object.assign(state[block], patch[block])
  20. }
  21. })
  22. uni.setStorageSync(STORAGE.stats, state)
  23. }
  24. },
  25. actions: {
  26. hydrate({ commit }) {
  27. const cached = uni.getStorageSync(STORAGE.stats)
  28. if (cached) commit('replace', cached)
  29. },
  30. merge({ commit }, patch) {
  31. commit('merge', patch)
  32. }
  33. }
  34. }