vue2-client 1.16.47 → 1.16.48

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 (25) hide show
  1. package/package.json +112 -112
  2. package/src/assets/img/paymentMethod/icon1.png +0 -0
  3. package/src/assets/img/paymentMethod/icon2.png +0 -0
  4. package/src/assets/img/paymentMethod/icon3.png +0 -0
  5. package/src/assets/img/paymentMethod/icon4.png +0 -0
  6. package/src/assets/img/paymentMethod/icon5.png +0 -0
  7. package/src/assets/img/paymentMethod/icon6.png +0 -0
  8. package/src/base-client/components/common/HIS/HButtons/HButtons.vue +47 -45
  9. package/src/base-client/components/common/HIS/HFormGroup/HFormGroup.vue +120 -120
  10. package/src/base-client/components/common/HIS/HFormGroup/index.js +3 -3
  11. package/src/base-client/components/common/HIS/HFormTable/HFormTable.vue +257 -256
  12. package/src/base-client/components/common/HIS/demo.vue +61 -61
  13. package/src/base-client/components/common/XAddNativeForm/XAddNativeForm.vue +1178 -1178
  14. package/src/base-client/components/common/XCollapse/XCollapse.vue +461 -461
  15. package/src/base-client/components/common/XInput/XInput.vue +147 -147
  16. package/src/base-client/components/common/XReport/XReportHospitalizationDemo.vue +45 -0
  17. package/src/base-client/components/common/XReportGrid/XReportTrGroup.vue +824 -824
  18. package/src/base-client/components/common/XTable/XTable.vue +1610 -1610
  19. package/src/base-client/components/common/XTimeline/XTimeline.vue +454 -454
  20. package/src/base-client/components/his/XCharge/testConfig.js +149 -0
  21. package/src/base-client/components/his/XHDescriptions/XHDescriptions.vue +6 -1
  22. package/src/base-client/components/his/XHisEditor/XHisEditor.vue +705 -705
  23. package/src/base-client/components/his/threeTestOrders/editor.vue +113 -113
  24. package/src/pages/userInfoDetailManage/ExceptionRecordQuery/index.vue +45 -45
  25. package/src/router/async/router.map.js +132 -129
@@ -1,1178 +1,1178 @@
1
- <template>
2
- <div id="XAddNativeForm">
3
- <a-form-model
4
- v-if="loaded"
5
- ref="selectForm"
6
- :zIndex="1001"
7
- :model="form"
8
- v-bind="formItemLayoutGen"
9
- :layout="layout">
10
- <template v-for="(item, key) in childTableData">
11
- <a-row
12
- v-if="childTablePriority"
13
- :gutter="16"
14
- :key="'childTableRow' + key">
15
- <a-card :title="item.name" :bordered="false" size="small">
16
- <x-form-table
17
- :key="'childTable_' + item.model"
18
- :title="item.name"
19
- :queryParamsName="item.childTableConfigName"
20
- :localEditMode="true"
21
- :fixed-query-form="childTableFixedQueryForm(item)"
22
- :service-name="serviceName"
23
- @innerXFormTableEmit="innerXFormTableEmit"
24
- @afterTableInit="childTableMounted(item)"
25
- :ref="'childXFormTable_' + item.model">
26
- </x-form-table>
27
- </a-card>
28
- </a-row>
29
- </template>
30
- <a-row ref="GroupItemRow">
31
- <a-col :span="3" v-if="!inXFormGroup && !(groups[0].groupName === DEFAULT_GROUP_NAME)">
32
- <a-tabs tab-position="left" v-model="activeTab" @change="scrollToGroup">
33
- <a-tab-pane
34
- v-for="(groupsItem,groupsIndex) in groups"
35
- :tab="groupsItem.groupName"
36
- :key="groupsIndex">
37
- </a-tab-pane>
38
- </a-tabs>
39
- </a-col>
40
- <a-col
41
- :span="(!inXFormGroup && !(groups[0].groupName === DEFAULT_GROUP_NAME)) ? 21: 24">
42
- <a-row
43
- :gutter="16"
44
- type="flex"
45
- :key="groupsIndex"
46
- v-for="(groupsItem,groupsIndex) in groups"
47
- >
48
- <a-col
49
- :span="24"
50
- :style="{ marginTop: groupsIndex === 0 ? '' : '8px',fontSize:inXFormGroup?'15px':'14px', marginLeft:'-5px' }"
51
- v-if="groupsItem.groupName !== DEFAULT_GROUP_NAME">
52
- <span class="xFormGroupTitle" :ref="`group-title-${groupsIndex}`">{{ groupsItem.groupName }}</span>
53
- </a-col>
54
- <x-form-item
55
- v-for="(item, index) in groupsItem.realJsonData"
56
- :key="index"
57
- :attr="item"
58
- :disabled="itemDisabled(item)"
59
- :read-only="readonly(item)"
60
- :files="files"
61
- v-bind="formItemLayoutGen"
62
- :style="layout === 'inline' ? { marginTop:'5px' } : undefined"
63
- :form="form"
64
- :images="images"
65
- :service-name="serviceName"
66
- mode="新增/修改"
67
- :layout="layout"
68
- :rules="rules[`${item.name}${item.model}`]"
69
- :get-data-params="getDataParams"
70
- :env="env"
71
- @x-form-item-emit-func="emitFunc"
72
- @rowChoose="rowChoose"
73
- :setForm="setForm"
74
- />
75
- </a-row>
76
- </a-col>
77
- </a-row>
78
- <a-row :gutter="16" v-for="(groupItem, groupIndex) in groupJsonData" :key="groupIndex">
79
- <a-card v-if="groupItem.groupItems.length > 0" :title="groupItem.name" :bordered="false" size="small">
80
- <x-form-item
81
- v-for="(item, index) in groupItem.groupItems"
82
- :key="index"
83
- :attr="item"
84
- :disabled="itemDisabled(item)"
85
- :readonly="readonly(item)"
86
- :files="files"
87
- v-bind="formItemLayoutGen"
88
- :style="layout ==='inline'?{marginTop:'5px'}:undefined"
89
- :form="form[groupItem.model]"
90
- :images="images"
91
- :service-name="serviceName"
92
- mode="新增/修改"
93
- :rules="rules[`${item.name}${item.model}`]"
94
- :get-data-params="getDataParams"
95
- :env="env"
96
- :setForm="setForm"
97
- @rowChoose="rowChoose"
98
- />
99
- </a-card>
100
- <template v-else>
101
- <slot
102
- name="groupFormItems"
103
- :form="form"
104
- :model="groupItem.model"
105
- :rules="rules"
106
- :modifyModelData="modifyModelData"></slot>
107
- </template>
108
- </a-row>
109
- <a-row :gutter="16" v-for="(item, key) in simpleFormJsonData" :key="'row' + key">
110
- <a-card v-if="item.value.length > 0" :title="item.name" :bordered="false" size="small">
111
- <x-form-item
112
- v-for="(formItem, formItemIndex) in item.value"
113
- :key="key + formItemIndex"
114
- :attr="formItem"
115
- :disabled="itemDisabled(formItem)"
116
- :readonly="readonly(formItem)"
117
- :files="files"
118
- v-bind="formItemLayoutGen"
119
- :style="layout ==='inline'?{marginTop:'5px'}:undefined"
120
- :form="form[groupItem.model]"
121
- :images="images"
122
- :service-name="serviceName"
123
- mode="新增/修改"
124
- :rules="rules[`${item.name}${item.model}`]"
125
- :get-data-params="getDataParams"
126
- :env="env"
127
- :setForm="setForm"
128
- @rowChoose="rowChoose"
129
- />
130
- </a-card>
131
- </a-row>
132
- <template v-for="(item, key) in childTableData">
133
- <a-row
134
- v-if="!childTablePriority"
135
- :gutter="16"
136
- :key="'childTableRow' + key">
137
- <a-card :title="item.name" :bordered="false" size="small">
138
- <x-form-table
139
- :key="'childTable_' + item.model"
140
- :title="item.name"
141
- :queryParamsName="item.childTableConfigName"
142
- :localEditMode="true"
143
- @innerXFormTableEmit="innerXFormTableEmit"
144
- :fixed-query-form="childTableFixedQueryForm(item)"
145
- :service-name="serviceName"
146
- @afterTableInit="childTableMounted(item)"
147
- :ref="'childXFormTable_' + item.model">
148
- </x-form-table>
149
- </a-card>
150
- </a-row>
151
- </template>
152
- <a-row type="flex" :justify="btnPlace" :style="{paddingLeft: '16px',paddingRight: '16px'}">
153
- <slot name="footer" :loading="loading">
154
- <a-button v-if="showSubmitBtn" :loading="loading" type="primary" @click="onSubmit()">{{ btnName }}</a-button>
155
- </slot>
156
- </a-row>
157
- </a-form-model>
158
- </div>
159
- </template>
160
- <script>
161
- import XFormItem from '@vue2-client/base-client/components/common/XForm/XFormItem'
162
- import { formatDate, setDataByRealKey } from '@vue2-client/utils/util'
163
- import * as util from '@vue2-client/utils/util'
164
- import { mapState } from 'vuex'
165
- import { addOrModify, getConfigByName, getConfigByNameAsync, runLogic } from '@vue2-client/services/api/common'
166
- import { checkIdNumber, REG_EMAIL, REG_LANDLINE, REG_PHONE } from '@vue2-client/utils/reg'
167
- import moment from 'moment/moment'
168
- import { executeStrFunction, executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
169
- import formValidationMixin from '@vue2-client/mixins/formValidationMixin'
170
-
171
- const DEFAULT_GROUP_NAME = '__default__'
172
- export default {
173
- name: 'XAddNativeForm',
174
- components: {
175
- XFormItem,
176
- XFormTable: () => import('@vue2-client/base-client/components/common/XFormTable/XFormTable.vue')
177
- },
178
- inject: {
179
- inXFormGroup: {
180
- default: false
181
- },
182
- formGroupContext: {
183
- default: null
184
- },
185
- formDataChange: {
186
- default: null
187
- }
188
- },
189
- props: {},
190
- data () {
191
- return {
192
- DEFAULT_GROUP_NAME,
193
- // 预览模式
194
- viewMode: false,
195
- // 是否处理表单Key值
196
- isHandleFormKey: true,
197
- // 内容加载是否完成
198
- loaded: false,
199
- // 业务类型
200
- businessType: '',
201
- // 业务标题
202
- title: '',
203
- // 新增或修改业务是否执行中
204
- loading: false,
205
- // 表单Model
206
- form: {},
207
- // 配置名称
208
- configName: undefined,
209
- // 配置内容,用于查询配置生成器的预览
210
- configContent: undefined,
211
- // 表单项集合
212
- formItems: [],
213
- // 服务名称
214
- serviceName: undefined,
215
- // 是否显示提交按钮
216
- showSubmitBtn: true,
217
- // 修改有文件的表单时使用
218
- files: [],
219
- images: [],
220
- // 校验
221
- rules: {},
222
- // 调用logic获取数据源的追加参数
223
- getDataParams: {},
224
- // 动态简易表单集合
225
- simpleFormJsonData: {},
226
- // 待修改的数据集
227
- modifyModelData: {},
228
- // 当前环境
229
- env: 'prod',
230
- // 表单主键
231
- primaryKey: null,
232
- // 表单模式 horizontal | vertical | inline
233
- layout: 'horizontal',
234
- // 提交按钮名称
235
- btnName: '提交',
236
- // 提交按钮位置 start / center / end
237
- btnPlace: 'center',
238
- // 子表是否排在前面
239
- childTablePriority: false
240
- }
241
- },
242
- computed: {
243
- // 过滤出用于新增/修改场景的表单项
244
- realJsonData: function () {
245
- return this.formItems.filter((item) => {
246
- return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && item.addOrEdit !== 'version' && !this.itemDisabled(item)
247
- })
248
- },
249
- // 表单项组 / 不是 数据组
250
- groups: function () {
251
- if (!this.realJsonData || this.realJsonData.length === 0) {
252
- return [{
253
- groupName: DEFAULT_GROUP_NAME,
254
- realJsonData: this.realJsonData,
255
- xAddFormLayout: 'horizontal'
256
- }]
257
- }
258
- const uniqueGroups = new Set(this.realJsonData.map(item => item.group).filter(Boolean))
259
- const allGroup = Array.from(uniqueGroups).map(group => {
260
- return {
261
- groupName: group,
262
- realJsonData: this.realJsonData.filter(item => item.group === group),
263
- xAddFormLayout: 'horizontal'
264
- }
265
- })
266
- // 判断每一组得formJson 长度相加是否等于 realJsonData 长度 避免错误数据
267
- if (allGroup.reduce((total, item) => total + item.realJsonData.length, 0) === this.realJsonData.length) {
268
- return allGroup
269
- } else {
270
- return [{
271
- groupName: DEFAULT_GROUP_NAME,
272
- realJsonData: this.realJsonData,
273
- xAddFormLayout: 'horizontal'
274
- }]
275
- }
276
- },
277
- // 拥有自定义校验函数得表单项
278
- customValidateItems: function () {
279
- return this.formItems.filter((item) => {
280
- return item?.rule?.type === 'customJs'
281
- })
282
- },
283
- // 过滤出用于新增/修改场景的表单项
284
- groupJsonData: function () {
285
- return this.formItems.filter((item) => {
286
- return item.type === 'group'
287
- }).map((item) => {
288
- item.groupItems = item.groupItems.filter((item) => {
289
- return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && item.addOrEdit !== 'version' && !this.itemDisabled(item)
290
- }).map((groupItem) => {
291
- // 只保留第一个下划线后面的内容
292
- // 多层校验规则需要将prop设置为 key1.key2.....
293
- groupItem.prop = `${item.model}.${groupItem.model.substring(groupItem.model.indexOf('_') + 1)}`
294
- groupItem.model = groupItem.model.substring(groupItem.model.indexOf('_') + 1)
295
- return groupItem
296
- })
297
- return item
298
- }
299
- )
300
- },
301
- // 过滤出用于子表数据新增/修改场景的表单项
302
- childTableData: function () {
303
- return this.formItems.filter((item) => {
304
- return item.type === 'childTable'
305
- })
306
- },
307
- // 过滤出用于form子表数据新增/修改场景的表单项
308
- childFormData: function () {
309
- return this.formItems.filter((item) => {
310
- return item.type === 'rowEdit'
311
- })
312
- },
313
- // 过滤出用于静默新增场景的表单项
314
- silenceAddJsonData: function () {
315
- return this.formItems.filter(function (item) {
316
- return item.addOrEdit === 'silenceAdd'
317
- })
318
- },
319
- // 过滤出版本号表单项
320
- versionJsonData: function () {
321
- return this.formItems.filter(function (item) {
322
- return item.addOrEdit === 'version'
323
- })
324
- },
325
- formItemLayoutGen () {
326
- if (this.layout === 'horizontal') {
327
- return {
328
- labelCol: { span: 4, offset: 2 },
329
- wrapperCol: { span: 14 },
330
- }
331
- } else if (this.layout === 'vertical') {
332
- return {}
333
- } else {
334
- if (!this.formItemLayout.labelCol || !this.formItemLayout.wrapperCol) {
335
- return {
336
- labelCol: { span: 8 },
337
- wrapperCol: { span: 16 },
338
- }
339
- }
340
- return {
341
- labelCol: { span: this.formItemLayout.labelCol },
342
- wrapperCol: { span: this.formItemLayout.wrapperCol },
343
- }
344
- }
345
- },
346
- ...mapState('account', { currUser: 'user' })
347
- },
348
- provide () {
349
- return {
350
- getComponentByName: this.getComponentByName,
351
- registerComponent: this.registerComponent,
352
- XFormContext: this,
353
- // 移除必填项
354
- removeRequired: this.removeRequired,
355
- // 设置必填项
356
- setRequired: this.setRequired,
357
- getSelf: () => this,
358
- }
359
- },
360
- watch: {
361
- form: {
362
- handler (val) {
363
- if (this.formDataChange && typeof this.formDataChange === 'function') {
364
- this.formDataChange(val)
365
- }
366
- },
367
- deep: true
368
- }
369
- },
370
- /** //todo 本来想要实现 配置 自定义函数时,表单项得红星提示,根据自定义校验函数得返回值来判断
371
- * 但是监听不到父组件formgorup得其他form得变化,所以暂时不实现
372
- */
373
- //
374
- // watch: {
375
- // form: {
376
- // handler (val) {
377
- // // 遍历表单配置
378
- // if (this.customValidateItems.length > 0) {
379
- // for (const item of this.customValidateItems) {
380
- // const itemIndex = this.formItems.findIndex(formItem => formItem.model === item.model)
381
- // if (itemIndex < 0) {
382
- // continue
383
- // }
384
- // try {
385
- // this.customJsValidate(null, val[item.model], (res) => {
386
- // // 如果返回error则设置错误信息
387
- // if (res instanceof Error) {
388
- // // 设置表单项的错误状态
389
- // this.$set(this.formItems[itemIndex], 'tempRequired', true)
390
- // } else {
391
- // // 清除错误状态
392
- // this.$set(this.formItems[itemIndex], 'tempRequired', true)
393
- // }
394
- // }, item)
395
- // } catch (e) {
396
- // console.error(e)
397
- // this.$set(this.formItems[itemIndex], 'tempRequired', true)
398
- // }
399
- // }
400
- // console.log('customValidateItems', JSON.stringify(this.customValidateItems))
401
- // }
402
- // },
403
- // deep: true
404
- // }
405
- // },
406
- mixins: [formValidationMixin],
407
- methods: {
408
- runLogic,
409
- getConfigByNameAsync,
410
- getConfigByName,
411
- init (params) {
412
- const {
413
- configName,
414
- configContent,
415
- formItems,
416
- formJson,
417
- viewMode,
418
- isHandleFormKey,
419
- isKeyHandle = true,
420
- showSubmitBtn = true,
421
- serviceName,
422
- primaryKey,
423
- modifyModelData = {},
424
- businessType,
425
- title,
426
- fixedAddForm = {},
427
- getDataParams = {},
428
- simpleFormJsonData = {},
429
- env = 'prod',
430
- layout,
431
- xAddFormLayout = 'horizontal',
432
- formItemLayout = {},
433
- btnName = '提交',
434
- childTablePriority = false,
435
- btnPlace = 'center'
436
- } = params
437
- this.loaded = false
438
- // 兼容需要省略 传递 layout: res.xAddFormLayout 可以使用 ...res 展开运算符 直接转递
439
- if (xAddFormLayout && layout === undefined) {
440
- this.layout = xAddFormLayout
441
- } else {
442
- this.layout = layout
443
- }
444
- this.formItemLayout = formItemLayout
445
- if ((isHandleFormKey === null || isHandleFormKey === undefined) && !isKeyHandle) {
446
- this.isHandleFormKey = isKeyHandle
447
- } else if (isHandleFormKey) {
448
- this.isHandleFormKey = isHandleFormKey
449
- } else {
450
- this.isHandleFormKey = isKeyHandle
451
- }
452
- this.childTablePriority = childTablePriority
453
- this.configName = configName
454
- this.configContent = configContent
455
- this.formItems = this.getFromItem(formItems, formJson)
456
- this.viewMode = viewMode
457
- this.showSubmitBtn = showSubmitBtn
458
- this.primaryKey = primaryKey
459
- this.serviceName = serviceName
460
- this.businessType = businessType
461
- this.title = title
462
- this.getDataParams = getDataParams
463
- this.simpleFormJsonData = simpleFormJsonData
464
- this.env = env
465
- this.btnName = btnName
466
- this.btnPlace = btnPlace
467
- // 如果 fixedAddForm 有 selected_id 值,并且设置了处理表单key值,则多给 selected_id 加前缀 避免处理错误
468
- if (fixedAddForm.selected_id && this.isHandleFormKey) {
469
- fixedAddForm._selected_id = fixedAddForm.selected_id
470
- delete fixedAddForm.selected_id
471
- }
472
- // 设置普通表单项的相关参数
473
- const formData = Object.assign({}, fixedAddForm)
474
- for (let i = 0; i < this.realJsonData.length; i++) {
475
- const item = this.realJsonData[i]
476
- this.setFormProps(formData, item, null)
477
- }
478
- // 设置表单分组项目相关参数
479
- for (let i = 0; i < this.groupJsonData.length; i++) {
480
- const groupItem = this.groupJsonData[i]
481
- formData[groupItem.model] = {}
482
- for (let j = 0; j < groupItem.groupItems.length; j++) {
483
- const item = groupItem.groupItems[j]
484
- this.setFormProps(formData[groupItem.model], item, item.prop)
485
- }
486
- }
487
- // 设置动态简易表单项的相关参数
488
- for (const key in this.simpleFormJsonData) {
489
- for (const item of this.simpleFormJsonData[key].value) {
490
- item.model = key + '@' + item.model
491
- this.setFormProps(formData, item, null)
492
- }
493
- }
494
-
495
- this.form = formData
496
- // 修改场景下对表单项赋值
497
- if (modifyModelData && modifyModelData.data) {
498
- this.modifyModelData = modifyModelData
499
- if (Object.keys(modifyModelData.data).length > 0) {
500
- this.getModifyModelData(modifyModelData)
501
- }
502
- }
503
- // 处理表单得附件
504
- if (modifyModelData && modifyModelData.files) {
505
- this.files = modifyModelData.files
506
- }
507
- if (modifyModelData && modifyModelData.images) {
508
- this.images = modifyModelData.images
509
- }
510
- this.loaded = true
511
- },
512
- scrollToGroup (index) {
513
- const groupElement = this.$refs[`group-title-${index}`][0]
514
- if (groupElement) {
515
- groupElement.scrollIntoView({ behavior: 'smooth' })
516
- }
517
- },
518
- registerComponent (componentName, component) {
519
- console.log('内部注册', this.$options.name, componentName)
520
- this.$refs[componentName] = component
521
- console.log('内部注册完成', this.$refs)
522
- },
523
- // 根据名字从注册到组件中获取组件
524
- getComponentByName (componentName) {
525
- console.log('内部取组件', this.$options.name, componentName)
526
- console.log('内部组件内容', this.$refs)
527
- return this.$refs[componentName]
528
- },
529
- // 兼容需要省略 传递 [formItems: res.formJson ] 可以使用 ...res 展开运算符 直接转递
530
- getFromItem (formItems, formJson) {
531
- const _formItems = formItems || formJson
532
- if (typeof formItems === 'string') {
533
- return JSON.parse(_formItems)
534
- } else {
535
- return JSON.parse(JSON.stringify(_formItems))
536
- }
537
- },
538
- innerXFormTableEmit (fun, record, id, actionType, index) {
539
- this.$emit(fun, record, id, actionType, index)
540
- },
541
- // 时间组件赋默认值
542
- // .type, item.formDefault
543
- getDateRange ({ type, formDefault: defaultValue, formValueFormat }) {
544
- // const format = type === 'datePicker' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'
545
- let format = 'YYYY-MM-DD HH:mm:ss'
546
- if (formValueFormat) {
547
- format = formValueFormat
548
- }
549
- let start
550
- switch (defaultValue) {
551
- case 'curYear':
552
- start = moment().startOf('year').format(format)
553
- break
554
- case 'curMonth':
555
- start = moment().startOf('month').format(format)
556
- break
557
- case 'curDay':
558
- start = moment().startOf('day').format(format)
559
- break
560
- case 'curTime':
561
- start = moment().format(format)
562
- break
563
- default:
564
- return defaultValue
565
- }
566
- return start
567
- },
568
- setFormProps (formData, item, groupItem) {
569
- const rulesKey = `${item.name}${item.model}`
570
- if (formData[item.model] === undefined || formData[item.model] === null) {
571
- formData[item.model] = undefined
572
- }
573
- if (!formData[item.model] && item.formDefault) {
574
- if (['datePicker', 'rangePicker', 'yearPicker', 'monthPicker', 'yearRangePicker', 'monthRangePicker'].includes(item.type)) {
575
- formData[item.model] = this.getDateRange(item)
576
- } else if (['treeSelect', 'select', 'checkbox'].includes(item.type) && ['curOrgId', 'curDepId', 'curUserId'].includes(item.formDefault)) {
577
- if (item.formDefault === 'curOrgId') {
578
- formData[item.model] = item.type === 'select' ? this.currUser.orgid : [this.currUser.orgid]
579
- }
580
- if (item.formDefault === 'curDepId') {
581
- formData[item.model] = item.type === 'select' ? this.currUser.depids : [this.currUser.depids]
582
- }
583
- if (item.formDefault === 'curUserId') {
584
- formData[item.model] = item.type === 'select' ? this.currUser.id : [this.currUser.id]
585
- }
586
- } else if (['addressSearch'].includes(item.type)) {
587
- formData[item.model] = item.formDefault
588
- formData[`${item.model}_lng_lat`] = item.formDefault_lng_lat
589
- } else {
590
- formData[item.model] = item.formDefault
591
- }
592
- }
593
- // 处理表单校验情况
594
- if (item.rule) {
595
- if (groupItem) {
596
- this.rules[groupItem] = []
597
- } else {
598
- this.rules[rulesKey] = []
599
- }
600
- const required = item.rule.required ? item.rule.required === true || item.rule.required === 'true' : false
601
- let trigger
602
- let message
603
- if (required) {
604
- switch (item.type) {
605
- case 'select':
606
- case 'checkbox':
607
- case 'radio':
608
- case 'treeSelect':
609
- case 'rangePicker':
610
- case 'monthPicker':
611
- case 'yearPicker':
612
- case 'datePicker':
613
- case 'file':
614
- case 'image':
615
- case 'citySelect':
616
- case 'addressSearch':
617
- case 'personSetting':
618
- message = '请选择' + item.name
619
- trigger = 'change'
620
- break
621
- default:
622
- message = '请输入' + item.name
623
- trigger = 'blur'
624
- }
625
- if (groupItem) {
626
- this.rules[groupItem].push({
627
- required: true,
628
- message: message,
629
- trigger: trigger
630
- })
631
- } else {
632
- this.rules[rulesKey].push({
633
- required: true,
634
- message: message,
635
- trigger: trigger
636
- })
637
- }
638
- }
639
-
640
- switch (item.rule.type) {
641
- case 'number':
642
- case 'integer':
643
- case 'float':
644
- // eslint-disable-next-line no-case-declarations
645
- let defaultValue
646
- // eslint-disable-next-line no-case-declarations
647
- let message
648
- switch (item.rule.type) {
649
- case 'number':
650
- item.numberInput = true
651
- message = '数字'
652
- defaultValue = 0
653
- break
654
- case 'integer':
655
- item.numberInput = true
656
- message = '整数'
657
- defaultValue = 0
658
- break
659
- case 'float':
660
- item.numberInput = true
661
- message = '小数'
662
- defaultValue = 0.0
663
- break
664
- }
665
- if (groupItem) {
666
- this.rules[groupItem].push({
667
- type: item.rule.type,
668
- message: item.name + '必须为' + message,
669
- transform: (value) => {
670
- if (value && value.length !== 0) {
671
- return Number(value)
672
- } else {
673
- return defaultValue
674
- }
675
- },
676
- trigger: 'blur'
677
- })
678
- } else {
679
- this.rules[rulesKey].push({
680
- type: item.rule.type,
681
- message: item.name + '必须为' + message,
682
- transform: (value) => {
683
- if (value && value.length !== 0) {
684
- return Number(value)
685
- } else {
686
- return defaultValue
687
- }
688
- },
689
- trigger: 'blur'
690
- })
691
- }
692
- break
693
- case 'email': {
694
- const validator = (rule, value, callback) => {
695
- if (value && !REG_EMAIL.test(value)) {
696
- callback(new Error('请输入正确的邮箱地址'))
697
- } else {
698
- callback()
699
- }
700
- }
701
- this.rules[groupItem || rulesKey].push({
702
- type: 'email',
703
- validator: validator,
704
- message: '请输入正确的邮箱地址',
705
- trigger: 'blur'
706
- })
707
- break
708
- }
709
- case 'userPhone': {
710
- this.rules[groupItem || rulesKey].push({
711
- type: 'userPhone',
712
- validator: (rule, value, callback) => {
713
- if (value && !REG_PHONE.test(value)) {
714
- callback(new Error('请输入正确的手机号码'))
715
- } else {
716
- callback()
717
- }
718
- },
719
- message: '请输入正确的手机号码',
720
- trigger: 'blur'
721
- })
722
- break
723
- }
724
- case 'idNumber': {
725
- this.rules[groupItem || rulesKey].push({
726
- validator: (rule, value, callback) => {
727
- if (value && !checkIdNumber(value)) {
728
- callback(new Error('请输入正确的身份证号码'))
729
- } else {
730
- callback()
731
- }
732
- },
733
- trigger: 'blur'
734
- })
735
- break
736
- }
737
- case 'landlineNumber': {
738
- this.rules[rulesKey].push({
739
- validator: (rule, value, callback) => {
740
- if (value && !REG_LANDLINE.test(value)) {
741
- callback(new Error('请输入正确的座机号码'))
742
- } else {
743
- callback()
744
- }
745
- },
746
- trigger: 'blur'
747
- })
748
- break
749
- }
750
- // 大于0
751
- case 'greaterThanZero': {
752
- item.numberInput = true
753
- this.rules[rulesKey].push({
754
- validator: (rule, value, callback) => {
755
- if (isNaN(value) || value <= 0) {
756
- callback(new Error('请输入一个大于0的数字'))
757
- } else {
758
- callback()
759
- }
760
- },
761
- trigger: 'blur'
762
- })
763
- break
764
- }
765
- // 大于等于0
766
- case 'greaterThanOrEqualZero': {
767
- item.numberInput = true
768
- this.rules[rulesKey].push({
769
- validator: (rule, value, callback) => {
770
- if (isNaN(value) || value < 0) {
771
- callback(new Error('请输入一个大于等于0的数字'))
772
- } else {
773
- callback()
774
- }
775
- },
776
- trigger: 'blur'
777
- })
778
- break
779
- }
780
- case 'stringLength': {
781
- this.rules[rulesKey].push({
782
- validator: (rule, value, callback) => {
783
- if (value && value.length < item.rule.minLen) {
784
- callback(new Error('长度不能少于' + item.rule.minLen + '个字符'))
785
- } else if (value && value.length > item.rule.maxLen) {
786
- callback(new Error('长度不能超过' + item.rule.maxLen + '个字符'))
787
- } else {
788
- callback()
789
- }
790
- },
791
- trigger: 'blur'
792
- })
793
- break
794
- }
795
- case 'customJs': {
796
- this.rules[rulesKey].push({
797
- validator: (rule, value, callback) => {
798
- this.customJsValidate(rule, value, callback, item)
799
- },
800
- trigger: 'blur'
801
- })
802
- break
803
- }
804
- }
805
- }
806
- },
807
- childTableMounted (item) {
808
- // 子表初始化时,设置表格数据
809
- if (this.form[item.model] && this.form[item.model].length > 0) {
810
- this.$refs[`childXFormTable_${item.model}`][0].setTableData(this.form[item.model])
811
- }
812
- },
813
- customJsValidate (rule, value, callback, item) {
814
- if (item.rule.customValidatorFunc) {
815
- executeStrFunctionByContext(this, item.rule.customValidatorFunc, [rule, value, callback, this.form, item, this.util, runLogic, getConfigByNameAsync])
816
- } else {
817
- callback()
818
- }
819
- },
820
- itemDisabled (value) {
821
- return (this.businessType === '新增' && value.addOrEdit === 'edit') ||
822
- (this.businessType === '修改' && value.addOrEdit === 'add')
823
- },
824
- readonly (value) {
825
- return value.addOrEdit === 'readonly'
826
- },
827
- async onSubmit () {
828
- const valid = await this.validateForm()
829
- if (!valid) return false
830
- if (this.viewMode) {
831
- this.$message.info('预览模式禁止新增和修改')
832
- return false
833
- }
834
- this.loading = true
835
- const requestForm = this.prepareForm()
836
- await this.appendSilenceAddFields(requestForm)
837
- const realForm = this.handleFormKeys(requestForm)
838
- // 增加子表数据
839
- if (this.childTableData.length > 0) {
840
- for (const item of this.childTableData) {
841
- const childModel = item.model
842
- const childDataRef = this.$refs['childXFormTable_' + item.model][0].getTableData()
843
- const childData = []
844
- for (const item of childDataRef) {
845
- childData.push(JSON.parse(JSON.stringify(item)))
846
- }
847
- for (let i = 0; i < childData.length; i++) {
848
- childData[i] = this.handleFormKeys(childData[i])
849
- // 外键不需要带表别名,所以此处放到表单处理后赋值
850
- if (realForm.id) {
851
- childData[i][item.childTableForeignKeyName] = realForm.id
852
- }
853
- }
854
- realForm[childModel] = childData
855
- }
856
- }
857
- // 增加form子表数据
858
- if (this.childFormData.length > 0) {
859
- for (const item of this.childFormData) {
860
- const childModel = item.model
861
- const childData = this.$refs[item.model].getTableData()
862
- for (let i = 0; i < childData.length; i++) {
863
- childData[i] = this.handleFormKeys(childData[i], true)
864
- // 外键不需要带表别名,所以此处放到表单处理后赋值
865
- if (realForm.id) {
866
- childData[i][item.foreignKey] = realForm.id
867
- }
868
- }
869
- realForm[childModel] = childData
870
- }
871
- }
872
- if (this.$listeners.onSubmit) {
873
- // 交由父级处理
874
- this.$emit('onSubmit', {
875
- businessType: this.businessType,
876
- serviceName: this.serviceName,
877
- realForm: realForm,
878
- currUserName: this.currUser.name,
879
- currUserId: this.currUser.id,
880
- orgId: this.currUser.orgid
881
- })
882
- } else {
883
- this.defaultSubmit(realForm)
884
- }
885
- },
886
-
887
- async asyncSubmit () {
888
- return new Promise((resolve, reject) => {
889
- this.$refs.selectForm.validate(async valid => {
890
- if (!valid) {
891
- reject(new Error('Form validation failed'))
892
- return
893
- }
894
- this.loading = true
895
- const requestForm = this.prepareForm()
896
- await this.appendSilenceAddFields(requestForm)
897
- const realForm = this.handleFormKeys(requestForm)
898
- resolve({
899
- realForm,
900
- businessType: this.businessType,
901
- serviceName: this.serviceName,
902
- currUserName: this.currUser.name,
903
- currUserId: this.currUser.id,
904
- orgId: this.currUser.orgid
905
- })
906
- })
907
- })
908
- },
909
-
910
- validateForm () {
911
- return new Promise((resolve) => {
912
- this.$refs.selectForm.validate(valid => resolve(valid))
913
- })
914
- },
915
-
916
- childTableFixedQueryForm (item) {
917
- if (this.modifyModelData?.primaryKeyData) {
918
- const fixedForm = {}
919
- fixedForm[item.childTableForeignKeyName] = Object.values(this.modifyModelData.primaryKeyData)[0]
920
- return fixedForm
921
- }
922
- return null
923
- },
924
-
925
- prepareForm () {
926
- const form = { ...this.form }
927
- for (const key of Object.keys(form)) {
928
- const value = form[key]
929
- if (value === null || (typeof value === 'object' && Object.keys(value).length === 0)) {
930
- form[key] = undefined
931
- }
932
- }
933
- return form
934
- },
935
-
936
- async appendSilenceAddFields (form) {
937
- if (this.businessType === '新增') {
938
- for (const item of this.silenceAddJsonData) {
939
- switch (item.silencePurpose) {
940
- case 'createTime':
941
- form[item.model] = formatDate('now')
942
- break
943
- case 'operator':
944
- form[item.model] = this.currUser.name
945
- break
946
- case 'operatorId':
947
- form[item.model] = this.currUser.id
948
- break
949
- case 'orgId':
950
- form[item.model] = this.currUser.orgid
951
- break
952
- case 'orgName':
953
- form[item.model] = this.currUser.orgs
954
- break
955
- case 'depId':
956
- form[item.model] = this.currUser.depids
957
- break
958
- case 'depName':
959
- form[item.model] = this.currUser.deps
960
- break
961
- }
962
- }
963
- for (const item of this.silenceAddJsonData.filter((item) => item.silencePurpose === 'customize')) {
964
- const result = await runLogic(item.silenceSource, form, this.serviceName)
965
- if (result) {
966
- const keys = Object.keys(result)
967
- if (keys.length === 1 && keys[0] === 'value') {
968
- form[item.model] = result.value
969
- } else {
970
- form[item.model] = result
971
- }
972
- } else {
973
- form[item.model] = result
974
- }
975
- }
976
- }
977
- },
978
-
979
- handleFormKeys (form, mustHandleKey = false) {
980
- const realForm = {}
981
- for (const key of Object.keys(form)) {
982
- const value = form[key]
983
- const extraFormKeyTagIndex = key.indexOf('@')
984
- if (extraFormKeyTagIndex !== -1) {
985
- const extraFormKey = key.substring(0, extraFormKeyTagIndex)
986
- const realKey = key.substring(extraFormKeyTagIndex + 1)
987
- if (!realForm[extraFormKey]) {
988
- realForm[extraFormKey] = {}
989
- }
990
- realForm[extraFormKey][realKey] = value
991
- } else {
992
- const realKey = this.isHandleFormKey || mustHandleKey ? this.getRealKey(key, mustHandleKey) : key
993
- // 如果发生重名,不覆盖,把key的别名带上
994
- if (realForm[realKey]) {
995
- realForm[key] = value
996
- } else {
997
- realForm[realKey] = value
998
- }
999
- }
1000
- }
1001
- return realForm
1002
- },
1003
- // 默认提交事件
1004
- defaultSubmit (realForm, callback) {
1005
- // 新增移除id
1006
- if (this.businessType === '新增') {
1007
- delete realForm.id
1008
- }
1009
- // 组织请求
1010
- const requestParameters = {
1011
- queryParamsName: this.configName,
1012
- queryParams: this.configContent,
1013
- form: realForm,
1014
- businessType: this.businessType,
1015
- operator: this.currUser.name
1016
- }
1017
- addOrModify(requestParameters, this.serviceName, this.env === 'dev').then(data => {
1018
- this.$message.success(this.businessType + '成功!')
1019
- // commit
1020
- this.$emit('afterSubmit', { type: this.businessType, id: data.id, data: data, form: requestParameters.form })
1021
- this.loading = false
1022
- if (callback) {
1023
- callback()
1024
- }
1025
- }).catch(e => {
1026
- this.loading = false
1027
- this.$message.error(this.businessType + '失败:' + e)
1028
- })
1029
- },
1030
- // 获取表单字段实际值
1031
- getRealKey (key, mustHandleKey = false) {
1032
- if (key === 'selected_id') return key
1033
- if (this.isHandleFormKey || mustHandleKey) {
1034
- return key.substring(key.indexOf('_') + 1)
1035
- } else {
1036
- return key
1037
- }
1038
- },
1039
- /**
1040
- * 获取被修改记录数据
1041
- * @param modifyModelData 被修改记录的数据
1042
- */
1043
- getModifyModelData (modifyModelData) {
1044
- if (modifyModelData.primaryKeyData) {
1045
- this.form = Object.assign(this.form, modifyModelData.primaryKeyData)
1046
- }
1047
- // 对动态简易表单项特殊处理
1048
- for (const key in modifyModelData.data) {
1049
- const realKey = this.isHandleFormKey ? this.getRealKey(key) : key
1050
- if (this.simpleFormJsonData[realKey]) {
1051
- const extraForm = JSON.parse(modifyModelData.data[key])
1052
- for (const key in extraForm) {
1053
- const model = realKey + '@' + key
1054
- this.form[model] = extraForm[key]
1055
- }
1056
- }
1057
- }
1058
- // 对普通表单项处理
1059
- for (let i = 0; i < this.realJsonData.length; i++) {
1060
- if (['FilesId', 'Images'].includes(this.realJsonData[i])) {
1061
- // 附件需要跳过 因为会通过 modifyModelData中的files,images属性给upload赋值
1062
- // 新增修改表单每次提交时只会提交最新添加的文件
1063
- continue
1064
- }
1065
- const item = this.realJsonData[i]
1066
- // 地址选择器 需要传递 经纬度字段, 配置中添加 `${item.model}_lng_lat` CRUD 只需勾选 SQL生成查询项
1067
- if (['addressSearch'].includes(item.type)) {
1068
- this.form[item.model] = modifyModelData.data[item.model] + ''
1069
- this.form[`${item.model}_lng_lat`] = modifyModelData.data[`${item.model}_lng_lat`] + ''
1070
- continue
1071
- }
1072
- if (modifyModelData.data[item.model] || modifyModelData.data[item.model] === 0) {
1073
- if (modifyModelData.data[item.model] instanceof Array) {
1074
- this.form[item.model] = modifyModelData.data[item.model]
1075
- } else {
1076
- this.form[item.model] = modifyModelData.data[item.model] + ''
1077
- }
1078
- }
1079
- }
1080
- // 对分组表单进行处理
1081
- for (let i = 0; i < this.groupJsonData.length; i++) {
1082
- const item = this.groupJsonData[i]
1083
- try {
1084
- if (modifyModelData.data[item.model]) {
1085
- this.form[item.model] = JSON.parse(modifyModelData.data[item.model])
1086
- }
1087
- } catch (e) {
1088
- if (modifyModelData.data[item.model]) {
1089
- this.form[item.model] = modifyModelData.data[item.model]
1090
- }
1091
- }
1092
- }
1093
- // 追加版本号信息
1094
- for (const item of this.versionJsonData) {
1095
- if (!modifyModelData.data[item.model]) {
1096
- this.form[item.model] = 0
1097
- } else {
1098
- this.form[item.model] = modifyModelData.data[item.model] + ''
1099
- }
1100
- }
1101
- },
1102
- setForm (obj) {
1103
- this.form = Object.assign(this.form, obj)
1104
- // 给子表赋外键条件
1105
- if (this.childFormData.length > 0) {
1106
- for (const item of this.childFormData) {
1107
- const child = this.$refs[item.model]
1108
- // 获取子表别名,以便在条件上添加别名
1109
- const alias = child.realQueryConfig.tableAliasName
1110
- // 有主键,且主键有值,添加主键条件
1111
- if (this.primaryKey && this.form[this.primaryKey]) {
1112
- const foreignKey = item.foreignKey
1113
- const fixedQueryForm = { [alias + '_' + foreignKey]: this.form[this.primaryKey] }
1114
- if (!child.fixedQueryForm) {
1115
- child.fixedQueryForm = fixedQueryForm
1116
- } else {
1117
- Object.assign(child.fixedQueryForm, fixedQueryForm)
1118
- }
1119
- child.refreshTable()
1120
- }
1121
- }
1122
- }
1123
- },
1124
- setFormWithKey (obj) {
1125
- setDataByRealKey(this.form, obj)
1126
- },
1127
- setFormWithNoKey (obj) {
1128
- setDataByRealKey(this.form, obj)
1129
- },
1130
- emitFunc (func, data, value) {
1131
- this.$emit(func, data, value)
1132
- this.$emit('x-form-item-emit-func', func, data, value)
1133
- },
1134
- // 直接转发事件的函数
1135
- emitEvent (event, ...args) {
1136
- this.$emit(event, ...args)
1137
- },
1138
- close () {
1139
- this.loaded = false
1140
- },
1141
- /**
1142
- * 行选择事件
1143
- * @param row 选中行集合
1144
- * @param attr 表单项属性
1145
- */
1146
- async rowChoose (row, attr, callback) {
1147
- // 如果配置了自定义函数
1148
- if (attr.dataChangeFunc) {
1149
- await executeStrFunction(attr.dataChangeFunc, [this.form, this.setForm, {
1150
- ...attr,
1151
- selectRows: row
1152
- }, util, this.mode, runLogic, getConfigByNameAsync])
1153
- } else {
1154
- // 默认填充选中行数据到当前表单
1155
- setDataByRealKey(this.form, row[0])
1156
- }
1157
- if (callback) {
1158
- callback()
1159
- }
1160
- },
1161
- }
1162
- }
1163
- </script>
1164
-
1165
- <style scoped lang="less">
1166
- :deep(.ant-form-inline .ant-form-item ) {
1167
- display: block !important;
1168
- }
1169
-
1170
- :deep(.ant-form-item-with-help) {
1171
- margin-bottom: 0;
1172
- }
1173
-
1174
- .xFormGroupTitle {
1175
- font-weight: bold;
1176
- color: @primary-color;
1177
- }
1178
- </style>
1
+ <template>
2
+ <div id="XAddNativeForm">
3
+ <a-form-model
4
+ v-if="loaded"
5
+ ref="selectForm"
6
+ :zIndex="1001"
7
+ :model="form"
8
+ v-bind="formItemLayoutGen"
9
+ :layout="layout">
10
+ <template v-for="(item, key) in childTableData">
11
+ <a-row
12
+ v-if="childTablePriority"
13
+ :gutter="16"
14
+ :key="'childTableRow' + key">
15
+ <a-card :title="item.name" :bordered="false" size="small">
16
+ <x-form-table
17
+ :key="'childTable_' + item.model"
18
+ :title="item.name"
19
+ :queryParamsName="item.childTableConfigName"
20
+ :localEditMode="true"
21
+ :fixed-query-form="childTableFixedQueryForm(item)"
22
+ :service-name="serviceName"
23
+ @innerXFormTableEmit="innerXFormTableEmit"
24
+ @afterTableInit="childTableMounted(item)"
25
+ :ref="'childXFormTable_' + item.model">
26
+ </x-form-table>
27
+ </a-card>
28
+ </a-row>
29
+ </template>
30
+ <a-row ref="GroupItemRow">
31
+ <a-col :span="3" v-if="!inXFormGroup && !(groups[0].groupName === DEFAULT_GROUP_NAME)">
32
+ <a-tabs tab-position="left" v-model="activeTab" @change="scrollToGroup">
33
+ <a-tab-pane
34
+ v-for="(groupsItem,groupsIndex) in groups"
35
+ :tab="groupsItem.groupName"
36
+ :key="groupsIndex">
37
+ </a-tab-pane>
38
+ </a-tabs>
39
+ </a-col>
40
+ <a-col
41
+ :span="(!inXFormGroup && !(groups[0].groupName === DEFAULT_GROUP_NAME)) ? 21: 24">
42
+ <a-row
43
+ :gutter="16"
44
+ type="flex"
45
+ :key="groupsIndex"
46
+ v-for="(groupsItem,groupsIndex) in groups"
47
+ >
48
+ <a-col
49
+ :span="24"
50
+ :style="{ marginTop: groupsIndex === 0 ? '' : '8px',fontSize:inXFormGroup?'15px':'14px', marginLeft:'-5px' }"
51
+ v-if="groupsItem.groupName !== DEFAULT_GROUP_NAME">
52
+ <span class="xFormGroupTitle" :ref="`group-title-${groupsIndex}`">{{ groupsItem.groupName }}</span>
53
+ </a-col>
54
+ <x-form-item
55
+ v-for="(item, index) in groupsItem.realJsonData"
56
+ :key="index"
57
+ :attr="item"
58
+ :disabled="itemDisabled(item)"
59
+ :read-only="readonly(item)"
60
+ :files="files"
61
+ v-bind="formItemLayoutGen"
62
+ :style="layout === 'inline' ? { marginTop:'5px' } : undefined"
63
+ :form="form"
64
+ :images="images"
65
+ :service-name="serviceName"
66
+ mode="新增/修改"
67
+ :layout="layout"
68
+ :rules="rules[`${item.name}${item.model}`]"
69
+ :get-data-params="getDataParams"
70
+ :env="env"
71
+ @x-form-item-emit-func="emitFunc"
72
+ @rowChoose="rowChoose"
73
+ :setForm="setForm"
74
+ />
75
+ </a-row>
76
+ </a-col>
77
+ </a-row>
78
+ <a-row :gutter="16" v-for="(groupItem, groupIndex) in groupJsonData" :key="groupIndex">
79
+ <a-card v-if="groupItem.groupItems.length > 0" :title="groupItem.name" :bordered="false" size="small">
80
+ <x-form-item
81
+ v-for="(item, index) in groupItem.groupItems"
82
+ :key="index"
83
+ :attr="item"
84
+ :disabled="itemDisabled(item)"
85
+ :readonly="readonly(item)"
86
+ :files="files"
87
+ v-bind="formItemLayoutGen"
88
+ :style="layout ==='inline'?{marginTop:'5px'}:undefined"
89
+ :form="form[groupItem.model]"
90
+ :images="images"
91
+ :service-name="serviceName"
92
+ mode="新增/修改"
93
+ :rules="rules[`${item.name}${item.model}`]"
94
+ :get-data-params="getDataParams"
95
+ :env="env"
96
+ :setForm="setForm"
97
+ @rowChoose="rowChoose"
98
+ />
99
+ </a-card>
100
+ <template v-else>
101
+ <slot
102
+ name="groupFormItems"
103
+ :form="form"
104
+ :model="groupItem.model"
105
+ :rules="rules"
106
+ :modifyModelData="modifyModelData"></slot>
107
+ </template>
108
+ </a-row>
109
+ <a-row :gutter="16" v-for="(item, key) in simpleFormJsonData" :key="'row' + key">
110
+ <a-card v-if="item.value.length > 0" :title="item.name" :bordered="false" size="small">
111
+ <x-form-item
112
+ v-for="(formItem, formItemIndex) in item.value"
113
+ :key="key + formItemIndex"
114
+ :attr="formItem"
115
+ :disabled="itemDisabled(formItem)"
116
+ :readonly="readonly(formItem)"
117
+ :files="files"
118
+ v-bind="formItemLayoutGen"
119
+ :style="layout ==='inline'?{marginTop:'5px'}:undefined"
120
+ :form="form[groupItem.model]"
121
+ :images="images"
122
+ :service-name="serviceName"
123
+ mode="新增/修改"
124
+ :rules="rules[`${item.name}${item.model}`]"
125
+ :get-data-params="getDataParams"
126
+ :env="env"
127
+ :setForm="setForm"
128
+ @rowChoose="rowChoose"
129
+ />
130
+ </a-card>
131
+ </a-row>
132
+ <template v-for="(item, key) in childTableData">
133
+ <a-row
134
+ v-if="!childTablePriority"
135
+ :gutter="16"
136
+ :key="'childTableRow' + key">
137
+ <a-card :title="item.name" :bordered="false" size="small">
138
+ <x-form-table
139
+ :key="'childTable_' + item.model"
140
+ :title="item.name"
141
+ :queryParamsName="item.childTableConfigName"
142
+ :localEditMode="true"
143
+ @innerXFormTableEmit="innerXFormTableEmit"
144
+ :fixed-query-form="childTableFixedQueryForm(item)"
145
+ :service-name="serviceName"
146
+ @afterTableInit="childTableMounted(item)"
147
+ :ref="'childXFormTable_' + item.model">
148
+ </x-form-table>
149
+ </a-card>
150
+ </a-row>
151
+ </template>
152
+ <a-row type="flex" :justify="btnPlace" :style="{paddingLeft: '16px',paddingRight: '16px'}">
153
+ <slot name="footer" :loading="loading">
154
+ <a-button v-if="showSubmitBtn" :loading="loading" type="primary" @click="onSubmit()">{{ btnName }}</a-button>
155
+ </slot>
156
+ </a-row>
157
+ </a-form-model>
158
+ </div>
159
+ </template>
160
+ <script>
161
+ import XFormItem from '@vue2-client/base-client/components/common/XForm/XFormItem'
162
+ import { formatDate, setDataByRealKey } from '@vue2-client/utils/util'
163
+ import * as util from '@vue2-client/utils/util'
164
+ import { mapState } from 'vuex'
165
+ import { addOrModify, getConfigByName, getConfigByNameAsync, runLogic } from '@vue2-client/services/api/common'
166
+ import { checkIdNumber, REG_EMAIL, REG_LANDLINE, REG_PHONE } from '@vue2-client/utils/reg'
167
+ import moment from 'moment/moment'
168
+ import { executeStrFunction, executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
169
+ import formValidationMixin from '@vue2-client/mixins/formValidationMixin'
170
+
171
+ const DEFAULT_GROUP_NAME = '__default__'
172
+ export default {
173
+ name: 'XAddNativeForm',
174
+ components: {
175
+ XFormItem,
176
+ XFormTable: () => import('@vue2-client/base-client/components/common/XFormTable/XFormTable.vue')
177
+ },
178
+ inject: {
179
+ inXFormGroup: {
180
+ default: false
181
+ },
182
+ formGroupContext: {
183
+ default: null
184
+ },
185
+ formDataChange: {
186
+ default: null
187
+ }
188
+ },
189
+ props: {},
190
+ data () {
191
+ return {
192
+ DEFAULT_GROUP_NAME,
193
+ // 预览模式
194
+ viewMode: false,
195
+ // 是否处理表单Key值
196
+ isHandleFormKey: true,
197
+ // 内容加载是否完成
198
+ loaded: false,
199
+ // 业务类型
200
+ businessType: '',
201
+ // 业务标题
202
+ title: '',
203
+ // 新增或修改业务是否执行中
204
+ loading: false,
205
+ // 表单Model
206
+ form: {},
207
+ // 配置名称
208
+ configName: undefined,
209
+ // 配置内容,用于查询配置生成器的预览
210
+ configContent: undefined,
211
+ // 表单项集合
212
+ formItems: [],
213
+ // 服务名称
214
+ serviceName: undefined,
215
+ // 是否显示提交按钮
216
+ showSubmitBtn: true,
217
+ // 修改有文件的表单时使用
218
+ files: [],
219
+ images: [],
220
+ // 校验
221
+ rules: {},
222
+ // 调用logic获取数据源的追加参数
223
+ getDataParams: {},
224
+ // 动态简易表单集合
225
+ simpleFormJsonData: {},
226
+ // 待修改的数据集
227
+ modifyModelData: {},
228
+ // 当前环境
229
+ env: 'prod',
230
+ // 表单主键
231
+ primaryKey: null,
232
+ // 表单模式 horizontal | vertical | inline
233
+ layout: 'horizontal',
234
+ // 提交按钮名称
235
+ btnName: '提交',
236
+ // 提交按钮位置 start / center / end
237
+ btnPlace: 'center',
238
+ // 子表是否排在前面
239
+ childTablePriority: false
240
+ }
241
+ },
242
+ computed: {
243
+ // 过滤出用于新增/修改场景的表单项
244
+ realJsonData: function () {
245
+ return this.formItems.filter((item) => {
246
+ return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && item.addOrEdit !== 'version' && !this.itemDisabled(item)
247
+ })
248
+ },
249
+ // 表单项组 / 不是 数据组
250
+ groups: function () {
251
+ if (!this.realJsonData || this.realJsonData.length === 0) {
252
+ return [{
253
+ groupName: DEFAULT_GROUP_NAME,
254
+ realJsonData: this.realJsonData,
255
+ xAddFormLayout: 'horizontal'
256
+ }]
257
+ }
258
+ const uniqueGroups = new Set(this.realJsonData.map(item => item.group).filter(Boolean))
259
+ const allGroup = Array.from(uniqueGroups).map(group => {
260
+ return {
261
+ groupName: group,
262
+ realJsonData: this.realJsonData.filter(item => item.group === group),
263
+ xAddFormLayout: 'horizontal'
264
+ }
265
+ })
266
+ // 判断每一组得formJson 长度相加是否等于 realJsonData 长度 避免错误数据
267
+ if (allGroup.reduce((total, item) => total + item.realJsonData.length, 0) === this.realJsonData.length) {
268
+ return allGroup
269
+ } else {
270
+ return [{
271
+ groupName: DEFAULT_GROUP_NAME,
272
+ realJsonData: this.realJsonData,
273
+ xAddFormLayout: 'horizontal'
274
+ }]
275
+ }
276
+ },
277
+ // 拥有自定义校验函数得表单项
278
+ customValidateItems: function () {
279
+ return this.formItems.filter((item) => {
280
+ return item?.rule?.type === 'customJs'
281
+ })
282
+ },
283
+ // 过滤出用于新增/修改场景的表单项
284
+ groupJsonData: function () {
285
+ return this.formItems.filter((item) => {
286
+ return item.type === 'group'
287
+ }).map((item) => {
288
+ item.groupItems = item.groupItems.filter((item) => {
289
+ return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && item.addOrEdit !== 'version' && !this.itemDisabled(item)
290
+ }).map((groupItem) => {
291
+ // 只保留第一个下划线后面的内容
292
+ // 多层校验规则需要将prop设置为 key1.key2.....
293
+ groupItem.prop = `${item.model}.${groupItem.model.substring(groupItem.model.indexOf('_') + 1)}`
294
+ groupItem.model = groupItem.model.substring(groupItem.model.indexOf('_') + 1)
295
+ return groupItem
296
+ })
297
+ return item
298
+ }
299
+ )
300
+ },
301
+ // 过滤出用于子表数据新增/修改场景的表单项
302
+ childTableData: function () {
303
+ return this.formItems.filter((item) => {
304
+ return item.type === 'childTable'
305
+ })
306
+ },
307
+ // 过滤出用于form子表数据新增/修改场景的表单项
308
+ childFormData: function () {
309
+ return this.formItems.filter((item) => {
310
+ return item.type === 'rowEdit'
311
+ })
312
+ },
313
+ // 过滤出用于静默新增场景的表单项
314
+ silenceAddJsonData: function () {
315
+ return this.formItems.filter(function (item) {
316
+ return item.addOrEdit === 'silenceAdd'
317
+ })
318
+ },
319
+ // 过滤出版本号表单项
320
+ versionJsonData: function () {
321
+ return this.formItems.filter(function (item) {
322
+ return item.addOrEdit === 'version'
323
+ })
324
+ },
325
+ formItemLayoutGen () {
326
+ if (this.layout === 'horizontal') {
327
+ return {
328
+ labelCol: { span: 4, offset: 2 },
329
+ wrapperCol: { span: 14 },
330
+ }
331
+ } else if (this.layout === 'vertical') {
332
+ return {}
333
+ } else {
334
+ if (!this.formItemLayout.labelCol || !this.formItemLayout.wrapperCol) {
335
+ return {
336
+ labelCol: { span: 8 },
337
+ wrapperCol: { span: 16 },
338
+ }
339
+ }
340
+ return {
341
+ labelCol: { span: this.formItemLayout.labelCol },
342
+ wrapperCol: { span: this.formItemLayout.wrapperCol },
343
+ }
344
+ }
345
+ },
346
+ ...mapState('account', { currUser: 'user' })
347
+ },
348
+ provide () {
349
+ return {
350
+ getComponentByName: this.getComponentByName,
351
+ registerComponent: this.registerComponent,
352
+ XFormContext: this,
353
+ // 移除必填项
354
+ removeRequired: this.removeRequired,
355
+ // 设置必填项
356
+ setRequired: this.setRequired,
357
+ getSelf: () => this,
358
+ }
359
+ },
360
+ watch: {
361
+ form: {
362
+ handler (val) {
363
+ if (this.formDataChange && typeof this.formDataChange === 'function') {
364
+ this.formDataChange(val)
365
+ }
366
+ },
367
+ deep: true
368
+ }
369
+ },
370
+ /** //todo 本来想要实现 配置 自定义函数时,表单项得红星提示,根据自定义校验函数得返回值来判断
371
+ * 但是监听不到父组件formgorup得其他form得变化,所以暂时不实现
372
+ */
373
+ //
374
+ // watch: {
375
+ // form: {
376
+ // handler (val) {
377
+ // // 遍历表单配置
378
+ // if (this.customValidateItems.length > 0) {
379
+ // for (const item of this.customValidateItems) {
380
+ // const itemIndex = this.formItems.findIndex(formItem => formItem.model === item.model)
381
+ // if (itemIndex < 0) {
382
+ // continue
383
+ // }
384
+ // try {
385
+ // this.customJsValidate(null, val[item.model], (res) => {
386
+ // // 如果返回error则设置错误信息
387
+ // if (res instanceof Error) {
388
+ // // 设置表单项的错误状态
389
+ // this.$set(this.formItems[itemIndex], 'tempRequired', true)
390
+ // } else {
391
+ // // 清除错误状态
392
+ // this.$set(this.formItems[itemIndex], 'tempRequired', true)
393
+ // }
394
+ // }, item)
395
+ // } catch (e) {
396
+ // console.error(e)
397
+ // this.$set(this.formItems[itemIndex], 'tempRequired', true)
398
+ // }
399
+ // }
400
+ // console.log('customValidateItems', JSON.stringify(this.customValidateItems))
401
+ // }
402
+ // },
403
+ // deep: true
404
+ // }
405
+ // },
406
+ mixins: [formValidationMixin],
407
+ methods: {
408
+ runLogic,
409
+ getConfigByNameAsync,
410
+ getConfigByName,
411
+ init (params) {
412
+ const {
413
+ configName,
414
+ configContent,
415
+ formItems,
416
+ formJson,
417
+ viewMode,
418
+ isHandleFormKey,
419
+ isKeyHandle = true,
420
+ showSubmitBtn = true,
421
+ serviceName,
422
+ primaryKey,
423
+ modifyModelData = {},
424
+ businessType,
425
+ title,
426
+ fixedAddForm = {},
427
+ getDataParams = {},
428
+ simpleFormJsonData = {},
429
+ env = 'prod',
430
+ layout,
431
+ xAddFormLayout = 'horizontal',
432
+ formItemLayout = {},
433
+ btnName = '提交',
434
+ childTablePriority = false,
435
+ btnPlace = 'center'
436
+ } = params
437
+ this.loaded = false
438
+ // 兼容需要省略 传递 layout: res.xAddFormLayout 可以使用 ...res 展开运算符 直接转递
439
+ if (xAddFormLayout && layout === undefined) {
440
+ this.layout = xAddFormLayout
441
+ } else {
442
+ this.layout = layout
443
+ }
444
+ this.formItemLayout = formItemLayout
445
+ if ((isHandleFormKey === null || isHandleFormKey === undefined) && !isKeyHandle) {
446
+ this.isHandleFormKey = isKeyHandle
447
+ } else if (isHandleFormKey) {
448
+ this.isHandleFormKey = isHandleFormKey
449
+ } else {
450
+ this.isHandleFormKey = isKeyHandle
451
+ }
452
+ this.childTablePriority = childTablePriority
453
+ this.configName = configName
454
+ this.configContent = configContent
455
+ this.formItems = this.getFromItem(formItems, formJson)
456
+ this.viewMode = viewMode
457
+ this.showSubmitBtn = showSubmitBtn
458
+ this.primaryKey = primaryKey
459
+ this.serviceName = serviceName
460
+ this.businessType = businessType
461
+ this.title = title
462
+ this.getDataParams = getDataParams
463
+ this.simpleFormJsonData = simpleFormJsonData
464
+ this.env = env
465
+ this.btnName = btnName
466
+ this.btnPlace = btnPlace
467
+ // 如果 fixedAddForm 有 selected_id 值,并且设置了处理表单key值,则多给 selected_id 加前缀 避免处理错误
468
+ if (fixedAddForm.selected_id && this.isHandleFormKey) {
469
+ fixedAddForm._selected_id = fixedAddForm.selected_id
470
+ delete fixedAddForm.selected_id
471
+ }
472
+ // 设置普通表单项的相关参数
473
+ const formData = Object.assign({}, fixedAddForm)
474
+ for (let i = 0; i < this.realJsonData.length; i++) {
475
+ const item = this.realJsonData[i]
476
+ this.setFormProps(formData, item, null)
477
+ }
478
+ // 设置表单分组项目相关参数
479
+ for (let i = 0; i < this.groupJsonData.length; i++) {
480
+ const groupItem = this.groupJsonData[i]
481
+ formData[groupItem.model] = {}
482
+ for (let j = 0; j < groupItem.groupItems.length; j++) {
483
+ const item = groupItem.groupItems[j]
484
+ this.setFormProps(formData[groupItem.model], item, item.prop)
485
+ }
486
+ }
487
+ // 设置动态简易表单项的相关参数
488
+ for (const key in this.simpleFormJsonData) {
489
+ for (const item of this.simpleFormJsonData[key].value) {
490
+ item.model = key + '@' + item.model
491
+ this.setFormProps(formData, item, null)
492
+ }
493
+ }
494
+
495
+ this.form = formData
496
+ // 修改场景下对表单项赋值
497
+ if (modifyModelData && modifyModelData.data) {
498
+ this.modifyModelData = modifyModelData
499
+ if (Object.keys(modifyModelData.data).length > 0) {
500
+ this.getModifyModelData(modifyModelData)
501
+ }
502
+ }
503
+ // 处理表单得附件
504
+ if (modifyModelData && modifyModelData.files) {
505
+ this.files = modifyModelData.files
506
+ }
507
+ if (modifyModelData && modifyModelData.images) {
508
+ this.images = modifyModelData.images
509
+ }
510
+ this.loaded = true
511
+ },
512
+ scrollToGroup (index) {
513
+ const groupElement = this.$refs[`group-title-${index}`][0]
514
+ if (groupElement) {
515
+ groupElement.scrollIntoView({ behavior: 'smooth' })
516
+ }
517
+ },
518
+ registerComponent (componentName, component) {
519
+ console.log('内部注册', this.$options.name, componentName)
520
+ this.$refs[componentName] = component
521
+ console.log('内部注册完成', this.$refs)
522
+ },
523
+ // 根据名字从注册到组件中获取组件
524
+ getComponentByName (componentName) {
525
+ console.log('内部取组件', this.$options.name, componentName)
526
+ console.log('内部组件内容', this.$refs)
527
+ return this.$refs[componentName]
528
+ },
529
+ // 兼容需要省略 传递 [formItems: res.formJson ] 可以使用 ...res 展开运算符 直接转递
530
+ getFromItem (formItems, formJson) {
531
+ const _formItems = formItems || formJson
532
+ if (typeof formItems === 'string') {
533
+ return JSON.parse(_formItems)
534
+ } else {
535
+ return JSON.parse(JSON.stringify(_formItems))
536
+ }
537
+ },
538
+ innerXFormTableEmit (fun, record, id, actionType, index) {
539
+ this.$emit(fun, record, id, actionType, index)
540
+ },
541
+ // 时间组件赋默认值
542
+ // .type, item.formDefault
543
+ getDateRange ({ type, formDefault: defaultValue, formValueFormat }) {
544
+ // const format = type === 'datePicker' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'
545
+ let format = 'YYYY-MM-DD HH:mm:ss'
546
+ if (formValueFormat) {
547
+ format = formValueFormat
548
+ }
549
+ let start
550
+ switch (defaultValue) {
551
+ case 'curYear':
552
+ start = moment().startOf('year').format(format)
553
+ break
554
+ case 'curMonth':
555
+ start = moment().startOf('month').format(format)
556
+ break
557
+ case 'curDay':
558
+ start = moment().startOf('day').format(format)
559
+ break
560
+ case 'curTime':
561
+ start = moment().format(format)
562
+ break
563
+ default:
564
+ return defaultValue
565
+ }
566
+ return start
567
+ },
568
+ setFormProps (formData, item, groupItem) {
569
+ const rulesKey = `${item.name}${item.model}`
570
+ if (formData[item.model] === undefined || formData[item.model] === null) {
571
+ formData[item.model] = undefined
572
+ }
573
+ if (!formData[item.model] && item.formDefault) {
574
+ if (['datePicker', 'rangePicker', 'yearPicker', 'monthPicker', 'yearRangePicker', 'monthRangePicker'].includes(item.type)) {
575
+ formData[item.model] = this.getDateRange(item)
576
+ } else if (['treeSelect', 'select', 'checkbox'].includes(item.type) && ['curOrgId', 'curDepId', 'curUserId'].includes(item.formDefault)) {
577
+ if (item.formDefault === 'curOrgId') {
578
+ formData[item.model] = item.type === 'select' ? this.currUser.orgid : [this.currUser.orgid]
579
+ }
580
+ if (item.formDefault === 'curDepId') {
581
+ formData[item.model] = item.type === 'select' ? this.currUser.depids : [this.currUser.depids]
582
+ }
583
+ if (item.formDefault === 'curUserId') {
584
+ formData[item.model] = item.type === 'select' ? this.currUser.id : [this.currUser.id]
585
+ }
586
+ } else if (['addressSearch'].includes(item.type)) {
587
+ formData[item.model] = item.formDefault
588
+ formData[`${item.model}_lng_lat`] = item.formDefault_lng_lat
589
+ } else {
590
+ formData[item.model] = item.formDefault
591
+ }
592
+ }
593
+ // 处理表单校验情况
594
+ if (item.rule) {
595
+ if (groupItem) {
596
+ this.rules[groupItem] = []
597
+ } else {
598
+ this.rules[rulesKey] = []
599
+ }
600
+ const required = item.rule.required ? item.rule.required === true || item.rule.required === 'true' : false
601
+ let trigger
602
+ let message
603
+ if (required) {
604
+ switch (item.type) {
605
+ case 'select':
606
+ case 'checkbox':
607
+ case 'radio':
608
+ case 'treeSelect':
609
+ case 'rangePicker':
610
+ case 'monthPicker':
611
+ case 'yearPicker':
612
+ case 'datePicker':
613
+ case 'file':
614
+ case 'image':
615
+ case 'citySelect':
616
+ case 'addressSearch':
617
+ case 'personSetting':
618
+ message = '请选择' + item.name
619
+ trigger = 'change'
620
+ break
621
+ default:
622
+ message = '请输入' + item.name
623
+ trigger = 'blur'
624
+ }
625
+ if (groupItem) {
626
+ this.rules[groupItem].push({
627
+ required: true,
628
+ message: message,
629
+ trigger: trigger
630
+ })
631
+ } else {
632
+ this.rules[rulesKey].push({
633
+ required: true,
634
+ message: message,
635
+ trigger: trigger
636
+ })
637
+ }
638
+ }
639
+
640
+ switch (item.rule.type) {
641
+ case 'number':
642
+ case 'integer':
643
+ case 'float':
644
+ // eslint-disable-next-line no-case-declarations
645
+ let defaultValue
646
+ // eslint-disable-next-line no-case-declarations
647
+ let message
648
+ switch (item.rule.type) {
649
+ case 'number':
650
+ item.numberInput = true
651
+ message = '数字'
652
+ defaultValue = 0
653
+ break
654
+ case 'integer':
655
+ item.numberInput = true
656
+ message = '整数'
657
+ defaultValue = 0
658
+ break
659
+ case 'float':
660
+ item.numberInput = true
661
+ message = '小数'
662
+ defaultValue = 0.0
663
+ break
664
+ }
665
+ if (groupItem) {
666
+ this.rules[groupItem].push({
667
+ type: item.rule.type,
668
+ message: item.name + '必须为' + message,
669
+ transform: (value) => {
670
+ if (value && value.length !== 0) {
671
+ return Number(value)
672
+ } else {
673
+ return defaultValue
674
+ }
675
+ },
676
+ trigger: 'blur'
677
+ })
678
+ } else {
679
+ this.rules[rulesKey].push({
680
+ type: item.rule.type,
681
+ message: item.name + '必须为' + message,
682
+ transform: (value) => {
683
+ if (value && value.length !== 0) {
684
+ return Number(value)
685
+ } else {
686
+ return defaultValue
687
+ }
688
+ },
689
+ trigger: 'blur'
690
+ })
691
+ }
692
+ break
693
+ case 'email': {
694
+ const validator = (rule, value, callback) => {
695
+ if (value && !REG_EMAIL.test(value)) {
696
+ callback(new Error('请输入正确的邮箱地址'))
697
+ } else {
698
+ callback()
699
+ }
700
+ }
701
+ this.rules[groupItem || rulesKey].push({
702
+ type: 'email',
703
+ validator: validator,
704
+ message: '请输入正确的邮箱地址',
705
+ trigger: 'blur'
706
+ })
707
+ break
708
+ }
709
+ case 'userPhone': {
710
+ this.rules[groupItem || rulesKey].push({
711
+ type: 'userPhone',
712
+ validator: (rule, value, callback) => {
713
+ if (value && !REG_PHONE.test(value)) {
714
+ callback(new Error('请输入正确的手机号码'))
715
+ } else {
716
+ callback()
717
+ }
718
+ },
719
+ message: '请输入正确的手机号码',
720
+ trigger: 'blur'
721
+ })
722
+ break
723
+ }
724
+ case 'idNumber': {
725
+ this.rules[groupItem || rulesKey].push({
726
+ validator: (rule, value, callback) => {
727
+ if (value && !checkIdNumber(value)) {
728
+ callback(new Error('请输入正确的身份证号码'))
729
+ } else {
730
+ callback()
731
+ }
732
+ },
733
+ trigger: 'blur'
734
+ })
735
+ break
736
+ }
737
+ case 'landlineNumber': {
738
+ this.rules[rulesKey].push({
739
+ validator: (rule, value, callback) => {
740
+ if (value && !REG_LANDLINE.test(value)) {
741
+ callback(new Error('请输入正确的座机号码'))
742
+ } else {
743
+ callback()
744
+ }
745
+ },
746
+ trigger: 'blur'
747
+ })
748
+ break
749
+ }
750
+ // 大于0
751
+ case 'greaterThanZero': {
752
+ item.numberInput = true
753
+ this.rules[rulesKey].push({
754
+ validator: (rule, value, callback) => {
755
+ if (isNaN(value) || value <= 0) {
756
+ callback(new Error('请输入一个大于0的数字'))
757
+ } else {
758
+ callback()
759
+ }
760
+ },
761
+ trigger: 'blur'
762
+ })
763
+ break
764
+ }
765
+ // 大于等于0
766
+ case 'greaterThanOrEqualZero': {
767
+ item.numberInput = true
768
+ this.rules[rulesKey].push({
769
+ validator: (rule, value, callback) => {
770
+ if (isNaN(value) || value < 0) {
771
+ callback(new Error('请输入一个大于等于0的数字'))
772
+ } else {
773
+ callback()
774
+ }
775
+ },
776
+ trigger: 'blur'
777
+ })
778
+ break
779
+ }
780
+ case 'stringLength': {
781
+ this.rules[rulesKey].push({
782
+ validator: (rule, value, callback) => {
783
+ if (value && value.length < item.rule.minLen) {
784
+ callback(new Error('长度不能少于' + item.rule.minLen + '个字符'))
785
+ } else if (value && value.length > item.rule.maxLen) {
786
+ callback(new Error('长度不能超过' + item.rule.maxLen + '个字符'))
787
+ } else {
788
+ callback()
789
+ }
790
+ },
791
+ trigger: 'blur'
792
+ })
793
+ break
794
+ }
795
+ case 'customJs': {
796
+ this.rules[rulesKey].push({
797
+ validator: (rule, value, callback) => {
798
+ this.customJsValidate(rule, value, callback, item)
799
+ },
800
+ trigger: 'blur'
801
+ })
802
+ break
803
+ }
804
+ }
805
+ }
806
+ },
807
+ childTableMounted (item) {
808
+ // 子表初始化时,设置表格数据
809
+ if (this.form[item.model] && this.form[item.model].length > 0) {
810
+ this.$refs[`childXFormTable_${item.model}`][0].setTableData(this.form[item.model])
811
+ }
812
+ },
813
+ customJsValidate (rule, value, callback, item) {
814
+ if (item.rule.customValidatorFunc) {
815
+ executeStrFunctionByContext(this, item.rule.customValidatorFunc, [rule, value, callback, this.form, item, this.util, runLogic, getConfigByNameAsync])
816
+ } else {
817
+ callback()
818
+ }
819
+ },
820
+ itemDisabled (value) {
821
+ return (this.businessType === '新增' && value.addOrEdit === 'edit') ||
822
+ (this.businessType === '修改' && value.addOrEdit === 'add')
823
+ },
824
+ readonly (value) {
825
+ return value.addOrEdit === 'readonly'
826
+ },
827
+ async onSubmit () {
828
+ const valid = await this.validateForm()
829
+ if (!valid) return false
830
+ if (this.viewMode) {
831
+ this.$message.info('预览模式禁止新增和修改')
832
+ return false
833
+ }
834
+ this.loading = true
835
+ const requestForm = this.prepareForm()
836
+ await this.appendSilenceAddFields(requestForm)
837
+ const realForm = this.handleFormKeys(requestForm)
838
+ // 增加子表数据
839
+ if (this.childTableData.length > 0) {
840
+ for (const item of this.childTableData) {
841
+ const childModel = item.model
842
+ const childDataRef = this.$refs['childXFormTable_' + item.model][0].getTableData()
843
+ const childData = []
844
+ for (const item of childDataRef) {
845
+ childData.push(JSON.parse(JSON.stringify(item)))
846
+ }
847
+ for (let i = 0; i < childData.length; i++) {
848
+ childData[i] = this.handleFormKeys(childData[i])
849
+ // 外键不需要带表别名,所以此处放到表单处理后赋值
850
+ if (realForm.id) {
851
+ childData[i][item.childTableForeignKeyName] = realForm.id
852
+ }
853
+ }
854
+ realForm[childModel] = childData
855
+ }
856
+ }
857
+ // 增加form子表数据
858
+ if (this.childFormData.length > 0) {
859
+ for (const item of this.childFormData) {
860
+ const childModel = item.model
861
+ const childData = this.$refs[item.model].getTableData()
862
+ for (let i = 0; i < childData.length; i++) {
863
+ childData[i] = this.handleFormKeys(childData[i], true)
864
+ // 外键不需要带表别名,所以此处放到表单处理后赋值
865
+ if (realForm.id) {
866
+ childData[i][item.foreignKey] = realForm.id
867
+ }
868
+ }
869
+ realForm[childModel] = childData
870
+ }
871
+ }
872
+ if (this.$listeners.onSubmit) {
873
+ // 交由父级处理
874
+ this.$emit('onSubmit', {
875
+ businessType: this.businessType,
876
+ serviceName: this.serviceName,
877
+ realForm: realForm,
878
+ currUserName: this.currUser.name,
879
+ currUserId: this.currUser.id,
880
+ orgId: this.currUser.orgid
881
+ })
882
+ } else {
883
+ this.defaultSubmit(realForm)
884
+ }
885
+ },
886
+
887
+ async asyncSubmit () {
888
+ return new Promise((resolve, reject) => {
889
+ this.$refs.selectForm.validate(async valid => {
890
+ if (!valid) {
891
+ reject(new Error('Form validation failed'))
892
+ return
893
+ }
894
+ this.loading = true
895
+ const requestForm = this.prepareForm()
896
+ await this.appendSilenceAddFields(requestForm)
897
+ const realForm = this.handleFormKeys(requestForm)
898
+ resolve({
899
+ realForm,
900
+ businessType: this.businessType,
901
+ serviceName: this.serviceName,
902
+ currUserName: this.currUser.name,
903
+ currUserId: this.currUser.id,
904
+ orgId: this.currUser.orgid
905
+ })
906
+ })
907
+ })
908
+ },
909
+
910
+ validateForm () {
911
+ return new Promise((resolve) => {
912
+ this.$refs.selectForm.validate(valid => resolve(valid))
913
+ })
914
+ },
915
+
916
+ childTableFixedQueryForm (item) {
917
+ if (this.modifyModelData?.primaryKeyData) {
918
+ const fixedForm = {}
919
+ fixedForm[item.childTableForeignKeyName] = Object.values(this.modifyModelData.primaryKeyData)[0]
920
+ return fixedForm
921
+ }
922
+ return null
923
+ },
924
+
925
+ prepareForm () {
926
+ const form = { ...this.form }
927
+ for (const key of Object.keys(form)) {
928
+ const value = form[key]
929
+ if (value === null || (typeof value === 'object' && Object.keys(value).length === 0)) {
930
+ form[key] = undefined
931
+ }
932
+ }
933
+ return form
934
+ },
935
+
936
+ async appendSilenceAddFields (form) {
937
+ if (this.businessType === '新增') {
938
+ for (const item of this.silenceAddJsonData) {
939
+ switch (item.silencePurpose) {
940
+ case 'createTime':
941
+ form[item.model] = formatDate('now')
942
+ break
943
+ case 'operator':
944
+ form[item.model] = this.currUser.name
945
+ break
946
+ case 'operatorId':
947
+ form[item.model] = this.currUser.id
948
+ break
949
+ case 'orgId':
950
+ form[item.model] = this.currUser.orgid
951
+ break
952
+ case 'orgName':
953
+ form[item.model] = this.currUser.orgs
954
+ break
955
+ case 'depId':
956
+ form[item.model] = this.currUser.depids
957
+ break
958
+ case 'depName':
959
+ form[item.model] = this.currUser.deps
960
+ break
961
+ }
962
+ }
963
+ for (const item of this.silenceAddJsonData.filter((item) => item.silencePurpose === 'customize')) {
964
+ const result = await runLogic(item.silenceSource, form, this.serviceName)
965
+ if (result) {
966
+ const keys = Object.keys(result)
967
+ if (keys.length === 1 && keys[0] === 'value') {
968
+ form[item.model] = result.value
969
+ } else {
970
+ form[item.model] = result
971
+ }
972
+ } else {
973
+ form[item.model] = result
974
+ }
975
+ }
976
+ }
977
+ },
978
+
979
+ handleFormKeys (form, mustHandleKey = false) {
980
+ const realForm = {}
981
+ for (const key of Object.keys(form)) {
982
+ const value = form[key]
983
+ const extraFormKeyTagIndex = key.indexOf('@')
984
+ if (extraFormKeyTagIndex !== -1) {
985
+ const extraFormKey = key.substring(0, extraFormKeyTagIndex)
986
+ const realKey = key.substring(extraFormKeyTagIndex + 1)
987
+ if (!realForm[extraFormKey]) {
988
+ realForm[extraFormKey] = {}
989
+ }
990
+ realForm[extraFormKey][realKey] = value
991
+ } else {
992
+ const realKey = this.isHandleFormKey || mustHandleKey ? this.getRealKey(key, mustHandleKey) : key
993
+ // 如果发生重名,不覆盖,把key的别名带上
994
+ if (realForm[realKey]) {
995
+ realForm[key] = value
996
+ } else {
997
+ realForm[realKey] = value
998
+ }
999
+ }
1000
+ }
1001
+ return realForm
1002
+ },
1003
+ // 默认提交事件
1004
+ defaultSubmit (realForm, callback) {
1005
+ // 新增移除id
1006
+ if (this.businessType === '新增') {
1007
+ delete realForm.id
1008
+ }
1009
+ // 组织请求
1010
+ const requestParameters = {
1011
+ queryParamsName: this.configName,
1012
+ queryParams: this.configContent,
1013
+ form: realForm,
1014
+ businessType: this.businessType,
1015
+ operator: this.currUser.name
1016
+ }
1017
+ addOrModify(requestParameters, this.serviceName, this.env === 'dev').then(data => {
1018
+ this.$message.success(this.businessType + '成功!')
1019
+ // commit
1020
+ this.$emit('afterSubmit', { type: this.businessType, id: data.id, data: data, form: requestParameters.form })
1021
+ this.loading = false
1022
+ if (callback) {
1023
+ callback()
1024
+ }
1025
+ }).catch(e => {
1026
+ this.loading = false
1027
+ this.$message.error(this.businessType + '失败:' + e)
1028
+ })
1029
+ },
1030
+ // 获取表单字段实际值
1031
+ getRealKey (key, mustHandleKey = false) {
1032
+ if (key === 'selected_id') return key
1033
+ if (this.isHandleFormKey || mustHandleKey) {
1034
+ return key.substring(key.indexOf('_') + 1)
1035
+ } else {
1036
+ return key
1037
+ }
1038
+ },
1039
+ /**
1040
+ * 获取被修改记录数据
1041
+ * @param modifyModelData 被修改记录的数据
1042
+ */
1043
+ getModifyModelData (modifyModelData) {
1044
+ if (modifyModelData.primaryKeyData) {
1045
+ this.form = Object.assign(this.form, modifyModelData.primaryKeyData)
1046
+ }
1047
+ // 对动态简易表单项特殊处理
1048
+ for (const key in modifyModelData.data) {
1049
+ const realKey = this.isHandleFormKey ? this.getRealKey(key) : key
1050
+ if (this.simpleFormJsonData[realKey]) {
1051
+ const extraForm = JSON.parse(modifyModelData.data[key])
1052
+ for (const key in extraForm) {
1053
+ const model = realKey + '@' + key
1054
+ this.form[model] = extraForm[key]
1055
+ }
1056
+ }
1057
+ }
1058
+ // 对普通表单项处理
1059
+ for (let i = 0; i < this.realJsonData.length; i++) {
1060
+ if (['FilesId', 'Images'].includes(this.realJsonData[i])) {
1061
+ // 附件需要跳过 因为会通过 modifyModelData中的files,images属性给upload赋值
1062
+ // 新增修改表单每次提交时只会提交最新添加的文件
1063
+ continue
1064
+ }
1065
+ const item = this.realJsonData[i]
1066
+ // 地址选择器 需要传递 经纬度字段, 配置中添加 `${item.model}_lng_lat` CRUD 只需勾选 SQL生成查询项
1067
+ if (['addressSearch'].includes(item.type)) {
1068
+ this.form[item.model] = modifyModelData.data[item.model] + ''
1069
+ this.form[`${item.model}_lng_lat`] = modifyModelData.data[`${item.model}_lng_lat`] + ''
1070
+ continue
1071
+ }
1072
+ if (modifyModelData.data[item.model] || modifyModelData.data[item.model] === 0) {
1073
+ if (modifyModelData.data[item.model] instanceof Array) {
1074
+ this.form[item.model] = modifyModelData.data[item.model]
1075
+ } else {
1076
+ this.form[item.model] = modifyModelData.data[item.model] + ''
1077
+ }
1078
+ }
1079
+ }
1080
+ // 对分组表单进行处理
1081
+ for (let i = 0; i < this.groupJsonData.length; i++) {
1082
+ const item = this.groupJsonData[i]
1083
+ try {
1084
+ if (modifyModelData.data[item.model]) {
1085
+ this.form[item.model] = JSON.parse(modifyModelData.data[item.model])
1086
+ }
1087
+ } catch (e) {
1088
+ if (modifyModelData.data[item.model]) {
1089
+ this.form[item.model] = modifyModelData.data[item.model]
1090
+ }
1091
+ }
1092
+ }
1093
+ // 追加版本号信息
1094
+ for (const item of this.versionJsonData) {
1095
+ if (!modifyModelData.data[item.model]) {
1096
+ this.form[item.model] = 0
1097
+ } else {
1098
+ this.form[item.model] = modifyModelData.data[item.model] + ''
1099
+ }
1100
+ }
1101
+ },
1102
+ setForm (obj) {
1103
+ this.form = Object.assign(this.form, obj)
1104
+ // 给子表赋外键条件
1105
+ if (this.childFormData.length > 0) {
1106
+ for (const item of this.childFormData) {
1107
+ const child = this.$refs[item.model]
1108
+ // 获取子表别名,以便在条件上添加别名
1109
+ const alias = child.realQueryConfig.tableAliasName
1110
+ // 有主键,且主键有值,添加主键条件
1111
+ if (this.primaryKey && this.form[this.primaryKey]) {
1112
+ const foreignKey = item.foreignKey
1113
+ const fixedQueryForm = { [alias + '_' + foreignKey]: this.form[this.primaryKey] }
1114
+ if (!child.fixedQueryForm) {
1115
+ child.fixedQueryForm = fixedQueryForm
1116
+ } else {
1117
+ Object.assign(child.fixedQueryForm, fixedQueryForm)
1118
+ }
1119
+ child.refreshTable()
1120
+ }
1121
+ }
1122
+ }
1123
+ },
1124
+ setFormWithKey (obj) {
1125
+ setDataByRealKey(this.form, obj)
1126
+ },
1127
+ setFormWithNoKey (obj) {
1128
+ setDataByRealKey(this.form, obj)
1129
+ },
1130
+ emitFunc (func, data, value) {
1131
+ this.$emit(func, data, value)
1132
+ this.$emit('x-form-item-emit-func', func, data, value)
1133
+ },
1134
+ // 直接转发事件的函数
1135
+ emitEvent (event, ...args) {
1136
+ this.$emit(event, ...args)
1137
+ },
1138
+ close () {
1139
+ this.loaded = false
1140
+ },
1141
+ /**
1142
+ * 行选择事件
1143
+ * @param row 选中行集合
1144
+ * @param attr 表单项属性
1145
+ */
1146
+ async rowChoose (row, attr, callback) {
1147
+ // 如果配置了自定义函数
1148
+ if (attr.dataChangeFunc) {
1149
+ await executeStrFunction(attr.dataChangeFunc, [this.form, this.setForm, {
1150
+ ...attr,
1151
+ selectRows: row
1152
+ }, util, this.mode, runLogic, getConfigByNameAsync])
1153
+ } else {
1154
+ // 默认填充选中行数据到当前表单
1155
+ setDataByRealKey(this.form, row[0])
1156
+ }
1157
+ if (callback) {
1158
+ callback()
1159
+ }
1160
+ },
1161
+ }
1162
+ }
1163
+ </script>
1164
+
1165
+ <style scoped lang="less">
1166
+ :deep(.ant-form-inline .ant-form-item ) {
1167
+ display: block !important;
1168
+ }
1169
+
1170
+ :deep(.ant-form-item-with-help) {
1171
+ margin-bottom: 0;
1172
+ }
1173
+
1174
+ .xFormGroupTitle {
1175
+ font-weight: bold;
1176
+ color: @primary-color;
1177
+ }
1178
+ </style>