@epic-designer/antd 1.0.5

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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chunks/button.cjs +44 -0
  3. package/dist/chunks/button.mjs +42 -0
  4. package/dist/chunks/card.cjs +39 -0
  5. package/dist/chunks/card.mjs +37 -0
  6. package/dist/chunks/col.cjs +39 -0
  7. package/dist/chunks/col.mjs +37 -0
  8. package/dist/chunks/datePicker.cjs +47 -0
  9. package/dist/chunks/datePicker.mjs +45 -0
  10. package/dist/chunks/form.cjs +116 -0
  11. package/dist/chunks/form.mjs +114 -0
  12. package/dist/chunks/formItem.cjs +24 -0
  13. package/dist/chunks/formItem.mjs +22 -0
  14. package/dist/chunks/modal.cjs +136 -0
  15. package/dist/chunks/modal.mjs +134 -0
  16. package/dist/chunks/row.cjs +39 -0
  17. package/dist/chunks/row.mjs +37 -0
  18. package/dist/chunks/uploadFile.cjs +138 -0
  19. package/dist/chunks/uploadFile.mjs +136 -0
  20. package/dist/chunks/uploadImage.cjs +152 -0
  21. package/dist/chunks/uploadImage.mjs +150 -0
  22. package/dist/index.cjs +3047 -0
  23. package/dist/index.d.cts +5 -0
  24. package/dist/index.d.mts +5 -0
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.mjs +3045 -0
  27. package/package.json +38 -0
  28. package/src/button/button.vue +19 -0
  29. package/src/button/index.ts +204 -0
  30. package/src/card/card.ts +38 -0
  31. package/src/card/index.ts +65 -0
  32. package/src/cascader/cascader.vue +24 -0
  33. package/src/cascader/index.ts +201 -0
  34. package/src/checkbox/index.ts +101 -0
  35. package/src/col/col.ts +38 -0
  36. package/src/col/index.ts +22 -0
  37. package/src/color-picker/index.ts +109 -0
  38. package/src/date-picker/datePicker.ts +48 -0
  39. package/src/date-picker/index.ts +301 -0
  40. package/src/form/form.vue +153 -0
  41. package/src/form/index.ts +196 -0
  42. package/src/form-item/formItem.vue +12 -0
  43. package/src/form-item/index.ts +10 -0
  44. package/src/index.less +33 -0
  45. package/src/index.ts +131 -0
  46. package/src/input/index.ts +171 -0
  47. package/src/input-number/index.ts +182 -0
  48. package/src/input-password/index.ts +154 -0
  49. package/src/modal/index.ts +20 -0
  50. package/src/modal/modal.vue +98 -0
  51. package/src/radio/index.ts +107 -0
  52. package/src/row/index.ts +116 -0
  53. package/src/row/row.ts +38 -0
  54. package/src/select/index.ts +231 -0
  55. package/src/slider/index.ts +145 -0
  56. package/src/switch/index.ts +143 -0
  57. package/src/textarea/index.ts +164 -0
  58. package/src/time-picker/index.ts +192 -0
  59. package/src/upload-file/index.ts +90 -0
  60. package/src/upload-file/uploadFile.vue +145 -0
  61. package/src/upload-image/index.ts +71 -0
  62. package/src/upload-image/uploadImage.vue +167 -0
package/src/col/col.ts ADDED
@@ -0,0 +1,38 @@
1
+ import type { ComponentSchema } from '@epic-designer/types';
2
+
3
+ import type { PropType } from 'vue';
4
+
5
+ import { defineComponent, h, renderSlot } from 'vue';
6
+
7
+ import { Col } from 'ant-design-vue';
8
+
9
+ export default defineComponent({
10
+ props: {
11
+ componentSchema: {
12
+ default: () => ({}),
13
+ require: true,
14
+ type: Object as PropType<ComponentSchema>,
15
+ },
16
+ },
17
+ setup(props, { slots }) {
18
+ return () => {
19
+ const componentSchema = {
20
+ ...props.componentSchema,
21
+ title: props.componentSchema?.label ?? '',
22
+ } as any;
23
+ const children = componentSchema.children;
24
+ delete componentSchema.children;
25
+
26
+ return h(Col, componentSchema, {
27
+ default: () =>
28
+ renderSlot(slots, 'edit-node', {}, () =>
29
+ children.map((subcomponentSchema: ComponentSchema) =>
30
+ renderSlot(slots, 'node', {
31
+ componentSchema: subcomponentSchema,
32
+ }),
33
+ ),
34
+ ),
35
+ });
36
+ };
37
+ },
38
+ });
@@ -0,0 +1,22 @@
1
+ import type { ComponentConfigModel } from '@epic-designer/types';
2
+
3
+ export default {
4
+ component: () => import('./col'),
5
+ config: {
6
+ attribute: [
7
+ {
8
+ field: 'componentProps.span',
9
+ label: '占位格数',
10
+ type: 'number',
11
+ },
12
+ ],
13
+ },
14
+ defaultSchema: {
15
+ componentProps: {
16
+ span: 6,
17
+ },
18
+ label: '栅格布局-列',
19
+ type: 'col',
20
+ children: [],
21
+ },
22
+ } as ComponentConfigModel;
@@ -0,0 +1,109 @@
1
+ import type { ComponentConfigModel } from '@epic-designer/types';
2
+
3
+ export default {
4
+ bindModel: 'value',
5
+ component: async () => (await import('ant-design-vue')).Input,
6
+ config: {
7
+ action: [],
8
+ attribute: [
9
+ {
10
+ field: 'field',
11
+ label: '字段名',
12
+ type: 'input',
13
+ },
14
+ {
15
+ field: 'label',
16
+ label: '标题',
17
+ type: 'input',
18
+ },
19
+ {
20
+ field: 'componentProps.defaultValue',
21
+ label: '默认值',
22
+ type: 'input',
23
+ },
24
+ {
25
+ componentProps: {
26
+ allowClear: true,
27
+ options: [
28
+ {
29
+ label: '大号',
30
+ value: 'large',
31
+ },
32
+ {
33
+ label: '中等',
34
+ value: 'middle',
35
+ },
36
+ {
37
+ label: '小型',
38
+ value: 'small',
39
+ },
40
+ ],
41
+ placeholder: '请选择',
42
+ },
43
+ field: 'componentProps.size',
44
+ label: '尺寸',
45
+ type: 'select',
46
+ },
47
+ {
48
+ componentProps: {
49
+ checkedValue: false,
50
+ unCheckedValue: true,
51
+ },
52
+ field: 'componentProps.bordered',
53
+ label: '无边框',
54
+ type: 'switch',
55
+ },
56
+ {
57
+ field: 'componentProps.allowClear',
58
+ label: '可清空',
59
+ type: 'switch',
60
+ },
61
+ {
62
+ field: 'componentProps.disabled',
63
+ label: '禁用',
64
+ type: 'switch',
65
+ },
66
+ {
67
+ field: 'componentProps.hidden',
68
+ label: '隐藏',
69
+ type: 'switch',
70
+ },
71
+ {
72
+ description: '校验规则需要配合表单使用',
73
+ field: 'rules',
74
+ label: '表单校验',
75
+ layout: 'vertical',
76
+ type: 'ERuleEditor',
77
+ },
78
+ ],
79
+ event: [
80
+ {
81
+ description: '值修改时',
82
+ type: 'change',
83
+ },
84
+ {
85
+ description: '获取焦点时',
86
+ type: 'focus',
87
+ },
88
+ {
89
+ description: '失去焦点时',
90
+ type: 'blur',
91
+ },
92
+ ],
93
+ },
94
+ defaultSchema: {
95
+ componentProps: {
96
+ style: {
97
+ width: '80px',
98
+ },
99
+ type: 'color',
100
+ },
101
+ field: 'color-picker',
102
+ input: true,
103
+ label: '颜色选择器',
104
+ type: 'color-picker',
105
+ },
106
+ groupName: '表单',
107
+ icon: 'icon--epic--palette-outline',
108
+ sort: 950,
109
+ } as ComponentConfigModel;
@@ -0,0 +1,48 @@
1
+ import { defineComponent, h, watch } from 'vue';
2
+
3
+ import { DatePicker } from 'ant-design-vue';
4
+ // 二次封装组件
5
+ export default defineComponent({
6
+ emits: ['update:modelValue', 'change', 'blur'],
7
+ name: 'EDatePicker',
8
+ props: {
9
+ modelValue: {
10
+ default: null,
11
+ type: [String, Object, Array],
12
+ },
13
+ type: {
14
+ default: 'date',
15
+ type: String,
16
+ },
17
+ },
18
+ setup(props, { emit }) {
19
+ watch(
20
+ () => props.type,
21
+ () => {
22
+ handleUpdate();
23
+ },
24
+ );
25
+
26
+ function handleUpdate(e = null): void {
27
+ emit('update:modelValue', e);
28
+ emit('change', e);
29
+ emit('blur', e);
30
+ }
31
+ return () => {
32
+ let cmp: any = DatePicker;
33
+
34
+ const compProps: Record<string, any> = {
35
+ 'onUpdate:value': handleUpdate,
36
+ picker: props.type.replace(/range$/, ''),
37
+ showTime: props.type.includes('time'),
38
+ value: props.modelValue,
39
+ };
40
+
41
+ // 判断日期类型,渲染相应组件
42
+ if (props.type.includes('range')) {
43
+ cmp = DatePicker.RangePicker;
44
+ }
45
+ return h(cmp, compProps);
46
+ };
47
+ },
48
+ });
@@ -0,0 +1,301 @@
1
+ import type { ComponentConfigModel } from '@epic-designer/types';
2
+
3
+ export default {
4
+ bindModel: 'modelValue',
5
+ component: () => import('./datePicker'),
6
+ config: {
7
+ attribute: [
8
+ {
9
+ field: 'field',
10
+ label: '字段名',
11
+ type: 'input',
12
+ },
13
+ {
14
+ componentProps: {
15
+ placeholder: '请输入',
16
+ },
17
+ field: 'label',
18
+ label: '标题',
19
+ type: 'input',
20
+ },
21
+ {
22
+ field: 'componentProps.defaultValue',
23
+ label: '默认值',
24
+ type: 'date',
25
+ },
26
+ {
27
+ changeSync: true,
28
+ componentProps: {
29
+ options: [
30
+ {
31
+ label: '日期',
32
+ value: 'date',
33
+ },
34
+ {
35
+ label: '周',
36
+ value: 'week',
37
+ },
38
+ {
39
+ label: '月份',
40
+ value: 'month',
41
+ },
42
+ {
43
+ label: '季度',
44
+ value: 'quarter',
45
+ },
46
+ {
47
+ label: '年份',
48
+ value: 'year',
49
+ },
50
+ {
51
+ label: '日期范围',
52
+ value: 'daterange',
53
+ },
54
+ {
55
+ label: '周范围',
56
+ value: 'weekrange',
57
+ },
58
+ {
59
+ label: '月份范围',
60
+ value: 'monthrange',
61
+ },
62
+ {
63
+ label: '季度范围',
64
+ value: 'quarterrange',
65
+ },
66
+ {
67
+ label: '年份范围',
68
+ value: 'yearrange',
69
+ },
70
+ ],
71
+ },
72
+ field: 'componentProps.type',
73
+ label: '日期类型',
74
+ onChange({ value, values }) {
75
+ values.componentProps.defaultValue = null;
76
+ values.componentProps.placeholder = [
77
+ 'daterange',
78
+ 'monthrange',
79
+ 'quarterrange',
80
+ 'weekrange',
81
+ 'yearrange',
82
+ ].includes(value)
83
+ ? ['请输入', '请输入']
84
+ : '请输入';
85
+
86
+ if (['date', 'daterange'].includes(value)) {
87
+ values.componentProps.format = 'YYYY-MM-DD';
88
+ values.componentProps.valueFormat = 'YYYY-MM-DD';
89
+ } else if (['week', 'weekrange'].includes(value)) {
90
+ values.componentProps.format = 'ww [周]';
91
+ values.componentProps.valueFormat = 'YYYY-MM-DD';
92
+ } else if (['month', 'monthrange'].includes(value)) {
93
+ values.componentProps.format = 'YYYY-MM';
94
+ values.componentProps.valueFormat = 'YYYY-MM';
95
+ } else if (['quarter', 'quarterrange'].includes(value)) {
96
+ values.componentProps.format = 'YYYY-Q季度';
97
+ values.componentProps.valueFormat = 'YYYY-Q季度';
98
+ } else if (['"yearrange"', 'year'].includes(value)) {
99
+ values.componentProps.format = 'YYYY';
100
+ values.componentProps.valueFormat = 'YYYY';
101
+ }
102
+ },
103
+ type: 'select',
104
+ },
105
+ {
106
+ field: 'componentProps.showTime',
107
+ label: '增加时间选择',
108
+ onChange: ({ value, values }) => {
109
+ if (value) {
110
+ values.componentProps.valueFormat = 'YYYY-MM-DD HH:mm:ss';
111
+ values.componentProps.format = 'YYYY-MM-DD HH:mm:ss';
112
+ } else {
113
+ values.componentProps.valueFormat = 'YYYY-MM-DD';
114
+ values.componentProps.format = 'YYYY-MM-DD';
115
+ }
116
+ },
117
+ show({ values }) {
118
+ return ['date', 'daterange'].includes(values.componentProps.type);
119
+ },
120
+ type: 'switch',
121
+ },
122
+ {
123
+ componentProps: {
124
+ placeholder: '请输入',
125
+ },
126
+ field: 'componentProps.placeholder',
127
+ label: '占位内容',
128
+ show: ({ values }) =>
129
+ ![
130
+ 'daterange',
131
+ 'monthrange',
132
+ 'quarterrange',
133
+ 'weekrange',
134
+ 'yearrange',
135
+ ].includes(values.componentProps.type),
136
+ type: 'input',
137
+ },
138
+ {
139
+ componentProps: {
140
+ placeholder: '请输入',
141
+ },
142
+ field: 'componentProps.placeholder.0',
143
+ label: '开始占位符',
144
+ show: ({ values }) =>
145
+ [
146
+ 'daterange',
147
+ 'monthrange',
148
+ 'quarterrange',
149
+ 'weekrange',
150
+ 'yearrange',
151
+ ].includes(values.componentProps.type),
152
+ type: 'input',
153
+ },
154
+
155
+ {
156
+ componentProps: {
157
+ placeholder: '请输入',
158
+ },
159
+ field: 'componentProps.placeholder.1',
160
+ label: '结束占位符',
161
+ show: ({ values }) =>
162
+ [
163
+ 'daterange',
164
+ 'monthrange',
165
+ 'quarterrange',
166
+ 'weekrange',
167
+ 'yearrange',
168
+ ].includes(values.componentProps.type),
169
+ type: 'input',
170
+ },
171
+ {
172
+ componentProps: {
173
+ placeholder: '请输入',
174
+ },
175
+ field: 'componentProps.format',
176
+ label: '显示格式',
177
+ type: 'input',
178
+ },
179
+ {
180
+ componentProps: {
181
+ placeholder: '请输入',
182
+ },
183
+ field: 'componentProps.valueFormat',
184
+ label: '数据格式',
185
+ type: 'input',
186
+ },
187
+ {
188
+ componentProps: {
189
+ allowClear: true,
190
+ options: [
191
+ {
192
+ label: '大号',
193
+ value: 'large',
194
+ },
195
+ {
196
+ label: '中等',
197
+ value: 'middle',
198
+ },
199
+ {
200
+ label: '小型',
201
+ value: 'small',
202
+ },
203
+ ],
204
+ placeholder: '请选择',
205
+ },
206
+ field: 'componentProps.size',
207
+ label: '尺寸',
208
+ type: 'select',
209
+ },
210
+
211
+ {
212
+ componentProps: {
213
+ allowClear: true,
214
+ options: [
215
+ {
216
+ label: 'bottomLeft',
217
+ value: 'bottomLeft',
218
+ },
219
+ {
220
+ label: 'bottomRight',
221
+ value: 'bottomRight',
222
+ },
223
+ {
224
+ label: 'topLeft',
225
+ value: 'topLeft',
226
+ },
227
+ {
228
+ label: 'topRight',
229
+ value: 'topRight',
230
+ },
231
+ ],
232
+ placeholder: '请选择',
233
+ },
234
+ field: 'componentProps.placement',
235
+ label: '弹出框位置',
236
+ type: 'select',
237
+ },
238
+ {
239
+ componentProps: {
240
+ checkedValue: false,
241
+ unCheckedValue: true,
242
+ },
243
+ field: 'componentProps.bordered',
244
+ label: '无边框',
245
+ type: 'switch',
246
+ },
247
+ {
248
+ field: 'componentProps.inputReadOnly',
249
+ label: '禁止键盘输入',
250
+ type: 'switch',
251
+ },
252
+ {
253
+ field: 'componentProps.allowClear',
254
+ label: '可清空',
255
+ type: 'switch',
256
+ },
257
+ {
258
+ field: 'componentProps.disabled',
259
+ label: '禁用',
260
+ type: 'switch',
261
+ },
262
+ {
263
+ field: 'componentProps.hidden',
264
+ label: '隐藏',
265
+ type: 'switch',
266
+ },
267
+ {
268
+ description: '校验规则需要配合表单使用',
269
+ field: 'rules',
270
+ label: '表单校验',
271
+ layout: 'vertical',
272
+ type: 'ERuleEditor',
273
+ },
274
+ ],
275
+ event: [
276
+ {
277
+ description: '值变化时',
278
+ type: 'change',
279
+ },
280
+ {
281
+ description: '点击确定按钮时',
282
+ type: 'ok',
283
+ },
284
+ ],
285
+ },
286
+ defaultSchema: {
287
+ componentProps: {
288
+ format: 'YYYY-MM-DD',
289
+ placeholder: '请选择',
290
+ type: 'date',
291
+ valueFormat: 'YYYY-MM-DD',
292
+ },
293
+ field: 'date',
294
+ input: true,
295
+ label: '日期选择器',
296
+ type: 'date',
297
+ },
298
+ groupName: '表单',
299
+ icon: 'icon--epic--calendar-month-outline-rounded',
300
+ sort: 910,
301
+ } as ComponentConfigModel;
@@ -0,0 +1,153 @@
1
+ <script lang="ts" setup>
2
+ import type { PageManager } from '@epic-designer/manager';
3
+ import type {
4
+ ComponentSchema,
5
+ DesignerProps,
6
+ FormDataModel,
7
+ } from '@epic-designer/types';
8
+
9
+ import type { VNode } from 'vue';
10
+
11
+ import { computed, inject, provide, ref } from 'vue';
12
+
13
+ import { Form } from 'ant-design-vue';
14
+
15
+ interface FormInstance extends InstanceType<typeof Form> {
16
+ getData?: () => FormDataModel;
17
+ scrollToField: (name: string) => void;
18
+ setData?: (data: FormDataModel) => void;
19
+ validate: () => Promise<unknown>;
20
+ validateFields: () => Promise<unknown>;
21
+ }
22
+
23
+ defineOptions({
24
+ inheritAttrs: false,
25
+ });
26
+
27
+ const props = withDefaults(
28
+ defineProps<{
29
+ componentSchema: ComponentSchema;
30
+ scrollToFirstError?: boolean;
31
+ }>(),
32
+ {
33
+ componentSchema: () => ({ type: '' }),
34
+ scrollToFirstError: false,
35
+ },
36
+ );
37
+
38
+ const designerProps = inject<DesignerProps>('designerProps');
39
+ const pageManager = inject<PageManager>('pageManager', {} as PageManager);
40
+ const form = ref<FormInstance | null>(null);
41
+ const forms = inject<{ [name: string]: any }>('forms', {});
42
+ const formData = pageManager.setFormData(
43
+ {},
44
+ props.componentSchema?.componentProps?.name,
45
+ );
46
+ provide('formData', formData);
47
+
48
+ /**
49
+ * 获取表单数据
50
+ */
51
+ function getData(): FormDataModel {
52
+ return formData;
53
+ }
54
+
55
+ /**
56
+ * 校验表单数据
57
+ */
58
+ async function validate() {
59
+ try {
60
+ return await form.value?.validateFields();
61
+ } catch (error) {
62
+ if (props.scrollToFirstError) {
63
+ // 滚动到第一个错误字段
64
+ form.value?.scrollToField(error.errorFields[0].name.toString());
65
+ }
66
+ throw error;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * 设置表单数据
72
+ * @param data
73
+ */
74
+ function setData(data: FormDataModel) {
75
+ Object.assign(formData, data);
76
+ }
77
+
78
+ // form组件需要特殊处理
79
+ const mountedForm = (vNode: VNode) => {
80
+ form.value = vNode.component?.exposed as FormInstance;
81
+
82
+ if (props.componentSchema?.type === 'form' && forms.value && form.value) {
83
+ const name =
84
+ props.componentSchema?.componentProps?.name ??
85
+ props.componentSchema?.name ??
86
+ ('default' as string);
87
+
88
+ form.value.validate = validate;
89
+ forms.value[name] = form.value;
90
+ form.value.getData = getData;
91
+ form.value.setData = setData;
92
+ return false;
93
+ }
94
+ };
95
+
96
+ const componentProps = computed(() => {
97
+ const recordProps = props.componentSchema!.componentProps;
98
+ let labelCol = recordProps.labelCol;
99
+ let wrapperCol = recordProps.wrapperCol;
100
+ if (recordProps.layout === 'vertical') {
101
+ labelCol = wrapperCol = { span: 24 };
102
+ } else if (
103
+ recordProps.layout === 'inline' &&
104
+ recordProps.labelLayout === 'fixed'
105
+ ) {
106
+ // 处理内联固定label宽度导致换行问题
107
+ labelCol = {};
108
+ wrapperCol = { flex: 1 };
109
+ } else if (recordProps.labelLayout === 'fixed') {
110
+ // 兼容 旧版本 labelWidth 是 number 的情况
111
+ labelCol = {
112
+ flex: `${typeof recordProps.labelWidth === 'number' ? `${recordProps.labelWidth}px` : recordProps.labelWidth}`,
113
+ };
114
+ wrapperCol = { flex: 1 };
115
+ }
116
+
117
+ return {
118
+ ...recordProps,
119
+ labelCol,
120
+ wrapperCol,
121
+ };
122
+ });
123
+
124
+ function onFinish() {}
125
+
126
+ const children = computed(() => {
127
+ return props.componentSchema!.children ?? [];
128
+ });
129
+
130
+ defineExpose({
131
+ form,
132
+ getData,
133
+ setData,
134
+ validate,
135
+ });
136
+ </script>
137
+ <template>
138
+ <Form
139
+ :model="formData"
140
+ v-bind="componentProps"
141
+ @finish="onFinish"
142
+ :class="{ 'epic-form-mode': designerProps?.formMode }"
143
+ @vue:mounted="mountedForm"
144
+ >
145
+ <slot name="edit-node">
146
+ <slot
147
+ v-for="item in children"
148
+ name="node"
149
+ :component-schema="item"
150
+ ></slot>
151
+ </slot>
152
+ </Form>
153
+ </template>