member.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import PersistedState from '../PersistedState'
  2. // initial state
  3. const state = {
  4. isOnline:PersistedState.getStorage('member','isOnline', false),
  5. token:PersistedState.getStorage('member','token'),
  6. info:PersistedState.getStorage('member','info'),
  7. point:PersistedState.getStorage('member','point', {}),
  8. inviterId:PersistedState.getStorage('member','inviterId', 0),
  9. isTokenInvalid:PersistedState.getStorage('member','isTokenInvalid', false),
  10. storeJoinin1:PersistedState.getStorage('member','storeJoinin1', {store_type:1}),
  11. storeJoinin0:PersistedState.getStorage('member','storeJoinin0', {store_type:0}),
  12. storeJoininType: PersistedState.getStorage('member','storeJoininType', 1)
  13. }
  14. // mutations
  15. const mutations = {
  16. sellerJoininSave (state, payload) {
  17. if(payload.storeJoinin.store_type==1){
  18. state.storeJoinin1 = Object.assign(
  19. state.storeJoinin1,
  20. payload.storeJoinin)
  21. }else{
  22. state.storeJoinin0 = Object.assign(
  23. state.storeJoinin0,
  24. payload.storeJoinin)
  25. }
  26. state.storeJoininType = payload.storeJoinin.store_type
  27. PersistedState.setStorage('member',state)
  28. },
  29. sellerJoininTypeSave (state, payload) {
  30. state.storeJoininType = payload.storeJoininType
  31. PersistedState.setStorage('member',state)
  32. },
  33. memberInviterId (state, payload) {
  34. state.inviterId = payload.inviterId
  35. PersistedState.setStorage('member',state)
  36. },
  37. memberPoint (state, payload) {
  38. state.point = Object.assign(
  39. state.point,
  40. payload.point)
  41. PersistedState.setStorage('member',state)
  42. },
  43. memberLogin (state, payload) {
  44. state.info = payload.info
  45. state.info.invalid_time = parseInt((new Date().getTime()) / 1000) + 3600// 一小时更新
  46. state.isOnline = true
  47. state.token = payload.token
  48. state.isTokenInvalid = false
  49. PersistedState.setStorage('member',state)
  50. },
  51. memberLogout (state) {
  52. state.info = null
  53. state.isOnline = false
  54. state.token = null
  55. PersistedState.setStorage('member',state)
  56. },
  57. memberUpdate (state, payload) {
  58. if (state.info) {
  59. state.info = payload.info
  60. state.info.invalid_time = parseInt((new Date().getTime()) / 1000) + 3600// 一小时更新
  61. PersistedState.setStorage('member',state)
  62. }
  63. },
  64. memberEdit (state, payload) {
  65. if (state.info) {
  66. let i
  67. for (i in payload) {
  68. state.info[i] = payload[i]
  69. }
  70. PersistedState.setStorage('member',state)
  71. }
  72. }
  73. }
  74. export default {
  75. state,
  76. mutations
  77. }