@vxe-ui/plugin-render-antd 4.0.2 → 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,140 @@
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 WidgetASwitchFormObjVO {
6
+ }
7
+
8
+ export function createWidgetASwitch (VxeUI: VxeUIExport) {
9
+ const getWidgetASwitchConfig = (params: VxeGlobalRendererHandles.CreateFormDesignWidgetConfigParams): VxeGlobalRendererHandles.CreateFormDesignWidgetConfigObj<WidgetASwitchFormObjVO> => {
10
+ return {
11
+ title: '是/否',
12
+ icon: 'vxe-icon-switch',
13
+ options: {
14
+ }
15
+ }
16
+ }
17
+
18
+ const WidgetASwitchFormComponent = defineComponent({
19
+ props: {
20
+ renderOpts: {
21
+ type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewOptions>,
22
+ default: () => ({})
23
+ },
24
+ renderParams: {
25
+ type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewParams<WidgetASwitchFormObjVO>>,
26
+ default: () => ({})
27
+ }
28
+ },
29
+ emits: [],
30
+ setup (props) {
31
+ const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
32
+ const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
33
+ const VxeUISwitchComponent = VxeUI.getComponent<VxeSwitchComponent>('VxeSwitch')
34
+ const VxeUIInputComponent = VxeUI.getComponent<VxeInputComponent>('VxeInput')
35
+
36
+ return () => {
37
+ const { renderParams } = props
38
+ const { widget } = renderParams
39
+
40
+ return h(VxeUIFormComponent, {
41
+ class: 'vxe-form-design--widget-render-form-wrapper',
42
+ vertical: true,
43
+ span: 24,
44
+ titleBold: true,
45
+ titleOverflow: true,
46
+ data: widget.options
47
+ }, {
48
+ default () {
49
+ return [
50
+ h(VxeUIFormItemComponent, {
51
+ title: VxeUI.getI18n('vxe.formDesign.widgetProp.name')
52
+ }, {
53
+ default () {
54
+ return h(VxeUIInputComponent, {
55
+ modelValue: widget.title,
56
+ 'onUpdate:modelValue' (val: any) {
57
+ widget.title = val
58
+ }
59
+ })
60
+ }
61
+ }),
62
+ h(VxeUIFormItemComponent, {
63
+ title: VxeUI.getI18n('vxe.formDesign.widgetProp.placeholder'),
64
+ field: 'placeholder',
65
+ itemRender: { name: 'ElInput' }
66
+ }),
67
+ h(VxeUIFormItemComponent, {
68
+ title: VxeUI.getI18n('vxe.formDesign.widgetProp.required')
69
+ }, {
70
+ default () {
71
+ return h(VxeUISwitchComponent, {
72
+ modelValue: widget.required,
73
+ 'onUpdate:modelValue' (val: any) {
74
+ widget.required = val
75
+ }
76
+ })
77
+ }
78
+ })
79
+ ]
80
+ }
81
+ })
82
+ }
83
+ }
84
+ })
85
+
86
+ const WidgetASwitchViewComponent = defineComponent({
87
+ props: {
88
+ renderOpts: {
89
+ type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewOptions>,
90
+ default: () => ({})
91
+ },
92
+ renderParams: {
93
+ type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewParams<WidgetASwitchFormObjVO>>,
94
+ default: () => ({})
95
+ }
96
+ },
97
+ emits: [],
98
+ setup (props) {
99
+ const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
100
+
101
+ const changeEvent = () => {
102
+ const { renderParams } = props
103
+ const { widget, $formView } = renderParams
104
+ if ($formView) {
105
+ const itemValue = $formView ? $formView.getItemValue(widget) : null
106
+ $formView.updateItemStatus(widget, itemValue)
107
+ }
108
+ }
109
+
110
+ return () => {
111
+ const { renderParams } = props
112
+ const { widget, $formView } = renderParams
113
+
114
+ return h(VxeUIFormItemComponent, {
115
+ class: ['vxe-form-design--widget-render-form-item'],
116
+ field: widget.field,
117
+ title: widget.title
118
+ }, {
119
+ default () {
120
+ return h(resolveComponent('a-switch') as ComponentOptions, {
121
+ checked: $formView ? $formView.getItemValue(widget) : null,
122
+ onChange: changeEvent,
123
+ 'onUpdate:checked' (val: any) {
124
+ if ($formView) {
125
+ $formView.setItemValue(widget, val)
126
+ }
127
+ }
128
+ })
129
+ }
130
+ })
131
+ }
132
+ }
133
+ })
134
+
135
+ return {
136
+ getWidgetASwitchConfig,
137
+ WidgetASwitchFormComponent,
138
+ WidgetASwitchViewComponent
139
+ }
140
+ }
@@ -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
+ }
package/src/index.ts ADDED
@@ -0,0 +1,71 @@
1
+ import { defineTableRender } from './table'
2
+ import { defineFormRender } from './form'
3
+ import { defineFormDesignRender } from './form-design'
4
+
5
+ import type { VxeUIPluginObject, VxeGlobalInterceptorHandles } from 'vxe-pc-ui'
6
+
7
+ /**
8
+ * 检查触发源是否属于目标节点
9
+ */
10
+ function getEventTargetNode (evnt: any, container: HTMLElement, className: string) {
11
+ let targetElem
12
+ let target = evnt.target
13
+ while (target && target.nodeType && target !== document) {
14
+ if (className && target.className && target.className.split && target.className.split(' ').indexOf(className) > -1) {
15
+ targetElem = target
16
+ } else if (target === container) {
17
+ return { flag: className ? !!targetElem : true, container, targetElem: targetElem }
18
+ }
19
+ target = target.parentNode
20
+ }
21
+ return { flag: false }
22
+ }
23
+
24
+ /**
25
+ * 事件兼容性处理
26
+ */
27
+ function handleClearEvent (params: VxeGlobalInterceptorHandles.InterceptorClearFilterParams | VxeGlobalInterceptorHandles.InterceptorClearEditParams | VxeGlobalInterceptorHandles.InterceptorClearAreasParams) {
28
+ const { $event } = params
29
+ const bodyElem = document.body
30
+ if (
31
+ // 下拉框
32
+ getEventTargetNode($event, bodyElem, 'ant-select-dropdown').flag ||
33
+ // 级联
34
+ getEventTargetNode($event, bodyElem, 'ant-cascader-menus').flag ||
35
+ // 日期
36
+ getEventTargetNode($event, bodyElem, 'ant-picker-dropdown').flag ||
37
+ getEventTargetNode($event, bodyElem, 'ant-calendar-picker-container').flag ||
38
+ // 时间选择
39
+ getEventTargetNode($event, bodyElem, 'ant-time-picker-panel').flag
40
+ ) {
41
+ return false
42
+ }
43
+ }
44
+
45
+ export const VxeUIPluginRenderAntd: VxeUIPluginObject = {
46
+ install (VxeUI, options?: {
47
+ Antd?: any
48
+ }) {
49
+ // 检查版本
50
+ if (!/^(4)\./.test(VxeUI.uiVersion)) {
51
+ console.error('[plugin-render-antd 4.x] Version 4.x is required')
52
+ }
53
+
54
+ defineTableRender(VxeUI)
55
+ defineFormRender(VxeUI)
56
+ defineFormDesignRender(VxeUI)
57
+
58
+ VxeUI.interceptor.add('event.clearFilter', handleClearEvent)
59
+ VxeUI.interceptor.add('event.clearEdit', handleClearEvent)
60
+ VxeUI.interceptor.add('event.clearAreas', handleClearEvent)
61
+
62
+ // 兼容老版本
63
+ VxeUI.interceptor.add('event.clearActived', handleClearEvent)
64
+ }
65
+ }
66
+
67
+ if (typeof window !== 'undefined' && window.VxeUI && window.VxeUI.use) {
68
+ window.VxeUI.use(VxeUIPluginRenderAntd)
69
+ }
70
+
71
+ export default VxeUIPluginRenderAntd