gbformdesign 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,190 +1,181 @@
1
- /**
2
- * 组件模板配置
3
- */
4
- import { COMPONENT_TYPES } from './componentTypes.js'
5
-
6
- // 基础组件
7
- export const BASIC_COMPONENT_TEMPLATES = [
8
- {
9
- name: '文本输入框',
10
- type: COMPONENT_TYPES.INPUT,
11
- icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="5" width="18" height="14" rx="2"/><line x1="7" y1="12" x2="17" y2="12"/><line x1="7" y1="9" x2="10" y2="9"/></svg>',
12
- value: '',
13
- required: true,
14
- defaultValue: '',
15
- props: {
16
- label: '文本输入框',
17
- variableName: '',
18
- placeholder: '请输入文本'
19
- },
20
- style: {
21
- width: '100%'
22
- }
23
- },
24
- {
25
- name: '多行文本',
26
- type: COMPONENT_TYPES.TEXTAREA,
27
- icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="7" y1="9" x2="17" y2="9"/><line x1="7" y1="12" x2="17" y2="12"/><line x1="7" y1="15" x2="13" y2="15"/></svg>',
28
- value: '',
29
- required: true,
30
- defaultValue: '',
31
- props: {
32
- label: '多行文本',
33
- variableName: '',
34
- placeholder: '请输入内容',
35
- rows: 3
36
- },
37
- style: {
38
- width: '100%'
39
- }
40
- },
41
- {
42
- name: '数字输入框',
43
- type: COMPONENT_TYPES.INPUT_NUMBER,
44
- icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="5" width="18" height="14" rx="2"/><line x1="7" y1="10" x2="7" y2="14"/><line x1="10" y1="10" x2="10" y2="14"/><line x1="13" y1="10" x2="13" y2="14"/></svg>',
45
- value: null,
46
- required: true,
47
- min: 1,
48
- max: 100,
49
- defaultValue: 1,
50
- props: {
51
- label: '数字输入框',
52
- variableName: '',
53
- placeholder: '请输入数字'
54
- },
55
- style: {
56
- width: '100%'
57
- }
58
- },
59
- {
60
- name: '单选框',
61
- type: COMPONENT_TYPES.RADIO_GROUP,
62
- icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="4" fill="currentColor"/></svg>',
63
- value: '',
64
- required: true,
65
- defaultValue: '1',
66
- props: {
67
- label: '单选框',
68
- variableName: '',
69
- options: [
70
- { label: '选项1', value: '1' },
71
- { label: '选项2', value: '2' },
72
- { label: '选项3', value: '3' }
73
- ]
74
- },
75
- style: {
76
- width: '100%'
77
- }
78
- },
79
- {
80
- name: '下拉选择',
81
- type: COMPONENT_TYPES.SELECT,
82
- icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="5" width="18" height="14" rx="2"/><polyline points="8 10 12 14 16 10"/></svg>',
83
- value: '',
84
- required: true,
85
- defaultValue: '',
86
- props: {
87
- label: '下拉选择',
88
- variableName: '',
89
- placeholder: '请选择',
90
- options: [
91
- { label: '选项1', value: '1' },
92
- { label: '选项2', value: '2' },
93
- { label: '选项3', value: '3' }
94
- ]
95
- },
96
- style: {
97
- width: '100%'
98
- }
99
- },
100
- {
101
- name: '多选框',
102
- type: COMPONENT_TYPES.CHECKBOX_GROUP,
103
- icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="7" height="7" rx="1"/><polyline points="4.5 7.5 6 9 9 6"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="4" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg>',
104
- value: [],
105
- required: true,
106
- defaultValue: [],
107
- props: {
108
- label: '多选框',
109
- variableName: '',
110
- options: [
111
- { label: '选项1', value: '1' },
112
- { label: '选项2', value: '2' },
113
- { label: '选项3', value: '3' }
114
- ]
115
- },
116
- style: {
117
- width: '100%'
118
- }
119
- },
120
- {
121
- name: '开关',
122
- type: COMPONENT_TYPES.SWITCH,
123
- icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="7" width="20" height="10" rx="5"/><circle cx="16" cy="12" r="3" fill="currentColor"/></svg>',
124
- value: false,
125
- required: false,
126
- defaultValue: false,
127
- props: {
128
- label: '开关',
129
- variableName: '',
130
- activeText: '是',
131
- inactiveText: '否'
132
- },
133
- style: {
134
- width: '100%'
135
- }
136
- },
137
- {
138
- name: '日期选择器',
139
- type: COMPONENT_TYPES.DATE_PICKER,
140
- icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="3" y1="10" x2="21" y2="10"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="16" y1="2" x2="16" y2="6"/><circle cx="12" cy="15" r="1.5" fill="currentColor"/></svg>',
141
- value: null,
142
- required: true,
143
- defaultValue: null,
144
- props: {
145
- label: '日期选择器',
146
- variableName: '',
147
- placeholder: '请选择日期'
148
- },
149
- style: {
150
- width: '100%'
151
- }
152
- }
153
- ]
154
-
155
- // 布局组件
156
- export const LAYOUT_COMPONENT_TEMPLATES = [
157
- {
158
- name: '分栏',
159
- type: COMPONENT_TYPES.ROW,
160
- icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="4" width="9" height="16" rx="1"/><rect x="13" y="4" width="9" height="16" rx="1"/></svg>',
161
- value: null,
162
- required: false,
163
- props: {
164
- gutter: 20,
165
- columns: [
166
- { span: 12 },
167
- { span: 12 }
168
- ]
169
- },
170
- style: {
171
- width: '100%'
172
- },
173
- children: []
174
- }
175
- ]
176
-
177
- // 组件分类配置
178
- export const COMPONENT_CATEGORIES = [
179
- {
180
- name: '基础组件',
181
- key: 'basic',
182
- templates: BASIC_COMPONENT_TEMPLATES
183
- },
184
- {
185
- name: '布局组件',
186
- key: 'layout',
187
- templates: LAYOUT_COMPONENT_TEMPLATES
188
- }
189
- ]
190
-
1
+ /**
2
+ * 组件模板配置
3
+ */
4
+ import { COMPONENT_TYPES } from './componentTypes.js'
5
+
6
+ // 基础组件
7
+ export const BASIC_COMPONENT_TEMPLATES = [
8
+ {
9
+ name: '文本输入框',
10
+ type: COMPONENT_TYPES.INPUT,
11
+ value: '',
12
+ required: true,
13
+ defaultValue: '',
14
+ props: {
15
+ label: '文本输入框',
16
+ variableName: '',
17
+ placeholder: '请输入文本'
18
+ },
19
+ style: {
20
+ width: '100%'
21
+ }
22
+ },
23
+ {
24
+ name: '多行文本',
25
+ type: COMPONENT_TYPES.TEXTAREA,
26
+ value: '',
27
+ required: true,
28
+ defaultValue: '',
29
+ props: {
30
+ label: '多行文本',
31
+ variableName: '',
32
+ placeholder: '请输入内容',
33
+ rows: 3
34
+ },
35
+ style: {
36
+ width: '100%'
37
+ }
38
+ },
39
+ {
40
+ name: '数字输入框',
41
+ type: COMPONENT_TYPES.INPUT_NUMBER,
42
+ value: null,
43
+ required: true,
44
+ min: 1,
45
+ max: 100,
46
+ defaultValue: 1,
47
+ props: {
48
+ label: '数字输入框',
49
+ variableName: '',
50
+ placeholder: '请输入数字'
51
+ },
52
+ style: {
53
+ width: '100%'
54
+ }
55
+ },
56
+ {
57
+ name: '单选框',
58
+ type: COMPONENT_TYPES.RADIO_GROUP,
59
+ value: '',
60
+ required: true,
61
+ defaultValue: '1',
62
+ props: {
63
+ label: '单选框',
64
+ variableName: '',
65
+ options: [
66
+ { label: '选项1', value: '1' },
67
+ { label: '选项2', value: '2' },
68
+ { label: '选项3', value: '3' }
69
+ ]
70
+ },
71
+ style: {
72
+ width: '100%'
73
+ }
74
+ },
75
+ {
76
+ name: '下拉选择',
77
+ type: COMPONENT_TYPES.SELECT,
78
+ value: '',
79
+ required: true,
80
+ defaultValue: '',
81
+ props: {
82
+ label: '下拉选择',
83
+ variableName: '',
84
+ placeholder: '请选择',
85
+ options: [
86
+ { label: '选项1', value: '1' },
87
+ { label: '选项2', value: '2' },
88
+ { label: '选项3', value: '3' }
89
+ ]
90
+ },
91
+ style: {
92
+ width: '100%'
93
+ }
94
+ },
95
+ {
96
+ name: '多选框',
97
+ type: COMPONENT_TYPES.CHECKBOX_GROUP,
98
+ value: [],
99
+ required: true,
100
+ defaultValue: [],
101
+ props: {
102
+ label: '多选框',
103
+ variableName: '',
104
+ options: [
105
+ { label: '选项1', value: '1' },
106
+ { label: '选项2', value: '2' },
107
+ { label: '选项3', value: '3' }
108
+ ]
109
+ },
110
+ style: {
111
+ width: '100%'
112
+ }
113
+ },
114
+ {
115
+ name: '开关',
116
+ type: COMPONENT_TYPES.SWITCH,
117
+ value: false,
118
+ required: false,
119
+ defaultValue: false,
120
+ props: {
121
+ label: '开关',
122
+ variableName: '',
123
+ activeText: '是',
124
+ inactiveText: '否'
125
+ },
126
+ style: {
127
+ width: '100%'
128
+ }
129
+ },
130
+ {
131
+ name: '日期选择器',
132
+ type: COMPONENT_TYPES.DATE_PICKER,
133
+ value: null,
134
+ required: true,
135
+ defaultValue: null,
136
+ props: {
137
+ label: '日期选择器',
138
+ variableName: '',
139
+ placeholder: '请选择日期'
140
+ },
141
+ style: {
142
+ width: '100%'
143
+ }
144
+ }
145
+ ]
146
+
147
+ // 布局组件
148
+ export const LAYOUT_COMPONENT_TEMPLATES = [
149
+ {
150
+ name: '分栏',
151
+ type: COMPONENT_TYPES.ROW,
152
+ value: null,
153
+ required: false,
154
+ props: {
155
+ gutter: 20,
156
+ columns: [
157
+ { span: 12 },
158
+ { span: 12 }
159
+ ]
160
+ },
161
+ style: {
162
+ width: '100%'
163
+ },
164
+ children: []
165
+ }
166
+ ]
167
+
168
+ // 组件分类配置
169
+ export const COMPONENT_CATEGORIES = [
170
+ {
171
+ name: '基础组件',
172
+ key: 'basic',
173
+ templates: BASIC_COMPONENT_TEMPLATES
174
+ },
175
+ {
176
+ name: '布局组件',
177
+ key: 'layout',
178
+ templates: LAYOUT_COMPONENT_TEMPLATES
179
+ }
180
+ ]
181
+
@@ -1,70 +1,70 @@
1
- /**
2
- * 组件类型常量定义
3
- */
4
-
5
- // 组件类型枚举
6
- export const COMPONENT_TYPES = {
7
- INPUT: 'input',
8
- TEXTAREA: 'textarea',
9
- INPUT_NUMBER: 'input-number',
10
- RADIO_GROUP: 'radio-group',
11
- CHECKBOX_GROUP: 'checkbox-group',
12
- SELECT: 'select',
13
- SWITCH: 'switch',
14
- DATE_PICKER: 'date-picker',
15
- ROW: 'row',
16
- BUTTON: 'button'
17
- }
18
-
19
- // 组件类型标签映射
20
- export const COMPONENT_TYPE_LABELS = {
21
- [COMPONENT_TYPES.INPUT]: '文本输入框',
22
- [COMPONENT_TYPES.TEXTAREA]: '多行文本',
23
- [COMPONENT_TYPES.INPUT_NUMBER]: '数字输入框',
24
- [COMPONENT_TYPES.RADIO_GROUP]: '单选框',
25
- [COMPONENT_TYPES.CHECKBOX_GROUP]: '多选框',
26
- [COMPONENT_TYPES.SELECT]: '下拉选择',
27
- [COMPONENT_TYPES.SWITCH]: '开关',
28
- [COMPONENT_TYPES.DATE_PICKER]: '日期选择器',
29
- [COMPONENT_TYPES.ROW]: '分栏',
30
- [COMPONENT_TYPES.BUTTON]: '按钮'
31
- }
32
-
33
- // 需要配置选项列表的组件类型
34
- export const OPTION_COMPONENT_TYPES = [
35
- COMPONENT_TYPES.RADIO_GROUP,
36
- COMPONENT_TYPES.CHECKBOX_GROUP,
37
- COMPONENT_TYPES.SELECT
38
- ]
39
-
40
- // 宽度预设值
41
- export const WIDTH_PRESETS = {
42
- FULL: 100,
43
- HALF: 50,
44
- THIRD: 33.33,
45
- QUARTER: 25
46
- }
47
-
48
- // 宽度比较容差
49
- export const WIDTH_TOLERANCE = 0.1
50
-
51
- // 默认配置
52
- export const DEFAULT_CONFIG = {
53
- MIN_NUMBER: 1,
54
- MAX_NUMBER: 100,
55
- DEFAULT_GUTTER: 20,
56
- DEFAULT_COLUMN_SPAN: 12,
57
- MIN_COLUMN_SPAN: 1,
58
- MAX_COLUMN_SPAN: 24,
59
- MIN_WIDTH: 10,
60
- MAX_WIDTH: 100,
61
- WIDTH_STEP: 5
62
- }
63
-
64
- // 日期默认值选项
65
- export const DATE_DEFAULT_OPTIONS = {
66
- TODAY: 'today',
67
- TOMORROW: 'tomorrow',
68
- NONE: ''
69
- }
70
-
1
+ /**
2
+ * 组件类型常量定义
3
+ */
4
+
5
+ // 组件类型枚举
6
+ export const COMPONENT_TYPES = {
7
+ INPUT: 'input',
8
+ TEXTAREA: 'textarea',
9
+ INPUT_NUMBER: 'input-number',
10
+ RADIO_GROUP: 'radio-group',
11
+ CHECKBOX_GROUP: 'checkbox-group',
12
+ SELECT: 'select',
13
+ SWITCH: 'switch',
14
+ DATE_PICKER: 'date-picker',
15
+ ROW: 'row',
16
+ BUTTON: 'button'
17
+ }
18
+
19
+ // 组件类型标签映射
20
+ export const COMPONENT_TYPE_LABELS = {
21
+ [COMPONENT_TYPES.INPUT]: '文本输入框',
22
+ [COMPONENT_TYPES.TEXTAREA]: '多行文本',
23
+ [COMPONENT_TYPES.INPUT_NUMBER]: '数字输入框',
24
+ [COMPONENT_TYPES.RADIO_GROUP]: '单选框',
25
+ [COMPONENT_TYPES.CHECKBOX_GROUP]: '多选框',
26
+ [COMPONENT_TYPES.SELECT]: '下拉选择',
27
+ [COMPONENT_TYPES.SWITCH]: '开关',
28
+ [COMPONENT_TYPES.DATE_PICKER]: '日期选择器',
29
+ [COMPONENT_TYPES.ROW]: '分栏',
30
+ [COMPONENT_TYPES.BUTTON]: '按钮'
31
+ }
32
+
33
+ // 需要配置选项列表的组件类型
34
+ export const OPTION_COMPONENT_TYPES = [
35
+ COMPONENT_TYPES.RADIO_GROUP,
36
+ COMPONENT_TYPES.CHECKBOX_GROUP,
37
+ COMPONENT_TYPES.SELECT
38
+ ]
39
+
40
+ // 宽度预设值
41
+ export const WIDTH_PRESETS = {
42
+ FULL: 100,
43
+ HALF: 50,
44
+ THIRD: 33.33,
45
+ QUARTER: 25
46
+ }
47
+
48
+ // 宽度比较容差
49
+ export const WIDTH_TOLERANCE = 0.1
50
+
51
+ // 默认配置
52
+ export const DEFAULT_CONFIG = {
53
+ MIN_NUMBER: 1,
54
+ MAX_NUMBER: 100,
55
+ DEFAULT_GUTTER: 20,
56
+ DEFAULT_COLUMN_SPAN: 12,
57
+ MIN_COLUMN_SPAN: 1,
58
+ MAX_COLUMN_SPAN: 24,
59
+ MIN_WIDTH: 10,
60
+ MAX_WIDTH: 100,
61
+ WIDTH_STEP: 5
62
+ }
63
+
64
+ // 日期默认值选项
65
+ export const DATE_DEFAULT_OPTIONS = {
66
+ TODAY: 'today',
67
+ TOMORROW: 'tomorrow',
68
+ NONE: ''
69
+ }
70
+
@@ -1,75 +1,75 @@
1
- /**
2
- * 组件工具函数
3
- */
4
-
5
- /**
6
- * 生成唯一的组件ID
7
- */
8
- export function generateComponentId() {
9
- return `component_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
10
- }
11
-
12
- /**
13
- * 确保组件有唯一ID
14
- */
15
- export function ensureComponentId(component) {
16
- if (!component.id) {
17
- component.id = generateComponentId()
18
- }
19
- return component
20
- }
21
-
22
- /**
23
- * 规范化数字值
24
- */
25
- export function normalizeNumberValue(value) {
26
- if (value === null || value === undefined || value === '') {
27
- return null
28
- }
29
- const num = Number(value)
30
- return isNaN(num) ? null : num
31
- }
32
-
33
- /**
34
- * 检查值是否为空
35
- */
36
- export function isEmpty(value) {
37
- return value === null || value === undefined || value === ''
38
- }
39
-
40
- /**
41
- * 规范化选项数组(将字符串选项转换为对象格式)
42
- */
43
- export function normalizeOptions(options) {
44
- if (!Array.isArray(options)) {
45
- return []
46
- }
47
- return options.map(opt => {
48
- if (typeof opt === 'string') {
49
- return { label: opt, value: opt }
50
- }
51
- return { ...opt }
52
- })
53
- }
54
-
55
- /**
56
- * 解析宽度值(从字符串或数字转换为数字)
57
- */
58
- export function parseWidth(width, defaultValue = 100) {
59
- if (width === undefined || width === null) {
60
- return defaultValue
61
- }
62
- if (typeof width === 'number') {
63
- return width
64
- }
65
- const widthStr = String(width).replace('%', '')
66
- const parsed = parseFloat(widthStr)
67
- return isNaN(parsed) ? defaultValue : parsed
68
- }
69
-
70
- /**
71
- * 获取字段名
72
- */
73
- export function getFieldName(component) {
74
- return component.props?.variableName || `field_${component.id || Date.now()}`
75
- }
1
+ /**
2
+ * 组件工具函数
3
+ */
4
+
5
+ /**
6
+ * 生成唯一的组件ID
7
+ */
8
+ export function generateComponentId() {
9
+ return `component_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
10
+ }
11
+
12
+ /**
13
+ * 确保组件有唯一ID
14
+ */
15
+ export function ensureComponentId(component) {
16
+ if (!component.id) {
17
+ component.id = generateComponentId()
18
+ }
19
+ return component
20
+ }
21
+
22
+ /**
23
+ * 规范化数字值
24
+ */
25
+ export function normalizeNumberValue(value) {
26
+ if (value === null || value === undefined || value === '') {
27
+ return null
28
+ }
29
+ const num = Number(value)
30
+ return isNaN(num) ? null : num
31
+ }
32
+
33
+ /**
34
+ * 检查值是否为空
35
+ */
36
+ export function isEmpty(value) {
37
+ return value === null || value === undefined || value === ''
38
+ }
39
+
40
+ /**
41
+ * 规范化选项数组(将字符串选项转换为对象格式)
42
+ */
43
+ export function normalizeOptions(options) {
44
+ if (!Array.isArray(options)) {
45
+ return []
46
+ }
47
+ return options.map(opt => {
48
+ if (typeof opt === 'string') {
49
+ return { label: opt, value: opt }
50
+ }
51
+ return { ...opt }
52
+ })
53
+ }
54
+
55
+ /**
56
+ * 解析宽度值(从字符串或数字转换为数字)
57
+ */
58
+ export function parseWidth(width, defaultValue = 100) {
59
+ if (width === undefined || width === null) {
60
+ return defaultValue
61
+ }
62
+ if (typeof width === 'number') {
63
+ return width
64
+ }
65
+ const widthStr = String(width).replace('%', '')
66
+ const parsed = parseFloat(widthStr)
67
+ return isNaN(parsed) ? defaultValue : parsed
68
+ }
69
+
70
+ /**
71
+ * 获取字段名
72
+ */
73
+ export function getFieldName(component) {
74
+ return component.props?.variableName || `field_${component.id || Date.now()}`
75
+ }