|
|
@@ -0,0 +1,249 @@
|
|
|
+import type {
|
|
|
+ TreatmentPlanDTO,
|
|
|
+ TreatmentPlanSubmitVO,
|
|
|
+ TreatmentPlanVO,
|
|
|
+} from './treatment-plan.schema';
|
|
|
+
|
|
|
+import type { PageQueryMethodArgs } from '#/request/schema';
|
|
|
+import type { PageVO } from '#/request/schema/record';
|
|
|
+
|
|
|
+import { pageQueryArgsTransform } from '#/request/schema';
|
|
|
+
|
|
|
+import {
|
|
|
+ decodeTreatmentPlan,
|
|
|
+ encodeTreatmentPlan,
|
|
|
+ encodeTreatmentPlanQuery,
|
|
|
+} from './treatment-plan.schema';
|
|
|
+
|
|
|
+/** 后端接口就绪后改为 false */
|
|
|
+export const USE_TREATMENT_PLAN_MOCK = true;
|
|
|
+
|
|
|
+type MethodLike<T> = PromiseLike<T> & {
|
|
|
+ send?: (force?: boolean) => PromiseLike<T>;
|
|
|
+};
|
|
|
+
|
|
|
+const MOCK_PDF_URL =
|
|
|
+ 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf';
|
|
|
+
|
|
|
+const MOCK_THERAPY_OPTIONS = [
|
|
|
+ '温中健脾,和胃止痛',
|
|
|
+ '益气补血,健脾养心',
|
|
|
+ '平肝潜阳,滋阴降火',
|
|
|
+ '疏肝理气,活血化瘀',
|
|
|
+ '清热利湿,通淋排石',
|
|
|
+ '补肾填精,强筋壮骨',
|
|
|
+] as const;
|
|
|
+
|
|
|
+const SEED_RECORDS: Omit<
|
|
|
+ TreatmentPlanDTO,
|
|
|
+ 'createTime' | 'id' | 'personalStudioId' | 'updateTime'
|
|
|
+>[] = [
|
|
|
+ {
|
|
|
+ disease: '慢性胃炎',
|
|
|
+ syndrome: '脾胃虚寒型',
|
|
|
+ therapy: '温中健脾,和胃止痛',
|
|
|
+ prescription: '理中汤加减',
|
|
|
+ createBy: '王刚',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ disease: '失眠',
|
|
|
+ syndrome: '心脾两虚型',
|
|
|
+ therapy: '益气补血,健脾养心',
|
|
|
+ prescription: '归脾汤加减',
|
|
|
+ createBy: '张许',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ disease: '高血压',
|
|
|
+ syndrome: '肝阳上亢型',
|
|
|
+ therapy: '平肝潜阳,滋阴降火',
|
|
|
+ prescription: '天麻钩藤饮加减',
|
|
|
+ createBy: '李虎',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ disease: '糖尿病',
|
|
|
+ syndrome: '气阴两虚型',
|
|
|
+ therapy: '益气养阴,生津止渴',
|
|
|
+ prescription: '生脉散合玉液汤加减',
|
|
|
+ createBy: '王刚',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ disease: '咳嗽',
|
|
|
+ syndrome: '风寒袭肺型',
|
|
|
+ therapy: '疏风散寒,宣肺止咳',
|
|
|
+ prescription: '三拗汤加减',
|
|
|
+ createBy: '张许',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ disease: '头痛',
|
|
|
+ syndrome: '肝阳上亢型',
|
|
|
+ therapy: '平肝潜阳,滋阴降火',
|
|
|
+ prescription: '天麻钩藤饮加减',
|
|
|
+ createBy: '李虎',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+function createInitialStore(): TreatmentPlanDTO[] {
|
|
|
+ const records: TreatmentPlanDTO[] = [];
|
|
|
+ for (let index = 0; index < 58; index += 1) {
|
|
|
+ const seed = SEED_RECORDS[index % SEED_RECORDS.length] ?? SEED_RECORDS[0];
|
|
|
+ if (!seed) continue;
|
|
|
+ const day = String((index % 28) + 1).padStart(2, '0');
|
|
|
+ const month = String((index % 12) + 1).padStart(2, '0');
|
|
|
+ records.push({
|
|
|
+ ...seed,
|
|
|
+ id: String(index + 1),
|
|
|
+ personalStudioId: '327477138296832',
|
|
|
+ createTime: `2026-${month}-${day}T10:00:00`,
|
|
|
+ updateTime: `2026-05-${day}T10:00:00`,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return records;
|
|
|
+}
|
|
|
+
|
|
|
+let nextId = 100;
|
|
|
+let store = createInitialStore();
|
|
|
+
|
|
|
+function delay<T>(runner: () => Promise<T> | T, ms = 120): MethodLike<T> {
|
|
|
+ const run = async () => {
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
+ return runner();
|
|
|
+ };
|
|
|
+ const promise = run();
|
|
|
+ return Object.assign(promise, { send: run });
|
|
|
+}
|
|
|
+
|
|
|
+function matchKeyword(record: TreatmentPlanDTO, keyword?: string) {
|
|
|
+ if (!keyword) return true;
|
|
|
+ const text = [
|
|
|
+ record.disease,
|
|
|
+ record.syndrome,
|
|
|
+ record.therapy,
|
|
|
+ record.prescription,
|
|
|
+ record.createBy,
|
|
|
+ ]
|
|
|
+ .filter(Boolean)
|
|
|
+ .join(' ');
|
|
|
+ return text.includes(keyword);
|
|
|
+}
|
|
|
+
|
|
|
+function matchWorkroom(record: TreatmentPlanDTO, workroomId?: string) {
|
|
|
+ if (!workroomId) return true;
|
|
|
+ return String(record.personalStudioId ?? '') === String(workroomId);
|
|
|
+}
|
|
|
+
|
|
|
+function toVo(dto: TreatmentPlanDTO): TreatmentPlanVO {
|
|
|
+ return decodeTreatmentPlan(dto);
|
|
|
+}
|
|
|
+
|
|
|
+export function mockListTreatmentPlanMethod(...args: PageQueryMethodArgs) {
|
|
|
+ const { params, data } = pageQueryArgsTransform(
|
|
|
+ args,
|
|
|
+ encodeTreatmentPlanQuery,
|
|
|
+ );
|
|
|
+ const pageNum = Number(params.pageNum ?? 1);
|
|
|
+ const pageSize = Number(params.pageSize ?? 10);
|
|
|
+ const keyword = data.mixture;
|
|
|
+ const workroomId = data.personalStudioId?.toString();
|
|
|
+
|
|
|
+ const filtered = store.filter(
|
|
|
+ (record) =>
|
|
|
+ matchKeyword(record, keyword) && matchWorkroom(record, workroomId),
|
|
|
+ );
|
|
|
+ const start = (pageNum - 1) * pageSize;
|
|
|
+ const items = filtered
|
|
|
+ .slice(start, start + pageSize)
|
|
|
+ .map((record) => toVo(record));
|
|
|
+
|
|
|
+ const result: PageVO<TreatmentPlanVO> = {
|
|
|
+ total: filtered.length,
|
|
|
+ items,
|
|
|
+ };
|
|
|
+ return delay(() => result);
|
|
|
+}
|
|
|
+
|
|
|
+export function mockGetTreatmentPlanMethod(vo: Partial<TreatmentPlanVO>) {
|
|
|
+ return delay(() => {
|
|
|
+ const record = store.find((item) => String(item.id) === String(vo.id));
|
|
|
+ if (!record) {
|
|
|
+ throw new Error('诊疗方案不存在');
|
|
|
+ }
|
|
|
+ return toVo(record);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function mockEditTreatmentPlanMethod(vo: TreatmentPlanSubmitVO) {
|
|
|
+ return delay(() => {
|
|
|
+ const dto = encodeTreatmentPlan(vo);
|
|
|
+ const now = new Date().toISOString();
|
|
|
+
|
|
|
+ if (vo.id) {
|
|
|
+ const index = store.findIndex(
|
|
|
+ (item) => String(item.id) === String(vo.id),
|
|
|
+ );
|
|
|
+ if (index === -1) {
|
|
|
+ throw new Error('诊疗方案不存在');
|
|
|
+ }
|
|
|
+ store[index] = {
|
|
|
+ ...store[index],
|
|
|
+ ...dto,
|
|
|
+ updateTime: now,
|
|
|
+ };
|
|
|
+ return String(vo.id);
|
|
|
+ }
|
|
|
+
|
|
|
+ const id = String(nextId++);
|
|
|
+ store.unshift({
|
|
|
+ ...dto,
|
|
|
+ id,
|
|
|
+ createBy: dto.createBy ?? '当前用户',
|
|
|
+ createTime: now,
|
|
|
+ updateTime: now,
|
|
|
+ });
|
|
|
+ return id;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function mockDeleteTreatmentPlanMethod(vo: Pick<TreatmentPlanVO, 'id'>) {
|
|
|
+ return delay(() => {
|
|
|
+ const before = store.length;
|
|
|
+ store = store.filter((item) => String(item.id) !== String(vo.id));
|
|
|
+ if (store.length === before) {
|
|
|
+ throw new Error('诊疗方案不存在');
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function mockListTherapyMethod(...args: PageQueryMethodArgs) {
|
|
|
+ const { params, data } = pageQueryArgsTransform(args);
|
|
|
+ const pageNum = Number(params.pageNum ?? 1);
|
|
|
+ const pageSize = Number(params.pageSize ?? 10);
|
|
|
+ const keyword = String(data.keyWord ?? data.keyword ?? '').trim();
|
|
|
+
|
|
|
+ const items = MOCK_THERAPY_OPTIONS.filter((name) =>
|
|
|
+ keyword ? name.includes(keyword) : true,
|
|
|
+ ).map((name, index) => ({
|
|
|
+ id: String(index + 1),
|
|
|
+ name,
|
|
|
+ code: String(index + 1),
|
|
|
+ }));
|
|
|
+
|
|
|
+ const start = (pageNum - 1) * pageSize;
|
|
|
+ const result: PageVO<(typeof items)[number]> = {
|
|
|
+ total: items.length,
|
|
|
+ items: items.slice(start, start + pageSize),
|
|
|
+ };
|
|
|
+ return delay(() => result);
|
|
|
+}
|
|
|
+
|
|
|
+/** 仅用于本地调试,重置 mock 数据 */
|
|
|
+export function resetTreatmentPlanMockStore() {
|
|
|
+ nextId = 100;
|
|
|
+ store = createInitialStore();
|
|
|
+}
|