Files
vueapp/api/config.ts
T
2026-06-09 17:00:23 +08:00

110 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { API_BASE_URL, ApiRequestError } from './auth'
export type ConfigOption = {
value: string
label: string
desc?: string
}
export type ConfigOptions = {
departments: ConfigOption[]
titles: ConfigOption[]
experiences: ConfigOption[]
}
export type ClinicalConfigPayload = {
department: number
title_name: string
practice_years: string
}
export type ClinicalConfigResult = Record<string, unknown>
export const MOCK_CONFIG_OPTIONS: ConfigOptions = {
departments: [
{ value: 'im', label: '内科', desc: '心内、呼吸、消化、肾内等临床场景' },
{ value: 'sur', label: '外科', desc: '普外、骨科、神外、胸外等临床场景' },
{ value: 'ped', label: '儿科', desc: '儿童常见病、急重症与沟通训练' },
{ value: 'obg', label: '妇产科', desc: '围产、妇科、产科急症训练' },
{ value: 'er', label: '急诊科', desc: '分诊、抢救、危急值处置训练' },
{ value: 'icu', label: '重症医学科', desc: '危重症评估与多学科决策训练' }
],
titles: [
{ value: 'resident', label: '住院医师', desc: '强化基础诊疗路径与病历思维' },
{ value: 'attending', label: '主治医师', desc: '提升独立诊疗和带教表达' },
{ value: 'associate_chief', label: '副主任医师', desc: '复杂病例决策与团队协作' },
{ value: 'chief', label: '主任医师', desc: '疑难病例、质控和教学管理' }
],
experiences: [
{ value: '1-3', label: '1-3年', desc: '基础病例训练优先' },
{ value: '3-5', label: '3-5年', desc: '进阶诊疗路径优先' },
{ value: '5-10', label: '5-10年', desc: '复杂病例推演优先' },
{ value: '10+', label: '10年以上', desc: '疑难病例与带教模拟优先' }
]
}
export function fetchConfigOptions() {
return Promise.resolve({
options: MOCK_CONFIG_OPTIONS,
defaults: {
department: 'im',
title: 'resident',
experience: '1-3'
},
mentor: {
name: '王主任',
message: '欢迎回来!请配置执业信息,开始精准带教模拟。'
}
})
}
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 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 || '无法连接服务'))
}
})
})
}