feat(web/miniapp): LAMP 检测管理页与小程序录入(#14)+ web 构建代码拆分
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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;
|
||||
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 || '上传失败')),
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user