Blame view

美国版/Food Labeling Management Platform/src/components/labels/LabelTemplateEditor/ElementsPanel.tsx 4.2 KB
884054fb   “wangming”   项目初始化
1
2
  import React from 'react';
  import { ScrollArea } from '../../ui/scroll-area';
143afd59   杨鑫   打印,标签
3
  import type { ElementLibraryCategory, ElementType } from '../../../types/labelTemplate';
884054fb   “wangming”   项目初始化
4
5
6
  
  /** 左侧标签库:四类分组(与产品图一致);打印时输入项可带 config 以正确显示为 input */
  const ELEMENT_CATEGORIES: {
143afd59   杨鑫   打印,标签
7
    title: ElementLibraryCategory;
884054fb   “wangming”   项目初始化
8
9
10
11
    subtitle?: string;
    items: { label: string; type: ElementType; config?: Record<string, unknown> }[];
  }[] = [
    {
58d2e61c   杨鑫   最新代码
12
      title: 'Template',
884054fb   “wangming”   项目初始化
13
14
15
16
17
18
19
20
21
22
23
      items: [
        { label: 'Text', type: 'TEXT_STATIC' },
        { label: 'QR Code', type: 'QRCODE' },
        { label: 'Barcode', type: 'BARCODE' },
        { label: 'Blank Space', type: 'BLANK' },
        { label: 'Price', type: 'TEXT_PRICE' },
        { label: 'Image', type: 'IMAGE' },
        { label: 'Logo', type: 'IMAGE' },
      ],
    },
    {
58d2e61c   杨鑫   最新代码
24
      title: 'Label',
884054fb   “wangming”   项目初始化
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
      items: [
        { label: 'Label Name', type: 'TEXT_PRODUCT' },
        { label: 'Text', type: 'TEXT_STATIC' },
        { label: 'QR Code', type: 'QRCODE' },
        { label: 'Barcode', type: 'BARCODE' },
        { label: 'Nutrition Facts', type: 'NUTRITION' },
        { label: 'Price', type: 'TEXT_PRICE' },
        { label: 'Duration Date', type: 'DATE' },
        { label: 'Duration Time', type: 'TIME' },
        { label: 'Duration', type: 'DURATION' },
        { label: 'Image', type: 'IMAGE' },
        { label: 'Label Type', type: 'TEXT_STATIC' },
        { label: 'How-to', type: 'TEXT_STATIC' },
        { label: 'Expiration Alert', type: 'TEXT_STATIC' },
      ],
    },
    {
58d2e61c   杨鑫   最新代码
42
      title: 'Auto-generated',
884054fb   “wangming”   项目初始化
43
44
45
46
47
48
49
50
51
      items: [
        { label: 'Company', type: 'TEXT_STATIC' },
        { label: 'Employee', type: 'TEXT_STATIC' },
        { label: 'Current Date', type: 'DATE' },
        { label: 'Current Time', type: 'TIME' },
        { label: 'Label ID', type: 'TEXT_STATIC' },
      ],
    },
    {
58d2e61c   杨鑫   最新代码
52
53
      title: 'Print input',
      subtitle: 'Click to add to canvas',
884054fb   “wangming”   项目初始化
54
55
56
57
      items: [
        { label: 'Text', type: 'TEXT_STATIC', config: { inputType: 'text' } },
        { label: 'Weight', type: 'WEIGHT' },
        { label: 'Number', type: 'TEXT_STATIC', config: { inputType: 'number', text: '0' } },
58d2e61c   杨鑫   最新代码
58
        { label: 'Date & Time', type: 'DATE', config: { inputType: 'datetime', format: 'YYYY-MM-DD HH:mm' } },
3d4c10ac   杨鑫   对接,标签产品
59
60
61
62
63
64
65
        {
          label: 'Multiple Options',
          type: 'TEXT_STATIC',
          config: {
            inputType: 'options',
            multipleOptionId: '',
            selectedOptionValues: [],
58d2e61c   杨鑫   最新代码
66
            text: 'Text',
3d4c10ac   杨鑫   对接,标签产品
67
68
69
70
            fontFamily: 'Arial',
            fontSize: 14,
            fontWeight: 'normal',
            textAlign: 'left',
3d4c10ac   杨鑫   对接,标签产品
71
72
          },
        },
884054fb   “wangming”   项目初始化
73
74
75
76
77
      ],
    },
  ];
  
  interface ElementsPanelProps {
143afd59   杨鑫   打印,标签
78
79
80
81
82
83
    onAddElement: (
      type: ElementType,
      configOverride: Partial<Record<string, unknown>> | undefined,
      libraryCategory: ElementLibraryCategory,
      paletteItemLabel: string,
    ) => void;
884054fb   “wangming”   项目初始化
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  }
  
  export function ElementsPanel({ onAddElement }: ElementsPanelProps) {
    return (
      <div className="w-44 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full">
        <div className="px-2 py-2 border-b border-gray-200 font-semibold text-gray-800 text-sm">
          Elements
        </div>
        <ScrollArea className="flex-1">
          <div className="p-1.5 space-y-3">
            {ELEMENT_CATEGORIES.map((cat) => (
              <div key={cat.title}>
                <div className="px-2 py-1 text-xs font-medium text-gray-500 uppercase tracking-wide">
                  {cat.title}
                </div>
                {cat.subtitle && (
                  <div className="px-2 py-0.5 text-[10px] text-gray-400">
                    {cat.subtitle}
                  </div>
                )}
                <div className="grid grid-cols-2 gap-1 mt-0.5">
                  {cat.items.map((item, i) => (
                    <button
                      key={`${cat.title}-${item.label}-${i}`}
                      type="button"
143afd59   杨鑫   打印,标签
109
110
111
                      onClick={() =>
                        onAddElement(item.type, item.config, cat.title, item.label)
                      }
884054fb   “wangming”   项目初始化
112
113
114
115
116
117
118
119
120
121
122
123
124
                      className="text-left px-2 py-1 text-xs rounded hover:bg-gray-100 border border-transparent hover:border-gray-200 truncate"
                    >
                      {item.label}
                    </button>
                  ))}
                </div>
              </div>
            ))}
          </div>
        </ScrollArea>
      </div>
    );
  }