createVNode.ts
3.51 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { AnyObject } from '@/types/global';
import { createVNode, Ref, VNode } from 'vue';
import { Form, FormItem, Input, InputNumber, Textarea, Modal, Select } from '@arco-design/web-vue';
import InputUpload from '@/components/input-upload/index.vue';
import { RenderContent } from '@arco-design/web-vue/es/_utils/types';
import { ModalConfig } from '@arco-design/web-vue/es/modal/interface';
import { set } from 'lodash';
export function createModalVNode(content: RenderContent, props?: object & Omit<ModalConfig, 'content'>) {
return Modal.open({
content,
titleAlign: 'start',
closable: false,
escToClose: false,
maskClosable: false,
okButtonProps: { size: 'small' },
cancelButtonProps: { size: 'small' },
...props,
});
}
export function createFormVNode(props?: AnyObject, children?: VNode | VNode[] | undefined): VNode {
return createVNode(Form, { autoLabelWidth: true, ...props }, () => children);
}
export function createFormItemVNode(props?: AnyObject, children?: string | VNode | VNode[]): VNode {
return createVNode(FormItem, { showColon: true, ...props }, () => children);
}
export function createSelectVNode(value: Ref, options: AnyObject[], props?: AnyObject): VNode {
return createVNode(Select, {
options,
'modelValue': value.value,
'placeholder': '请选择',
'onUpdate:modelValue': (val?: unknown) => set(value, 'value', val),
...props,
});
}
export function createSelectionFormItemVNode(value: Ref, options: AnyObject[], itemProps?: AnyObject, props?: AnyObject): VNode {
return createFormItemVNode(itemProps, createSelectVNode(value, options, props));
}
export function createInputVNode(value: Ref, props?: AnyObject): VNode {
return createVNode(Input, {
'modelValue': value.value,
'placeholder': '请输入',
'onUpdate:modelValue': (val?: string) => set(value, 'value', val || ''),
...props,
});
}
export function createInputFormItemVNode(value: Ref, itemProps?: AnyObject, props?: AnyObject): VNode {
return createFormItemVNode(itemProps, createInputVNode(value, props));
}
export function createInputNumberVNode(value: Ref, props?: AnyObject): VNode {
return createVNode(InputNumber, {
'modelValue': value.value,
'placeholder': '请输入',
'onUpdate:modelValue': (val?: string) => set(value, 'value', val || 0),
'min': 0,
'max': 255,
...props,
});
}
export function createInputNumberFormItemVNode(value: Ref, itemProps?: AnyObject, props?: AnyObject): VNode {
return createFormItemVNode(itemProps, createInputNumberVNode(value, props));
}
export function createTextareaVNode(value: Ref, props?: AnyObject) {
return createVNode(Textarea, {
'modelValue': value.value,
'placeholder': '请输入',
'onUpdate:modelValue': (val?: string) => set(value, 'value', val || 0),
'max-length': 500,
'show-word-limit': true,
'auto-size': { minRows: 3, maxRows: 6 },
...props,
});
}
export function createTextareaFormItemVNode(value: Ref, itemProps?: AnyObject, props?: AnyObject) {
return createFormItemVNode(itemProps, createTextareaVNode(value, props));
}
export function createInputUploadVNode(value: Ref, props?: AnyObject): VNode {
return createVNode(InputUpload, {
'modelValue': value.value,
'placeholder': '请选择',
'onUpdate:modelValue': (val?: string) => set(value, 'value', val || 0),
...props,
});
}
export function createInputUploadFormItemVNode(value: Ref, itemProps?: AnyObject, props?: AnyObject): VNode {
return createFormItemVNode(itemProps, createInputUploadVNode(value, props));
}