108 lines
3.3 KiB
TypeScript
108 lines
3.3 KiB
TypeScript
import type { DebugPublishMeta } from '../../utils/debugPublish';
|
|
import { inferGradeFromAge } from '../../utils/debugPublish';
|
|
import { PAPER_SHEET_WORKSHEET_DEFINITIONS } from '../../config/worksheets/papers';
|
|
|
|
type PaperSheetWorksheetRow =
|
|
(typeof PAPER_SHEET_WORKSHEET_DEFINITIONS)[number];
|
|
|
|
const WORKSHEET_BY_ID = Object.fromEntries(
|
|
PAPER_SHEET_WORKSHEET_DEFINITIONS.map((m) => [m.id, m]),
|
|
) as Record<string, PaperSheetWorksheetRow>;
|
|
|
|
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;
|
|
}
|
|
|
|
/** 纸张类型选项(展示顺序与用户需求一致) */
|
|
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 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[id];
|
|
return m ? { title: m.title, desc: m.subtitle } : undefined;
|
|
}
|
|
|
|
export function isValidMode(id: string): boolean {
|
|
return id in WORKSHEET_BY_ID;
|
|
}
|
|
|
|
export function getPublishMetaByMode(id: string): DebugPublishMeta | null {
|
|
const m = WORKSHEET_BY_ID[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',
|
|
};
|
|
}
|