@vxe-ui/plugin-render-antd 4.0.3 → 4.0.4

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.
@@ -0,0 +1,148 @@
1
+ import { defineComponent, h, PropType, resolveComponent, ComponentOptions } from 'vue'
2
+
3
+ import type { VxeUIExport, VxeGlobalRendererHandles, VxeFormComponent, VxeFormItemComponent, VxeSwitchComponent, VxeInputComponent } from 'vxe-pc-ui'
4
+
5
+ interface WidgetATextareaFormObjVO {
6
+ placeholder: string
7
+ }
8
+
9
+ export function createWidgetATextarea (VxeUI: VxeUIExport) {
10
+ const getWidgetATextareaConfig = (params: VxeGlobalRendererHandles.CreateFormDesignWidgetConfigParams): VxeGlobalRendererHandles.CreateFormDesignWidgetConfigObj<WidgetATextareaFormObjVO> => {
11
+ return {
12
+ title: '文本域',
13
+ icon: 'vxe-icon-textarea',
14
+ options: {
15
+ placeholder: '请输入'
16
+ }
17
+ }
18
+ }
19
+
20
+ const WidgetATextareaFormComponent = defineComponent({
21
+ props: {
22
+ renderOpts: {
23
+ type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewOptions>,
24
+ default: () => ({})
25
+ },
26
+ renderParams: {
27
+ type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewParams<WidgetATextareaFormObjVO>>,
28
+ default: () => ({})
29
+ }
30
+ },
31
+ emits: [],
32
+ setup (props) {
33
+ const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
34
+ const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
35
+ const VxeUISwitchComponent = VxeUI.getComponent<VxeSwitchComponent>('VxeSwitch')
36
+ const VxeUIInputComponent = VxeUI.getComponent<VxeInputComponent>('VxeInput')
37
+
38
+ return () => {
39
+ const { renderParams } = props
40
+ const { widget } = renderParams
41
+
42
+ return h(VxeUIFormComponent, {
43
+ class: 'vxe-form-design--widget-render-form-wrapper',
44
+ vertical: true,
45
+ span: 24,
46
+ titleBold: true,
47
+ titleOverflow: true,
48
+ data: widget.options
49
+ }, {
50
+ default () {
51
+ return [
52
+ h(VxeUIFormItemComponent, {
53
+ title: VxeUI.getI18n('vxe.formDesign.widgetProp.name')
54
+ }, {
55
+ default () {
56
+ return h(VxeUIInputComponent, {
57
+ modelValue: widget.title,
58
+ 'onUpdate:modelValue' (val: any) {
59
+ widget.title = val
60
+ }
61
+ })
62
+ }
63
+ }),
64
+ h(VxeUIFormItemComponent, {
65
+ title: VxeUI.getI18n('vxe.formDesign.widgetProp.placeholder'),
66
+ field: 'placeholder',
67
+ itemRender: { name: 'ElInput' }
68
+ }),
69
+ h(VxeUIFormItemComponent, {
70
+ title: VxeUI.getI18n('vxe.formDesign.widgetProp.required')
71
+ }, {
72
+ default () {
73
+ return h(VxeUISwitchComponent, {
74
+ modelValue: widget.required,
75
+ 'onUpdate:modelValue' (val: any) {
76
+ widget.required = val
77
+ }
78
+ })
79
+ }
80
+ })
81
+ ]
82
+ }
83
+ })
84
+ }
85
+ }
86
+ })
87
+
88
+ const WidgetATextareaViewComponent = defineComponent({
89
+ props: {
90
+ renderOpts: {
91
+ type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewOptions>,
92
+ default: () => ({})
93
+ },
94
+ renderParams: {
95
+ type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewParams<WidgetATextareaFormObjVO>>,
96
+ default: () => ({})
97
+ }
98
+ },
99
+ emits: [],
100
+ setup (props) {
101
+ const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
102
+
103
+ const changeEvent = () => {
104
+ const { renderParams } = props
105
+ const { widget, $formView } = renderParams
106
+ if ($formView) {
107
+ const itemValue = $formView ? $formView.getItemValue(widget) : null
108
+ $formView.updateItemStatus(widget, itemValue)
109
+ }
110
+ }
111
+
112
+ return () => {
113
+ const { renderParams } = props
114
+ const { widget, $formView } = renderParams
115
+ const { options } = widget
116
+
117
+ return h(VxeUIFormItemComponent, {
118
+ class: ['vxe-form-design--widget-render-form-item'],
119
+ field: widget.field,
120
+ title: widget.title
121
+ }, {
122
+ default () {
123
+ return h(resolveComponent('a-textarea') as ComponentOptions, {
124
+ value: $formView ? $formView.getItemValue(widget) : null,
125
+ placeholder: options.placeholder,
126
+ autoSize: {
127
+ minRows: 2,
128
+ maxRows: 4
129
+ },
130
+ onChange: changeEvent,
131
+ 'onUpdate:value' (val: any) {
132
+ if ($formView) {
133
+ $formView.setItemValue(widget, val)
134
+ }
135
+ }
136
+ })
137
+ }
138
+ })
139
+ }
140
+ }
141
+ })
142
+
143
+ return {
144
+ getWidgetATextareaConfig,
145
+ WidgetATextareaFormComponent,
146
+ WidgetATextareaViewComponent
147
+ }
148
+ }
@@ -0,0 +1,255 @@
1
+ import { VNode, h, onMounted, ref, watch } from 'vue'
2
+
3
+ import type { VxeUIExport, VxeGlobalRendererHandles, VxeFormItemComponent, VxeButtonComponent, VxeTextareaComponent, VxeTipComponent } from 'vxe-pc-ui'
4
+
5
+ export interface WidgetDataSourceOptionSubObjVO {
6
+ value: string,
7
+ }
8
+
9
+ export interface WidgetDataSourceOptionObjVO {
10
+ value: string,
11
+ options?: WidgetDataSourceOptionSubObjVO[]
12
+ }
13
+
14
+ export function useWidgetPropDataSource (VxeUI: VxeUIExport, props: {
15
+ readonly renderOpts: VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewOptions;
16
+ readonly renderParams: VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewParams<{
17
+ options: WidgetDataSourceOptionObjVO[]
18
+ }>;
19
+ }, isSubOption: boolean) {
20
+ const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
21
+ const VxeUIButtonComponent = VxeUI.getComponent<VxeButtonComponent>('VxeButton')
22
+ const VxeUITextareaComponent = VxeUI.getComponent<VxeTextareaComponent>('VxeTextarea')
23
+ const VxeUITipComponent = VxeUI.getComponent<VxeTipComponent>('VxeTip')
24
+
25
+ const optionsContent = ref('')
26
+ const expandIndexList = ref<number[]>([])
27
+
28
+ const addOptionEvent = () => {
29
+ const { renderParams } = props
30
+ const { widget } = renderParams
31
+ const options = widget.options.options || []
32
+ options.push({
33
+ value: VxeUI.getI18n('vxe.formDesign.widgetProp.dataSource.defValue', [options.length + 1])
34
+ })
35
+ widget.options.options = [...options]
36
+ }
37
+
38
+ const subRE = /^(\s|\t)+/
39
+
40
+ const hasSubOption = (str: string) => {
41
+ return subRE.test(str)
42
+ }
43
+
44
+ const expandAllOption = () => {
45
+ const { renderParams } = props
46
+ const { widget } = renderParams
47
+ const options = widget.options.options || []
48
+ const indexList: number[] = []
49
+ options.forEach((group, gIndex) => {
50
+ const { options } = group
51
+ if (options && options.length) {
52
+ indexList.push(gIndex)
53
+ }
54
+ })
55
+ expandIndexList.value = indexList
56
+ }
57
+
58
+ const toggleExpandOption = (item: WidgetDataSourceOptionSubObjVO, gIndex: number) => {
59
+ if (expandIndexList.value.includes(gIndex)) {
60
+ expandIndexList.value = expandIndexList.value.filter(num => num !== gIndex)
61
+ } else {
62
+ expandIndexList.value.push(gIndex)
63
+ }
64
+ }
65
+
66
+ const confirmBatchAddOptionEvent = () => {
67
+ const { renderParams } = props
68
+ const { widget } = renderParams
69
+ const optList: WidgetDataSourceOptionSubObjVO[] = []
70
+ const rowList = optionsContent.value.split('\n')
71
+ let prevGroup: Required<WidgetDataSourceOptionObjVO> | null = null
72
+ if (isSubOption) {
73
+ rowList.forEach((str, index) => {
74
+ const nextStr = rowList[index + 1]
75
+ const value = str.trim()
76
+ if (!value) {
77
+ return
78
+ }
79
+ const item: WidgetDataSourceOptionSubObjVO = {
80
+ value
81
+ }
82
+ if (prevGroup) {
83
+ if (hasSubOption(str)) {
84
+ prevGroup.options.push(item)
85
+ return
86
+ }
87
+ prevGroup = null
88
+ optList.push(item)
89
+ } else {
90
+ optList.push(item)
91
+ }
92
+ if (nextStr) {
93
+ if (hasSubOption(nextStr)) {
94
+ prevGroup = Object.assign(item, { options: [] })
95
+ }
96
+ }
97
+ })
98
+ } else {
99
+ rowList.forEach((str) => {
100
+ optList.push({
101
+ value: str.trim()
102
+ })
103
+ })
104
+ }
105
+ widget.options.options = optList
106
+ expandAllOption()
107
+ }
108
+
109
+ const openPopupEditEvent = () => {
110
+ const { renderParams } = props
111
+ const { widget } = renderParams
112
+
113
+ const contList: string[] = []
114
+ widget.options.options?.forEach(group => {
115
+ contList.push(group.value)
116
+ group.options?.forEach(item => {
117
+ contList.push(`\t${item.value}`)
118
+ })
119
+ })
120
+
121
+ optionsContent.value = contList.join('\n')
122
+
123
+ VxeUI.modal.open({
124
+ title: `${widget.title} - ${VxeUI.getI18n('vxe.formDesign.widgetProp.dataSource.batchEditOption')}`,
125
+ width: 500,
126
+ height: '50vh ',
127
+ resize: true,
128
+ showFooter: true,
129
+ showCancelButton: true,
130
+ showConfirmButton: true,
131
+ confirmButtonText: VxeUI.getI18n('vxe.formDesign.widgetProp.dataSource.buildOption'),
132
+ onConfirm: confirmBatchAddOptionEvent,
133
+ slots: {
134
+ default () {
135
+ return h('div', {
136
+ class: 'vxe-form-design--widget-form-item-data-source-popup'
137
+ }, [
138
+ h(VxeUITipComponent, {
139
+ status: 'primary',
140
+ title: '',
141
+ content: VxeUI.getI18n(`vxe.formDesign.widgetProp.dataSource.${isSubOption ? 'batchEditSubTip' : 'batchEditTip'}`)
142
+ }),
143
+ h(VxeUITextareaComponent, {
144
+ resize: 'none',
145
+ modelValue: optionsContent.value,
146
+ 'onUpdate:modelValue' (val: any) {
147
+ optionsContent.value = val
148
+ }
149
+ })
150
+ ])
151
+ }
152
+ }
153
+ })
154
+ }
155
+
156
+ const renderOption = (item: WidgetDataSourceOptionSubObjVO, hasFirstLevel: boolean, isExpand: boolean, gIndex: number, hasSub: boolean, isFirst: boolean, isLast: boolean) => {
157
+ return h('div', {
158
+ class: ['vxe-form-design--widget-form-item-data-source-option', {
159
+ 'is--first': isFirst,
160
+ 'is--last': isLast
161
+ }]
162
+ }, [
163
+ h('div', {
164
+ class: 'vxe-form-design--widget-expand-btn'
165
+ }, hasFirstLevel && hasSub
166
+ ? [
167
+ h('i', {
168
+ class: isExpand ? VxeUI.getIcon().FORM_DESIGN_WIDGET_OPTION_EXPAND_CLOSE : VxeUI.getIcon().FORM_DESIGN_WIDGET_OPTION_EXPAND_OPEN,
169
+ onClick () {
170
+ toggleExpandOption(item, gIndex)
171
+ }
172
+ })
173
+ ]
174
+ : []),
175
+ h('input', {
176
+ class: 'vxe-default-input',
177
+ value: item.value,
178
+ onInput (evnt: InputEvent & { target: HTMLInputElement }) {
179
+ item.value = evnt.target.value
180
+ }
181
+ }),
182
+ h(VxeUIButtonComponent, {
183
+ status: 'danger',
184
+ mode: 'text',
185
+ icon: VxeUI.getIcon().FORM_DESIGN_WIDGET_DELETE
186
+ })
187
+ ])
188
+ }
189
+
190
+ const renderOptions = () => {
191
+ const { renderParams } = props
192
+ const { widget } = renderParams
193
+ const { options } = widget
194
+ const groups = options.options
195
+ const optVNs: VNode[] = []
196
+ if (groups) {
197
+ groups.forEach((group, gIndex) => {
198
+ const { options } = group
199
+ const isExpand = expandIndexList.value.includes(gIndex)
200
+ if (options && options.length) {
201
+ optVNs.push(renderOption(group, true, isExpand, gIndex, true, gIndex === 0, gIndex === groups.length - 1))
202
+ if (isExpand) {
203
+ optVNs.push(
204
+ h('div', {
205
+ class: 'vxe-form-design--widget-form-item-data-source-sub-option'
206
+ }, options.map(item => renderOption(item, false, isExpand, 0, false, false, false)))
207
+ )
208
+ }
209
+ } else {
210
+ optVNs.push(renderOption(group, true, isExpand, gIndex, false, gIndex === 0, gIndex === groups.length - 1))
211
+ }
212
+ })
213
+ }
214
+ return optVNs
215
+ }
216
+
217
+ watch(() => props.renderParams.widget, () => {
218
+ expandAllOption()
219
+ })
220
+
221
+ onMounted(() => {
222
+ expandAllOption()
223
+ })
224
+
225
+ return {
226
+ renderDataSourceFormItem () {
227
+ return h(VxeUIFormItemComponent, {
228
+ title: VxeUI.getI18n('vxe.formDesign.widgetProp.dataSource.name'),
229
+ field: 'options'
230
+ }, {
231
+ default () {
232
+ return [
233
+ h('div', {}, [
234
+ h(VxeUIButtonComponent, {
235
+ status: 'primary',
236
+ mode: 'text',
237
+ content: VxeUI.getI18n('vxe.formDesign.widgetProp.dataSource.addOption'),
238
+ onClick: addOptionEvent
239
+ }),
240
+ h(VxeUIButtonComponent, {
241
+ status: 'primary',
242
+ mode: 'text',
243
+ content: VxeUI.getI18n('vxe.formDesign.widgetProp.dataSource.batchEditOption'),
244
+ onClick: openPopupEditEvent
245
+ })
246
+ ]),
247
+ h('div', {
248
+ class: 'vxe-form-design--widget-form-item-data-source'
249
+ }, renderOptions())
250
+ ]
251
+ }
252
+ })
253
+ }
254
+ }
255
+ }