feat:作业纸

This commit is contained in:
R524809
2026-10-23 16:53:22 +08:00
parent fe1074e3f0
commit 98dc338848
14 changed files with 757 additions and 247 deletions
@@ -1,53 +1,42 @@
import type { DebugPublishMeta } from '../../utils/debugPublish';
import { inferGradeFromAge } from '../../utils/debugPublish';
import { PAPER_SHEET_WORKSHEET_DEFINITIONS } from '../../config/worksheets/papers';
import {
PAPER_SHEET_WORKSHEET_DEFINITIONS,
PAPER_SHEET_WORKSHEET_ID,
PAPER_TYPES,
type PaperType,
} from '../../config/worksheets/papers';
type PaperSheetWorksheetRow =
(typeof PAPER_SHEET_WORKSHEET_DEFINITIONS)[number];
export { PAPER_SHEET_WORKSHEET_ID, type PaperType };
export const PAPER_TYPE_OPTIONS = PAPER_TYPES;
const WORKSHEET_BY_ID = Object.fromEntries(
PAPER_SHEET_WORKSHEET_DEFINITIONS.map((m) => [m.id, m]),
) as Record<string, PaperSheetWorksheetRow>;
const WORKSHEET_BY_ID = new Map(
PAPER_SHEET_WORKSHEET_DEFINITIONS.map((entry) => [entry.id, entry]),
);
export const PAPER_SHEET_WORKSHEET_ID = PAPER_SHEET_WORKSHEET_DEFINITIONS[0].id;
/** 纸张类型 id */
export type PaperType =
| 'tian'
| 'mi'
| 'square'
| 'four-line'
| 'letter'
| 'horizontal'
| 'vertical'
| 'dictation-hanzi'
| 'dictation-pinyin'
| 'homework-log';
export interface PaperTypeOption {
id: PaperType;
name: string;
/** 次要说明 */
desc: string;
/** 只接收已注册条目;旧综合入口继续支持 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 const PAPER_TYPE_OPTIONS: PaperTypeOption[] = [
{ id: 'tian', name: '田字格', desc: '汉字练习' },
{ id: 'mi', name: '米字格', desc: '书法练习' },
{ id: 'square', name: '方格', desc: '书法练字纸' },
{ id: 'four-line', name: '四线三格', desc: '拼音 / 字母' },
{ id: 'letter', name: '信纸', desc: '横线信笺' },
{ id: 'horizontal', name: '横线', desc: '横线本' },
{ id: 'vertical', name: '竖线', desc: '竖排书写' },
{ id: 'dictation-hanzi', name: '汉字听写', desc: '田字格 + 订正栏' },
{
id: 'dictation-pinyin',
name: '拼音/英语听写',
desc: '四线三格 + 订正栏',
},
{ id: 'homework-log', name: '作业登记表', desc: '分科登记' },
];
export function getWorksheetIdForPaperType(paperType: PaperType): string {
return PAPER_SHEET_WORKSHEET_DEFINITIONS.find(
(entry) => entry.renderConfig.paperType === paperType,
)!.id;
}
export interface PaperColorOption {
id: string;
@@ -75,16 +64,16 @@ export function isValidPaperType(id: string): id is PaperType {
}
export function getModeInfo(id: string) {
const m = WORKSHEET_BY_ID[id];
const m = WORKSHEET_BY_ID.get(id);
return m ? { title: m.title, desc: m.subtitle } : undefined;
}
export function isValidMode(id: string): boolean {
return id in WORKSHEET_BY_ID;
return WORKSHEET_BY_ID.has(id);
}
export function getPublishMetaByMode(id: string): DebugPublishMeta | null {
const m = WORKSHEET_BY_ID[id];
const m = WORKSHEET_BY_ID.get(id);
if (!m) return null;
return {
id: m.id,