Files
shanxia2.0/miniprogram/api/admin.js
2026-07-17 21:59:47 +08:00

42 lines
1.2 KiB
JavaScript

/**
* 管理端公共选项(审批人选人等)
* 协议:门户信封 code===200
*/
import { request, parseResponseJson } from '@/utils/request'
function unwrap(res) {
const body = parseResponseJson(res)
if (!body || typeof body !== 'object') {
throw new Error('接口响应异常')
}
if (body.code != null && body.code !== 200) {
throw new Error(body.message || body.msg || '请求失败')
}
return body.data != null ? body.data : body
}
/**
* @returns {Promise<Array<{ userId: string, nickName: string, userNo: string, label: string }>>}
*/
export async function fetchUserOptions() {
const res = await request({
url: '/web/admin/users/options',
method: 'GET'
})
const data = unwrap(res)
const list = Array.isArray(data) ? data : []
return list
.map((item) => {
const userId = String(item.value ?? item.userId ?? item.id ?? '')
const nickName = String(item.nickName ?? item.label ?? item.userName ?? '')
const userNo = String(item.userNo ?? item.userName ?? '')
return {
userId,
nickName,
userNo,
label: nickName || userNo || userId
}
})
.filter((u) => u.userId)
}