|
|
@@ -0,0 +1,270 @@
|
|
|
+import type {
|
|
|
+ IntellectualPropertyDTO,
|
|
|
+ IntellectualPropertySubmitVO,
|
|
|
+ IntellectualPropertyVO,
|
|
|
+ PatentStatus,
|
|
|
+ PatentType,
|
|
|
+} from './intellectual-property.schema';
|
|
|
+
|
|
|
+import type { PageQueryMethodArgs } from '#/request/schema';
|
|
|
+import type { PageVO } from '#/request/schema/record';
|
|
|
+
|
|
|
+import { pageQueryArgsTransform } from '#/request/schema';
|
|
|
+
|
|
|
+import {
|
|
|
+ decodeIntellectualProperty,
|
|
|
+ encodeIntellectualProperty,
|
|
|
+ encodeIntellectualPropertyQuery,
|
|
|
+} from './intellectual-property.schema';
|
|
|
+
|
|
|
+/** 后端接口就绪后改为 false */
|
|
|
+export const USE_INTELLECTUAL_PROPERTY_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<
|
|
|
+ IntellectualPropertyDTO,
|
|
|
+ 'createTime' | 'id' | 'personalStudioId' | 'updateTime'
|
|
|
+>[] = [
|
|
|
+ {
|
|
|
+ patentNumber: 'CN202310123456.7',
|
|
|
+ title: '一种治疗慢性胃炎的中药复方制剂',
|
|
|
+ patentType: 'invention',
|
|
|
+ inventors: '张三, 李四, 王五',
|
|
|
+ applicationDate: '2023-03-15',
|
|
|
+ status: 'rejected',
|
|
|
+ authorizationDate: '2024-06-20',
|
|
|
+ commentCount: 5,
|
|
|
+ createBy: '张三',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ patentNumber: 'CN202410234567.8',
|
|
|
+ title: '基于人工智能的中医诊断辅助系统',
|
|
|
+ patentType: 'invention',
|
|
|
+ inventors: '赵六, 钱七',
|
|
|
+ applicationDate: '2024-01-10',
|
|
|
+ status: 'under_review',
|
|
|
+ authorizationDate: '2025-02-28',
|
|
|
+ commentCount: 3,
|
|
|
+ createBy: '赵六',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ patentNumber: 'CN202210345678.9',
|
|
|
+ title: '改进型针灸治疗仪',
|
|
|
+ patentType: 'utility_model',
|
|
|
+ inventors: '孙八, 周九',
|
|
|
+ applicationDate: '2022-08-22',
|
|
|
+ status: 'authorized',
|
|
|
+ authorizationDate: '2023-05-18',
|
|
|
+ commentCount: 8,
|
|
|
+ createBy: '孙八',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ patentNumber: 'CN202310456789.0',
|
|
|
+ title: '一种中药提取装置',
|
|
|
+ patentType: 'utility_model',
|
|
|
+ inventors: '吴十, 郑十一',
|
|
|
+ applicationDate: '2023-06-01',
|
|
|
+ status: 'authorized',
|
|
|
+ authorizationDate: '2024-03-12',
|
|
|
+ commentCount: 2,
|
|
|
+ createBy: '吴十',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ patentNumber: 'CN202410567890.1',
|
|
|
+ title: '便携式脉诊仪外观设计',
|
|
|
+ patentType: 'design',
|
|
|
+ inventors: '王十二',
|
|
|
+ applicationDate: '2024-02-14',
|
|
|
+ status: 'under_review',
|
|
|
+ authorizationDate: '2025-01-20',
|
|
|
+ commentCount: 1,
|
|
|
+ createBy: '王十二',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ patentNumber: 'CN202210678901.2',
|
|
|
+ title: '一种艾灸烟雾净化装置',
|
|
|
+ patentType: 'utility_model',
|
|
|
+ inventors: '李十三, 张十四',
|
|
|
+ applicationDate: '2022-11-05',
|
|
|
+ status: 'authorized',
|
|
|
+ authorizationDate: '2023-09-30',
|
|
|
+ commentCount: 6,
|
|
|
+ createBy: '李十三',
|
|
|
+ fileUrl: MOCK_PDF_URL,
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+function createInitialStore(): IntellectualPropertyDTO[] {
|
|
|
+ const records: IntellectualPropertyDTO[] = [];
|
|
|
+ for (let index = 0; index < 12; 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: IntellectualPropertyDTO, keyword?: string) {
|
|
|
+ if (!keyword) return true;
|
|
|
+ const text = [
|
|
|
+ record.title,
|
|
|
+ record.patentNumber,
|
|
|
+ record.inventors,
|
|
|
+ record.createBy,
|
|
|
+ ]
|
|
|
+ .filter(Boolean)
|
|
|
+ .join(' ');
|
|
|
+ return text.includes(keyword);
|
|
|
+}
|
|
|
+
|
|
|
+function matchWorkroom(record: IntellectualPropertyDTO, workroomId?: string) {
|
|
|
+ if (!workroomId) return true;
|
|
|
+ return String(record.personalStudioId ?? '') === String(workroomId);
|
|
|
+}
|
|
|
+
|
|
|
+function matchPatentType(
|
|
|
+ record: IntellectualPropertyDTO,
|
|
|
+ patentType?: PatentType,
|
|
|
+) {
|
|
|
+ if (!patentType) return true;
|
|
|
+ return record.patentType === patentType;
|
|
|
+}
|
|
|
+
|
|
|
+function matchStatus(record: IntellectualPropertyDTO, status?: PatentStatus) {
|
|
|
+ if (!status) return true;
|
|
|
+ return record.status === status;
|
|
|
+}
|
|
|
+
|
|
|
+function toVo(dto: IntellectualPropertyDTO): IntellectualPropertyVO {
|
|
|
+ return decodeIntellectualProperty(dto);
|
|
|
+}
|
|
|
+
|
|
|
+export function mockListIntellectualPropertyMethod(
|
|
|
+ ...args: PageQueryMethodArgs
|
|
|
+) {
|
|
|
+ const { params, data } = pageQueryArgsTransform(
|
|
|
+ args,
|
|
|
+ encodeIntellectualPropertyQuery,
|
|
|
+ );
|
|
|
+ const pageNum = Number(params.pageNum ?? 1);
|
|
|
+ const pageSize = Number(params.pageSize ?? 10);
|
|
|
+ const keyword = data.mixture;
|
|
|
+ const workroomId = data.personalStudioId?.toString();
|
|
|
+ const patentType = data.patentType;
|
|
|
+ const status = data.status;
|
|
|
+
|
|
|
+ const filtered = store.filter(
|
|
|
+ (record) =>
|
|
|
+ matchKeyword(record, keyword) &&
|
|
|
+ matchWorkroom(record, workroomId) &&
|
|
|
+ matchPatentType(record, patentType) &&
|
|
|
+ matchStatus(record, status),
|
|
|
+ );
|
|
|
+ const start = (pageNum - 1) * pageSize;
|
|
|
+ const items = filtered
|
|
|
+ .slice(start, start + pageSize)
|
|
|
+ .map((record) => toVo(record));
|
|
|
+
|
|
|
+ const result: PageVO<IntellectualPropertyVO> = {
|
|
|
+ total: filtered.length,
|
|
|
+ items,
|
|
|
+ };
|
|
|
+ return delay(() => result);
|
|
|
+}
|
|
|
+
|
|
|
+export function mockGetIntellectualPropertyMethod(
|
|
|
+ vo: Partial<IntellectualPropertyVO>,
|
|
|
+) {
|
|
|
+ return delay(() => {
|
|
|
+ const record = store.find((item) => String(item.id) === String(vo.id));
|
|
|
+ if (!record) {
|
|
|
+ throw new Error('专利不存在');
|
|
|
+ }
|
|
|
+ return toVo(record);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function mockEditIntellectualPropertyMethod(
|
|
|
+ vo: IntellectualPropertySubmitVO,
|
|
|
+) {
|
|
|
+ return delay(() => {
|
|
|
+ const dto = encodeIntellectualProperty(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,
|
|
|
+ commentCount: 0,
|
|
|
+ createBy: dto.createBy ?? '当前用户',
|
|
|
+ createTime: now,
|
|
|
+ updateTime: now,
|
|
|
+ });
|
|
|
+ return id;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function mockDeleteIntellectualPropertyMethod(
|
|
|
+ vo: Pick<IntellectualPropertyVO, '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 resetIntellectualPropertyMockStore() {
|
|
|
+ nextId = 100;
|
|
|
+ store = createInitialStore();
|
|
|
+}
|