| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- import type {
- AuditRecordDTO,
- AuditRecordVO,
- } from '#/request/schema/audit-record';
- import { z } from '#/adapter/form';
- import { decodeList } from '#/request/schema';
- import { decodeAuditRecord } from '#/request/schema/audit-record';
- // ---------------------------------------------------------------------------
- // 枚举
- // ---------------------------------------------------------------------------
- export type PaperCategory = 'conference' | 'degree' | 'journal';
- /** 后端 `type` 字段:0-期刊论文 1-学位论文 2-会议论文 */
- export type PaperTypeDTO = '0' | '1' | '2';
- const PAPER_TYPE_TO_DTO: Record<PaperCategory, PaperTypeDTO> = {
- journal: '0',
- degree: '1',
- conference: '2',
- };
- const PAPER_TYPE_FROM_DTO: Record<PaperTypeDTO, PaperCategory> = {
- '0': 'journal',
- '1': 'degree',
- '2': 'conference',
- };
- export const PAPER_CATEGORY_OPTIONS = [
- { label: '期刊论文', value: 'journal' },
- { label: '学位论文', value: 'degree' },
- { label: '会议论文', value: 'conference' },
- ] as const satisfies ReadonlyArray<{
- label: string;
- value: PaperCategory;
- }>;
- export function getPaperCategoryLabel(category?: PaperCategory) {
- return (
- PAPER_CATEGORY_OPTIONS.find((item) => item.value === category)?.label ?? ''
- );
- }
- export function decodePaperType(type?: number | string): PaperCategory {
- const normalized = type?.toString();
- if (normalized === '0' || normalized === '1' || normalized === '2') {
- return PAPER_TYPE_FROM_DTO[normalized];
- }
- return 'journal';
- }
- /** 按 Tab 分类过滤分页结果(后端未按 type 过滤时的兜底) */
- export function filterPaperPageByCategory<
- T extends { items: PaperVO[]; total: number },
- >(page: T, category?: PaperCategory): T {
- if (!category) return page;
- const items = page.items.filter((item) => item.category === category);
- return { ...page, items };
- }
- function encodePaperType(category: PaperCategory): PaperTypeDTO {
- return PAPER_TYPE_TO_DTO[category];
- }
- // ---------------------------------------------------------------------------
- // DTO
- // ---------------------------------------------------------------------------
- /** 论文 DTO,对应 `OutcomePaperDetail` */
- export interface PaperDTO extends AuditRecordDTO {
- id?: number | string;
- status?: string;
- remark?: string;
- personalStudioId?: number | string;
- fileUrl?: string;
- downloadCount?: number;
- browseCount?: number;
- commentCount?: number;
- praiseCount?: number;
- /** 分类 0-期刊论文 1-学位论文 2-会议论文 */
- type?: PaperTypeDTO | string;
- title?: string;
- author?: string;
- journalName?: string;
- publishYear?: string;
- phase?: string;
- keyword?: string;
- }
- export interface PaperQueryDTO {
- mixture?: string;
- personalStudioId?: number | string;
- type?: PaperTypeDTO | string;
- status?: string;
- pageNum?: number;
- pageSize?: number;
- }
- // ---------------------------------------------------------------------------
- // VO
- // ---------------------------------------------------------------------------
- export interface PaperVO extends AuditRecordVO {
- id?: string;
- workroomId: string;
- category: PaperCategory;
- title: string;
- authors: string;
- journalName: string;
- publishYear: string;
- volumeInfo?: string;
- keywords?: string;
- pdfUrl?: string;
- downloadCount?: number;
- commentCount?: number;
- }
- export type PaperSubmitVO = PaperVO;
- export interface PaperQueryVO {
- keyword?: string;
- workroomId?: string;
- category?: PaperCategory;
- }
- // ---------------------------------------------------------------------------
- // Schema
- // ---------------------------------------------------------------------------
- export const PaperVOSchema = z.object({
- id: z.string().optional(),
- workroomId: z.string().min(1, '工作室不能为空'),
- category: z.enum(['journal', 'degree', 'conference'], {
- message: '请选择论文分类',
- }),
- title: z.string().min(1, '请输入论文标题'),
- authors: z.string().min(1, '请输入作者'),
- journalName: z.string().min(1, '请输入期刊名称'),
- publishYear: z.string().min(1, '请输入发表年份'),
- volumeInfo: z.string().optional(),
- keywords: z.string().optional(),
- });
- // ---------------------------------------------------------------------------
- // 编解码
- // ---------------------------------------------------------------------------
- export function decodePaper(dto: PaperDTO): PaperVO {
- return {
- ...decodeAuditRecord(dto),
- id: dto.id?.toString(),
- workroomId: dto.personalStudioId?.toString() ?? '',
- category: decodePaperType(dto.type),
- title: dto.title ?? '',
- authors: dto.author ?? '',
- journalName: dto.journalName ?? '',
- publishYear: dto.publishYear ?? '',
- volumeInfo: dto.phase,
- keywords: dto.keyword,
- pdfUrl: dto.fileUrl,
- downloadCount: dto.downloadCount ?? 0,
- commentCount: dto.commentCount ?? 0,
- };
- }
- export function encodePaperQuery(query: Partial<PaperQueryVO>): PaperQueryDTO {
- return {
- mixture: query.keyword,
- personalStudioId: query.workroomId,
- type: query.category ? encodePaperType(query.category) : undefined,
- };
- }
- export function encodePaper(vo: PaperSubmitVO): PaperDTO {
- return {
- id: vo.id,
- personalStudioId: vo.workroomId,
- fileUrl: vo.pdfUrl,
- type: encodePaperType(vo.category),
- title: vo.title,
- author: vo.authors,
- journalName: vo.journalName,
- publishYear: vo.publishYear,
- phase: vo.volumeInfo,
- keyword: vo.keywords,
- };
- }
- export function decodePaperList(dto: PaperDTO[]) {
- return decodeList(dto, decodePaper);
- }
|