feat: 联调对话功能

This commit is contained in:
王天骄
2026-06-09 17:00:23 +08:00
parent 3414d0662c
commit 2192b855a1
77 changed files with 1082 additions and 487 deletions
+52 -17
View File
@@ -1,3 +1,5 @@
import { API_BASE_URL, ApiRequestError } from './auth'
export type ConfigOption = {
value: string
label: string
@@ -11,21 +13,12 @@ export type ConfigOptions = {
}
export type ClinicalConfigPayload = {
userId: string
phone: string
institutionId: string
department: string
title: string
experience: string
departmentName: string
titleName: string
experienceName: string
department: number
title_name: string
practice_years: string
}
export type ClinicalConfigResult = ClinicalConfigPayload & {
id: string
updatedAt: string
}
export type ClinicalConfigResult = Record<string, unknown>
export const MOCK_CONFIG_OPTIONS: ConfigOptions = {
departments: [
@@ -65,10 +58,52 @@ export function fetchConfigOptions() {
})
}
function readAccessToken() {
try {
return uni.getStorageSync('clinical-thinking-access-token') || ''
} catch {
return ''
}
}
function readErrorMessage(data: unknown, fallback: string) {
if (data && typeof data === 'object') {
const payload = data as Record<string, unknown>
const message = payload.message || payload.detail || payload.error
if (typeof message === 'string' && message.trim()) return message
}
return fallback
}
export function saveClinicalConfig(payload: ClinicalConfigPayload): Promise<ClinicalConfigResult> {
return Promise.resolve({
id: `mock-config-${Date.now()}`,
...payload,
updatedAt: new Date().toISOString()
return new Promise((resolve, reject) => {
const token = readAccessToken()
const header: Record<string, string> = {
'Content-Type': 'application/json'
}
if (token) {
header.Authorization = `Bearer ${token}`
}
uni.request({
url: `${API_BASE_URL}/user/profile/config/`,
method: 'POST',
timeout: 10000,
header,
data: payload,
success: response => {
if (response.statusCode >= 200 && response.statusCode < 300) {
resolve(response.data as ClinicalConfigResult)
return
}
const data = response.data as Record<string, unknown> | undefined
const code = typeof data?.code === 'string' ? data.code : undefined
reject(new ApiRequestError(readErrorMessage(response.data, `保存失败(${response.statusCode}`), code, response.statusCode))
},
fail: error => {
reject(new ApiRequestError(error.errMsg || '无法连接服务'))
}
})
})
}