feat(mobile-oa-h5): add OA start runtime API helpers

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-11 13:36:27 +08:00
1 parent 834b1a59a7
commit 4a1802af36
2 files changed
+64 -2

No files matched your search

+42 -1
View File
@@ -1,4 +1,4 @@
import { get, post, request } from '../utils/http.js'
import { get, post, put, request } from '../utils/http.js'
export function fetchUserList(params) {
return get('/web/admin/users', params)
@@ -38,4 +38,45 @@ export function uploadAttachment(file) {
})
}
// —— 发起审批运行时(对齐 web-admin oaApproval.ts)——
export function fetchOaGroupList() {
return get('/web/admin/oa-approval/groups')
}
export function fetchOaTemplates() {
return get('/web/admin/oa-approval/templates')
}
export function fetchOaTemplateDetail(appId) {
return get(`/web/admin/oa-approval/templates/${encodeURIComponent(appId)}`)
}
export function fetchOaFlowPreview(appId, { formData, initiatorSelectByNode } = {}) {
return post(`/web/admin/oa-approval/templates/${encodeURIComponent(appId)}/flow-preview`, {
formData: formData || {},
initiatorSelectByNode: initiatorSelectByNode || undefined
})
}
export function fetchCreateOaInstanceDraft(data) {
return post('/web/admin/oa-approval/drafts', data)
}
export function fetchUpdateOaInstanceDraft(id, data) {
return put(`/web/admin/oa-approval/drafts/${encodeURIComponent(id)}`, data)
}
export function fetchOaInstanceDraftDetail(id) {
return get(`/web/admin/oa-approval/drafts/${encodeURIComponent(id)}`)
}
export function fetchSubmitOaInstanceDraft(id, data) {
return post(`/web/admin/oa-approval/drafts/${encodeURIComponent(id)}/submit`, data)
}
export function fetchStartOaInstance(data) {
return post('/web/admin/oa-approval/instances', data)
}
export { post }
+22 -1
View File
@@ -14,10 +14,13 @@ export async function request({ url, method = 'GET', data, headers = {} }) {
const path = url.startsWith('/') ? url : `/${url}`
const full = `${API_BASE}${path}`
const token = getToken()
if (!token) {
throw new Error('未携带登录态,请从小程序入口打开')
}
const init = {
method: method.toUpperCase(),
headers: {
...(token ? { Authorization: `Bearer ${token}` } : {}),
Authorization: `Bearer ${token}`,
...headers
}
}
@@ -38,6 +41,16 @@ export async function request({ url, method = 'GET', data, headers = {} }) {
}
const res = await fetch(finalUrl, init)
const body = await res.json().catch(() => null)
if (res.status === 401) {
throw new Error('登录已失效,请返回小程序重新登录')
}
if (body && typeof body === 'object' && body.detail && body.code == null) {
throw new Error(
res.status === 401 || /not authenticated/i.test(String(body.detail))
? '登录已失效,请返回小程序重新登录'
: String(body.detail)
)
}
return unwrap(body)
}
@@ -48,3 +61,11 @@ export function get(url, params) {
export function post(url, data) {
return request({ url, method: 'POST', data })
}
export function put(url, data) {
return request({ url, method: 'PUT', data })
}
export function put(url, data) {
return request({ url, method: 'PUT', data })
}