| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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 VideoCategory = 'clinical_skill' | 'clinical_teaching' | 'theory';
- export type VideoSortType = 'latest' | 'popular';
- export const VIDEO_CATEGORY_OPTIONS = [
- { label: '临床技能', value: 'clinical_skill' },
- { label: '临床教学', value: 'clinical_teaching' },
- { label: '理论讲解', value: 'theory' },
- ] as const satisfies ReadonlyArray<{
- label: string;
- value: VideoCategory;
- }>;
- export function getVideoCategoryLabel(category?: VideoCategory) {
- return (
- VIDEO_CATEGORY_OPTIONS.find((item) => item.value === category)?.label ?? ''
- );
- }
- // ---------------------------------------------------------------------------
- // DTO
- // ---------------------------------------------------------------------------
- export interface VideoDTO extends AuditRecordDTO {
- id?: number | string;
- personalStudioId?: number | string;
- videoName?: string;
- speakerName?: string;
- category?: VideoCategory;
- videoUrl?: string;
- videoFirstUrl?: string;
- duration?: string;
- viewCount?: number;
- status?: boolean;
- }
- export interface VideoQueryDTO {
- mixture?: string;
- personalStudioId?: number | string;
- category?: VideoCategory;
- sortType?: VideoSortType;
- pageNum?: number;
- pageSize?: number;
- }
- // ---------------------------------------------------------------------------
- // VO
- // ---------------------------------------------------------------------------
- export interface VideoVO extends AuditRecordVO {
- id?: string;
- workroomId: string;
- name: string;
- speaker?: string;
- category: VideoCategory;
- videoUrl?: string;
- thumbnailUrl?: string;
- duration?: string;
- viewCount?: number;
- status: boolean;
- }
- export type VideoSubmitVO = VideoVO;
- export interface VideoQueryVO {
- keyword?: string;
- workroomId?: string;
- category?: VideoCategory;
- sortType?: VideoSortType;
- }
- // ---------------------------------------------------------------------------
- // Schema
- // ---------------------------------------------------------------------------
- export const VideoVOSchema = z.object({
- id: z.string().optional(),
- workroomId: z.string().min(1, '工作室不能为空'),
- name: z.string().min(1, '请输入视频名称'),
- speaker: z.string().optional(),
- category: z.enum(['clinical_skill', 'clinical_teaching', 'theory'], {
- message: '请选择视频分类',
- }),
- status: z.boolean(),
- });
- // ---------------------------------------------------------------------------
- // 编解码
- // ---------------------------------------------------------------------------
- export function decodeVideo(dto: VideoDTO): VideoVO {
- return {
- ...decodeAuditRecord(dto),
- id: dto.id?.toString(),
- workroomId: dto.personalStudioId?.toString() ?? '',
- name: dto.videoName ?? '',
- speaker: dto.speakerName,
- category: dto.category ?? 'clinical_skill',
- videoUrl: dto.videoUrl,
- thumbnailUrl: dto.videoFirstUrl,
- duration: dto.duration,
- viewCount: dto.viewCount ?? 0,
- status: dto.status ?? true,
- };
- }
- export function encodeVideoQuery(query: Partial<VideoQueryVO>): VideoQueryDTO {
- return {
- mixture: query.keyword,
- personalStudioId: query.workroomId,
- category: query.category,
- sortType: query.sortType,
- };
- }
- export function encodeVideo(vo: VideoSubmitVO): VideoDTO {
- return {
- id: vo.id,
- personalStudioId: vo.workroomId,
- videoName: vo.name,
- speakerName: vo.speaker,
- category: vo.category,
- videoUrl: vo.videoUrl,
- videoFirstUrl: vo.thumbnailUrl,
- duration: vo.duration,
- status: vo.status,
- };
- }
- export function decodeVideoList(dto: VideoDTO[]) {
- return decodeList(dto, decodeVideo);
- }
|