|
|
@@ -0,0 +1,252 @@
|
|
|
+import type {
|
|
|
+ PaperCategory,
|
|
|
+ PaperDTO,
|
|
|
+ PaperSubmitVO,
|
|
|
+ PaperVO,
|
|
|
+} from './paper.schema';
|
|
|
+
|
|
|
+import type { PageQueryMethodArgs } from '#/request/schema';
|
|
|
+import type { PageVO } from '#/request/schema/record';
|
|
|
+
|
|
|
+import { pageQueryArgsTransform } from '#/request/schema';
|
|
|
+
|
|
|
+import { decodePaper, encodePaper, encodePaperQuery } from './paper.schema';
|
|
|
+
|
|
|
+/** 后端接口就绪后改为 false */
|
|
|
+export const USE_PAPER_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 SEED_RECORDS: Omit<
|
|
|
+ PaperDTO,
|
|
|
+ 'createTime' | 'id' | 'personalStudioId' | 'updateTime'
|
|
|
+>[] = [
|
|
|
+ {
|
|
|
+ category: 'journal',
|
|
|
+ title: '中医药治疗慢性胃炎的临床研究',
|
|
|
+ authors: '王教授, 张主任, 李医师',
|
|
|
+ journalName: '中华中医药杂志',
|
|
|
+ publishYear: '2026',
|
|
|
+ volumeInfo: '第41卷第3期',
|
|
|
+ keywords: '中医药; 慢性胃炎; 临床研究',
|
|
|
+ downloadCount: 156,
|
|
|
+ commentCount: 8,
|
|
|
+ createBy: '王刚',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ category: 'journal',
|
|
|
+ title: '针灸联合推拿治疗腰椎间盘突出症的疗效观察',
|
|
|
+ authors: '李明, 赵华',
|
|
|
+ journalName: '中国针灸',
|
|
|
+ publishYear: '2025',
|
|
|
+ volumeInfo: '第45卷第12期',
|
|
|
+ keywords: '针灸; 推拿; 腰椎间盘突出',
|
|
|
+ downloadCount: 89,
|
|
|
+ commentCount: 5,
|
|
|
+ createBy: '张许',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ category: 'degree',
|
|
|
+ title: '基于数据挖掘的方剂配伍规律研究',
|
|
|
+ authors: '陈思远',
|
|
|
+ journalName: '北京中医药大学',
|
|
|
+ publishYear: '2024',
|
|
|
+ volumeInfo: '博士学位论文',
|
|
|
+ keywords: '数据挖掘; 方剂; 配伍规律',
|
|
|
+ downloadCount: 42,
|
|
|
+ commentCount: 3,
|
|
|
+ createBy: '李虎',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ category: 'conference',
|
|
|
+ title: '人工智能辅助中医辨证论治系统的设计与实现',
|
|
|
+ authors: '刘洋, 周敏, 孙伟',
|
|
|
+ journalName: '全国中医药信息学术年会',
|
|
|
+ publishYear: '2025',
|
|
|
+ volumeInfo: '2025年11月',
|
|
|
+ keywords: '人工智能; 中医辨证; 辅助诊疗',
|
|
|
+ downloadCount: 67,
|
|
|
+ commentCount: 12,
|
|
|
+ createBy: '王刚',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ category: 'journal',
|
|
|
+ title: '经典名方化裁治疗失眠的临床体会',
|
|
|
+ authors: '黄医师, 吴教授',
|
|
|
+ journalName: '中医杂志',
|
|
|
+ publishYear: '2025',
|
|
|
+ volumeInfo: '第66卷第8期',
|
|
|
+ keywords: '经典名方; 失眠; 临床体会',
|
|
|
+ downloadCount: 203,
|
|
|
+ commentCount: 15,
|
|
|
+ createBy: '张许',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ category: 'journal',
|
|
|
+ title: '中药外敷治疗膝骨关节炎的Meta分析',
|
|
|
+ authors: '郑研究员, 钱博士',
|
|
|
+ journalName: '中国中药杂志',
|
|
|
+ publishYear: '2024',
|
|
|
+ volumeInfo: '第49卷第6期',
|
|
|
+ keywords: '中药外敷; 膝骨关节炎; Meta分析',
|
|
|
+ downloadCount: 118,
|
|
|
+ commentCount: 6,
|
|
|
+ createBy: '李虎',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+function createInitialStore(): PaperDTO[] {
|
|
|
+ const records: PaperDTO[] = [];
|
|
|
+ for (let index = 0; index < 42; 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: PaperDTO, keyword?: string) {
|
|
|
+ if (!keyword) return true;
|
|
|
+ const text = [
|
|
|
+ record.title,
|
|
|
+ record.authors,
|
|
|
+ record.keywords,
|
|
|
+ record.journalName,
|
|
|
+ record.createBy,
|
|
|
+ ]
|
|
|
+ .filter(Boolean)
|
|
|
+ .join(' ');
|
|
|
+ return text.includes(keyword);
|
|
|
+}
|
|
|
+
|
|
|
+function matchWorkroom(record: PaperDTO, workroomId?: string) {
|
|
|
+ if (!workroomId) return true;
|
|
|
+ return String(record.personalStudioId ?? '') === String(workroomId);
|
|
|
+}
|
|
|
+
|
|
|
+function matchCategory(record: PaperDTO, category?: PaperCategory) {
|
|
|
+ if (!category) return true;
|
|
|
+ return record.category === category;
|
|
|
+}
|
|
|
+
|
|
|
+function toVo(dto: PaperDTO): PaperVO {
|
|
|
+ return decodePaper(dto);
|
|
|
+}
|
|
|
+
|
|
|
+export function mockListPaperMethod(...args: PageQueryMethodArgs) {
|
|
|
+ const { params, data } = pageQueryArgsTransform(args, encodePaperQuery);
|
|
|
+ const pageNum = Number(params.pageNum ?? 1);
|
|
|
+ const pageSize = Number(params.pageSize ?? 10);
|
|
|
+ const keyword = data.mixture;
|
|
|
+ const workroomId = data.personalStudioId?.toString();
|
|
|
+ const category = data.category;
|
|
|
+
|
|
|
+ const filtered = store.filter(
|
|
|
+ (record) =>
|
|
|
+ matchKeyword(record, keyword) &&
|
|
|
+ matchWorkroom(record, workroomId) &&
|
|
|
+ matchCategory(record, category),
|
|
|
+ );
|
|
|
+ const start = (pageNum - 1) * pageSize;
|
|
|
+ const items = filtered
|
|
|
+ .slice(start, start + pageSize)
|
|
|
+ .map((record) => toVo(record));
|
|
|
+
|
|
|
+ const result: PageVO<PaperVO> = {
|
|
|
+ total: filtered.length,
|
|
|
+ items,
|
|
|
+ };
|
|
|
+ return delay(() => result);
|
|
|
+}
|
|
|
+
|
|
|
+export function mockGetPaperMethod(vo: Partial<PaperVO>) {
|
|
|
+ return delay(() => {
|
|
|
+ const record = store.find((item) => String(item.id) === String(vo.id));
|
|
|
+ if (!record) {
|
|
|
+ throw new Error('论文不存在');
|
|
|
+ }
|
|
|
+ return toVo(record);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function mockEditPaperMethod(vo: PaperSubmitVO) {
|
|
|
+ return delay(() => {
|
|
|
+ const dto = encodePaper(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,
|
|
|
+ downloadCount: 0,
|
|
|
+ commentCount: 0,
|
|
|
+ createBy: dto.createBy ?? '当前用户',
|
|
|
+ createTime: now,
|
|
|
+ updateTime: now,
|
|
|
+ });
|
|
|
+ return id;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function mockDeletePaperMethod(vo: Pick<PaperVO, '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;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/** 仅用于本地调试,重置 mock 数据 */
|
|
|
+export function resetPaperMockStore() {
|
|
|
+ nextId = 100;
|
|
|
+ store = createInitialStore();
|
|
|
+}
|