user.js 2.3 KB

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