综合办公系统
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { login, logout, getInfo } from '@/api/login'
  2. import { listUser } from '@/api/system/user'
  3. import { listDept } from '@/api/system/dept'
  4. import { getToken, setToken, removeToken } from '@/utils/auth'
  5. const user = {
  6. state: {
  7. token: getToken(),
  8. id: '',
  9. name: '',
  10. avatar: '',
  11. deptId: '',
  12. deptName: '',
  13. roles: [],
  14. permissions: [],
  15. userList: [],
  16. deptList: []
  17. },
  18. mutations: {
  19. SET_TOKEN: (state, token) => {
  20. state.token = token
  21. },
  22. SET_ID: (state, id) => {
  23. state.id = id
  24. },
  25. SET_NAME: (state, name) => {
  26. state.name = name
  27. },
  28. SET_DEPTID: (state, deptId) => {
  29. state.deptId = deptId
  30. },
  31. SET_DEPTNAME: (state, deptName) => {
  32. state.deptName = deptName
  33. },
  34. SET_AVATAR: (state, avatar) => {
  35. state.avatar = avatar
  36. },
  37. SET_ROLES: (state, roles) => {
  38. state.roles = roles
  39. },
  40. SET_PERMISSIONS: (state, permissions) => {
  41. state.permissions = permissions
  42. },
  43. SET_USERLIST: (state, userList) => {
  44. state.userList = userList
  45. },
  46. SET_DEPTLIST: (state, deptList) => {
  47. state.deptList = deptList
  48. },
  49. },
  50. actions: {
  51. // 登录
  52. Login({ commit }, userInfo) {
  53. const username = userInfo.username.trim()
  54. const password = userInfo.password
  55. const code = userInfo.code
  56. const uuid = userInfo.uuid
  57. return new Promise((resolve, reject) => {
  58. login(username, password, code, uuid).then(res => {
  59. setToken(res.token)
  60. commit('SET_TOKEN', res.token)
  61. resolve()
  62. }).catch(error => {
  63. reject(error)
  64. })
  65. })
  66. },
  67. // 获取用户信息
  68. GetInfo({ commit, state }) {
  69. return new Promise((resolve, reject) => {
  70. getInfo().then(res => {
  71. const user = res.user
  72. const avatar = (user.avatar == "" || user.avatar == null) ? require("@/assets/images/user.png") : process.env.VUE_APP_BASE_API + user.avatar;
  73. if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
  74. commit('SET_ROLES', res.roles)
  75. commit('SET_PERMISSIONS', res.permissions)
  76. } else {
  77. commit('SET_ROLES', ['ROLE_DEFAULT'])
  78. }
  79. commit('SET_ID', user.userId)
  80. commit('SET_NAME', user.nickName)
  81. commit('SET_DEPTID', user.deptId)
  82. commit('SET_DEPTNAME', user.dept.deptName)
  83. commit('SET_AVATAR', avatar)
  84. listUser({ pageNum: 1, pageSize: 9999 }).then(result => {
  85. commit('SET_USERLIST', result.rows)
  86. listDept({ pageNum: 1, pageSize: 9999 }).then(response => {
  87. let deptList = response.data.filter(item => item.deptName != '四川中水成勘院测绘工程有限责任公司')
  88. commit('SET_DEPTLIST', deptList)
  89. })
  90. })
  91. resolve(res)
  92. }).catch(error => {
  93. reject(error)
  94. })
  95. })
  96. },
  97. // 退出系统
  98. LogOut({ commit, state }) {
  99. return new Promise((resolve, reject) => {
  100. logout(state.token).then(() => {
  101. commit('SET_TOKEN', '')
  102. commit('SET_ROLES', [])
  103. commit('SET_PERMISSIONS', [])
  104. removeToken()
  105. resolve()
  106. }).catch(error => {
  107. reject(error)
  108. })
  109. })
  110. },
  111. // 前端 登出
  112. FedLogOut({ commit }) {
  113. return new Promise(resolve => {
  114. commit('SET_TOKEN', '')
  115. removeToken()
  116. resolve()
  117. })
  118. }
  119. }
  120. }
  121. export default user