65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import Taro from '@tarojs/taro';
|
|
import { get, patch } from './request';
|
|
import { getApiBaseUrl } from './config';
|
|
|
|
export interface LampTest {
|
|
id: string;
|
|
roomId?: string;
|
|
diseases?: string[];
|
|
status: string;
|
|
sampleInfo?: string;
|
|
result?: string;
|
|
resultImageUrl?: string;
|
|
crossStatus?: string;
|
|
crossReason?: string;
|
|
note?: string;
|
|
createdAt?: string;
|
|
}
|
|
|
|
export interface LampTestStep {
|
|
id: string;
|
|
lampTestId: string;
|
|
stepNo: number;
|
|
name: string;
|
|
done: boolean;
|
|
note?: string;
|
|
}
|
|
|
|
export const listLampTests = (status?: string) =>
|
|
get<LampTest[]>('/lamp-tests', status ? { status } : undefined);
|
|
export const listLampSteps = (id: string) => get<LampTestStep[]>(`/lamp-tests/${id}/steps`);
|
|
export const updateLampStep = (id: string, stepNo: number, done: boolean) =>
|
|
patch<LampTestStep>(`/lamp-tests/${id}/steps/${stepNo}`, { done });
|
|
export const updateLampResult = (id: string, result: string) =>
|
|
patch<LampTest>(`/lamp-tests/${id}`, { result });
|
|
|
|
export const uploadLampResultImage = (id: string, filePath: string): Promise<{ url: string }> => {
|
|
const token = Taro.getStorageSync('token');
|
|
const header: Record<string, string> = {};
|
|
if (token) {
|
|
header['Authorization'] = `Bearer ${token}`;
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
Taro.uploadFile({
|
|
url: `${getApiBaseUrl()}/lamp-tests/${id}/result-image`,
|
|
filePath,
|
|
name: 'file',
|
|
header,
|
|
timeout: 60000,
|
|
success: (res) => {
|
|
try {
|
|
const body = JSON.parse(res.data || '{}');
|
|
if (res.statusCode >= 400) {
|
|
reject(new Error(body?.error || `上传失败 (${res.statusCode})`));
|
|
return;
|
|
}
|
|
resolve(body);
|
|
} catch {
|
|
reject(new Error('解析失败'));
|
|
}
|
|
},
|
|
fail: (err) => reject(new Error(err?.errMsg || '上传失败')),
|
|
});
|
|
});
|
|
};
|