You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.3 KiB

  1. import {
  2. getInfo,
  3. } from '@/api/login'
  4. import {
  5. getToken,
  6. setToken,
  7. removeToken
  8. } from '@/utils/auth'
  9. const user = {
  10. state: {
  11. token: getToken(),
  12. name: '',
  13. type: '',
  14. orgId: '',
  15. },
  16. mutations: {
  17. SET_TOKEN: (state, token) => {
  18. state.token = token
  19. },
  20. SET_NAME: (state, name) => {
  21. state.name = name
  22. },
  23. SET_TYPE: (state, type) => {
  24. state.type = type
  25. },
  26. SET_ORGID: (state, orgId) => {
  27. state.orgId = orgId
  28. },
  29. },
  30. actions: {
  31. // 登录
  32. Login({
  33. commit
  34. }, userInfo) {
  35. setToken(userInfo.token)
  36. commit('SET_TOKEN', userInfo.token)
  37. commit('SET_NAME', userInfo.name)
  38. commit('SET_TYPE', userInfo.type)
  39. commit('SET_ORGID', userInfo.orgId)
  40. },
  41. // 获取用户信息
  42. GetInfo({
  43. commit,
  44. state
  45. }) {
  46. return new Promise((resolve, reject) => {
  47. getInfo().then(response => {
  48. const userInfo = response.result
  49. commit('SET_NAME', userInfo.name)
  50. commit('SET_TYPE', userInfo.type)
  51. commit('SET_ORGID', userInfo.orgId)
  52. resolve()
  53. }).catch(error => {
  54. reject(error)
  55. })
  56. })
  57. },
  58. }
  59. }
  60. export default user