刘光辉
3 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import type { WatermarkConfig, WatermarkPosition } from '#/api/x/dms/watermark';
 
export type PreviewOrientation = 'landscape' | 'portrait';
 
export function previewPage(position: WatermarkPosition, orientation: PreviewOrientation) {
  return orientation === 'landscape'
    ? { widthMm: position.paperHeightMm, heightMm: position.paperWidthMm, xMm: position.landscapeXMm, yMm: position.landscapeYMm }
    : { widthMm: position.paperWidthMm, heightMm: position.paperHeightMm, xMm: position.portraitXMm, yMm: position.portraitYMm };
}
 
export function previewContent(config: WatermarkConfig) {
  if (config.contentTemplate === '{/CUSTOM_BARCODE_TEXT}') return 'REC-2026-001';
  const samples: Record<string, string> = {
    CUN: '张三',
    CDN: '质控部',
    CDT: new Date().toLocaleString('zh-CN'),
    FILENAME: '示例文件.docx',
    FILENO: 'DOC-2026-001',
    VERSION: 'V1.0',
    FILESTATE: '受控',
    CurrPage: '1',
    TotalPage: '3',
  };
  return (config.contentTemplate || '').replaceAll(/\{\/([^}]+)\}/g, (token, name: string) => samples[name] ?? token);
}