seller.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import PersistedState from '../PersistedState'
  2. // initial state
  3. const state = {
  4. isOnline: PersistedState.getStorage('seller','isOnline',false),
  5. token: PersistedState.getStorage('seller','token'),
  6. info: PersistedState.getStorage('seller','info'),
  7. isTokenInvalid: PersistedState.getStorage('seller','isTokenInvalid',false)
  8. }
  9. // mutations
  10. const mutations = {
  11. sellerLogin (state, payload) {
  12. state.info = payload.info
  13. state.info.invalid_time = parseInt((new Date().getTime()) / 1000) + 3600// 一小时更新
  14. state.isOnline = true
  15. state.token = payload.token
  16. state.isTokenInvalid = false
  17. PersistedState.setStorage('seller',state)
  18. },
  19. sellerLogout (state) {
  20. state.info = null
  21. state.isOnline = false
  22. state.token = null
  23. PersistedState.setStorage('seller',state)
  24. },
  25. sellerUpdate (state, payload) {
  26. if (state.info) {
  27. state.info = payload.info
  28. state.info.invalid_time = parseInt((new Date().getTime()) / 1000) + 3600// 一小时更新
  29. PersistedState.setStorage('seller',state)
  30. }
  31. },
  32. sellerEdit (state, payload) {
  33. if (state.info) {
  34. let i
  35. for (i in payload) {
  36. state.info[i] = payload[i]
  37. }
  38. PersistedState.setStorage('seller',state)
  39. }
  40. }
  41. }
  42. export default {
  43. state,
  44. mutations
  45. }