admin.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * 管理端公共选项(审批人选人等)
  3. * 协议:门户信封 code===200
  4. */
  5. import { request, parseResponseJson } from '@/utils/request'
  6. function unwrap(res) {
  7. const body = parseResponseJson(res)
  8. if (!body || typeof body !== 'object') {
  9. throw new Error('接口响应异常')
  10. }
  11. if (body.code != null && body.code !== 200) {
  12. throw new Error(body.message || body.msg || '请求失败')
  13. }
  14. return body.data != null ? body.data : body
  15. }
  16. /**
  17. * @returns {Promise<Array<{ userId: string, nickName: string, userNo: string, label: string }>>}
  18. */
  19. export async function fetchUserOptions() {
  20. const res = await request({
  21. url: '/web/admin/users/options',
  22. method: 'GET'
  23. })
  24. const data = unwrap(res)
  25. const list = Array.isArray(data) ? data : []
  26. return list
  27. .map((item) => {
  28. const userId = String(item.value ?? item.userId ?? item.id ?? '')
  29. const nickName = String(item.nickName ?? item.label ?? item.userName ?? '')
  30. const userNo = String(item.userNo ?? item.userName ?? '')
  31. return {
  32. userId,
  33. nickName,
  34. userNo,
  35. label: nickName || userNo || userId
  36. }
  37. })
  38. .filter((u) => u.userId)
  39. }