97 lines
2.9 KiB
TypeScript
97 lines
2.9 KiB
TypeScript
import type { DebugPublishMeta } from '../../utils/debugPublish';
|
|
import { inferGradeFromAge } from '../../utils/debugPublish';
|
|
import {
|
|
PAPER_SHEET_WORKSHEET_DEFINITIONS,
|
|
PAPER_SHEET_WORKSHEET_ID,
|
|
PAPER_TYPES,
|
|
type PaperType,
|
|
} from '../../config/worksheets/papers';
|
|
|
|
export { PAPER_SHEET_WORKSHEET_ID, type PaperType };
|
|
export const PAPER_TYPE_OPTIONS = PAPER_TYPES;
|
|
|
|
const WORKSHEET_BY_ID = new Map(
|
|
PAPER_SHEET_WORKSHEET_DEFINITIONS.map((entry) => [entry.id, entry]),
|
|
);
|
|
|
|
/** 只接收已注册条目;旧综合入口继续支持 type,并兼容分享中的 mode。 */
|
|
export function resolvePaperEntry(options: {
|
|
id?: string;
|
|
type?: string;
|
|
mode?: string;
|
|
}) {
|
|
const id = options.id || PAPER_SHEET_WORKSHEET_ID;
|
|
const entry = WORKSHEET_BY_ID.get(id);
|
|
if (!entry) throw new Error('当前作业纸暂不可用,请更新小程序');
|
|
const legacyType = options.type || options.mode;
|
|
const paperType =
|
|
entry.renderConfig.paperType ||
|
|
(legacyType && isValidPaperType(legacyType)
|
|
? legacyType
|
|
: DEFAULT_PAPER_TYPE);
|
|
return { entry, paperType };
|
|
}
|
|
|
|
export function getWorksheetIdForPaperType(paperType: PaperType): string {
|
|
return PAPER_SHEET_WORKSHEET_DEFINITIONS.find(
|
|
(entry) => entry.renderConfig.paperType === paperType,
|
|
)!.id;
|
|
}
|
|
|
|
export interface PaperColorOption {
|
|
id: string;
|
|
name: string;
|
|
/** 主线条颜色 */
|
|
value: string;
|
|
}
|
|
|
|
/** 颜色选项:浅红、浅绿、黑色 */
|
|
export const PAPER_COLOR_OPTIONS: PaperColorOption[] = [
|
|
{ id: 'red', name: '浅红', value: '#E48A8A' },
|
|
{ id: 'green', name: '浅绿', value: '#7FB069' },
|
|
{ id: 'black', name: '黑色', value: '#333333' },
|
|
];
|
|
|
|
export const DEFAULT_PAPER_TYPE: PaperType = 'tian';
|
|
export const DEFAULT_PAPER_COLOR = PAPER_COLOR_OPTIONS[0].value;
|
|
|
|
export function getPaperTypeName(id: string): string {
|
|
return PAPER_TYPE_OPTIONS.find((p) => p.id === id)?.name || '作业纸';
|
|
}
|
|
|
|
export function isValidPaperType(id: string): id is PaperType {
|
|
return PAPER_TYPE_OPTIONS.some((p) => p.id === id);
|
|
}
|
|
|
|
export function getModeInfo(id: string) {
|
|
const m = WORKSHEET_BY_ID.get(id);
|
|
return m ? { title: m.title, desc: m.subtitle } : undefined;
|
|
}
|
|
|
|
export function isValidMode(id: string): boolean {
|
|
return WORKSHEET_BY_ID.has(id);
|
|
}
|
|
|
|
export function getPublishMetaByMode(id: string): DebugPublishMeta | null {
|
|
const m = WORKSHEET_BY_ID.get(id);
|
|
if (!m) return null;
|
|
return {
|
|
id: m.id,
|
|
title: m.title,
|
|
subtitle: m.subtitle,
|
|
category: 'papers',
|
|
subcategory: 'paper-sheet',
|
|
path: `/papersPages/paperSheet/paperSheet?id=${m.id}`,
|
|
ageMin: m.ageMin,
|
|
ageMax: m.ageMax,
|
|
grade: inferGradeFromAge(m.ageMin, m.ageMax),
|
|
difficulty: m.difficulty,
|
|
previewImg: '',
|
|
tags: [...m.tags],
|
|
isNew: true,
|
|
isHot: false,
|
|
sortOrder: m.sortOrder,
|
|
status: 'draft',
|
|
};
|
|
}
|