From 4a1802af36d7149e1d7d4c33e6b164fc2a53ec67 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Tue, 11 Aug 2026 13:36:27 +0800 Subject: [PATCH] feat(mobile-oa-h5): add OA start runtime API helpers Co-authored-by: Cursor --- mobile-oa-h5/src/api/oa.js | 43 +++++++++++++++++++++++++++++++++- mobile-oa-h5/src/utils/http.js | 23 +++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/mobile-oa-h5/src/api/oa.js b/mobile-oa-h5/src/api/oa.js index 3b2f9b7c..8ad4365f 100644 --- a/mobile-oa-h5/src/api/oa.js +++ b/mobile-oa-h5/src/api/oa.js @@ -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 } diff --git a/mobile-oa-h5/src/utils/http.js b/mobile-oa-h5/src/utils/http.js index 4687141a..54728896 100644 --- a/mobile-oa-h5/src/utils/http.js +++ b/mobile-oa-h5/src/utils/http.js @@ -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 }) +}