diff --git a/src/types/template.ts b/src/types/template.ts new file mode 100644 index 0000000..b8f7560 --- /dev/null +++ b/src/types/template.ts @@ -0,0 +1,109 @@ +// 对齐方式 +export type Align = 'left' | 'center' | 'right'; + +// 字体大小 +export type FontSize = 'small' | 'normal' | 'large' | 'xlarge'; + +// 条码格式 +export type BarcodeFormat = 'CODE128' | 'QR' | 'EAN13'; + +// 基础样式 +export interface BlockStyle { + align?: Align; + fontSize?: FontSize; + bold?: boolean; + italic?: boolean; + underline?: boolean; + lineHeight?: number; + marginTop?: number; + marginBottom?: number; +} + +// 列定义 +export interface Column { + content?: string; + align?: Align; + width?: string | number; + bold?: boolean; + header?: string; +} + +// Block 类型 +export interface TextBlock extends BlockStyle { + type: 'text'; + content: string; +} + +export interface RowBlock extends BlockStyle { + type: 'row'; + columns: Column[]; +} + +export interface TableBlock extends BlockStyle { + type: 'table'; + columns: Column[]; + data: string; // mustache expression +} + +export interface ListBlock extends BlockStyle { + type: 'list'; + data: string; // mustache expression + itemTemplate: Block[]; +} + +export interface DividerBlock extends BlockStyle { + type: 'divider'; + char?: string; +} + +export interface ImageBlock extends BlockStyle { + type: 'image'; + src: string; // mustache expression or URL + maxWidth?: number; +} + +export interface BarcodeBlock extends BlockStyle { + type: 'barcode'; + format: BarcodeFormat; + data: string; // mustache expression + height?: number; +} + +export interface SpaceBlock extends BlockStyle { + type: 'space'; + lines?: number; +} + +export type Block = + | TextBlock + | RowBlock + | TableBlock + | ListBlock + | DividerBlock + | ImageBlock + | BarcodeBlock + | SpaceBlock; + +// 页面设置 +export interface PageConfig { + marginTop?: number; + marginBottom?: number; +} + +// 默认样式 +export interface DefaultStyle { + fontSize?: FontSize; + lineHeight?: number; + marginBottom?: number; +} + +// 完整模板 +export interface Template { + id: string; + name: string; + description?: string; + width: string; // e.g., "80mm" + page?: PageConfig; + defaults?: DefaultStyle; + blocks: Block[]; +}