user.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { getState, setState } from '@/store/modules/vuexStorange'
  2. import { getSelfInfo } from '@/utils/auth'
  3. /** 员工用户信息 */
  4. const state = {
  5. selfInfo: null,
  6. user: null,
  7. shopUser: null
  8. }
  9. const getters = {
  10. // 员工用户信息
  11. getSelfInfo: (state) => {
  12. getState(state, 'selfInfo', 'selfInfo')
  13. // if (state.selfInfo) return state.selfInfo
  14. // let data = {}
  15. // getSelfInfo().then(res => {
  16. // data = res
  17. // })
  18. // return data
  19. return state.selfInfo
  20. },
  21. // 用户信息
  22. getUser: (state) => {
  23. getState(state, 'user', 'userInfo')
  24. return state.user
  25. },
  26. // 商城用户信息
  27. getShopUser: (state) => {
  28. getState(state, 'shopUser', 'shopUser')
  29. return state.shopUser
  30. }
  31. }
  32. const actions = {
  33. // 员工用户信息
  34. setSelfInfo({
  35. commit,
  36. dispatch,
  37. getters,
  38. rootGetters,
  39. rootState,
  40. state
  41. }, userInfo) {
  42. commit('SET_BASIC_USER', userInfo)
  43. },
  44. delSelfInfo({
  45. commit,
  46. dispatch,
  47. getters,
  48. rootGetters,
  49. rootState,
  50. state
  51. }) {
  52. commit('DEL_BASIC_USER')
  53. },
  54. // 后台管理用户信息
  55. setUser({
  56. commit,
  57. dispatch,
  58. getters,
  59. rootGetters,
  60. rootState,
  61. state
  62. }, userInfo) {
  63. commit('SET_USER', userInfo)
  64. },
  65. delUser({
  66. commit,
  67. dispatch,
  68. getters,
  69. rootGetters,
  70. rootState,
  71. state
  72. }) {
  73. commit('DEL_USER')
  74. },
  75. // 商城用户信息
  76. setShopUser({
  77. commit,
  78. dispatch,
  79. getters,
  80. rootGetters,
  81. rootState,
  82. state
  83. }, userInfo) {
  84. commit('SET_SHOP_USER', userInfo)
  85. },
  86. delShopUser({
  87. commit,
  88. dispatch,
  89. getters,
  90. rootGetters,
  91. rootState,
  92. state
  93. }) {
  94. commit('DEL_SHOP_USER')
  95. }
  96. }
  97. const mutations = {
  98. // 员工用户信息
  99. SET_BASIC_USER(state, userInfo = {}) {
  100. setState(state, userInfo, 'selfInfo', 'selfInfo')
  101. },
  102. DEL_BASIC_USER(state) {
  103. state.selfInfo = ''
  104. },
  105. // 后台管理用户信息
  106. SET_USER(state, userInfo = {}) {
  107. setState(state, userInfo, 'user', 'userInfo')
  108. },
  109. DEL_USER(state) {
  110. state.user = ''
  111. },
  112. // 商城用户信息
  113. SET_SHOP_USER(state, userInfo = {}) {
  114. setState(state, userInfo, 'shopUser', 'shopUser')
  115. },
  116. DEL_USER(state) {
  117. state.shopUser = ''
  118. }
  119. }
  120. export default {
  121. state,
  122. getters,
  123. actions,
  124. mutations
  125. }