user.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {
  2. getToken,
  3. setToken
  4. } from '@/utils/auth'
  5. import Cache from '@/utils/cache'
  6. const getDefaultState = () => {
  7. return {
  8. token: getToken(),
  9. info: Cache.get('userInfo'),
  10. allset: '',
  11. person:Cache.get('personInfo'),
  12. //核销员
  13. staff:'',
  14. }
  15. }
  16. const state = getDefaultState()
  17. const mutations = {
  18. SET_TOKEN: (state, token) => {
  19. setToken(token)
  20. state.token = token
  21. },
  22. SET_INFO: (state, info) => {
  23. Cache.set('userInfo', info)
  24. state.info = info
  25. },
  26. SET_ALL_SET: (state, allset) => {
  27. Cache.set('allset', allset)
  28. state.allset = allset
  29. },
  30. SET_PERSON: (state, person) => {
  31. Cache.set('personInfo', person)
  32. state.person = person
  33. },
  34. SET_STAFF: (state, staff) => {
  35. Cache.set('staff', staff)
  36. state.staff = staff
  37. },
  38. }
  39. const actions = {
  40. token({
  41. commit
  42. }, token) {
  43. commit('SET_TOKEN', token)
  44. },
  45. info({
  46. commit
  47. }, info) {
  48. commit('SET_INFO', info)
  49. },
  50. allset({
  51. commit
  52. }, allset) {
  53. commit('SET_ALL_SET', allset)
  54. },
  55. person({
  56. commit
  57. }, person) {
  58. commit('SET_PERSON', person)
  59. },
  60. staff({
  61. commit
  62. }, staff) {
  63. commit('SET_STAFF', staff)
  64. },
  65. }
  66. export default {
  67. namespaced: true,
  68. state,
  69. mutations,
  70. actions
  71. }