vue2-client 1.10.32 → 1.10.35
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.
- package/package.json +1 -1
- package/src/App.vue +196 -196
- package/src/base-client/components/common/XAddNativeForm/demo.vue +43 -43
- package/src/base-client/components/common/XAddReport/XAddReport.vue +1 -1
- package/src/base-client/components/common/XConversation/XConversation.vue +12 -0
- package/src/base-client/components/common/XDataCard/XDataCard.vue +17 -16
- package/src/base-client/components/common/XForm/XFormItem.vue +1248 -1286
- package/src/base-client/components/common/XFormCol/XFormCol.vue +157 -157
- package/src/base-client/components/common/XFormGroup/XFormGroup.vue +301 -301
- package/src/base-client/components/common/XFormTable/XFormTable.vue +12 -0
- package/src/base-client/components/common/XFormTable/demo.vue +2 -2
- package/src/base-client/components/common/XIntervalPicker/XIntervalPicker.vue +121 -0
- package/src/base-client/components/common/XReportDrawer/XReportDrawer.vue +1 -1
- package/src/base-client/components/common/XReportGrid/XReport.vue +1079 -1070
- package/src/base-client/components/common/XReportGrid/XReportDemo.vue +46 -47
- package/src/base-client/components/common/XReportGrid/XReportDesign.vue +628 -628
- package/src/base-client/components/common/XReportGrid/XReportJsonRender.vue +380 -380
- package/src/base-client/components/common/XReportGrid/XReportTrGroup.vue +1104 -1104
- package/src/base-client/components/common/XReportGrid/print.js +184 -184
- package/src/base-client/components/common/XTab/XTab.vue +57 -25
- package/src/components/cache/AKeepAlive.js +11 -4
- package/src/layouts/BlankView.vue +59 -3
- package/src/pages/ReportGrid/index.vue +76 -76
- package/src/router/async/router.map.js +95 -148
- package/src/router/guards.js +260 -263
- package/src/utils/microAppUtils.js +49 -40
- package/src/utils/routerUtil.js +526 -450
|
@@ -1,301 +1,301 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div :class="groups.length ? 'XFormGroupClass' : ''">
|
|
3
|
-
<a-empty v-if="loadingErr" description="配置走丢了"/>
|
|
4
|
-
<a-spin v-else tip="正在努力加载..." :spinning="spinning" wrapperClassName="heigth100">
|
|
5
|
-
<a-row :gutter="24" style="height: 100%">
|
|
6
|
-
<a-col :span="3" v-if="showLeftTab && groups.length">
|
|
7
|
-
<a-tabs tab-position="left" v-model="activeTab" @change="scrollToGroup">
|
|
8
|
-
<template v-for="(item, index) in groups">
|
|
9
|
-
<a-tab-pane
|
|
10
|
-
:tab="item.describe"
|
|
11
|
-
:key="index"
|
|
12
|
-
v-if="item.describe && (formShow[`show${item.groupName}`] || formShow[`show${item.slotName}`])">
|
|
13
|
-
</a-tab-pane>
|
|
14
|
-
</template>
|
|
15
|
-
</a-tabs>
|
|
16
|
-
</a-col>
|
|
17
|
-
<a-col :span="showLeftTab ? 21 : 24" class="formGroupContext" ref="formGroupContext">
|
|
18
|
-
<div class="group-item" :ref="`group-${index}`" :key="index" v-for="(item, index) in groups">
|
|
19
|
-
<a-row :style="{ marginTop: index === 0 ? '' : '8px' }" v-if="formShow[`show${item.groupName}`] || formShow[`show${item.slotName}`]">
|
|
20
|
-
<a-col :span="5">
|
|
21
|
-
<span class="xFormGroupTitle">{{ item.describe }}</span>
|
|
22
|
-
</a-col>
|
|
23
|
-
</a-row>
|
|
24
|
-
<div v-show="formShow[`show${item.slotName}`]">
|
|
25
|
-
<template v-if="item.formGroupType === 'slot'">
|
|
26
|
-
<slot :name="item.slotName" :data="allFormData" :index="index">
|
|
27
|
-
<a-empty :description="`[${item.describe}:${item.slotName}]插槽没有使用`"/>
|
|
28
|
-
</slot>
|
|
29
|
-
</template>
|
|
30
|
-
</div>
|
|
31
|
-
<x-add-native-form
|
|
32
|
-
@x-form-item-emit-func="emitFunc"
|
|
33
|
-
v-if="item.formGroupType !== 'slot' && formShow[`show${item.groupName}`]"
|
|
34
|
-
:ref="`nativeForm-${index}`"/>
|
|
35
|
-
</div>
|
|
36
|
-
</a-col>
|
|
37
|
-
</a-row>
|
|
38
|
-
</a-spin>
|
|
39
|
-
</div>
|
|
40
|
-
</template>
|
|
41
|
-
|
|
42
|
-
<script>
|
|
43
|
-
import XAddNativeForm from '@vue2-client/base-client/components/common/XAddNativeForm/XAddNativeForm.vue'
|
|
44
|
-
|
|
45
|
-
export default {
|
|
46
|
-
name: 'XFormGroup',
|
|
47
|
-
components: {
|
|
48
|
-
XAddNativeForm
|
|
49
|
-
},
|
|
50
|
-
data () {
|
|
51
|
-
return {
|
|
52
|
-
// 页面宽度
|
|
53
|
-
screenWidth: document.documentElement.clientWidth,
|
|
54
|
-
formList: [],
|
|
55
|
-
groups: [],
|
|
56
|
-
modifyModelData: {},
|
|
57
|
-
serviceName: '',
|
|
58
|
-
showLeftTab: false,
|
|
59
|
-
showSubmitBtn: false,
|
|
60
|
-
loading: false,
|
|
61
|
-
allFormData: {},
|
|
62
|
-
businessType: {},
|
|
63
|
-
formShow: {},
|
|
64
|
-
env: 'dev',
|
|
65
|
-
spinning: true,
|
|
66
|
-
loadingErr: false,
|
|
67
|
-
activeTab: 0
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
mounted () {
|
|
71
|
-
},
|
|
72
|
-
beforeDestroy () {
|
|
73
|
-
const formGroupContext = this.$refs.formGroupContext?.$el
|
|
74
|
-
if (formGroupContext && formGroupContext.removeEventListener) {
|
|
75
|
-
formGroupContext.removeEventListener('scroll', this.onScroll)
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
provide () {
|
|
79
|
-
return {
|
|
80
|
-
inXFormGroup: true,
|
|
81
|
-
formGroupContext: this
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
methods: {
|
|
85
|
-
setRef (refName, refValue) {
|
|
86
|
-
if (!this.$refs[refName]) {
|
|
87
|
-
this.$refs[refName] = refValue
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
/**
|
|
91
|
-
* 初始化
|
|
92
|
-
* @param groups 表单组诗句
|
|
93
|
-
* @param modifyModelData 修改的数据
|
|
94
|
-
* @param serviceName 服务名
|
|
95
|
-
* @param env 环境
|
|
96
|
-
* @param showLeftTab 是否展示左侧索引页
|
|
97
|
-
* @param businessType 新增还是修改
|
|
98
|
-
*/
|
|
99
|
-
init ({
|
|
100
|
-
groups,
|
|
101
|
-
modifyModelData = {},
|
|
102
|
-
serviceName = process.env.VUE_APP_SYSTEM_NAME,
|
|
103
|
-
env = 'prod',
|
|
104
|
-
showLeftTab = false,
|
|
105
|
-
businessType = '新增'
|
|
106
|
-
}) {
|
|
107
|
-
Object.assign(this, { groups, modifyModelData, serviceName, env, showLeftTab, businessType })
|
|
108
|
-
this.initView()
|
|
109
|
-
this.$nextTick(() => {
|
|
110
|
-
const formGroupContext = this.$refs.formGroupContext?.$el
|
|
111
|
-
if (formGroupContext && formGroupContext.addEventListener) {
|
|
112
|
-
formGroupContext.addEventListener('scroll', this.onScroll)
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
},
|
|
116
|
-
// 初始化组件
|
|
117
|
-
initView () {
|
|
118
|
-
this.spinning = true
|
|
119
|
-
const promises = []
|
|
120
|
-
for (let i = 0; i < this.groups.length; i++) {
|
|
121
|
-
promises.push(this.initData(i))
|
|
122
|
-
}
|
|
123
|
-
Promise.all(promises).then(() => {
|
|
124
|
-
this.spinning = false
|
|
125
|
-
}).catch(() => {
|
|
126
|
-
this.loadingErr = true
|
|
127
|
-
this.spinning = false
|
|
128
|
-
})
|
|
129
|
-
},
|
|
130
|
-
getNativeFormRef (group) {
|
|
131
|
-
if (!group) {
|
|
132
|
-
console.warn('getNativeFormRef(group) group is required')
|
|
133
|
-
return null
|
|
134
|
-
}
|
|
135
|
-
return this.groups.map((item, index) => {
|
|
136
|
-
if (item.groupName === group) {
|
|
137
|
-
return this.$refs[`nativeForm-${index}`][0]
|
|
138
|
-
} else {
|
|
139
|
-
return null
|
|
140
|
-
}
|
|
141
|
-
}).filter(ref => ref !== null)
|
|
142
|
-
},
|
|
143
|
-
getNativeForm (group) {
|
|
144
|
-
const formref = this.getNativeFormRef(group)
|
|
145
|
-
return formref.length ? formref[0].form : null
|
|
146
|
-
},
|
|
147
|
-
initData (index) {
|
|
148
|
-
// 定义当前表单配置
|
|
149
|
-
const res = this.groups[index]
|
|
150
|
-
// 如果是插槽组件
|
|
151
|
-
if (res?.formGroupType === 'slot') {
|
|
152
|
-
// 组织插槽表单的结果
|
|
153
|
-
this.allFormData[res.slotName] = {}
|
|
154
|
-
this.$set(this.formShow, `show${res.slotName}`, true)
|
|
155
|
-
return
|
|
156
|
-
}
|
|
157
|
-
this.$set(this.formShow, `show${res.groupName}`, true)
|
|
158
|
-
// 组织native表单存储的结果
|
|
159
|
-
this.allFormData[res.groupName] = {}
|
|
160
|
-
this.formList.push(res)
|
|
161
|
-
let modifyModelData = {}
|
|
162
|
-
if (this.modifyModelData[res.groupName]) {
|
|
163
|
-
modifyModelData = {
|
|
164
|
-
data: this.modifyModelData[res.groupName],
|
|
165
|
-
files: this.modifyModelData[res.groupName].files,
|
|
166
|
-
images: this.modifyModelData[res.groupName].images
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const params = {
|
|
170
|
-
layout: res.xAddFormLayout,
|
|
171
|
-
formItems: res.formJson,
|
|
172
|
-
showSubmitBtn: false,
|
|
173
|
-
serviceName: this.serviceName,
|
|
174
|
-
fixedAddForm: modifyModelData.data,
|
|
175
|
-
modifyModelData: modifyModelData,
|
|
176
|
-
businessType: this.businessType,
|
|
177
|
-
env: this.env,
|
|
178
|
-
...res
|
|
179
|
-
}
|
|
180
|
-
params.showSubmitBtn = false
|
|
181
|
-
this.$nextTick(() => {
|
|
182
|
-
this.$refs[`nativeForm-${index}`][0].init(params)
|
|
183
|
-
})
|
|
184
|
-
},
|
|
185
|
-
scrollToGroup (index) {
|
|
186
|
-
const groupElement = this.$refs[`group-${index}`][0]
|
|
187
|
-
if (groupElement) {
|
|
188
|
-
groupElement.scrollIntoView({ behavior: 'smooth' })
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
xFormShow (func, data, index) {
|
|
192
|
-
if (data) {
|
|
193
|
-
this.groups.forEach((item, index) => {
|
|
194
|
-
if (data === item.groupName) {
|
|
195
|
-
this.$set(this.formShow, `show${item.groupName}`, func === 'x-form-show')
|
|
196
|
-
if (func === 'x-form-show') {
|
|
197
|
-
this.initData(index)
|
|
198
|
-
}
|
|
199
|
-
} else if (data === item.slotName) {
|
|
200
|
-
this.$set(this.formShow, `show${item.slotName}`, func === 'x-form-show')
|
|
201
|
-
if (func === 'x-form-show') {
|
|
202
|
-
this.initData(index)
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
// xfromitem 一路传递上来的事件
|
|
209
|
-
emitFunc (func, data, index) {
|
|
210
|
-
if (func === 'x-form-show' || func === 'x-form-no-show') {
|
|
211
|
-
this.xFormShow(func, data, index)
|
|
212
|
-
} else {
|
|
213
|
-
let value = null
|
|
214
|
-
try {
|
|
215
|
-
if (data && data.model && this.$refs[`nativeForm-${index}`]) {
|
|
216
|
-
value = this.$refs[`nativeForm-${index}`]?.form[data.model]
|
|
217
|
-
}
|
|
218
|
-
this.$emit(func, data, value)
|
|
219
|
-
} catch (error) { console.error(error) }
|
|
220
|
-
this.$emit('x-form-item-emit-func', func, data, value)
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
// 提交表单
|
|
224
|
-
asyncSubmit () {
|
|
225
|
-
return this.onSubmit()
|
|
226
|
-
},
|
|
227
|
-
async onSubmit () {
|
|
228
|
-
let pass = true
|
|
229
|
-
const promises = this.groups.map((item, index) => {
|
|
230
|
-
const nativeFormRef = this.$refs[`nativeForm-${index}`] ? this.$refs[`nativeForm-${index}`][0] : undefined
|
|
231
|
-
if ((item.groupName || item.slotName) && nativeFormRef && typeof nativeFormRef.asyncSubmit === 'function') {
|
|
232
|
-
// 如果 ref 存在 asyncSubmit 方法,则调用 asyncSubmit 方法
|
|
233
|
-
return nativeFormRef.asyncSubmit().then(res => {
|
|
234
|
-
this.allFormData[item.slotName || item.groupName] = res.realForm
|
|
235
|
-
}).catch(_err => {
|
|
236
|
-
pass = false
|
|
237
|
-
this.scrollToGroup(index)
|
|
238
|
-
})
|
|
239
|
-
} else {
|
|
240
|
-
console.warn(item.groupName + '未找到组件,或者组件没有 asyncSubmit 方法')
|
|
241
|
-
// 如果 ref 不存在或没有 asyncSubmit 方法,则返回一个已解决的 Promise
|
|
242
|
-
return Promise.resolve()
|
|
243
|
-
}
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
await Promise.all(promises)
|
|
248
|
-
|
|
249
|
-
if (pass) {
|
|
250
|
-
return Promise.resolve(this.allFormData)
|
|
251
|
-
} else {
|
|
252
|
-
this.$message.error('请检查表单填写是否正确')
|
|
253
|
-
return Promise.reject(new Error('Form validation failed'))
|
|
254
|
-
}
|
|
255
|
-
} catch (error) {
|
|
256
|
-
return Promise.reject(new Error('An unexpected error occurred'))
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
onScroll () {
|
|
260
|
-
const formGroupContext = this.$refs.formGroupContext.$el
|
|
261
|
-
let groupItems = []
|
|
262
|
-
if (formGroupContext && formGroupContext.querySelectorAll) {
|
|
263
|
-
groupItems = formGroupContext.querySelectorAll('.group-item')
|
|
264
|
-
}
|
|
265
|
-
let activeIndex = this.activeTab
|
|
266
|
-
|
|
267
|
-
groupItems.forEach((item, index) => {
|
|
268
|
-
const rect = item.getBoundingClientRect()
|
|
269
|
-
if (rect.top <= 205 && rect.bottom > 200) {
|
|
270
|
-
activeIndex = index
|
|
271
|
-
}
|
|
272
|
-
})
|
|
273
|
-
this.activeTab = activeIndex
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
</script>
|
|
278
|
-
<style lang="less" scoped>
|
|
279
|
-
.XFormGroupClass {
|
|
280
|
-
height: 100%;
|
|
281
|
-
|
|
282
|
-
.heigth100 {
|
|
283
|
-
height: 100%;
|
|
284
|
-
|
|
285
|
-
:deep(.ant-spin-container) {
|
|
286
|
-
height: 100%;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
.xFormGroupTitle {
|
|
291
|
-
font-size: 15px;
|
|
292
|
-
font-weight: bold;
|
|
293
|
-
color: @primary-color;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
.formGroupContext {
|
|
297
|
-
height: 100%;
|
|
298
|
-
overflow-y: scroll;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="groups.length ? 'XFormGroupClass' : ''">
|
|
3
|
+
<a-empty v-if="loadingErr" description="配置走丢了"/>
|
|
4
|
+
<a-spin v-else tip="正在努力加载..." :spinning="spinning" wrapperClassName="heigth100">
|
|
5
|
+
<a-row :gutter="24" style="height: 100%">
|
|
6
|
+
<a-col :span="3" v-if="showLeftTab && groups.length">
|
|
7
|
+
<a-tabs tab-position="left" v-model="activeTab" @change="scrollToGroup">
|
|
8
|
+
<template v-for="(item, index) in groups">
|
|
9
|
+
<a-tab-pane
|
|
10
|
+
:tab="item.describe"
|
|
11
|
+
:key="index"
|
|
12
|
+
v-if="item.describe && (formShow[`show${item.groupName}`] || formShow[`show${item.slotName}`])">
|
|
13
|
+
</a-tab-pane>
|
|
14
|
+
</template>
|
|
15
|
+
</a-tabs>
|
|
16
|
+
</a-col>
|
|
17
|
+
<a-col :span="showLeftTab ? 21 : 24" class="formGroupContext" ref="formGroupContext">
|
|
18
|
+
<div class="group-item" :ref="`group-${index}`" :key="index" v-for="(item, index) in groups">
|
|
19
|
+
<a-row :style="{ marginTop: index === 0 ? '' : '8px' }" v-if="formShow[`show${item.groupName}`] || formShow[`show${item.slotName}`]">
|
|
20
|
+
<a-col :span="5">
|
|
21
|
+
<span class="xFormGroupTitle">{{ item.describe }}</span>
|
|
22
|
+
</a-col>
|
|
23
|
+
</a-row>
|
|
24
|
+
<div v-show="formShow[`show${item.slotName}`]">
|
|
25
|
+
<template v-if="item.formGroupType === 'slot'">
|
|
26
|
+
<slot :name="item.slotName" :data="allFormData" :index="index">
|
|
27
|
+
<a-empty :description="`[${item.describe}:${item.slotName}]插槽没有使用`"/>
|
|
28
|
+
</slot>
|
|
29
|
+
</template>
|
|
30
|
+
</div>
|
|
31
|
+
<x-add-native-form
|
|
32
|
+
@x-form-item-emit-func="emitFunc"
|
|
33
|
+
v-if="item.formGroupType !== 'slot' && formShow[`show${item.groupName}`]"
|
|
34
|
+
:ref="`nativeForm-${index}`"/>
|
|
35
|
+
</div>
|
|
36
|
+
</a-col>
|
|
37
|
+
</a-row>
|
|
38
|
+
</a-spin>
|
|
39
|
+
</div>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script>
|
|
43
|
+
import XAddNativeForm from '@vue2-client/base-client/components/common/XAddNativeForm/XAddNativeForm.vue'
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
name: 'XFormGroup',
|
|
47
|
+
components: {
|
|
48
|
+
XAddNativeForm
|
|
49
|
+
},
|
|
50
|
+
data () {
|
|
51
|
+
return {
|
|
52
|
+
// 页面宽度
|
|
53
|
+
screenWidth: document.documentElement.clientWidth,
|
|
54
|
+
formList: [],
|
|
55
|
+
groups: [],
|
|
56
|
+
modifyModelData: {},
|
|
57
|
+
serviceName: '',
|
|
58
|
+
showLeftTab: false,
|
|
59
|
+
showSubmitBtn: false,
|
|
60
|
+
loading: false,
|
|
61
|
+
allFormData: {},
|
|
62
|
+
businessType: {},
|
|
63
|
+
formShow: {},
|
|
64
|
+
env: 'dev',
|
|
65
|
+
spinning: true,
|
|
66
|
+
loadingErr: false,
|
|
67
|
+
activeTab: 0
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
mounted () {
|
|
71
|
+
},
|
|
72
|
+
beforeDestroy () {
|
|
73
|
+
const formGroupContext = this.$refs.formGroupContext?.$el
|
|
74
|
+
if (formGroupContext && formGroupContext.removeEventListener) {
|
|
75
|
+
formGroupContext.removeEventListener('scroll', this.onScroll)
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
provide () {
|
|
79
|
+
return {
|
|
80
|
+
inXFormGroup: true,
|
|
81
|
+
formGroupContext: this
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
methods: {
|
|
85
|
+
setRef (refName, refValue) {
|
|
86
|
+
if (!this.$refs[refName]) {
|
|
87
|
+
this.$refs[refName] = refValue
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* 初始化
|
|
92
|
+
* @param groups 表单组诗句
|
|
93
|
+
* @param modifyModelData 修改的数据
|
|
94
|
+
* @param serviceName 服务名
|
|
95
|
+
* @param env 环境
|
|
96
|
+
* @param showLeftTab 是否展示左侧索引页
|
|
97
|
+
* @param businessType 新增还是修改
|
|
98
|
+
*/
|
|
99
|
+
init ({
|
|
100
|
+
groups,
|
|
101
|
+
modifyModelData = {},
|
|
102
|
+
serviceName = process.env.VUE_APP_SYSTEM_NAME,
|
|
103
|
+
env = 'prod',
|
|
104
|
+
showLeftTab = false,
|
|
105
|
+
businessType = '新增'
|
|
106
|
+
}) {
|
|
107
|
+
Object.assign(this, { groups, modifyModelData, serviceName, env, showLeftTab, businessType })
|
|
108
|
+
this.initView()
|
|
109
|
+
this.$nextTick(() => {
|
|
110
|
+
const formGroupContext = this.$refs.formGroupContext?.$el
|
|
111
|
+
if (formGroupContext && formGroupContext.addEventListener) {
|
|
112
|
+
formGroupContext.addEventListener('scroll', this.onScroll)
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
},
|
|
116
|
+
// 初始化组件
|
|
117
|
+
initView () {
|
|
118
|
+
this.spinning = true
|
|
119
|
+
const promises = []
|
|
120
|
+
for (let i = 0; i < this.groups.length; i++) {
|
|
121
|
+
promises.push(this.initData(i))
|
|
122
|
+
}
|
|
123
|
+
Promise.all(promises).then(() => {
|
|
124
|
+
this.spinning = false
|
|
125
|
+
}).catch(() => {
|
|
126
|
+
this.loadingErr = true
|
|
127
|
+
this.spinning = false
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
getNativeFormRef (group) {
|
|
131
|
+
if (!group) {
|
|
132
|
+
console.warn('getNativeFormRef(group) group is required')
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
return this.groups.map((item, index) => {
|
|
136
|
+
if (item.groupName === group) {
|
|
137
|
+
return this.$refs[`nativeForm-${index}`][0]
|
|
138
|
+
} else {
|
|
139
|
+
return null
|
|
140
|
+
}
|
|
141
|
+
}).filter(ref => ref !== null)
|
|
142
|
+
},
|
|
143
|
+
getNativeForm (group) {
|
|
144
|
+
const formref = this.getNativeFormRef(group)
|
|
145
|
+
return formref.length ? formref[0].form : null
|
|
146
|
+
},
|
|
147
|
+
initData (index) {
|
|
148
|
+
// 定义当前表单配置
|
|
149
|
+
const res = this.groups[index]
|
|
150
|
+
// 如果是插槽组件
|
|
151
|
+
if (res?.formGroupType === 'slot') {
|
|
152
|
+
// 组织插槽表单的结果
|
|
153
|
+
this.allFormData[res.slotName] = {}
|
|
154
|
+
this.$set(this.formShow, `show${res.slotName}`, true)
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
this.$set(this.formShow, `show${res.groupName}`, true)
|
|
158
|
+
// 组织native表单存储的结果
|
|
159
|
+
this.allFormData[res.groupName] = {}
|
|
160
|
+
this.formList.push(res)
|
|
161
|
+
let modifyModelData = {}
|
|
162
|
+
if (this.modifyModelData[res.groupName]) {
|
|
163
|
+
modifyModelData = {
|
|
164
|
+
data: this.modifyModelData[res.groupName],
|
|
165
|
+
files: this.modifyModelData[res.groupName].files,
|
|
166
|
+
images: this.modifyModelData[res.groupName].images
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const params = {
|
|
170
|
+
layout: res.xAddFormLayout,
|
|
171
|
+
formItems: res.formJson,
|
|
172
|
+
showSubmitBtn: false,
|
|
173
|
+
serviceName: this.serviceName,
|
|
174
|
+
fixedAddForm: modifyModelData.data,
|
|
175
|
+
modifyModelData: modifyModelData,
|
|
176
|
+
businessType: this.businessType,
|
|
177
|
+
env: this.env,
|
|
178
|
+
...res
|
|
179
|
+
}
|
|
180
|
+
params.showSubmitBtn = false
|
|
181
|
+
this.$nextTick(() => {
|
|
182
|
+
this.$refs[`nativeForm-${index}`][0].init(params)
|
|
183
|
+
})
|
|
184
|
+
},
|
|
185
|
+
scrollToGroup (index) {
|
|
186
|
+
const groupElement = this.$refs[`group-${index}`][0]
|
|
187
|
+
if (groupElement) {
|
|
188
|
+
groupElement.scrollIntoView({ behavior: 'smooth' })
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
xFormShow (func, data, index) {
|
|
192
|
+
if (data) {
|
|
193
|
+
this.groups.forEach((item, index) => {
|
|
194
|
+
if (data === item.groupName) {
|
|
195
|
+
this.$set(this.formShow, `show${item.groupName}`, func === 'x-form-show')
|
|
196
|
+
if (func === 'x-form-show') {
|
|
197
|
+
this.initData(index)
|
|
198
|
+
}
|
|
199
|
+
} else if (data === item.slotName) {
|
|
200
|
+
this.$set(this.formShow, `show${item.slotName}`, func === 'x-form-show')
|
|
201
|
+
if (func === 'x-form-show') {
|
|
202
|
+
this.initData(index)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
// xfromitem 一路传递上来的事件
|
|
209
|
+
emitFunc (func, data, index) {
|
|
210
|
+
if (func === 'x-form-show' || func === 'x-form-no-show') {
|
|
211
|
+
this.xFormShow(func, data, index)
|
|
212
|
+
} else {
|
|
213
|
+
let value = null
|
|
214
|
+
try {
|
|
215
|
+
if (data && data.model && this.$refs[`nativeForm-${index}`]) {
|
|
216
|
+
value = this.$refs[`nativeForm-${index}`]?.form[data.model]
|
|
217
|
+
}
|
|
218
|
+
this.$emit(func, data, value)
|
|
219
|
+
} catch (error) { console.error(error) }
|
|
220
|
+
this.$emit('x-form-item-emit-func', func, data, value)
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
// 提交表单
|
|
224
|
+
asyncSubmit () {
|
|
225
|
+
return this.onSubmit()
|
|
226
|
+
},
|
|
227
|
+
async onSubmit () {
|
|
228
|
+
let pass = true
|
|
229
|
+
const promises = this.groups.map((item, index) => {
|
|
230
|
+
const nativeFormRef = this.$refs[`nativeForm-${index}`] ? this.$refs[`nativeForm-${index}`][0] : undefined
|
|
231
|
+
if ((item.groupName || item.slotName) && nativeFormRef && typeof nativeFormRef.asyncSubmit === 'function') {
|
|
232
|
+
// 如果 ref 存在 asyncSubmit 方法,则调用 asyncSubmit 方法
|
|
233
|
+
return nativeFormRef.asyncSubmit().then(res => {
|
|
234
|
+
this.allFormData[item.slotName || item.groupName] = res.realForm
|
|
235
|
+
}).catch(_err => {
|
|
236
|
+
pass = false
|
|
237
|
+
this.scrollToGroup(index)
|
|
238
|
+
})
|
|
239
|
+
} else {
|
|
240
|
+
console.warn(item.groupName + '未找到组件,或者组件没有 asyncSubmit 方法')
|
|
241
|
+
// 如果 ref 不存在或没有 asyncSubmit 方法,则返回一个已解决的 Promise
|
|
242
|
+
return Promise.resolve()
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
try {
|
|
247
|
+
await Promise.all(promises)
|
|
248
|
+
|
|
249
|
+
if (pass) {
|
|
250
|
+
return Promise.resolve(this.allFormData)
|
|
251
|
+
} else {
|
|
252
|
+
this.$message.error('请检查表单填写是否正确')
|
|
253
|
+
return Promise.reject(new Error('Form validation failed'))
|
|
254
|
+
}
|
|
255
|
+
} catch (error) {
|
|
256
|
+
return Promise.reject(new Error('An unexpected error occurred'))
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
onScroll () {
|
|
260
|
+
const formGroupContext = this.$refs.formGroupContext.$el
|
|
261
|
+
let groupItems = []
|
|
262
|
+
if (formGroupContext && formGroupContext.querySelectorAll) {
|
|
263
|
+
groupItems = formGroupContext.querySelectorAll('.group-item')
|
|
264
|
+
}
|
|
265
|
+
let activeIndex = this.activeTab
|
|
266
|
+
|
|
267
|
+
groupItems.forEach((item, index) => {
|
|
268
|
+
const rect = item.getBoundingClientRect()
|
|
269
|
+
if (rect.top <= 205 && rect.bottom > 200) {
|
|
270
|
+
activeIndex = index
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
this.activeTab = activeIndex
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
</script>
|
|
278
|
+
<style lang="less" scoped>
|
|
279
|
+
.XFormGroupClass {
|
|
280
|
+
height: 100%;
|
|
281
|
+
|
|
282
|
+
.heigth100 {
|
|
283
|
+
height: 100%;
|
|
284
|
+
|
|
285
|
+
:deep(.ant-spin-container) {
|
|
286
|
+
height: 100%;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.xFormGroupTitle {
|
|
291
|
+
font-size: 15px;
|
|
292
|
+
font-weight: bold;
|
|
293
|
+
color: @primary-color;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.formGroupContext {
|
|
297
|
+
height: 100%;
|
|
298
|
+
overflow-y: scroll;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
</style>
|
|
@@ -159,6 +159,18 @@ export default {
|
|
|
159
159
|
return null
|
|
160
160
|
},
|
|
161
161
|
},
|
|
162
|
+
setGlobalData: {
|
|
163
|
+
default: () => () => {
|
|
164
|
+
console.warn('setGlobalData is not provided.')
|
|
165
|
+
return null
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
getGlobalData: {
|
|
169
|
+
default: () => () => {
|
|
170
|
+
console.warn('getGlobalData is not provided.')
|
|
171
|
+
return null
|
|
172
|
+
},
|
|
173
|
+
},
|
|
162
174
|
getSelectedData: {
|
|
163
175
|
default: () => () => {
|
|
164
176
|
console.warn('getSelectedData is not provided.')
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
title="示例表单"
|
|
7
7
|
:queryParamsName="queryParamsName"
|
|
8
8
|
:fixedAddForm="fixedAddForm"
|
|
9
|
-
service-name="af-
|
|
9
|
+
service-name="af-system"
|
|
10
10
|
@action="action"
|
|
11
11
|
@columnClick="columnClick"
|
|
12
12
|
ref="xFormTable">
|
|
@@ -25,7 +25,7 @@ export default {
|
|
|
25
25
|
data () {
|
|
26
26
|
return {
|
|
27
27
|
// 查询配置文件名
|
|
28
|
-
queryParamsName: '
|
|
28
|
+
queryParamsName: 'ceshiCRUD',
|
|
29
29
|
// 查询配置左侧tree
|
|
30
30
|
// xTreeConfigName: 'addressType',
|
|
31
31
|
// 新增表单固定值
|