af-mobile-client-vue3 1.4.24 → 1.4.26

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.
@@ -1,1638 +1,1638 @@
1
- <script setup lang="ts">
2
- import type { FieldType } from 'vant'
3
- import type { Numeric } from 'vant/es/utils'
4
- import ImageUploader from '@af-mobile-client-vue3/components/core/ImageUploader/index.vue'
5
- import XGridDropOption from '@af-mobile-client-vue3/components/core/XGridDropOption/index.vue'
6
- import XMultiSelect from '@af-mobile-client-vue3/components/core/XMultiSelect/index.vue'
7
- import XSelect from '@af-mobile-client-vue3/components/core/XSelect/index.vue'
8
- import XLocationPicker from '@af-mobile-client-vue3/components/data/XOlMap/XLocationPicker/index.vue'
9
- import { getConfigByNameAsync, runLogic } from '@af-mobile-client-vue3/services/api/common'
10
- import { post } from '@af-mobile-client-vue3/services/restTools'
11
- import { searchToListOption, searchToOption } from '@af-mobile-client-vue3/services/v3Api'
12
- import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
13
- import { getDict } from '@af-mobile-client-vue3/utils/dictUtil'
14
- import { mobileUtil } from '@af-mobile-client-vue3/utils/mobileUtil'
15
- import { executeStrFunctionByContext } from '@af-mobile-client-vue3/utils/runEvalFunction'
16
- import { areaList } from '@vant/area-data'
17
- import dayjs from 'dayjs/esm/index'
18
- import { debounce } from 'lodash-es'
19
- import {
20
- showToast,
21
- Area as VanArea,
22
- Button as VanButton,
23
- Calendar as VanCalendar,
24
- Cascader as VanCascader,
25
- Checkbox as VanCheckbox,
26
- CheckboxGroup as vanCheckboxGroup,
27
- DatePicker as VanDatePicker,
28
- Field as VanField,
29
- Picker as VanPicker,
30
- PickerGroup as VanPickerGroup,
31
- Popup as VanPopup,
32
- Radio as VanRadio,
33
- RadioGroup as VanRadioGroup,
34
- Rate as VanRate,
35
- Slider as VanSlider,
36
- Stepper as VanStepper,
37
- Switch as VanSwitch,
38
- TimePicker as VanTimePicker,
39
- } from 'vant'
40
- import { computed, defineEmits, defineModel, defineProps, getCurrentInstance, onBeforeMount, ref, watch } from 'vue'
41
-
42
- const props = defineProps({
43
- attr: {
44
- type: Object,
45
- },
46
- form: {
47
- type: Object,
48
- },
49
- // 整表只读:来自 XForm,统一控制交互
50
- formReadonly: {
51
- type: Boolean,
52
- default: false,
53
- },
54
- datePickerFilter: {
55
- type: Function,
56
- default: () => true,
57
- },
58
- datePickerFormatter: {
59
- type: Function,
60
- default: (type, val) => val,
61
- },
62
- mode: {
63
- type: String,
64
- default: '查询',
65
- },
66
- serviceName: {
67
- type: String,
68
- default: undefined,
69
- },
70
- // 调用logic获取数据源的追加参数
71
- getDataParams: {
72
- type: Object,
73
- default: undefined,
74
- },
75
- disabled: {
76
- type: Boolean,
77
- default: false,
78
- },
79
- rules: {
80
- type: Object,
81
- default: () => {},
82
- },
83
- // 用 defineModel 替代 modelValue/emit
84
- modelValue: {
85
- type: [String, Number, Boolean, Array, Object],
86
- default: undefined,
87
- },
88
- showLabel: {
89
- type: Boolean,
90
- default: true,
91
- },
92
- // radio/checkbox/select/mul-select 选项数据结构
93
- columnsField: {
94
- type: Object,
95
- default: () => {
96
- return { text: 'label', value: 'value' }
97
- },
98
- },
99
- isAsyncUpload: {
100
- type: Boolean,
101
- default: false,
102
- },
103
-
104
- })
105
-
106
- const emits = defineEmits(['setForm', 'xFormItemEmitFunc', 'scanCodeOrNfc'])
107
-
108
- // 用 defineModel 替代 modelValue/emit
109
- const modelData = defineModel<string | number | boolean | any[] | Record<string, any>>()
110
-
111
- // 获取字典
112
- interface OptionItem {
113
- label: string
114
- value: any
115
- children?: OptionItem[]
116
- }
117
-
118
- // 判断并初始化防抖函数
119
- let debouncedUserLinkFunc: (() => void) | null = null
120
- let debouncedDepLinkFunc: (() => void) | null = null
121
- let debouncedUpdateOptions: (() => void) | null = null
122
-
123
- const { attr, form, mode, serviceName, getDataParams, columnsField } = props
124
- // 配置的表单值格式(仅针对 datePicker 生效)
125
- // 作用:统一控制日期值的格式化输入/输出与选择器展示粒度
126
- // 可选:'YYYY' | 'YYYY-MM' | 'YYYY-MM-DD' | 'YYYY-MM-DD HH' | 'YYYY-MM-DD HH:mm' | 'YYYY-MM-DD HH:mm:ss'
127
- const formValueFormat = computed(() => {
128
- // 默认全格式
129
- return (attr && (attr as any).formValueFormat) || 'YYYY-MM-DD HH:mm:ss'
130
- })
131
-
132
- // 根据 formValueFormat 动态计算日期列类型(决定 VanDatePicker 展示年/月/日)
133
- // 例如:YYYY 只显示年;YYYY-MM 显示年、月;YYYY-MM-DD 显示年、月、日
134
- const dateColumnsType = computed(() => {
135
- const format = formValueFormat.value
136
- const columns: string[] = ['year']
137
- if (format.includes('MM'))
138
- columns.push('month')
139
- if (format.includes('DD'))
140
- columns.push('day')
141
- return columns as any
142
- })
143
-
144
- // 是否包含时间(决定是否展示时间页签与 VanTimePicker)
145
- const hasTime = computed(() => formValueFormat.value.includes('HH'))
146
-
147
- // 根据 formValueFormat 动态计算时间列类型(决定时/分/秒的展示)
148
- // 例如:包含 HH 显示小时;包含 mm 显示分钟;包含 ss 显示秒
149
- const timeColumnsType = computed(() => {
150
- const format = formValueFormat.value
151
- const columns: string[] = []
152
- if (format.includes('HH'))
153
- columns.push('hour')
154
- if (format.includes('mm'))
155
- columns.push('minute')
156
- if (format.includes('ss'))
157
- columns.push('second')
158
- return columns as any
159
- })
160
- const calendarShow = ref(false)
161
- const option = ref([])
162
- const pickerValue = ref(undefined)
163
- const timePickerValue = ref(undefined)
164
- const area = ref<any>(undefined)
165
- const showPicker = ref(false)
166
- const showDatePicker = ref(false)
167
- const showTimePicker = ref(false)
168
- const showArea = ref(false)
169
- const errorMessage = ref('')
170
- const showTreeSelect = ref(false)
171
- const treeValue = ref('')
172
- // 懒加载 最后检索版本
173
- const lastFetchId = ref(0)
174
- const customizeReadOnly = ref(false)
175
-
176
- // 登录信息 (可以在配置的动态函数中使用 this.setupState 获取到当前组件内的全部函数和变量 例:this.setupState.userState)
177
- const userState = useUserStore().getLogin()
178
- const currUser = computed(() => userState.f.resources.id)
179
- const userInfo = computed(() => ({
180
- orgId: userState.f.resources.orgid,
181
- userId: userState.f.resources.id,
182
- }))
183
-
184
- // 是否展示当前项
185
- const showItem = ref(true)
186
-
187
- // 当前组件实例(不推荐使用,可能会在后续的版本更迭中调整,暂时用来绑定函数的上下文)
188
- const currInst = getCurrentInstance()
189
-
190
- // 配置中心->表单项变更触发函数
191
- async function dataChangeFunc() {
192
- if (attr.dataChangeFunc) {
193
- await executeStrFunctionByContext(currInst, attr.dataChangeFunc, [props.form, (formData: any) => emits('setForm', formData), attr, null, mode, runLogic, getConfigByNameAsync, userState.f.resources])
194
- }
195
- }
196
- const dataChangeFuncdebounce = debounce(dataChangeFunc, 300)
197
- // 配置中心->表单项展示函数
198
- async function showFormItemFunc() {
199
- if (attr.showFormItemFunc) {
200
- const obj = await executeStrFunctionByContext(currInst, attr.showFormItemFunc, [form, attr, null, mode])
201
- // 判断是 bool 还是 obj 兼容
202
- if (typeof obj === 'boolean') {
203
- showItem.value = obj
204
- }
205
- else if (obj && typeof obj === 'object') {
206
- // obj 是一个对象,并且不是数组
207
- if (Object.prototype.hasOwnProperty.call(obj, 'show')) {
208
- showItem.value = obj?.show
209
- }
210
- if (Object.prototype.hasOwnProperty.call(obj, 'readOnly')) {
211
- customizeReadOnly.value = obj?.readOnly
212
- }
213
- }
214
- }
215
- }
216
- const showFormItemFuncdebounce = debounce(showFormItemFunc, 300)
217
- /**
218
- * 检测是否传入了有效的值
219
- * @returns any
220
- */
221
- function checkModel(val = props.modelValue) {
222
- if (val === null || val === undefined || val === '')
223
- return false
224
- if (Array.isArray(val))
225
- return val.length > 0
226
- return true
227
- }
228
- /**
229
- * 获取表单项的默认值
230
- * @returns any
231
- */
232
- function getDefaultValue() {
233
- const val = props.modelValue
234
- // 如果有有效值,直接返回(datePicker 初始值需按 formValueFormat 归一)
235
- // 目的:外部通过 formData 传入的初始值在组件挂载即与配置格式一致
236
- if (checkModel(val)) {
237
- if (attr.type === 'datePicker' && typeof val === 'string') {
238
- const parsed = dayjs(val)
239
- if (parsed.isValid())
240
- return parsed.format(formValueFormat.value)
241
- }
242
- return val
243
- }
244
-
245
- // 根据类型获取默认值
246
- const getDefaultByType = () => {
247
- const def = mode !== '查询' ? attr.formDefault : attr.queryFormDefault
248
-
249
- if (['treeSelect', 'select', 'checkbox'].includes(attr.type) && ['curOrgId', 'curDepId', 'curUserId'].includes(def)) {
250
- if (def === 'curOrgId') {
251
- if (attr.type === 'treeSelect') {
252
- treeValue.value = userState.f.resources.orgs
253
- }
254
- return attr.type === 'select' ? userState.f.resources.orgid : [userState.f.resources.orgid]
255
- }
256
- if (def === 'curDepId') {
257
- if (attr.type === 'treeSelect') {
258
- treeValue.value = userState.f.resources.deps
259
- }
260
- return attr.type === 'select' ? userState.f.resources.depids : [userState.f.resources.depids]
261
- }
262
- if (def === 'curUserId') {
263
- if (attr.type === 'treeSelect') {
264
- treeValue.value = userState.f.resources.name
265
- }
266
- return attr.type === 'select' ? userState.f.resources.id : [userState.f.resources.id]
267
- }
268
- }
269
-
270
- // 数组类型默认值
271
- const arrayTypes = ['uploader', 'checkbox', 'file', 'area', 'image', 'treeSelect']
272
- if (arrayTypes.includes(attr.type)) {
273
- return def !== undefined ? def : []
274
- }
275
-
276
- // 特殊类型默认值
277
- const specialDefaults = {
278
- switch: false,
279
- stepper: 1,
280
- addressSearch: val,
281
- }
282
-
283
- if (specialDefaults[attr.type] !== undefined) {
284
- return specialDefaults[attr.type]
285
- }
286
-
287
- // 日期时间类型:调用 getDateRange,并传入 formValueFormat
288
- // 说明:让初始化/查询默认值同样遵循配置的格式显示
289
- const dateTypes = ['rangePicker', 'yearPicker', 'monthPicker', 'yearRangePicker', 'monthRangePicker', 'datePicker', 'timePicker']
290
- if (dateTypes.includes(attr.type)) {
291
- return getDateRange({
292
- type: attr.type,
293
- formDefault: attr.formDefault ?? '',
294
- queryFormDefault: attr.queryFormDefault ?? '',
295
- queryType: attr.queryType,
296
- queryValueFormat: attr.queryValueFormat,
297
- name: attr.name ?? '',
298
- formValueFormat: formValueFormat.value,
299
- }) ?? []
300
- }
301
-
302
- // 其他类型(字符串、数字等)
303
- return def ?? ''
304
- }
305
-
306
- return getDefaultByType()
307
- }
308
-
309
- // 初始化日期组件初始值,组件自定义格式显示值和实际值(日期相关初始化都在此函数中操作)
310
- function getDateRange({
311
- type,
312
- formDefault: defaultValue,
313
- queryFormDefault,
314
- queryType,
315
- queryValueFormat: defaultFormat,
316
- name,
317
- formValueFormat: formFormat,
318
- }: {
319
- type: string
320
- formDefault: string
321
- queryFormDefault: string
322
- queryType?: string
323
- queryValueFormat?: string
324
- name: string
325
- // 新增:用于优先覆盖 datePicker 的显示/存储格式
326
- formValueFormat?: string
327
- }): string | [string, string] | undefined {
328
- const formatMap: Record<string, string> = {
329
- yearPicker: 'YYYY',
330
- yearRangePicker: 'YYYY',
331
- monthPicker: 'YYYY-MM',
332
- monthRangePicker: 'YYYY-MM',
333
- datePicker: 'YYYY-MM-DD HH:mm:ss',
334
- rangePicker: 'YYYY-MM-DD HH:mm:ss',
335
- }
336
- if (mode) {
337
- // datePicker 优先使用 formValueFormat(否则退回 queryValueFormat 或默认映射)
338
- const preferFormat = type === 'datePicker' ? (formFormat || defaultFormat) : defaultFormat
339
- const format = preferFormat || formatMap[type]
340
- const val = mode === '查询' ? queryFormDefault : defaultValue
341
- let start: string, end: string
342
- switch (val) {
343
- case 'curYear':
344
- start = dayjs().startOf('year').format(format)
345
- end = dayjs().endOf('year').format(format)
346
- break
347
- case 'curMonth':
348
- start = dayjs().startOf('month').format(format)
349
- end = dayjs().endOf('month').format(format)
350
- break
351
- case 'curDay':
352
- start = dayjs().startOf('day').format(format)
353
- end = dayjs().endOf('day').format(format)
354
- break
355
- case 'curTime':
356
- start = dayjs().format(format)
357
- end = dayjs().format(format)
358
- break
359
- default:
360
- return undefined
361
- }
362
- if (['monthPicker', 'yearPicker', 'datePicker'].includes(type)) {
363
- if (mode !== '查询') {
364
- if (queryType === 'BETWEEN') {
365
- return [start, end]
366
- }
367
- if (name.includes('开始') || name.includes('起始')) {
368
- return start
369
- }
370
- else {
371
- return end
372
- }
373
- }
374
- else {
375
- return start
376
- }
377
- }
378
- // rangePicker组件表单显示的值
379
- if (mode === '查询' && type === 'rangePicker') {
380
- pickerValue.value = `${start} ~ ${end}`
381
- }
382
- return mode !== '查询' ? start : [start, end]
383
- }
384
- else {
385
- return undefined
386
- }
387
- }
388
-
389
- // 监听 props.form 的变化
390
- watch(
391
- () => props.form,
392
- (newVal, oldVal) => {
393
- // 如果是从函数获取 options
394
- if (props.attr.keyName && (props.attr.keyName.toString().includes('async ') || props.attr.keyName.toString().includes('function'))) {
395
- debouncedUpdateOptions()
396
- }
397
- if (props.attr.showFormItemFunc) {
398
- showFormItemFuncdebounce()
399
- }
400
- },
401
- { deep: true },
402
- )
403
-
404
- // 监听 modelData 的变化,调用 dataChangeFunc
405
- watch(
406
- () => modelData.value,
407
- (newVal, oldVal) => {
408
- // 避免初始化时的调用
409
- if (newVal !== oldVal) {
410
- dataChangeFuncdebounce()
411
- }
412
- },
413
- { deep: true },
414
- )
415
-
416
- // 监听 option.value 的变化
417
- watch(
418
- () => option.value,
419
- (newOption) => {
420
- if (attr.type === 'treeSelect' && newOption && newOption.length > 0) {
421
- // 你可以在这里调用 findOptionInTree 函数来查找默认值对应的 label
422
- const result = findOptionInTree(option.value, modelData.value)
423
- if (attr.type === 'treeSelect' && result)
424
- treeValue.value = result.label
425
- }
426
- },
427
- )
428
-
429
- function updateFile(files, _index) {
430
- modelData.value = files
431
- }
432
-
433
- // 表单校验的类型校验
434
- function formTypeCheck(attr, value) {
435
- if (mode === '查询' || mode === '预览')
436
- return
437
- // if (!attr.rule || !attr.rule.required || attr.rule.required === 'false')
438
- // return
439
- switch (attr.rule.type) {
440
- case 'string':
441
- if (value.length === 0) {
442
- errorMessage.value = `请输入${attr.name}`
443
- return
444
- }
445
- break
446
- case 'number':
447
- if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(value)) {
448
- errorMessage.value = `${attr.name}必须为数字`
449
- return
450
- }
451
- break
452
- case 'boolean':
453
- case 'array':
454
- case 'regexp':
455
- if (value) {
456
- errorMessage.value = ''
457
- return
458
- }
459
- break
460
- case 'integer':
461
- if (!/^-?\d+$/.test(value)) {
462
- errorMessage.value = `${attr.name}必须为整数`
463
- return
464
- }
465
- break
466
- case 'float':
467
- if (!/^-?\d+\.\d+$/.test(value)) {
468
- errorMessage.value = `${attr.name}必须为小数`
469
- return
470
- }
471
- break
472
- case 'email':
473
- if (!/^[\w.%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i.test(value)) {
474
- errorMessage.value = `请输入正确的邮箱地址`
475
- return
476
- }
477
- break
478
- case 'idNumber':
479
- if (!/^(?:\d{15}|\d{17}[0-9X])$/.test(value)) {
480
- errorMessage.value = `请输入正确的身份证号码`
481
- return
482
- }
483
- break
484
- case 'userPhone':
485
- if (!/^1[3-9]\d{9}$/.test(value)) {
486
- errorMessage.value = `请输入正确的手机号码`
487
- return
488
- }
489
- break
490
- case 'landlineNumber':
491
- if (!/^0\d{2,3}[-\s]?\d{7,8}$/.test(value)) {
492
- errorMessage.value = `请输入正确的座机号码`
493
- return
494
- }
495
- break
496
- case 'greaterThanZero':
497
- if (!/^(?:[1-9]\d*(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(value)) {
498
- errorMessage.value = `请输入一个大于0的数字`
499
- return
500
- }
501
- break
502
- case 'greaterThanOrEqualZero':
503
- if (!/^(?:\d+|\d*\.\d+)$/.test(value)) {
504
- errorMessage.value = `请输入一个大于等于0的数字`
505
- return
506
- }
507
- break
508
- case 'stringLength':
509
- if (!(value.length >= attr.rule.minLen && value.length < attr.rule.maxLen)) {
510
- errorMessage.value = `长度必须在${attr.rule.minLen}~${attr.rule.maxLen}之间`
511
- return
512
- }
513
- break
514
- case 'customJs':
515
- // eslint-disable-next-line no-case-declarations
516
- const funcStr = attr.rule.customValidatorFunc
517
- // 输入的数据是否符合条件
518
- // eslint-disable-next-line no-case-declarations
519
- const status = ref(true)
520
- // 提取函数体部分
521
- // eslint-disable-next-line no-case-declarations
522
- const funcBodyMatch = funcStr.match(/function\s*\(.*?\)\s*\{([\s\S]*)\}/)
523
- if (!funcBodyMatch)
524
- throw new Error('自定义校验函数不合法')
525
- // eslint-disable-next-line no-case-declarations
526
- const funcBody = funcBodyMatch[1].trim() // 提取函数体
527
- // 使用 new Function 创建函数
528
- // eslint-disable-next-line no-new-func,no-case-declarations
529
- const customValidatorFunc = new Function('rule', 'value', 'callback', 'form', 'attr', 'util', funcBody)
530
- // 定义 callback 函数
531
- // eslint-disable-next-line no-case-declarations
532
- const callback = (error) => {
533
- if (error) {
534
- errorMessage.value = `${error}`
535
- status.value = false // 表示有错误发生
536
- }
537
- }
538
- // 调用自定义校验函数
539
- customValidatorFunc(
540
- attr.rule,
541
- value,
542
- callback,
543
- form,
544
- attr,
545
- {}, // util 对象(可以根据需要传递)
546
- )
547
- if (!status.value)
548
- return
549
- break
550
- default:
551
- errorMessage.value = ''
552
- break
553
- }
554
- errorMessage.value = ''
555
- }
556
-
557
- onBeforeMount(() => {
558
- init()
559
- modelData.value = getDefaultValue()
560
- showFormItemFunc()
561
- dataChangeFunc()
562
- if (attr?.keyName?.toString()?.startsWith('search@根据表单项[') && attr?.keyName?.toString().endsWith(']联动人员'))
563
- debouncedUserLinkFunc = debounce(() => updateResOptions('人员'), 200)
564
-
565
- if (attr?.keyName?.toString()?.startsWith('search@根据表单项[') && attr?.keyName?.toString().endsWith(']联动部门'))
566
- debouncedDepLinkFunc = debounce(() => updateResOptions('部门'), 200)
567
-
568
- if (attr.keyName && (attr?.keyName?.toString().indexOf('async ') !== -1 || attr?.keyName?.toString()?.indexOf('function') !== -1)) {
569
- debouncedUpdateOptions = debounce(updateOptions, 200)
570
- }
571
- })
572
- // 是否展示表单左侧label文字
573
- const labelData = computed(() => {
574
- return props.showLabel ? attr.name : null
575
- })
576
- // 是否展示表单左侧label文字
577
- const labelAlign = computed(() => {
578
- return attr.labelAlign ? attr.labelAlign : 'left'
579
- })
580
- // 是否只读
581
- const readonly = computed(() => {
582
- return props.formReadonly || attr.addOrEdit === 'readonly' || mode === '预览' || customizeReadOnly.value
583
- })
584
-
585
- // 判断是否显示空提示(只读且值为空)
586
- const showEmptyTip = computed(() => {
587
- if ((attr.type === 'image' || attr.type === 'file') && props.formReadonly) {
588
- const value = modelData.value
589
- return !value || (Array.isArray(value) && value.length === 0)
590
- }
591
- return false
592
- })
593
-
594
- // 提示内容
595
- const placeholder = computed(() => {
596
- if (attr.addOrEdit === 'readonly' || mode === '预览' || props.formReadonly) {
597
- // 根据类型返回更具体的空状态提示
598
- if (attr.type === 'image') {
599
- return '暂无图片'
600
- }
601
- else if (attr.type === 'file') {
602
- return '暂无文件'
603
- }
604
- return '暂无内容'
605
- }
606
- else
607
- if (attr.placeholder) {
608
- return attr.placeholder
609
- }
610
- else {
611
- switch (attr.type) {
612
- case 'datePicker':
613
- case 'timePicker':
614
- case 'rangePicker':
615
- case 'radio':
616
- case 'select':
617
- case 'treeSelect':
618
- case 'area':
619
- case 'citySelect':
620
- case 'picker':
621
- return `请选择${attr.name}`
622
- case 'addressSearch':
623
- case 'input':
624
- case 'textarea':
625
- case 'intervalPicker':
626
- return `请输入${attr.name}`
627
- default:
628
- return `请选择${attr.name}`
629
- }
630
- }
631
- })
632
-
633
- const formatDate = date => `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
634
-
635
- function onCalendarConfirm(values) {
636
- modelData.value = [formatDate(values[0]), formatDate(values[1])]
637
- pickerValue.value = `${formatDate(values[0])} ~ ${formatDate(values[1])}`
638
- calendarShow.value = false
639
- }
640
-
641
- // js 函数作为数据源
642
- async function updateOptions() {
643
- if (attr.keyName && (attr.keyName.toString().includes('async ') || attr.keyName.toString().includes('function '))) {
644
- option.value = await executeStrFunctionByContext(currInst, attr.keyName, [props.form, runLogic, props.mode, getConfigByNameAsync, post, userState.f.resources])
645
- }
646
- }
647
-
648
- function init() {
649
- if (attr.keyName && typeof attr.keyName === 'string') {
650
- if (attr.keyName && attr.keyName.includes('logic@')) {
651
- getData({}, (res) => {
652
- option.value = res
653
- initRadioValue()
654
- })
655
- }
656
- else if (attr.keyName && attr.keyName.includes('config@')) {
657
- const configName = attr.keyName.substring(7)
658
- getDict(configName, (result) => {
659
- if (result)
660
- option.value = result
661
- }, serviceName)
662
- }
663
- else if (attr.keyName && attr.keyName.includes('search@')) {
664
- let source = attr.keyName.substring(7)
665
- const userid = currUser.value
666
- let roleName = 'roleName'
667
- if (source.startsWith('根据角色[') && source.endsWith(']获取人员')) {
668
- const startIndex = source.indexOf('[') + 1
669
- const endIndex = source.indexOf(']', startIndex)
670
- roleName = source.substring(startIndex, endIndex)
671
- source = '根据角色获取人员'
672
- }
673
- const searchData = { source, userid, roleName }
674
- if (source.startsWith('根据表单项[') && source.endsWith(']联动人员'))
675
- updateResOptions('人员')
676
- else if (source.startsWith('根据表单项[') && source.endsWith(']联动部门'))
677
- updateResOptions('部门')
678
- else if (attr.type === 'select' || attr.type === 'checkbox')
679
- searchToListOption(searchData, res => getDataCallback(res))
680
- else
681
- searchToOption(searchData, res => getDataCallback(res))
682
- }
683
- else if (attr.keyName.toString().includes('async ') || attr.keyName.toString().includes('function ')) {
684
- updateOptions()
685
- }
686
- else {
687
- initRadioValue()
688
- }
689
- }
690
- }
691
-
692
- function getDataCallback(res) {
693
- option.value = res
694
- if (attr.type === 'radio')
695
- initRadioValue()
696
- }
697
-
698
- async function updateResOptions(type) {
699
- if (attr?.keyName?.toString()?.startsWith('search@根据表单项[') && attr?.keyName?.toString()?.endsWith(`]联动${type}`)) {
700
- const searchData = { source: `获取${type}`, userid: currUser.value }
701
- const startIndex = attr.keyName.indexOf('[') + 1
702
- const endIndex = attr.keyName.indexOf(']', startIndex)
703
- const formModel = attr.keyName.substring(startIndex, endIndex).replace('.', '_')
704
- const formModelData = form[formModel]
705
- if (formModel?.length && formModelData?.length) {
706
- await searchToListOption(searchData, (res) => {
707
- getDataCallback(res.filter((h) => {
708
- return formModelData['0'] === h.f_organization_id || formModelData['0'] === h.f_department_id || formModelData['0'] === h.parentid
709
- // if (formModel.indexOf('org') > -1) {
710
- // return formModelData?.includes(h.orgid || h.f_organization_id || h.parentid)
711
- // } else {
712
- // return formModelData?.includes(h?.parentid)
713
- // }
714
- }))
715
- })
716
- }
717
- }
718
- }
719
-
720
- function initRadioValue() {
721
- if ((mode === '新增' || mode === '修改') && attr.type === 'radio' && !props.modelValue) {
722
- if (attr.keys && attr.keys.length > 0)
723
- modelData.value = attr.keys[0].value
724
- else if (option.value && option.value.length > 0)
725
- modelData.value = option.value[0].value
726
- }
727
- }
728
-
729
- function getData(value, callback) {
730
- if (value !== '') {
731
- const logicName = attr.keyName
732
- const logic = logicName.substring(6)
733
- // 调用logic前设置参数
734
- if (getDataParams && getDataParams[attr.model])
735
- Object.assign(value, getDataParams[attr.model])
736
- Object.assign(value, userInfo.value)
737
- runLogic(logic, value, serviceName).then((res) => {
738
- callback(res)
739
- })
740
- }
741
- }
742
-
743
- // 已废弃 不进行维护
744
- function onPickerConfirm({ selectedOptions }) {
745
- showPicker.value = false
746
- modelData.value = selectedOptions[0].text
747
- }
748
-
749
- // 日期时间选择数据
750
- const dateTimePickerValue = ref<any>({})
751
- // 展示日期时间选择器:根据 formValueFormat 初始化 VanDatePicker/VanTimePicker 的当前值
752
- // 规则:
753
- // - 若已有字符串值,按 formValueFormat 解析并拆分为日期/时间数组
754
- // - 若无值,按当前时间生成匹配格式的默认数组
755
- function showDataTimePicker() {
756
- if (props.modelValue && typeof props.modelValue === 'string') {
757
- const base = dayjs(props.modelValue as string, formValueFormat.value)
758
- const dateArr: string[] = []
759
- dateArr.push(base.format('YYYY'))
760
- if (dateColumnsType.value.includes('month'))
761
- dateArr.push(base.format('MM'))
762
- if (dateColumnsType.value.includes('day'))
763
- dateArr.push(base.format('DD'))
764
- const timeArr: string[] = []
765
- if (hasTime.value) {
766
- if (timeColumnsType.value.includes('hour'))
767
- timeArr.push(base.format('HH'))
768
- if (timeColumnsType.value.includes('minute'))
769
- timeArr.push(base.format('mm'))
770
- if (timeColumnsType.value.includes('second'))
771
- timeArr.push(base.format('ss'))
772
- }
773
- dateTimePickerValue.value = {
774
- date: dateArr,
775
- time: timeArr.length ? timeArr : ['00', '00', '00'].slice(0, timeColumnsType.value.length),
776
- }
777
- }
778
- else {
779
- const now = dayjs()
780
- const dateArr: string[] = []
781
- dateArr.push(now.format('YYYY'))
782
- if (dateColumnsType.value.includes('month'))
783
- dateArr.push(now.format('MM'))
784
- if (dateColumnsType.value.includes('day'))
785
- dateArr.push(now.format('DD'))
786
- const timeArr: string[] = []
787
- if (hasTime.value) {
788
- if (timeColumnsType.value.includes('hour'))
789
- timeArr.push(now.format('HH'))
790
- if (timeColumnsType.value.includes('minute'))
791
- timeArr.push(now.format('mm'))
792
- if (timeColumnsType.value.includes('second'))
793
- timeArr.push(now.format('ss'))
794
- }
795
- dateTimePickerValue.value = {
796
- date: dateArr,
797
- time: timeArr.length ? timeArr : ['00', '00', '00'].slice(0, timeColumnsType.value.length),
798
- }
799
- }
800
- showDatePicker.value = true
801
- }
802
-
803
- function onDatePickerConfirm({ selectedValues }) {
804
- showDatePicker.value = false
805
- modelData.value = selectedValues.join('-')
806
- }
807
-
808
- // 已废弃 不进行维护
809
- function onTimePickerConfirm({ selectedValues }) {
810
- showTimePicker.value = false
811
- timePickerValue.value = selectedValues.join(':')
812
- modelData.value = timePickerValue.value
813
- }
814
-
815
- // 没人用到本次先不动。后续需要看这个组件需要怎么使用
816
- function onAreaConfirm({ selectedOptions }) {
817
- area.value = `${selectedOptions[0].text}-${selectedOptions[1].text}-${selectedOptions[2].text}`
818
- showArea.value = false
819
- modelData.value = [{
820
- province: selectedOptions[0].text,
821
- city: selectedOptions[1].text,
822
- district: selectedOptions[2].text,
823
- }]
824
- }
825
-
826
- // 日期时间选择确认:将选择的年月日(+时分秒)拼装后,最终使用 formValueFormat 输出到 v-model
827
- function onDateTimePickerConfirm() {
828
- showDatePicker.value = false
829
- const dateParts = dateTimePickerValue.value.date as string[]
830
- const timeParts = (dateTimePickerValue.value.time as string[]) || []
831
- const year = dateParts[0]
832
- const month = dateParts[1] || '01'
833
- const day = dateParts[2] || '01'
834
- const hour = hasTime.value && timeParts[0] ? timeParts[0] : '00'
835
- const minute = hasTime.value && timeParts[1] ? timeParts[1] : '00'
836
- const second = hasTime.value && timeParts[2] ? timeParts[2] : '00'
837
- const full = `${year}-${month}-${day} ${hour}:${minute}:${second}`
838
- modelData.value = dayjs(full, 'YYYY-MM-DD HH:mm:ss').format(formValueFormat.value)
839
- }
840
-
841
- function onPickerCancel() {
842
- showDatePicker.value = false
843
- }
844
-
845
- const showAddressPicker = ref(false)
846
- const addressValue = ref('')
847
-
848
- // XLocationPicker 默认加载的中心点
849
- const defaultMapCenter = computed(() => {
850
- const lonLat = form[`${attr.model}_lon_lat`]
851
- if (lonLat && typeof lonLat === 'string' && lonLat.includes(',')) {
852
- const [lon, lat] = lonLat.split(',').map(Number)
853
- if (!Number.isNaN(lon) && !Number.isNaN(lat)) {
854
- return [lon, lat] as [number, number]
855
- }
856
- }
857
- return undefined
858
- })
859
-
860
- // 处理地址选择器确认
861
- function handleAddressConfirm(location) {
862
- // 构造新的数据格式
863
- const formData = {
864
- [`${attr.model}_lon_lat`]: `${location.longitude},${location.latitude}`,
865
- [attr.model]: location.address,
866
- }
867
- // 更新表单数据
868
- emits('setForm', formData)
869
- showAddressPicker.value = false
870
- }
871
-
872
- // 重置方法,供父组件调用
873
- function reset() {
874
- modelData.value = getDefaultValue()
875
- errorMessage.value = ''
876
- treeValue.value = null
877
- area.value = null
878
- pickerValue.value = null
879
- }
880
-
881
- defineExpose({
882
- reset,
883
- })
884
-
885
- // 数据处理
886
- function cleanEmptyChildren(options, fieldNames = { text: 'label', value: 'value', children: 'children' }) {
887
- if (!Array.isArray(options))
888
- return options
889
-
890
- const childrenKey = fieldNames.children || 'children'
891
-
892
- return options.map((option) => {
893
- // 深拷贝选项,避免修改原始数据
894
- const newOption = { ...option }
895
-
896
- // 如果存在children属性且是空数组
897
- if (newOption[childrenKey] && Array.isArray(newOption[childrenKey]) && newOption[childrenKey].length === 0) {
898
- delete newOption[childrenKey]
899
- }
900
- // 如果存在children属性且非空,则递归处理
901
- else if (newOption[childrenKey] && Array.isArray(newOption[childrenKey])) {
902
- newOption[childrenKey] = cleanEmptyChildren(newOption[childrenKey], fieldNames)
903
- }
904
- return newOption
905
- })
906
- }
907
-
908
- // 级联选择完成事件
909
- function onTreeSelectFinish({ selectedOptions }) {
910
- const index = selectedOptions.length - 1
911
- treeValue.value = selectedOptions[index].label
912
- if (mode === '查询') {
913
- modelData.value = [selectedOptions[index].value]
914
- }
915
- else {
916
- modelData.value = selectedOptions[index].value
917
- }
918
- showTreeSelect.value = false
919
- }
920
-
921
- function emitFunc(func, data) {
922
- emits('xFormItemEmitFunc', func, data, data?.model ? form[data.model] : form)
923
- }
924
-
925
- function findOptionInTree(options, value) {
926
- // 在当前层级查找
927
- const foundItem = options.find(item => item[columnsField.value] === value)
928
- if (foundItem) {
929
- return foundItem
930
- }
931
- // 递归查找子级
932
- for (const item of options) {
933
- if (item.children?.length) {
934
- const foundInChildren = findOptionInTree(item.children, value)
935
- if (foundInChildren)
936
- return foundInChildren
937
- }
938
- }
939
-
940
- return null
941
- }
942
-
943
- // 懒加载搜索函数
944
- async function handleLazySearch(searchText: string) {
945
- if (!attr.keyName || typeof attr.keyName !== 'string') {
946
- return []
947
- }
948
-
949
- try {
950
- // 如果是 search@ 类型的数据源
951
- if (attr.keyName.includes('search@')) {
952
- let source = attr.keyName.substring(7)
953
- const userid = currUser.value
954
- let roleName = 'roleName'
955
-
956
- if (source.startsWith('根据角色[') && source.endsWith(']获取人员')) {
957
- const startIndex = source.indexOf('[') + 1
958
- const endIndex = source.indexOf(']', startIndex)
959
- roleName = source.substring(startIndex, endIndex)
960
- source = '根据角色获取人员'
961
- }
962
-
963
- const searchData = {
964
- source,
965
- userid,
966
- roleName,
967
- searchText, // 添加搜索关键词
968
- }
969
-
970
- return new Promise((resolve) => {
971
- if (attr.type === 'select' || attr.type === 'checkbox') {
972
- searchToListOption(searchData, (res) => {
973
- // 根据搜索关键词过滤结果
974
- const filtered = res.filter((item) => {
975
- const text = item[columnsField.value.text] || item.label || ''
976
- return text.toString().toLowerCase().includes(searchText.toLowerCase())
977
- })
978
- resolve(filtered)
979
- })
980
- }
981
- else {
982
- searchToOption(searchData, (res) => {
983
- const filtered = res.filter((item) => {
984
- const text = item[columnsField.value.text] || item.label || ''
985
- return text.toString().toLowerCase().includes(searchText.toLowerCase())
986
- })
987
- resolve(filtered)
988
- })
989
- }
990
- })
991
- }
992
-
993
- // logic 数据源
994
- if (attr.keyName.includes('logic@')) {
995
- const logicName = attr.keyName.substring(6)
996
- const value = { word: searchText, ...userInfo.value }
997
-
998
- // 调用logic前设置参数
999
- if (getDataParams && getDataParams[attr.model]) {
1000
- Object.assign(value, getDataParams[attr.model])
1001
- }
1002
-
1003
- lastFetchId.value++
1004
- const fetchId = lastFetchId.value
1005
- // 根据搜索关键词过滤结果
1006
- const results = await runLogic(logicName, value, serviceName) as any
1007
- if (fetchId !== lastFetchId.value) {
1008
- return
1009
- }
1010
- if (searchText) {
1011
- return results.filter((item) => {
1012
- const text = item[columnsField.value.text] || item.label || ''
1013
- return text.toString().toLowerCase().includes(searchText.toLowerCase())
1014
- })
1015
- }
1016
- return results
1017
- }
1018
-
1019
- // 自定义 js 函数
1020
- if (attr.keyName.includes('async ') || attr.keyName.includes('function ')) {
1021
- const results = await executeStrFunctionByContext(currInst, attr.keyName, [
1022
- { ...props.form, searchText },
1023
- runLogic,
1024
- props.mode,
1025
- getConfigByNameAsync,
1026
- post,
1027
- userState,
1028
- ])
1029
- // 根据搜索关键词过滤结果
1030
- return results.filter((item) => {
1031
- const text = item[columnsField.value.text] || item.label || ''
1032
- return text.toString().toLowerCase().includes(searchText.toLowerCase())
1033
- })
1034
- }
1035
-
1036
- return []
1037
- }
1038
- catch (error) {
1039
- console.error('懒加载搜索失败:', error)
1040
- return []
1041
- }
1042
- }
1043
-
1044
- // 扫码/NFC
1045
- function scanCodeOrNfc(attr) {
1046
- if (attr.type === 'scanCode') {
1047
- // 扫码逻辑
1048
- mobileUtil.execute({
1049
- funcName: 'scanBarcode',
1050
- param: {},
1051
- callbackFunc: (res: any) => {
1052
- console.log('扫码结果:------', res)
1053
- if (res && res.status === 'success') {
1054
- if (res.data.status && res.data.status === 'cancelled') {
1055
- showToast(res.data?.message || '扫码已取消')
1056
- return
1057
- }
1058
- modelData.value = res.data?.rawValue
1059
- showToast('扫码成功')
1060
- emitFunc('xFormItemEmitFunc', res)
1061
- }
1062
- else {
1063
- showToast('扫码失败')
1064
- }
1065
- },
1066
- })
1067
- }
1068
- else if (attr.type === 'nfc') {
1069
- // NFC逻辑
1070
- mobileUtil.execute({
1071
- funcName: 'startNfcScan',
1072
- param: {},
1073
- callbackFunc: (res: any) => {
1074
- console.log('nfc结果:------', res)
1075
- if (res && res.status === 'success') {
1076
- modelData.value = res.data?.id
1077
- showToast('NFC 检测成功')
1078
- emitFunc('xFormItemEmitFunc', res)
1079
- }
1080
- else {
1081
- showToast(res?.message || 'NFC 功能不可用')
1082
- }
1083
- },
1084
- })
1085
- }
1086
- }
1087
- </script>
1088
-
1089
- <template>
1090
- <div>
1091
- <!-- switch开关 -->
1092
- <VanField
1093
- v-if="attr.type === 'switch' && showItem"
1094
- name="switch"
1095
- :label="labelData"
1096
- :label-align="labelAlign"
1097
- :input-align="attr.inputAlign ? attr.inputAlign : 'right'"
1098
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1099
- :required="attr.rule.required === 'true'"
1100
- >
1101
- <template #input>
1102
- <VanSwitch v-model="modelData" />
1103
- </template>
1104
- </VanField>
1105
-
1106
- <!-- 复选框 -->
1107
- <!-- <VanField
1108
- v-if="attr.type === 'checkbox'"
1109
- name="checkbox"
1110
- :label="labelData"
1111
- >
1112
- <template #input>
1113
- <VanCheckbox v-model="modelData" shape="square" />
1114
- </template>
1115
- </VanField> -->
1116
-
1117
- <!-- 多选框-checkbox-复选框组 -->
1118
- <template v-if="attr.type === 'checkbox' && showItem">
1119
- <!-- 勾选 -->
1120
- <VanField
1121
- v-if="attr.showMode === 'checkbox' && mode !== '查询'"
1122
- name="checkboxGroup"
1123
- :label="labelData"
1124
- :label-align="labelAlign"
1125
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1126
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1127
- :required="attr.rule.required === 'true'"
1128
- >
1129
- <template #input>
1130
- <van-checkbox-group v-model="modelData as any[]" direction="horizontal" shape="square" :disabled="readonly">
1131
- <VanCheckbox v-for="(item, index) in option" :key="index" style="padding: 2px" :name="item[columnsField.value]" :shape="rules?.[attr.model].shape" :value="item[columnsField.value]">
1132
- {{ item[columnsField.text] }}
1133
- </VanCheckbox>
1134
- </van-checkbox-group>
1135
- </template>
1136
- </VanField>
1137
- <VanField
1138
- v-if="attr.showMode === 'checkbox' && mode === '查询'"
1139
- name="checkboxGroup"
1140
- :label="labelData"
1141
- :label-align="labelAlign"
1142
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1143
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1144
- >
1145
- <template #input>
1146
- <XGridDropOption
1147
- v-model="(modelData as string[])"
1148
- :column-num="labelData ? 3 : 4"
1149
- :multiple="true"
1150
- :columns="option"
1151
- />
1152
- </template>
1153
- </VanField>
1154
- <!-- 下拉 -->
1155
- <XMultiSelect
1156
- v-if="(!attr.showMode || attr.showMode === 'select') && mode === '查询'"
1157
- v-model="modelData"
1158
- :label="labelData"
1159
- :readonly="readonly"
1160
- :placeholder="placeholder"
1161
- :columns="option"
1162
- :select-value="Array.isArray(modelData) ? modelData : []"
1163
- :option="attr.option ? attr.option : columnsField"
1164
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1165
- :required="attr.rule.required === 'true'"
1166
- :lazy-load="attr.lazyLoad"
1167
- :on-search="attr.lazyLoad ? handleLazySearch : null"
1168
- />
1169
- </template>
1170
-
1171
- <!-- 单选框 -->
1172
- <VanField
1173
- v-if="attr.type === 'radio' && mode !== '查询' && showItem"
1174
- name="radio"
1175
- center
1176
- :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1177
- :label="labelData"
1178
- :label-align="labelAlign"
1179
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1180
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1181
- :required="attr.rule.required === 'true'"
1182
- >
1183
- <template #input>
1184
- <VanRadioGroup v-model="modelData" direction="horizontal" :disabled="readonly">
1185
- <VanRadio v-for="(item, index) in option" :key="index" style="padding: 2px" :name="item[columnsField.value]" :value="item[columnsField.value]">
1186
- {{ item[columnsField.text] }}
1187
- </VanRadio>
1188
- </VanRadioGroup>
1189
- </template>
1190
- </VanField>
1191
-
1192
- <!-- 单选框-查询 -->
1193
- <VanField
1194
- v-if="attr.type === 'radio' && mode === '查询' && showItem"
1195
- name="radio"
1196
- :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1197
- :label="labelData"
1198
- :label-align="labelAlign"
1199
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1200
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1201
- >
1202
- <template #input>
1203
- <XGridDropOption
1204
- v-model="(modelData as string)"
1205
- :column-num="labelData ? 3 : 4"
1206
- :columns="option"
1207
- />
1208
- </template>
1209
- </VanField>
1210
-
1211
- <!-- 步进器 -->
1212
- <VanField
1213
- v-if="attr.type === 'stepper' && showItem"
1214
- name="stepper"
1215
- :label="labelData"
1216
- :label-align="labelAlign"
1217
- :input-align="attr.inputAlign ? attr.inputAlign : 'center'"
1218
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1219
- :required="attr.rule.required === 'true'"
1220
- >
1221
- <template #input>
1222
- <VanStepper v-model="modelData as any" :disabled="readonly" />
1223
- </template>
1224
- </VanField>
1225
-
1226
- <!-- 评分 -->
1227
- <VanField
1228
- v-if="attr.type === 'rate' && showItem"
1229
- name="rate"
1230
- :label="labelData"
1231
- :label-align="labelAlign"
1232
- :input-align="attr.inputAlign ? attr.inputAlign : 'center'"
1233
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1234
- :required="attr.rule.required === 'true'"
1235
- >
1236
- <template #input>
1237
- <VanRate v-model="modelData as number" :size="25" :count="attr.displayCount || 5" :readonly="readonly" void-color="#eee" void-icon="star" color="#ffd21e" />
1238
- </template>
1239
- </VanField>
1240
-
1241
- <!-- 滑块 -->
1242
- <VanField
1243
- v-if="attr.type === 'slider' && showItem"
1244
- name="slider"
1245
- :label="labelData"
1246
- :label-align="labelAlign"
1247
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1248
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1249
- :required="attr.rule.required === 'true'"
1250
- >
1251
- <template #input>
1252
- <VanSlider v-model="modelData as number" :readonly="readonly" />
1253
- </template>
1254
- </VanField>
1255
-
1256
- <!-- 文件上传 -->
1257
- <!-- 图片上传, 手机端拍照 -->
1258
- <VanField
1259
- v-if="(attr.type === 'image' || attr.type === 'file') && showItem"
1260
- name="image"
1261
- :label="labelData"
1262
- center
1263
- :label-align="labelAlign"
1264
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1265
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1266
- :required="attr.rule.required === 'true'"
1267
- >
1268
- <template #input>
1269
- <!-- 只读且为空时显示空提示 -->
1270
- <div v-if="showEmptyTip" class="empty-tip">
1271
- {{ placeholder }}
1272
- </div>
1273
- <!-- 有值或非只读时显示上传组件 -->
1274
- <ImageUploader
1275
- v-else
1276
- upload-mode="server"
1277
- :image-list="(modelData as any[])"
1278
- authority="admin"
1279
- :attr="attr"
1280
- :mode="props.mode"
1281
- :readonly="readonly"
1282
- :is-async-upload="isAsyncUpload"
1283
- @update-file-list="updateFile"
1284
- />
1285
- </template>
1286
- </VanField>
1287
-
1288
- <!-- 选择器 琉璃中不存在,不进行维护后续将删除 -->
1289
- <VanField
1290
- v-if="attr.type === 'picker' && showItem"
1291
- v-model="pickerValue"
1292
- name="picker"
1293
- :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1294
- :label="labelData"
1295
- :label-align="labelAlign"
1296
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1297
- readonly
1298
- is-link
1299
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1300
- @click="readonly ? null : showPicker = true"
1301
- />
1302
- <VanPopup v-model:show="showPicker" round position="bottom" teleport="body" overlay-class="date-picker-overlay">
1303
- <VanPicker
1304
- v-model="(modelData as Numeric[])"
1305
- :title="attr.name"
1306
- :columns="attr.selectKey"
1307
- :readonly="readonly"
1308
- :columns-field-names="attr.customFieldName ? attr.customFieldName : { text: 'text', value: 'value', children: 'children' }"
1309
- :confirm-button-text="attr.confirmButtonText || attr.confirmButtonText === '' ? attr.confirmButtonText : '确认'"
1310
- :cancel-button-text="attr.cancelButtonText || attr.cancelButtonText === '' ? attr.cancelButtonText : '取消'"
1311
- @cancel="showPicker = false"
1312
- @confirm="onPickerConfirm"
1313
- />
1314
- </VanPopup>
1315
-
1316
- <!-- 日历选择-查询 -->
1317
- <VanField
1318
- v-if="attr.type === 'rangePicker' && mode === '查询' && showItem"
1319
- v-model="(pickerValue as string | number)"
1320
- is-link
1321
- readonly
1322
- name="rangePicker"
1323
- :label="labelData"
1324
- :label-align="labelAlign"
1325
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1326
- :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1327
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1328
- @click="calendarShow = true"
1329
- />
1330
- <VanCalendar
1331
- v-model:show="calendarShow"
1332
- switch-mode="year-month"
1333
- type="range"
1334
- teleport="body"
1335
- overlay-class="date-picker-overlay"
1336
- :show-confirm="attr.showConfirm"
1337
- @confirm="onCalendarConfirm"
1338
- />
1339
-
1340
- <!-- 日期选择-非查询 -->
1341
- <VanField
1342
- v-if="(attr.type === 'datePicker' || attr.type === 'rangePicker') && mode !== '查询' && showItem"
1343
- v-model="(modelData as string | number)"
1344
- name="datePicker"
1345
- :label="labelData"
1346
- :label-align="labelAlign"
1347
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1348
- readonly
1349
- :is-link="true"
1350
- :placeholder="placeholder"
1351
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1352
- :required="attr.rule.required === 'true'"
1353
- @click="readonly ? null : showDataTimePicker()"
1354
- />
1355
- <VanPopup v-model:show="showDatePicker" position="bottom" teleport="body" overlay-class="date-picker-overlay">
1356
- <VanPickerGroup
1357
- :title="attr.name"
1358
- :tabs="hasTime ? ['选择日期', '选择时间'] : ['选择日期']"
1359
- next-step-text="下一步"
1360
- :confirm-button-text="attr.confirmButtonText ? attr.confirmButtonText : '确认'"
1361
- :cancel-button-text="attr.cancelButtonText ? attr.cancelButtonText : '取消'"
1362
- @confirm="onDateTimePickerConfirm"
1363
- @cancel="onPickerCancel"
1364
- >
1365
- <VanDatePicker
1366
- v-model="dateTimePickerValue.date"
1367
- :columns-type="attr.dateColumnsType || dateColumnsType"
1368
- />
1369
- <VanTimePicker
1370
- v-if="hasTime"
1371
- v-model="dateTimePickerValue.time"
1372
- :columns-type="attr.timeColumnsType || timeColumnsType"
1373
- :min-time="attr.minTime ? attr.minTime : '00:00:00'"
1374
- :max-time="attr.maxTime ? attr.maxTime : '23:59:59'"
1375
- />
1376
- </VanPickerGroup>
1377
- </VanPopup>
1378
-
1379
- <!-- 日期选择-查询 -->
1380
- <VanField
1381
- v-if="attr.type === 'datePicker' && mode === '查询' && showItem"
1382
- v-model="(modelData as string | number)"
1383
- name="datePicker"
1384
- :label="labelData"
1385
- :label-align="labelAlign"
1386
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1387
- readonly
1388
- :is-link="true"
1389
- :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1390
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1391
- @click="readonly ? null : showDataTimePicker()"
1392
- />
1393
- <VanPopup v-model:show="showDatePicker" position="bottom" teleport="body" overlay-class="date-picker-overlay">
1394
- <VanPickerGroup
1395
- :title="attr.name"
1396
- :tabs="hasTime ? ['选择日期', '选择时间'] : ['选择日期']"
1397
- next-step-text="下一步"
1398
- :confirm-button-text="attr.confirmButtonText ? attr.confirmButtonText : '确认'"
1399
- :cancel-button-text="attr.cancelButtonText ? attr.cancelButtonText : '取消'"
1400
- @confirm="onDateTimePickerConfirm"
1401
- @cancel="onPickerCancel"
1402
- >
1403
- <VanDatePicker
1404
- v-model="dateTimePickerValue.date"
1405
- :columns-type="attr.dateColumnsType || dateColumnsType"
1406
- />
1407
- <VanTimePicker
1408
- v-if="hasTime"
1409
- v-model="dateTimePickerValue.time"
1410
- :columns-type="attr.timeColumnsType || timeColumnsType"
1411
- :min-time="attr.minTime ? attr.minTime : '00:00:00'"
1412
- :max-time="attr.maxTime ? attr.maxTime : '23:59:59'"
1413
- />
1414
- </VanPickerGroup>
1415
- </VanPopup>
1416
-
1417
- <!-- 时间选择 --该配置未在pc找到不进行维护 后续将删除 -->
1418
- <VanField
1419
- v-if="attr.type === 'timePicker' && showItem"
1420
- v-model="timePickerValue"
1421
- name="timePicker"
1422
- is-link
1423
- readonly
1424
- :placeholder="attr.placeholder"
1425
- :label="labelData"
1426
- :label-align="labelAlign"
1427
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1428
- :rules="[{ required: attr.rule.required === 'true', message: '请选择' }]"
1429
- @click="readonly ? null : (showTimePicker = true)"
1430
- />
1431
- <VanPopup v-model:show="showTimePicker" position="bottom" teleport="body" overlay-class="date-picker-overlay">
1432
- <VanTimePicker
1433
- v-model="modelData as string[]"
1434
- :title="attr.name"
1435
- :columns-type="attr.columnsType ? attr.columnsType : ['hour', 'minute', 'second']"
1436
- :min-time="attr.minTime ? attr.minTime : '00:00:00'"
1437
- :max-time="attr.maxTime ? attr.maxTime : '23:59:59'"
1438
- :readonly="readonly"
1439
- @cancel="showTimePicker = false"
1440
- @confirm="onTimePickerConfirm"
1441
- />
1442
- </VanPopup>
1443
-
1444
- <!-- 省市区选择 -->
1445
- <VanField
1446
- v-if="(attr.type === 'area' || attr.type === 'citySelect') && showItem"
1447
- v-model="area"
1448
- name="area"
1449
- :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1450
- is-link
1451
- readonly
1452
- :label="labelData"
1453
- :label-align="labelAlign"
1454
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1455
- :rules="[{ required: attr.rule.required === 'true', message: '请选择' }]"
1456
- :required="attr.rule.required === 'true'"
1457
- @click="readonly ? null : (showArea = true)"
1458
- />
1459
- <VanPopup v-model:show="showArea" position="bottom" teleport="body" overlay-class="date-picker-overlay">
1460
- <VanArea
1461
- v-model="modelData as string" :title="attr.name" :area-list="areaList"
1462
- @confirm="onAreaConfirm"
1463
- @cancel="showArea = false"
1464
- />
1465
- </VanPopup>
1466
-
1467
- <!-- 单选下拉列表 -->
1468
- <XSelect
1469
- v-if="attr.type === 'select' && showItem"
1470
- v-model="modelData"
1471
- :label="labelData"
1472
- :readonly="readonly"
1473
- clearable
1474
- :placeholder="placeholder"
1475
- :columns="option"
1476
- :option="attr.option ? attr.option : columnsField"
1477
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1478
- :required="attr.rule.required === 'true'"
1479
- :lazy-load="attr.lazyLoad"
1480
- :on-search="attr.lazyLoad ? handleLazySearch : null"
1481
- />
1482
-
1483
- <!-- 文本区域 -->
1484
- <VanField
1485
- v-if="attr.type === 'textarea' && showItem"
1486
- v-model="(modelData as string)"
1487
- rows="3"
1488
- autosize
1489
- :label="labelData"
1490
- :label-align="labelAlign"
1491
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1492
- type="textarea"
1493
- :readonly="readonly"
1494
- :maxlength="attr.maxlength ? attr.maxlength : 200"
1495
- :placeholder="attr.placeholder ? attr.placeholder : `请输入${attr.name}`"
1496
- show-word-limit
1497
- :rules="[{ required: attr.rule.required === 'true', message: `请填写${attr.name}` }]"
1498
- :required="attr.rule.required === 'true'"
1499
- />
1500
-
1501
- <!-- 文本输入框 -->
1502
- <VanField
1503
- v-if="(attr.type === 'input' || attr.type === 'intervalPicker' || attr.type === 'scanCode' || attr.type === 'nfc') && showItem"
1504
- v-model="(modelData as string)"
1505
- style="align-items: center"
1506
- :label="labelData"
1507
- :label-align="labelAlign"
1508
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1509
- :type="attr.type as FieldType"
1510
- :readonly="readonly"
1511
- :disabled="attr.disabled"
1512
- :placeholder="placeholder"
1513
- :error-message="errorMessage"
1514
- :clearable="attr.clearable"
1515
- :rules="[{ required: attr.rule.required === 'true', message: `请填写${attr.name}` }]"
1516
- :required="attr.rule.required === 'true'"
1517
- @blur="() => formTypeCheck(attr, modelData as string)"
1518
- >
1519
- <template #input>
1520
- <input
1521
- :value="modelData"
1522
- :readonly="readonly"
1523
- class="van-field__control"
1524
- :placeholder="placeholder"
1525
- style="flex: 1; min-width: 0;"
1526
- @input="e => modelData = (e.target as HTMLInputElement).value"
1527
- @blur="() => formTypeCheck(attr, modelData as string)"
1528
- >
1529
- <VanButton
1530
- v-if="(attr.type === 'input' || attr.type === 'intervalPicker') && !props.formReadonly && attr.inputOnAfterName && attr.inputOnAfterFunc && !attr.inputOnAfterName.includes('|')"
1531
- class="action-btn"
1532
- round
1533
- type="primary"
1534
- size="small"
1535
- @click="emitFunc(attr.inputOnAfterFunc, attr)"
1536
- >
1537
- {{ attr.inputOnAfterName }}
1538
- </VanButton>
1539
- <VanButton
1540
- v-if="(attr.type === 'scanCode' || attr.type === 'nfc') && !props.formReadonly"
1541
- class="action-btn scan-nfc"
1542
- round
1543
- size="small"
1544
- @click="scanCodeOrNfc(attr)"
1545
- >
1546
- {{ attr.type === 'scanCode' ? '扫码' : 'NFC' }}
1547
- </VanButton>
1548
- </template>
1549
- </VanField>
1550
-
1551
- <!-- 地址选择器 -->
1552
- <VanField
1553
- v-if="attr.type === 'addressSearch' && showItem"
1554
- v-model="modelData as string"
1555
- name="addressSearch"
1556
- :label="labelData"
1557
- :label-align="labelAlign"
1558
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1559
- readonly
1560
- is-link
1561
- :placeholder="placeholder"
1562
- :rules="[{ required: attr.rule.required === 'true', message: '请选择地址' }]"
1563
- :required="attr.rule.required === 'true'"
1564
- @click="readonly ? null : (showAddressPicker = true)"
1565
- />
1566
- <VanPopup
1567
- v-model:show="showAddressPicker"
1568
- position="bottom"
1569
- :style="{ height: '80vh' }"
1570
- teleport="body"
1571
- overlay-class="date-picker-overlay"
1572
- >
1573
- <XLocationPicker
1574
- :default-center="defaultMapCenter"
1575
- :service-name="serviceName"
1576
- @confirm="handleAddressConfirm"
1577
- />
1578
- </VanPopup>
1579
-
1580
- <!-- pc的树形选择框————》 手机端采用 Cascader 级联选择 -->
1581
- <VanField
1582
- v-if="attr.type === 'treeSelect' && showItem"
1583
- v-model="treeValue"
1584
- name="treeSelect"
1585
- :label="labelData"
1586
- :label-align="labelAlign"
1587
- :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1588
- readonly
1589
- is-link
1590
- :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1591
- :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1592
- :required="attr.rule.required === 'true'"
1593
- @click="readonly ? null : (showTreeSelect = true)"
1594
- />
1595
- <VanPopup
1596
- v-model:show="showTreeSelect"
1597
- position="bottom"
1598
- teleport="body"
1599
- overlay-class="date-picker-overlay"
1600
- >
1601
- <VanCascader
1602
- :options="cleanEmptyChildren(option, attr.customFieldName ? attr.customFieldName : { text: 'label', value: 'value', children: 'children' })"
1603
- :field-names="attr.customFieldName ? attr.customFieldName : { text: 'label', value: 'value', children: 'children' }"
1604
- :title="attr.name"
1605
- :closeable="true"
1606
- @close="showTreeSelect = false"
1607
- @finish="onTreeSelectFinish"
1608
- />
1609
- </VanPopup>
1610
- </div>
1611
- </template>
1612
-
1613
- <style scoped>
1614
- .date-picker-overlay {
1615
- background-color: rgba(0, 0, 0, 0.2); /* 设置为半透明的黑色 */
1616
- }
1617
- .action-btn {
1618
- border-radius: 10px;
1619
- margin-left: 8px;
1620
- min-width: 4rem;
1621
- max-width: 6rem;
1622
- }
1623
-
1624
- /* 扫码/NFC按钮特殊样式 */
1625
- .action-btn.scan-nfc {
1626
- background-color: transparent;
1627
- border: 1px dashed #aca8a8;
1628
- color: #1989fa;
1629
- }
1630
-
1631
- /* 空提示样式 */
1632
- .empty-tip {
1633
- color: #969799;
1634
- font-size: 14px;
1635
- text-align: center;
1636
- padding: 16px 0;
1637
- }
1638
- </style>
1
+ <script setup lang="ts">
2
+ import type { FieldType } from 'vant'
3
+ import type { Numeric } from 'vant/es/utils'
4
+ import ImageUploader from '@af-mobile-client-vue3/components/core/ImageUploader/index.vue'
5
+ import XGridDropOption from '@af-mobile-client-vue3/components/core/XGridDropOption/index.vue'
6
+ import XMultiSelect from '@af-mobile-client-vue3/components/core/XMultiSelect/index.vue'
7
+ import XSelect from '@af-mobile-client-vue3/components/core/XSelect/index.vue'
8
+ import XLocationPicker from '@af-mobile-client-vue3/components/data/XOlMap/XLocationPicker/index.vue'
9
+ import { getConfigByNameAsync, runLogic } from '@af-mobile-client-vue3/services/api/common'
10
+ import { post } from '@af-mobile-client-vue3/services/restTools'
11
+ import { searchToListOption, searchToOption } from '@af-mobile-client-vue3/services/v3Api'
12
+ import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
13
+ import { getDict } from '@af-mobile-client-vue3/utils/dictUtil'
14
+ import { mobileUtil } from '@af-mobile-client-vue3/utils/mobileUtil'
15
+ import { executeStrFunctionByContext } from '@af-mobile-client-vue3/utils/runEvalFunction'
16
+ import { areaList } from '@vant/area-data'
17
+ import dayjs from 'dayjs/esm/index'
18
+ import { debounce } from 'lodash-es'
19
+ import {
20
+ showToast,
21
+ Area as VanArea,
22
+ Button as VanButton,
23
+ Calendar as VanCalendar,
24
+ Cascader as VanCascader,
25
+ Checkbox as VanCheckbox,
26
+ CheckboxGroup as vanCheckboxGroup,
27
+ DatePicker as VanDatePicker,
28
+ Field as VanField,
29
+ Picker as VanPicker,
30
+ PickerGroup as VanPickerGroup,
31
+ Popup as VanPopup,
32
+ Radio as VanRadio,
33
+ RadioGroup as VanRadioGroup,
34
+ Rate as VanRate,
35
+ Slider as VanSlider,
36
+ Stepper as VanStepper,
37
+ Switch as VanSwitch,
38
+ TimePicker as VanTimePicker,
39
+ } from 'vant'
40
+ import { computed, defineEmits, defineModel, defineProps, getCurrentInstance, onBeforeMount, ref, watch } from 'vue'
41
+
42
+ const props = defineProps({
43
+ attr: {
44
+ type: Object,
45
+ },
46
+ form: {
47
+ type: Object,
48
+ },
49
+ // 整表只读:来自 XForm,统一控制交互
50
+ formReadonly: {
51
+ type: Boolean,
52
+ default: false,
53
+ },
54
+ datePickerFilter: {
55
+ type: Function,
56
+ default: () => true,
57
+ },
58
+ datePickerFormatter: {
59
+ type: Function,
60
+ default: (type, val) => val,
61
+ },
62
+ mode: {
63
+ type: String,
64
+ default: '查询',
65
+ },
66
+ serviceName: {
67
+ type: String,
68
+ default: undefined,
69
+ },
70
+ // 调用logic获取数据源的追加参数
71
+ getDataParams: {
72
+ type: Object,
73
+ default: undefined,
74
+ },
75
+ disabled: {
76
+ type: Boolean,
77
+ default: false,
78
+ },
79
+ rules: {
80
+ type: Object,
81
+ default: () => {},
82
+ },
83
+ // 用 defineModel 替代 modelValue/emit
84
+ modelValue: {
85
+ type: [String, Number, Boolean, Array, Object],
86
+ default: undefined,
87
+ },
88
+ showLabel: {
89
+ type: Boolean,
90
+ default: true,
91
+ },
92
+ // radio/checkbox/select/mul-select 选项数据结构
93
+ columnsField: {
94
+ type: Object,
95
+ default: () => {
96
+ return { text: 'label', value: 'value' }
97
+ },
98
+ },
99
+ isAsyncUpload: {
100
+ type: Boolean,
101
+ default: false,
102
+ },
103
+
104
+ })
105
+
106
+ const emits = defineEmits(['setForm', 'xFormItemEmitFunc', 'scanCodeOrNfc'])
107
+
108
+ // 用 defineModel 替代 modelValue/emit
109
+ const modelData = defineModel<string | number | boolean | any[] | Record<string, any>>()
110
+
111
+ // 获取字典
112
+ interface OptionItem {
113
+ label: string
114
+ value: any
115
+ children?: OptionItem[]
116
+ }
117
+
118
+ // 判断并初始化防抖函数
119
+ let debouncedUserLinkFunc: (() => void) | null = null
120
+ let debouncedDepLinkFunc: (() => void) | null = null
121
+ let debouncedUpdateOptions: (() => void) | null = null
122
+
123
+ const { attr, form, mode, serviceName, getDataParams, columnsField } = props
124
+ // 配置的表单值格式(仅针对 datePicker 生效)
125
+ // 作用:统一控制日期值的格式化输入/输出与选择器展示粒度
126
+ // 可选:'YYYY' | 'YYYY-MM' | 'YYYY-MM-DD' | 'YYYY-MM-DD HH' | 'YYYY-MM-DD HH:mm' | 'YYYY-MM-DD HH:mm:ss'
127
+ const formValueFormat = computed(() => {
128
+ // 默认全格式
129
+ return (attr && (attr as any).formValueFormat) || 'YYYY-MM-DD HH:mm:ss'
130
+ })
131
+
132
+ // 根据 formValueFormat 动态计算日期列类型(决定 VanDatePicker 展示年/月/日)
133
+ // 例如:YYYY 只显示年;YYYY-MM 显示年、月;YYYY-MM-DD 显示年、月、日
134
+ const dateColumnsType = computed(() => {
135
+ const format = formValueFormat.value
136
+ const columns: string[] = ['year']
137
+ if (format.includes('MM'))
138
+ columns.push('month')
139
+ if (format.includes('DD'))
140
+ columns.push('day')
141
+ return columns as any
142
+ })
143
+
144
+ // 是否包含时间(决定是否展示时间页签与 VanTimePicker)
145
+ const hasTime = computed(() => formValueFormat.value.includes('HH'))
146
+
147
+ // 根据 formValueFormat 动态计算时间列类型(决定时/分/秒的展示)
148
+ // 例如:包含 HH 显示小时;包含 mm 显示分钟;包含 ss 显示秒
149
+ const timeColumnsType = computed(() => {
150
+ const format = formValueFormat.value
151
+ const columns: string[] = []
152
+ if (format.includes('HH'))
153
+ columns.push('hour')
154
+ if (format.includes('mm'))
155
+ columns.push('minute')
156
+ if (format.includes('ss'))
157
+ columns.push('second')
158
+ return columns as any
159
+ })
160
+ const calendarShow = ref(false)
161
+ const option = ref([])
162
+ const pickerValue = ref(undefined)
163
+ const timePickerValue = ref(undefined)
164
+ const area = ref<any>(undefined)
165
+ const showPicker = ref(false)
166
+ const showDatePicker = ref(false)
167
+ const showTimePicker = ref(false)
168
+ const showArea = ref(false)
169
+ const errorMessage = ref('')
170
+ const showTreeSelect = ref(false)
171
+ const treeValue = ref('')
172
+ // 懒加载 最后检索版本
173
+ const lastFetchId = ref(0)
174
+ const customizeReadOnly = ref(false)
175
+
176
+ // 登录信息 (可以在配置的动态函数中使用 this.setupState 获取到当前组件内的全部函数和变量 例:this.setupState.userState)
177
+ const userState = useUserStore().getLogin()
178
+ const currUser = computed(() => userState.f.resources.id)
179
+ const userInfo = computed(() => ({
180
+ orgId: userState.f.resources.orgid,
181
+ userId: userState.f.resources.id,
182
+ }))
183
+
184
+ // 是否展示当前项
185
+ const showItem = ref(true)
186
+
187
+ // 当前组件实例(不推荐使用,可能会在后续的版本更迭中调整,暂时用来绑定函数的上下文)
188
+ const currInst = getCurrentInstance()
189
+
190
+ // 配置中心->表单项变更触发函数
191
+ async function dataChangeFunc() {
192
+ if (attr.dataChangeFunc) {
193
+ await executeStrFunctionByContext(currInst, attr.dataChangeFunc, [props.form, (formData: any) => emits('setForm', formData), attr, null, mode, runLogic, getConfigByNameAsync, userState.f.resources])
194
+ }
195
+ }
196
+ const dataChangeFuncdebounce = debounce(dataChangeFunc, 300)
197
+ // 配置中心->表单项展示函数
198
+ async function showFormItemFunc() {
199
+ if (attr.showFormItemFunc) {
200
+ const obj = await executeStrFunctionByContext(currInst, attr.showFormItemFunc, [form, attr, null, mode])
201
+ // 判断是 bool 还是 obj 兼容
202
+ if (typeof obj === 'boolean') {
203
+ showItem.value = obj
204
+ }
205
+ else if (obj && typeof obj === 'object') {
206
+ // obj 是一个对象,并且不是数组
207
+ if (Object.prototype.hasOwnProperty.call(obj, 'show')) {
208
+ showItem.value = obj?.show
209
+ }
210
+ if (Object.prototype.hasOwnProperty.call(obj, 'readOnly')) {
211
+ customizeReadOnly.value = obj?.readOnly
212
+ }
213
+ }
214
+ }
215
+ }
216
+ const showFormItemFuncdebounce = debounce(showFormItemFunc, 300)
217
+ /**
218
+ * 检测是否传入了有效的值
219
+ * @returns any
220
+ */
221
+ function checkModel(val = props.modelValue) {
222
+ if (val === null || val === undefined || val === '')
223
+ return false
224
+ if (Array.isArray(val))
225
+ return val.length > 0
226
+ return true
227
+ }
228
+ /**
229
+ * 获取表单项的默认值
230
+ * @returns any
231
+ */
232
+ function getDefaultValue() {
233
+ const val = props.modelValue
234
+ // 如果有有效值,直接返回(datePicker 初始值需按 formValueFormat 归一)
235
+ // 目的:外部通过 formData 传入的初始值在组件挂载即与配置格式一致
236
+ if (checkModel(val)) {
237
+ if (attr.type === 'datePicker' && typeof val === 'string') {
238
+ const parsed = dayjs(val)
239
+ if (parsed.isValid())
240
+ return parsed.format(formValueFormat.value)
241
+ }
242
+ return val
243
+ }
244
+
245
+ // 根据类型获取默认值
246
+ const getDefaultByType = () => {
247
+ const def = mode !== '查询' ? attr.formDefault : attr.queryFormDefault
248
+
249
+ if (['treeSelect', 'select', 'checkbox'].includes(attr.type) && ['curOrgId', 'curDepId', 'curUserId'].includes(def)) {
250
+ if (def === 'curOrgId') {
251
+ if (attr.type === 'treeSelect') {
252
+ treeValue.value = userState.f.resources.orgs
253
+ }
254
+ return attr.type === 'select' ? userState.f.resources.orgid : [userState.f.resources.orgid]
255
+ }
256
+ if (def === 'curDepId') {
257
+ if (attr.type === 'treeSelect') {
258
+ treeValue.value = userState.f.resources.deps
259
+ }
260
+ return attr.type === 'select' ? userState.f.resources.depids : [userState.f.resources.depids]
261
+ }
262
+ if (def === 'curUserId') {
263
+ if (attr.type === 'treeSelect') {
264
+ treeValue.value = userState.f.resources.name
265
+ }
266
+ return attr.type === 'select' ? userState.f.resources.id : [userState.f.resources.id]
267
+ }
268
+ }
269
+
270
+ // 数组类型默认值
271
+ const arrayTypes = ['uploader', 'checkbox', 'file', 'area', 'image', 'treeSelect']
272
+ if (arrayTypes.includes(attr.type)) {
273
+ return def !== undefined ? def : []
274
+ }
275
+
276
+ // 特殊类型默认值
277
+ const specialDefaults = {
278
+ switch: false,
279
+ stepper: 1,
280
+ addressSearch: val,
281
+ }
282
+
283
+ if (specialDefaults[attr.type] !== undefined) {
284
+ return specialDefaults[attr.type]
285
+ }
286
+
287
+ // 日期时间类型:调用 getDateRange,并传入 formValueFormat
288
+ // 说明:让初始化/查询默认值同样遵循配置的格式显示
289
+ const dateTypes = ['rangePicker', 'yearPicker', 'monthPicker', 'yearRangePicker', 'monthRangePicker', 'datePicker', 'timePicker']
290
+ if (dateTypes.includes(attr.type)) {
291
+ return getDateRange({
292
+ type: attr.type,
293
+ formDefault: attr.formDefault ?? '',
294
+ queryFormDefault: attr.queryFormDefault ?? '',
295
+ queryType: attr.queryType,
296
+ queryValueFormat: attr.queryValueFormat,
297
+ name: attr.name ?? '',
298
+ formValueFormat: formValueFormat.value,
299
+ }) ?? []
300
+ }
301
+
302
+ // 其他类型(字符串、数字等)
303
+ return def ?? ''
304
+ }
305
+
306
+ return getDefaultByType()
307
+ }
308
+
309
+ // 初始化日期组件初始值,组件自定义格式显示值和实际值(日期相关初始化都在此函数中操作)
310
+ function getDateRange({
311
+ type,
312
+ formDefault: defaultValue,
313
+ queryFormDefault,
314
+ queryType,
315
+ queryValueFormat: defaultFormat,
316
+ name,
317
+ formValueFormat: formFormat,
318
+ }: {
319
+ type: string
320
+ formDefault: string
321
+ queryFormDefault: string
322
+ queryType?: string
323
+ queryValueFormat?: string
324
+ name: string
325
+ // 新增:用于优先覆盖 datePicker 的显示/存储格式
326
+ formValueFormat?: string
327
+ }): string | [string, string] | undefined {
328
+ const formatMap: Record<string, string> = {
329
+ yearPicker: 'YYYY',
330
+ yearRangePicker: 'YYYY',
331
+ monthPicker: 'YYYY-MM',
332
+ monthRangePicker: 'YYYY-MM',
333
+ datePicker: 'YYYY-MM-DD HH:mm:ss',
334
+ rangePicker: 'YYYY-MM-DD HH:mm:ss',
335
+ }
336
+ if (mode) {
337
+ // datePicker 优先使用 formValueFormat(否则退回 queryValueFormat 或默认映射)
338
+ const preferFormat = type === 'datePicker' ? (formFormat || defaultFormat) : defaultFormat
339
+ const format = preferFormat || formatMap[type]
340
+ const val = mode === '查询' ? queryFormDefault : defaultValue
341
+ let start: string, end: string
342
+ switch (val) {
343
+ case 'curYear':
344
+ start = dayjs().startOf('year').format(format)
345
+ end = dayjs().endOf('year').format(format)
346
+ break
347
+ case 'curMonth':
348
+ start = dayjs().startOf('month').format(format)
349
+ end = dayjs().endOf('month').format(format)
350
+ break
351
+ case 'curDay':
352
+ start = dayjs().startOf('day').format(format)
353
+ end = dayjs().endOf('day').format(format)
354
+ break
355
+ case 'curTime':
356
+ start = dayjs().format(format)
357
+ end = dayjs().format(format)
358
+ break
359
+ default:
360
+ return undefined
361
+ }
362
+ if (['monthPicker', 'yearPicker', 'datePicker'].includes(type)) {
363
+ if (mode !== '查询') {
364
+ if (queryType === 'BETWEEN') {
365
+ return [start, end]
366
+ }
367
+ if (name.includes('开始') || name.includes('起始')) {
368
+ return start
369
+ }
370
+ else {
371
+ return end
372
+ }
373
+ }
374
+ else {
375
+ return start
376
+ }
377
+ }
378
+ // rangePicker组件表单显示的值
379
+ if (mode === '查询' && type === 'rangePicker') {
380
+ pickerValue.value = `${start} ~ ${end}`
381
+ }
382
+ return mode !== '查询' ? start : [start, end]
383
+ }
384
+ else {
385
+ return undefined
386
+ }
387
+ }
388
+
389
+ // 监听 props.form 的变化
390
+ watch(
391
+ () => props.form,
392
+ (newVal, oldVal) => {
393
+ // 如果是从函数获取 options
394
+ if (props.attr.keyName && (props.attr.keyName.toString().includes('async ') || props.attr.keyName.toString().includes('function'))) {
395
+ debouncedUpdateOptions()
396
+ }
397
+ if (props.attr.showFormItemFunc) {
398
+ showFormItemFuncdebounce()
399
+ }
400
+ },
401
+ { deep: true },
402
+ )
403
+
404
+ // 监听 modelData 的变化,调用 dataChangeFunc
405
+ watch(
406
+ () => modelData.value,
407
+ (newVal, oldVal) => {
408
+ // 避免初始化时的调用
409
+ if (newVal !== oldVal) {
410
+ dataChangeFuncdebounce()
411
+ }
412
+ },
413
+ { deep: true },
414
+ )
415
+
416
+ // 监听 option.value 的变化
417
+ watch(
418
+ () => option.value,
419
+ (newOption) => {
420
+ if (attr.type === 'treeSelect' && newOption && newOption.length > 0) {
421
+ // 你可以在这里调用 findOptionInTree 函数来查找默认值对应的 label
422
+ const result = findOptionInTree(option.value, modelData.value)
423
+ if (attr.type === 'treeSelect' && result)
424
+ treeValue.value = result.label
425
+ }
426
+ },
427
+ )
428
+
429
+ function updateFile(files, _index) {
430
+ modelData.value = files
431
+ }
432
+
433
+ // 表单校验的类型校验
434
+ function formTypeCheck(attr, value) {
435
+ if (mode === '查询' || mode === '预览')
436
+ return
437
+ // if (!attr.rule || !attr.rule.required || attr.rule.required === 'false')
438
+ // return
439
+ switch (attr.rule.type) {
440
+ case 'string':
441
+ if (value.length === 0) {
442
+ errorMessage.value = `请输入${attr.name}`
443
+ return
444
+ }
445
+ break
446
+ case 'number':
447
+ if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(value)) {
448
+ errorMessage.value = `${attr.name}必须为数字`
449
+ return
450
+ }
451
+ break
452
+ case 'boolean':
453
+ case 'array':
454
+ case 'regexp':
455
+ if (value) {
456
+ errorMessage.value = ''
457
+ return
458
+ }
459
+ break
460
+ case 'integer':
461
+ if (!/^-?\d+$/.test(value)) {
462
+ errorMessage.value = `${attr.name}必须为整数`
463
+ return
464
+ }
465
+ break
466
+ case 'float':
467
+ if (!/^-?\d+\.\d+$/.test(value)) {
468
+ errorMessage.value = `${attr.name}必须为小数`
469
+ return
470
+ }
471
+ break
472
+ case 'email':
473
+ if (!/^[\w.%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i.test(value)) {
474
+ errorMessage.value = `请输入正确的邮箱地址`
475
+ return
476
+ }
477
+ break
478
+ case 'idNumber':
479
+ if (!/^(?:\d{15}|\d{17}[0-9X])$/.test(value)) {
480
+ errorMessage.value = `请输入正确的身份证号码`
481
+ return
482
+ }
483
+ break
484
+ case 'userPhone':
485
+ if (!/^1[3-9]\d{9}$/.test(value)) {
486
+ errorMessage.value = `请输入正确的手机号码`
487
+ return
488
+ }
489
+ break
490
+ case 'landlineNumber':
491
+ if (!/^0\d{2,3}[-\s]?\d{7,8}$/.test(value)) {
492
+ errorMessage.value = `请输入正确的座机号码`
493
+ return
494
+ }
495
+ break
496
+ case 'greaterThanZero':
497
+ if (!/^(?:[1-9]\d*(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(value)) {
498
+ errorMessage.value = `请输入一个大于0的数字`
499
+ return
500
+ }
501
+ break
502
+ case 'greaterThanOrEqualZero':
503
+ if (!/^(?:\d+|\d*\.\d+)$/.test(value)) {
504
+ errorMessage.value = `请输入一个大于等于0的数字`
505
+ return
506
+ }
507
+ break
508
+ case 'stringLength':
509
+ if (!(value.length >= attr.rule.minLen && value.length < attr.rule.maxLen)) {
510
+ errorMessage.value = `长度必须在${attr.rule.minLen}~${attr.rule.maxLen}之间`
511
+ return
512
+ }
513
+ break
514
+ case 'customJs':
515
+ // eslint-disable-next-line no-case-declarations
516
+ const funcStr = attr.rule.customValidatorFunc
517
+ // 输入的数据是否符合条件
518
+ // eslint-disable-next-line no-case-declarations
519
+ const status = ref(true)
520
+ // 提取函数体部分
521
+ // eslint-disable-next-line no-case-declarations
522
+ const funcBodyMatch = funcStr.match(/function\s*\(.*?\)\s*\{([\s\S]*)\}/)
523
+ if (!funcBodyMatch)
524
+ throw new Error('自定义校验函数不合法')
525
+ // eslint-disable-next-line no-case-declarations
526
+ const funcBody = funcBodyMatch[1].trim() // 提取函数体
527
+ // 使用 new Function 创建函数
528
+ // eslint-disable-next-line no-new-func,no-case-declarations
529
+ const customValidatorFunc = new Function('rule', 'value', 'callback', 'form', 'attr', 'util', funcBody)
530
+ // 定义 callback 函数
531
+ // eslint-disable-next-line no-case-declarations
532
+ const callback = (error) => {
533
+ if (error) {
534
+ errorMessage.value = `${error}`
535
+ status.value = false // 表示有错误发生
536
+ }
537
+ }
538
+ // 调用自定义校验函数
539
+ customValidatorFunc(
540
+ attr.rule,
541
+ value,
542
+ callback,
543
+ form,
544
+ attr,
545
+ {}, // util 对象(可以根据需要传递)
546
+ )
547
+ if (!status.value)
548
+ return
549
+ break
550
+ default:
551
+ errorMessage.value = ''
552
+ break
553
+ }
554
+ errorMessage.value = ''
555
+ }
556
+
557
+ onBeforeMount(() => {
558
+ init()
559
+ modelData.value = getDefaultValue()
560
+ showFormItemFunc()
561
+ dataChangeFunc()
562
+ if (attr?.keyName?.toString()?.startsWith('search@根据表单项[') && attr?.keyName?.toString().endsWith(']联动人员'))
563
+ debouncedUserLinkFunc = debounce(() => updateResOptions('人员'), 200)
564
+
565
+ if (attr?.keyName?.toString()?.startsWith('search@根据表单项[') && attr?.keyName?.toString().endsWith(']联动部门'))
566
+ debouncedDepLinkFunc = debounce(() => updateResOptions('部门'), 200)
567
+
568
+ if (attr.keyName && (attr?.keyName?.toString().indexOf('async ') !== -1 || attr?.keyName?.toString()?.indexOf('function') !== -1)) {
569
+ debouncedUpdateOptions = debounce(updateOptions, 200)
570
+ }
571
+ })
572
+ // 是否展示表单左侧label文字
573
+ const labelData = computed(() => {
574
+ return props.showLabel ? attr.name : null
575
+ })
576
+ // 是否展示表单左侧label文字
577
+ const labelAlign = computed(() => {
578
+ return attr.labelAlign ? attr.labelAlign : 'left'
579
+ })
580
+ // 是否只读
581
+ const readonly = computed(() => {
582
+ return props.formReadonly || attr.addOrEdit === 'readonly' || mode === '预览' || customizeReadOnly.value
583
+ })
584
+
585
+ // 判断是否显示空提示(只读且值为空)
586
+ const showEmptyTip = computed(() => {
587
+ if ((attr.type === 'image' || attr.type === 'file') && props.formReadonly) {
588
+ const value = modelData.value
589
+ return !value || (Array.isArray(value) && value.length === 0)
590
+ }
591
+ return false
592
+ })
593
+
594
+ // 提示内容
595
+ const placeholder = computed(() => {
596
+ if (attr.addOrEdit === 'readonly' || mode === '预览' || props.formReadonly) {
597
+ // 根据类型返回更具体的空状态提示
598
+ if (attr.type === 'image') {
599
+ return '暂无图片'
600
+ }
601
+ else if (attr.type === 'file') {
602
+ return '暂无文件'
603
+ }
604
+ return '暂无内容'
605
+ }
606
+ else
607
+ if (attr.placeholder) {
608
+ return attr.placeholder
609
+ }
610
+ else {
611
+ switch (attr.type) {
612
+ case 'datePicker':
613
+ case 'timePicker':
614
+ case 'rangePicker':
615
+ case 'radio':
616
+ case 'select':
617
+ case 'treeSelect':
618
+ case 'area':
619
+ case 'citySelect':
620
+ case 'picker':
621
+ return `请选择${attr.name}`
622
+ case 'addressSearch':
623
+ case 'input':
624
+ case 'textarea':
625
+ case 'intervalPicker':
626
+ return `请输入${attr.name}`
627
+ default:
628
+ return `请选择${attr.name}`
629
+ }
630
+ }
631
+ })
632
+
633
+ const formatDate = date => `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
634
+
635
+ function onCalendarConfirm(values) {
636
+ modelData.value = [formatDate(values[0]), formatDate(values[1])]
637
+ pickerValue.value = `${formatDate(values[0])} ~ ${formatDate(values[1])}`
638
+ calendarShow.value = false
639
+ }
640
+
641
+ // js 函数作为数据源
642
+ async function updateOptions() {
643
+ if (attr.keyName && (attr.keyName.toString().includes('async ') || attr.keyName.toString().includes('function '))) {
644
+ option.value = await executeStrFunctionByContext(currInst, attr.keyName, [props.form, runLogic, props.mode, getConfigByNameAsync, post, userState.f.resources])
645
+ }
646
+ }
647
+
648
+ function init() {
649
+ if (attr.keyName && typeof attr.keyName === 'string') {
650
+ if (attr.keyName && attr.keyName.includes('logic@')) {
651
+ getData({}, (res) => {
652
+ option.value = res
653
+ initRadioValue()
654
+ })
655
+ }
656
+ else if (attr.keyName && attr.keyName.includes('config@')) {
657
+ const configName = attr.keyName.substring(7)
658
+ getDict(configName, (result) => {
659
+ if (result)
660
+ option.value = result
661
+ }, serviceName)
662
+ }
663
+ else if (attr.keyName && attr.keyName.includes('search@')) {
664
+ let source = attr.keyName.substring(7)
665
+ const userid = currUser.value
666
+ let roleName = 'roleName'
667
+ if (source.startsWith('根据角色[') && source.endsWith(']获取人员')) {
668
+ const startIndex = source.indexOf('[') + 1
669
+ const endIndex = source.indexOf(']', startIndex)
670
+ roleName = source.substring(startIndex, endIndex)
671
+ source = '根据角色获取人员'
672
+ }
673
+ const searchData = { source, userid, roleName }
674
+ if (source.startsWith('根据表单项[') && source.endsWith(']联动人员'))
675
+ updateResOptions('人员')
676
+ else if (source.startsWith('根据表单项[') && source.endsWith(']联动部门'))
677
+ updateResOptions('部门')
678
+ else if (attr.type === 'select' || attr.type === 'checkbox')
679
+ searchToListOption(searchData, res => getDataCallback(res))
680
+ else
681
+ searchToOption(searchData, res => getDataCallback(res))
682
+ }
683
+ else if (attr.keyName.toString().includes('async ') || attr.keyName.toString().includes('function ')) {
684
+ updateOptions()
685
+ }
686
+ else {
687
+ initRadioValue()
688
+ }
689
+ }
690
+ }
691
+
692
+ function getDataCallback(res) {
693
+ option.value = res
694
+ if (attr.type === 'radio')
695
+ initRadioValue()
696
+ }
697
+
698
+ async function updateResOptions(type) {
699
+ if (attr?.keyName?.toString()?.startsWith('search@根据表单项[') && attr?.keyName?.toString()?.endsWith(`]联动${type}`)) {
700
+ const searchData = { source: `获取${type}`, userid: currUser.value }
701
+ const startIndex = attr.keyName.indexOf('[') + 1
702
+ const endIndex = attr.keyName.indexOf(']', startIndex)
703
+ const formModel = attr.keyName.substring(startIndex, endIndex).replace('.', '_')
704
+ const formModelData = form[formModel]
705
+ if (formModel?.length && formModelData?.length) {
706
+ await searchToListOption(searchData, (res) => {
707
+ getDataCallback(res.filter((h) => {
708
+ return formModelData['0'] === h.f_organization_id || formModelData['0'] === h.f_department_id || formModelData['0'] === h.parentid
709
+ // if (formModel.indexOf('org') > -1) {
710
+ // return formModelData?.includes(h.orgid || h.f_organization_id || h.parentid)
711
+ // } else {
712
+ // return formModelData?.includes(h?.parentid)
713
+ // }
714
+ }))
715
+ })
716
+ }
717
+ }
718
+ }
719
+
720
+ function initRadioValue() {
721
+ if ((mode === '新增' || mode === '修改') && attr.type === 'radio' && !props.modelValue) {
722
+ if (attr.keys && attr.keys.length > 0)
723
+ modelData.value = attr.keys[0].value
724
+ else if (option.value && option.value.length > 0)
725
+ modelData.value = option.value[0].value
726
+ }
727
+ }
728
+
729
+ function getData(value, callback) {
730
+ if (value !== '') {
731
+ const logicName = attr.keyName
732
+ const logic = logicName.substring(6)
733
+ // 调用logic前设置参数
734
+ if (getDataParams && getDataParams[attr.model])
735
+ Object.assign(value, getDataParams[attr.model])
736
+ Object.assign(value, userInfo.value)
737
+ runLogic(logic, value, serviceName).then((res) => {
738
+ callback(res)
739
+ })
740
+ }
741
+ }
742
+
743
+ // 已废弃 不进行维护
744
+ function onPickerConfirm({ selectedOptions }) {
745
+ showPicker.value = false
746
+ modelData.value = selectedOptions[0].text
747
+ }
748
+
749
+ // 日期时间选择数据
750
+ const dateTimePickerValue = ref<any>({})
751
+ // 展示日期时间选择器:根据 formValueFormat 初始化 VanDatePicker/VanTimePicker 的当前值
752
+ // 规则:
753
+ // - 若已有字符串值,按 formValueFormat 解析并拆分为日期/时间数组
754
+ // - 若无值,按当前时间生成匹配格式的默认数组
755
+ function showDataTimePicker() {
756
+ if (props.modelValue && typeof props.modelValue === 'string') {
757
+ const base = dayjs(props.modelValue as string, formValueFormat.value)
758
+ const dateArr: string[] = []
759
+ dateArr.push(base.format('YYYY'))
760
+ if (dateColumnsType.value.includes('month'))
761
+ dateArr.push(base.format('MM'))
762
+ if (dateColumnsType.value.includes('day'))
763
+ dateArr.push(base.format('DD'))
764
+ const timeArr: string[] = []
765
+ if (hasTime.value) {
766
+ if (timeColumnsType.value.includes('hour'))
767
+ timeArr.push(base.format('HH'))
768
+ if (timeColumnsType.value.includes('minute'))
769
+ timeArr.push(base.format('mm'))
770
+ if (timeColumnsType.value.includes('second'))
771
+ timeArr.push(base.format('ss'))
772
+ }
773
+ dateTimePickerValue.value = {
774
+ date: dateArr,
775
+ time: timeArr.length ? timeArr : ['00', '00', '00'].slice(0, timeColumnsType.value.length),
776
+ }
777
+ }
778
+ else {
779
+ const now = dayjs()
780
+ const dateArr: string[] = []
781
+ dateArr.push(now.format('YYYY'))
782
+ if (dateColumnsType.value.includes('month'))
783
+ dateArr.push(now.format('MM'))
784
+ if (dateColumnsType.value.includes('day'))
785
+ dateArr.push(now.format('DD'))
786
+ const timeArr: string[] = []
787
+ if (hasTime.value) {
788
+ if (timeColumnsType.value.includes('hour'))
789
+ timeArr.push(now.format('HH'))
790
+ if (timeColumnsType.value.includes('minute'))
791
+ timeArr.push(now.format('mm'))
792
+ if (timeColumnsType.value.includes('second'))
793
+ timeArr.push(now.format('ss'))
794
+ }
795
+ dateTimePickerValue.value = {
796
+ date: dateArr,
797
+ time: timeArr.length ? timeArr : ['00', '00', '00'].slice(0, timeColumnsType.value.length),
798
+ }
799
+ }
800
+ showDatePicker.value = true
801
+ }
802
+
803
+ function onDatePickerConfirm({ selectedValues }) {
804
+ showDatePicker.value = false
805
+ modelData.value = selectedValues.join('-')
806
+ }
807
+
808
+ // 已废弃 不进行维护
809
+ function onTimePickerConfirm({ selectedValues }) {
810
+ showTimePicker.value = false
811
+ timePickerValue.value = selectedValues.join(':')
812
+ modelData.value = timePickerValue.value
813
+ }
814
+
815
+ // 没人用到本次先不动。后续需要看这个组件需要怎么使用
816
+ function onAreaConfirm({ selectedOptions }) {
817
+ area.value = `${selectedOptions[0].text}-${selectedOptions[1].text}-${selectedOptions[2].text}`
818
+ showArea.value = false
819
+ modelData.value = [{
820
+ province: selectedOptions[0].text,
821
+ city: selectedOptions[1].text,
822
+ district: selectedOptions[2].text,
823
+ }]
824
+ }
825
+
826
+ // 日期时间选择确认:将选择的年月日(+时分秒)拼装后,最终使用 formValueFormat 输出到 v-model
827
+ function onDateTimePickerConfirm() {
828
+ showDatePicker.value = false
829
+ const dateParts = dateTimePickerValue.value.date as string[]
830
+ const timeParts = (dateTimePickerValue.value.time as string[]) || []
831
+ const year = dateParts[0]
832
+ const month = dateParts[1] || '01'
833
+ const day = dateParts[2] || '01'
834
+ const hour = hasTime.value && timeParts[0] ? timeParts[0] : '00'
835
+ const minute = hasTime.value && timeParts[1] ? timeParts[1] : '00'
836
+ const second = hasTime.value && timeParts[2] ? timeParts[2] : '00'
837
+ const full = `${year}-${month}-${day} ${hour}:${minute}:${second}`
838
+ modelData.value = dayjs(full, 'YYYY-MM-DD HH:mm:ss').format(formValueFormat.value)
839
+ }
840
+
841
+ function onPickerCancel() {
842
+ showDatePicker.value = false
843
+ }
844
+
845
+ const showAddressPicker = ref(false)
846
+ const addressValue = ref('')
847
+
848
+ // XLocationPicker 默认加载的中心点
849
+ const defaultMapCenter = computed(() => {
850
+ const lonLat = form[`${attr.model}_lon_lat`]
851
+ if (lonLat && typeof lonLat === 'string' && lonLat.includes(',')) {
852
+ const [lon, lat] = lonLat.split(',').map(Number)
853
+ if (!Number.isNaN(lon) && !Number.isNaN(lat)) {
854
+ return [lon, lat] as [number, number]
855
+ }
856
+ }
857
+ return undefined
858
+ })
859
+
860
+ // 处理地址选择器确认
861
+ function handleAddressConfirm(location) {
862
+ // 构造新的数据格式
863
+ const formData = {
864
+ [`${attr.model}_lon_lat`]: `${location.longitude},${location.latitude}`,
865
+ [attr.model]: location.address,
866
+ }
867
+ // 更新表单数据
868
+ emits('setForm', formData)
869
+ showAddressPicker.value = false
870
+ }
871
+
872
+ // 重置方法,供父组件调用
873
+ function reset() {
874
+ modelData.value = getDefaultValue()
875
+ errorMessage.value = ''
876
+ treeValue.value = null
877
+ area.value = null
878
+ pickerValue.value = null
879
+ }
880
+
881
+ defineExpose({
882
+ reset,
883
+ })
884
+
885
+ // 数据处理
886
+ function cleanEmptyChildren(options, fieldNames = { text: 'label', value: 'value', children: 'children' }) {
887
+ if (!Array.isArray(options))
888
+ return options
889
+
890
+ const childrenKey = fieldNames.children || 'children'
891
+
892
+ return options.map((option) => {
893
+ // 深拷贝选项,避免修改原始数据
894
+ const newOption = { ...option }
895
+
896
+ // 如果存在children属性且是空数组
897
+ if (newOption[childrenKey] && Array.isArray(newOption[childrenKey]) && newOption[childrenKey].length === 0) {
898
+ delete newOption[childrenKey]
899
+ }
900
+ // 如果存在children属性且非空,则递归处理
901
+ else if (newOption[childrenKey] && Array.isArray(newOption[childrenKey])) {
902
+ newOption[childrenKey] = cleanEmptyChildren(newOption[childrenKey], fieldNames)
903
+ }
904
+ return newOption
905
+ })
906
+ }
907
+
908
+ // 级联选择完成事件
909
+ function onTreeSelectFinish({ selectedOptions }) {
910
+ const index = selectedOptions.length - 1
911
+ treeValue.value = selectedOptions[index].label
912
+ if (mode === '查询') {
913
+ modelData.value = [selectedOptions[index].value]
914
+ }
915
+ else {
916
+ modelData.value = selectedOptions[index].value
917
+ }
918
+ showTreeSelect.value = false
919
+ }
920
+
921
+ function emitFunc(func, data) {
922
+ emits('xFormItemEmitFunc', func, data, data?.model ? form[data.model] : form)
923
+ }
924
+
925
+ function findOptionInTree(options, value) {
926
+ // 在当前层级查找
927
+ const foundItem = options.find(item => item[columnsField.value] === value)
928
+ if (foundItem) {
929
+ return foundItem
930
+ }
931
+ // 递归查找子级
932
+ for (const item of options) {
933
+ if (item.children?.length) {
934
+ const foundInChildren = findOptionInTree(item.children, value)
935
+ if (foundInChildren)
936
+ return foundInChildren
937
+ }
938
+ }
939
+
940
+ return null
941
+ }
942
+
943
+ // 懒加载搜索函数
944
+ async function handleLazySearch(searchText: string) {
945
+ if (!attr.keyName || typeof attr.keyName !== 'string') {
946
+ return []
947
+ }
948
+
949
+ try {
950
+ // 如果是 search@ 类型的数据源
951
+ if (attr.keyName.includes('search@')) {
952
+ let source = attr.keyName.substring(7)
953
+ const userid = currUser.value
954
+ let roleName = 'roleName'
955
+
956
+ if (source.startsWith('根据角色[') && source.endsWith(']获取人员')) {
957
+ const startIndex = source.indexOf('[') + 1
958
+ const endIndex = source.indexOf(']', startIndex)
959
+ roleName = source.substring(startIndex, endIndex)
960
+ source = '根据角色获取人员'
961
+ }
962
+
963
+ const searchData = {
964
+ source,
965
+ userid,
966
+ roleName,
967
+ searchText, // 添加搜索关键词
968
+ }
969
+
970
+ return new Promise((resolve) => {
971
+ if (attr.type === 'select' || attr.type === 'checkbox') {
972
+ searchToListOption(searchData, (res) => {
973
+ // 根据搜索关键词过滤结果
974
+ const filtered = res.filter((item) => {
975
+ const text = item[columnsField.value.text] || item.label || ''
976
+ return text.toString().toLowerCase().includes(searchText.toLowerCase())
977
+ })
978
+ resolve(filtered)
979
+ })
980
+ }
981
+ else {
982
+ searchToOption(searchData, (res) => {
983
+ const filtered = res.filter((item) => {
984
+ const text = item[columnsField.value.text] || item.label || ''
985
+ return text.toString().toLowerCase().includes(searchText.toLowerCase())
986
+ })
987
+ resolve(filtered)
988
+ })
989
+ }
990
+ })
991
+ }
992
+
993
+ // logic 数据源
994
+ if (attr.keyName.includes('logic@')) {
995
+ const logicName = attr.keyName.substring(6)
996
+ const value = { word: searchText, ...userInfo.value }
997
+
998
+ // 调用logic前设置参数
999
+ if (getDataParams && getDataParams[attr.model]) {
1000
+ Object.assign(value, getDataParams[attr.model])
1001
+ }
1002
+
1003
+ lastFetchId.value++
1004
+ const fetchId = lastFetchId.value
1005
+ // 根据搜索关键词过滤结果
1006
+ const results = await runLogic(logicName, value, serviceName) as any
1007
+ if (fetchId !== lastFetchId.value) {
1008
+ return
1009
+ }
1010
+ if (searchText) {
1011
+ return results.filter((item) => {
1012
+ const text = item[columnsField.value.text] || item.label || ''
1013
+ return text.toString().toLowerCase().includes(searchText.toLowerCase())
1014
+ })
1015
+ }
1016
+ return results
1017
+ }
1018
+
1019
+ // 自定义 js 函数
1020
+ if (attr.keyName.includes('async ') || attr.keyName.includes('function ')) {
1021
+ const results = await executeStrFunctionByContext(currInst, attr.keyName, [
1022
+ { ...props.form, searchText },
1023
+ runLogic,
1024
+ props.mode,
1025
+ getConfigByNameAsync,
1026
+ post,
1027
+ userState,
1028
+ ])
1029
+ // 根据搜索关键词过滤结果
1030
+ return results.filter((item) => {
1031
+ const text = item[columnsField.value.text] || item.label || ''
1032
+ return text.toString().toLowerCase().includes(searchText.toLowerCase())
1033
+ })
1034
+ }
1035
+
1036
+ return []
1037
+ }
1038
+ catch (error) {
1039
+ console.error('懒加载搜索失败:', error)
1040
+ return []
1041
+ }
1042
+ }
1043
+
1044
+ // 扫码/NFC
1045
+ function scanCodeOrNfc(attr) {
1046
+ if (attr.type === 'scanCode') {
1047
+ // 扫码逻辑
1048
+ mobileUtil.execute({
1049
+ funcName: 'scanBarcode',
1050
+ param: {},
1051
+ callbackFunc: (res: any) => {
1052
+ console.log('扫码结果:------', res)
1053
+ if (res && res.status === 'success') {
1054
+ if (res.data.status && res.data.status === 'cancelled') {
1055
+ showToast(res.data?.message || '扫码已取消')
1056
+ return
1057
+ }
1058
+ modelData.value = res.data?.rawValue
1059
+ showToast('扫码成功')
1060
+ emitFunc('xFormItemEmitFunc', res)
1061
+ }
1062
+ else {
1063
+ showToast('扫码失败')
1064
+ }
1065
+ },
1066
+ })
1067
+ }
1068
+ else if (attr.type === 'nfc') {
1069
+ // NFC逻辑
1070
+ mobileUtil.execute({
1071
+ funcName: 'startNfcScan',
1072
+ param: {},
1073
+ callbackFunc: (res: any) => {
1074
+ console.log('nfc结果:------', res)
1075
+ if (res && res.status === 'success') {
1076
+ modelData.value = res.data?.id
1077
+ showToast('NFC 检测成功')
1078
+ emitFunc('xFormItemEmitFunc', res)
1079
+ }
1080
+ else {
1081
+ showToast(res?.message || 'NFC 功能不可用')
1082
+ }
1083
+ },
1084
+ })
1085
+ }
1086
+ }
1087
+ </script>
1088
+
1089
+ <template>
1090
+ <div>
1091
+ <!-- switch开关 -->
1092
+ <VanField
1093
+ v-if="attr.type === 'switch' && showItem"
1094
+ name="switch"
1095
+ :label="labelData"
1096
+ :label-align="labelAlign"
1097
+ :input-align="attr.inputAlign ? attr.inputAlign : 'right'"
1098
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1099
+ :required="attr.rule.required === 'true'"
1100
+ >
1101
+ <template #input>
1102
+ <VanSwitch v-model="modelData" />
1103
+ </template>
1104
+ </VanField>
1105
+
1106
+ <!-- 复选框 -->
1107
+ <!-- <VanField
1108
+ v-if="attr.type === 'checkbox'"
1109
+ name="checkbox"
1110
+ :label="labelData"
1111
+ >
1112
+ <template #input>
1113
+ <VanCheckbox v-model="modelData" shape="square" />
1114
+ </template>
1115
+ </VanField> -->
1116
+
1117
+ <!-- 多选框-checkbox-复选框组 -->
1118
+ <template v-if="attr.type === 'checkbox' && showItem">
1119
+ <!-- 勾选 -->
1120
+ <VanField
1121
+ v-if="attr.showMode === 'checkbox' && mode !== '查询'"
1122
+ name="checkboxGroup"
1123
+ :label="labelData"
1124
+ :label-align="labelAlign"
1125
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1126
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1127
+ :required="attr.rule.required === 'true'"
1128
+ >
1129
+ <template #input>
1130
+ <van-checkbox-group v-model="modelData as any[]" direction="horizontal" shape="square" :disabled="readonly">
1131
+ <VanCheckbox v-for="(item, index) in option" :key="index" style="padding: 2px" :name="item[columnsField.value]" :shape="rules?.[attr.model].shape" :value="item[columnsField.value]">
1132
+ {{ item[columnsField.text] }}
1133
+ </VanCheckbox>
1134
+ </van-checkbox-group>
1135
+ </template>
1136
+ </VanField>
1137
+ <VanField
1138
+ v-if="attr.showMode === 'checkbox' && mode === '查询'"
1139
+ name="checkboxGroup"
1140
+ :label="labelData"
1141
+ :label-align="labelAlign"
1142
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1143
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1144
+ >
1145
+ <template #input>
1146
+ <XGridDropOption
1147
+ v-model="(modelData as string[])"
1148
+ :column-num="labelData ? 3 : 4"
1149
+ :multiple="true"
1150
+ :columns="option"
1151
+ />
1152
+ </template>
1153
+ </VanField>
1154
+ <!-- 下拉 -->
1155
+ <XMultiSelect
1156
+ v-if="(!attr.showMode || attr.showMode === 'select') && mode === '查询'"
1157
+ v-model="modelData"
1158
+ :label="labelData"
1159
+ :readonly="readonly"
1160
+ :placeholder="placeholder"
1161
+ :columns="option"
1162
+ :select-value="Array.isArray(modelData) ? modelData : []"
1163
+ :option="attr.option ? attr.option : columnsField"
1164
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1165
+ :required="attr.rule.required === 'true'"
1166
+ :lazy-load="attr.lazyLoad"
1167
+ :on-search="attr.lazyLoad ? handleLazySearch : null"
1168
+ />
1169
+ </template>
1170
+
1171
+ <!-- 单选框 -->
1172
+ <VanField
1173
+ v-if="attr.type === 'radio' && mode !== '查询' && showItem"
1174
+ name="radio"
1175
+ center
1176
+ :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1177
+ :label="labelData"
1178
+ :label-align="labelAlign"
1179
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1180
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1181
+ :required="attr.rule.required === 'true'"
1182
+ >
1183
+ <template #input>
1184
+ <VanRadioGroup v-model="modelData" direction="horizontal" :disabled="readonly">
1185
+ <VanRadio v-for="(item, index) in option" :key="index" style="padding: 2px" :name="item[columnsField.value]" :value="item[columnsField.value]">
1186
+ {{ item[columnsField.text] }}
1187
+ </VanRadio>
1188
+ </VanRadioGroup>
1189
+ </template>
1190
+ </VanField>
1191
+
1192
+ <!-- 单选框-查询 -->
1193
+ <VanField
1194
+ v-if="attr.type === 'radio' && mode === '查询' && showItem"
1195
+ name="radio"
1196
+ :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1197
+ :label="labelData"
1198
+ :label-align="labelAlign"
1199
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1200
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1201
+ >
1202
+ <template #input>
1203
+ <XGridDropOption
1204
+ v-model="(modelData as string)"
1205
+ :column-num="labelData ? 3 : 4"
1206
+ :columns="option"
1207
+ />
1208
+ </template>
1209
+ </VanField>
1210
+
1211
+ <!-- 步进器 -->
1212
+ <VanField
1213
+ v-if="attr.type === 'stepper' && showItem"
1214
+ name="stepper"
1215
+ :label="labelData"
1216
+ :label-align="labelAlign"
1217
+ :input-align="attr.inputAlign ? attr.inputAlign : 'center'"
1218
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1219
+ :required="attr.rule.required === 'true'"
1220
+ >
1221
+ <template #input>
1222
+ <VanStepper v-model="modelData as any" :disabled="readonly" />
1223
+ </template>
1224
+ </VanField>
1225
+
1226
+ <!-- 评分 -->
1227
+ <VanField
1228
+ v-if="attr.type === 'rate' && showItem"
1229
+ name="rate"
1230
+ :label="labelData"
1231
+ :label-align="labelAlign"
1232
+ :input-align="attr.inputAlign ? attr.inputAlign : 'center'"
1233
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1234
+ :required="attr.rule.required === 'true'"
1235
+ >
1236
+ <template #input>
1237
+ <VanRate v-model="modelData as number" :size="25" :count="attr.displayCount || 5" :readonly="readonly" void-color="#eee" void-icon="star" color="#ffd21e" />
1238
+ </template>
1239
+ </VanField>
1240
+
1241
+ <!-- 滑块 -->
1242
+ <VanField
1243
+ v-if="attr.type === 'slider' && showItem"
1244
+ name="slider"
1245
+ :label="labelData"
1246
+ :label-align="labelAlign"
1247
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1248
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1249
+ :required="attr.rule.required === 'true'"
1250
+ >
1251
+ <template #input>
1252
+ <VanSlider v-model="modelData as number" :readonly="readonly" />
1253
+ </template>
1254
+ </VanField>
1255
+
1256
+ <!-- 文件上传 -->
1257
+ <!-- 图片上传, 手机端拍照 -->
1258
+ <VanField
1259
+ v-if="(attr.type === 'image' || attr.type === 'file') && showItem"
1260
+ name="image"
1261
+ :label="labelData"
1262
+ center
1263
+ :label-align="labelAlign"
1264
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1265
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1266
+ :required="attr.rule.required === 'true'"
1267
+ >
1268
+ <template #input>
1269
+ <!-- 只读且为空时显示空提示 -->
1270
+ <div v-if="showEmptyTip" class="empty-tip">
1271
+ {{ placeholder }}
1272
+ </div>
1273
+ <!-- 有值或非只读时显示上传组件 -->
1274
+ <ImageUploader
1275
+ v-else
1276
+ upload-mode="server"
1277
+ :image-list="(modelData as any[])"
1278
+ authority="admin"
1279
+ :attr="attr"
1280
+ :mode="props.mode"
1281
+ :readonly="readonly"
1282
+ :is-async-upload="isAsyncUpload"
1283
+ @update-file-list="updateFile"
1284
+ />
1285
+ </template>
1286
+ </VanField>
1287
+
1288
+ <!-- 选择器 琉璃中不存在,不进行维护后续将删除 -->
1289
+ <VanField
1290
+ v-if="attr.type === 'picker' && showItem"
1291
+ v-model="pickerValue"
1292
+ name="picker"
1293
+ :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1294
+ :label="labelData"
1295
+ :label-align="labelAlign"
1296
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1297
+ readonly
1298
+ is-link
1299
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1300
+ @click="readonly ? null : showPicker = true"
1301
+ />
1302
+ <VanPopup v-model:show="showPicker" round position="bottom" teleport="body" overlay-class="date-picker-overlay">
1303
+ <VanPicker
1304
+ v-model="(modelData as Numeric[])"
1305
+ :title="attr.name"
1306
+ :columns="attr.selectKey"
1307
+ :readonly="readonly"
1308
+ :columns-field-names="attr.customFieldName ? attr.customFieldName : { text: 'text', value: 'value', children: 'children' }"
1309
+ :confirm-button-text="attr.confirmButtonText || attr.confirmButtonText === '' ? attr.confirmButtonText : '确认'"
1310
+ :cancel-button-text="attr.cancelButtonText || attr.cancelButtonText === '' ? attr.cancelButtonText : '取消'"
1311
+ @cancel="showPicker = false"
1312
+ @confirm="onPickerConfirm"
1313
+ />
1314
+ </VanPopup>
1315
+
1316
+ <!-- 日历选择-查询 -->
1317
+ <VanField
1318
+ v-if="attr.type === 'rangePicker' && mode === '查询' && showItem"
1319
+ v-model="(pickerValue as string | number)"
1320
+ is-link
1321
+ readonly
1322
+ name="rangePicker"
1323
+ :label="labelData"
1324
+ :label-align="labelAlign"
1325
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1326
+ :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1327
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1328
+ @click="calendarShow = true"
1329
+ />
1330
+ <VanCalendar
1331
+ v-model:show="calendarShow"
1332
+ switch-mode="year-month"
1333
+ type="range"
1334
+ teleport="body"
1335
+ overlay-class="date-picker-overlay"
1336
+ :show-confirm="attr.showConfirm"
1337
+ @confirm="onCalendarConfirm"
1338
+ />
1339
+
1340
+ <!-- 日期选择-非查询 -->
1341
+ <VanField
1342
+ v-if="(attr.type === 'datePicker' || attr.type === 'rangePicker') && mode !== '查询' && showItem"
1343
+ v-model="(modelData as string | number)"
1344
+ name="datePicker"
1345
+ :label="labelData"
1346
+ :label-align="labelAlign"
1347
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1348
+ readonly
1349
+ :is-link="true"
1350
+ :placeholder="placeholder"
1351
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1352
+ :required="attr.rule.required === 'true'"
1353
+ @click="readonly ? null : showDataTimePicker()"
1354
+ />
1355
+ <VanPopup v-model:show="showDatePicker" position="bottom" teleport="body" overlay-class="date-picker-overlay">
1356
+ <VanPickerGroup
1357
+ :title="attr.name"
1358
+ :tabs="hasTime ? ['选择日期', '选择时间'] : ['选择日期']"
1359
+ next-step-text="下一步"
1360
+ :confirm-button-text="attr.confirmButtonText ? attr.confirmButtonText : '确认'"
1361
+ :cancel-button-text="attr.cancelButtonText ? attr.cancelButtonText : '取消'"
1362
+ @confirm="onDateTimePickerConfirm"
1363
+ @cancel="onPickerCancel"
1364
+ >
1365
+ <VanDatePicker
1366
+ v-model="dateTimePickerValue.date"
1367
+ :columns-type="attr.dateColumnsType || dateColumnsType"
1368
+ />
1369
+ <VanTimePicker
1370
+ v-if="hasTime"
1371
+ v-model="dateTimePickerValue.time"
1372
+ :columns-type="attr.timeColumnsType || timeColumnsType"
1373
+ :min-time="attr.minTime ? attr.minTime : '00:00:00'"
1374
+ :max-time="attr.maxTime ? attr.maxTime : '23:59:59'"
1375
+ />
1376
+ </VanPickerGroup>
1377
+ </VanPopup>
1378
+
1379
+ <!-- 日期选择-查询 -->
1380
+ <VanField
1381
+ v-if="attr.type === 'datePicker' && mode === '查询' && showItem"
1382
+ v-model="(modelData as string | number)"
1383
+ name="datePicker"
1384
+ :label="labelData"
1385
+ :label-align="labelAlign"
1386
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1387
+ readonly
1388
+ :is-link="true"
1389
+ :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1390
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1391
+ @click="readonly ? null : showDataTimePicker()"
1392
+ />
1393
+ <VanPopup v-model:show="showDatePicker" position="bottom" teleport="body" overlay-class="date-picker-overlay">
1394
+ <VanPickerGroup
1395
+ :title="attr.name"
1396
+ :tabs="hasTime ? ['选择日期', '选择时间'] : ['选择日期']"
1397
+ next-step-text="下一步"
1398
+ :confirm-button-text="attr.confirmButtonText ? attr.confirmButtonText : '确认'"
1399
+ :cancel-button-text="attr.cancelButtonText ? attr.cancelButtonText : '取消'"
1400
+ @confirm="onDateTimePickerConfirm"
1401
+ @cancel="onPickerCancel"
1402
+ >
1403
+ <VanDatePicker
1404
+ v-model="dateTimePickerValue.date"
1405
+ :columns-type="attr.dateColumnsType || dateColumnsType"
1406
+ />
1407
+ <VanTimePicker
1408
+ v-if="hasTime"
1409
+ v-model="dateTimePickerValue.time"
1410
+ :columns-type="attr.timeColumnsType || timeColumnsType"
1411
+ :min-time="attr.minTime ? attr.minTime : '00:00:00'"
1412
+ :max-time="attr.maxTime ? attr.maxTime : '23:59:59'"
1413
+ />
1414
+ </VanPickerGroup>
1415
+ </VanPopup>
1416
+
1417
+ <!-- 时间选择 --该配置未在pc找到不进行维护 后续将删除 -->
1418
+ <VanField
1419
+ v-if="attr.type === 'timePicker' && showItem"
1420
+ v-model="timePickerValue"
1421
+ name="timePicker"
1422
+ is-link
1423
+ readonly
1424
+ :placeholder="attr.placeholder"
1425
+ :label="labelData"
1426
+ :label-align="labelAlign"
1427
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1428
+ :rules="[{ required: attr.rule.required === 'true', message: '请选择' }]"
1429
+ @click="readonly ? null : (showTimePicker = true)"
1430
+ />
1431
+ <VanPopup v-model:show="showTimePicker" position="bottom" teleport="body" overlay-class="date-picker-overlay">
1432
+ <VanTimePicker
1433
+ v-model="modelData as string[]"
1434
+ :title="attr.name"
1435
+ :columns-type="attr.columnsType ? attr.columnsType : ['hour', 'minute', 'second']"
1436
+ :min-time="attr.minTime ? attr.minTime : '00:00:00'"
1437
+ :max-time="attr.maxTime ? attr.maxTime : '23:59:59'"
1438
+ :readonly="readonly"
1439
+ @cancel="showTimePicker = false"
1440
+ @confirm="onTimePickerConfirm"
1441
+ />
1442
+ </VanPopup>
1443
+
1444
+ <!-- 省市区选择 -->
1445
+ <VanField
1446
+ v-if="(attr.type === 'area' || attr.type === 'citySelect') && showItem"
1447
+ v-model="area"
1448
+ name="area"
1449
+ :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1450
+ is-link
1451
+ readonly
1452
+ :label="labelData"
1453
+ :label-align="labelAlign"
1454
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1455
+ :rules="[{ required: attr.rule.required === 'true', message: '请选择' }]"
1456
+ :required="attr.rule.required === 'true'"
1457
+ @click="readonly ? null : (showArea = true)"
1458
+ />
1459
+ <VanPopup v-model:show="showArea" position="bottom" teleport="body" overlay-class="date-picker-overlay">
1460
+ <VanArea
1461
+ v-model="modelData as string" :title="attr.name" :area-list="areaList"
1462
+ @confirm="onAreaConfirm"
1463
+ @cancel="showArea = false"
1464
+ />
1465
+ </VanPopup>
1466
+
1467
+ <!-- 单选下拉列表 -->
1468
+ <XSelect
1469
+ v-if="attr.type === 'select' && showItem"
1470
+ v-model="modelData"
1471
+ :label="labelData"
1472
+ :readonly="readonly"
1473
+ clearable
1474
+ :placeholder="placeholder"
1475
+ :columns="option"
1476
+ :option="attr.option ? attr.option : columnsField"
1477
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1478
+ :required="attr.rule.required === 'true'"
1479
+ :lazy-load="attr.lazyLoad"
1480
+ :on-search="attr.lazyLoad ? handleLazySearch : null"
1481
+ />
1482
+
1483
+ <!-- 文本区域 -->
1484
+ <VanField
1485
+ v-if="attr.type === 'textarea' && showItem"
1486
+ v-model="(modelData as string)"
1487
+ rows="3"
1488
+ autosize
1489
+ :label="labelData"
1490
+ :label-align="labelAlign"
1491
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1492
+ type="textarea"
1493
+ :readonly="readonly"
1494
+ :maxlength="attr.maxlength ? attr.maxlength : 200"
1495
+ :placeholder="attr.placeholder ? attr.placeholder : `请输入${attr.name}`"
1496
+ show-word-limit
1497
+ :rules="[{ required: attr.rule.required === 'true', message: `请填写${attr.name}` }]"
1498
+ :required="attr.rule.required === 'true'"
1499
+ />
1500
+
1501
+ <!-- 文本输入框 -->
1502
+ <VanField
1503
+ v-if="(attr.type === 'input' || attr.type === 'intervalPicker' || attr.type === 'scanCode' || attr.type === 'nfc') && showItem"
1504
+ v-model="(modelData as string)"
1505
+ style="align-items: center"
1506
+ :label="labelData"
1507
+ :label-align="labelAlign"
1508
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1509
+ :type="attr.type as FieldType"
1510
+ :readonly="readonly"
1511
+ :disabled="attr.disabled"
1512
+ :placeholder="placeholder"
1513
+ :error-message="errorMessage"
1514
+ :clearable="attr.clearable"
1515
+ :rules="[{ required: attr.rule.required === 'true', message: `请填写${attr.name}` }]"
1516
+ :required="attr.rule.required === 'true'"
1517
+ @blur="() => formTypeCheck(attr, modelData as string)"
1518
+ >
1519
+ <template #input>
1520
+ <input
1521
+ :value="modelData"
1522
+ :readonly="readonly"
1523
+ class="van-field__control"
1524
+ :placeholder="placeholder"
1525
+ style="flex: 1; min-width: 0;"
1526
+ @input="e => modelData = (e.target as HTMLInputElement).value"
1527
+ @blur="() => formTypeCheck(attr, modelData as string)"
1528
+ >
1529
+ <VanButton
1530
+ v-if="(attr.type === 'input' || attr.type === 'intervalPicker') && !props.formReadonly && attr.inputOnAfterName && attr.inputOnAfterFunc && !attr.inputOnAfterName.includes('|')"
1531
+ class="action-btn"
1532
+ round
1533
+ type="primary"
1534
+ size="small"
1535
+ @click="emitFunc(attr.inputOnAfterFunc, attr)"
1536
+ >
1537
+ {{ attr.inputOnAfterName }}
1538
+ </VanButton>
1539
+ <VanButton
1540
+ v-if="(attr.type === 'scanCode' || attr.type === 'nfc') && !props.formReadonly"
1541
+ class="action-btn scan-nfc"
1542
+ round
1543
+ size="small"
1544
+ @click="scanCodeOrNfc(attr)"
1545
+ >
1546
+ {{ attr.type === 'scanCode' ? '扫码' : 'NFC' }}
1547
+ </VanButton>
1548
+ </template>
1549
+ </VanField>
1550
+
1551
+ <!-- 地址选择器 -->
1552
+ <VanField
1553
+ v-if="attr.type === 'addressSearch' && showItem"
1554
+ v-model="modelData as string"
1555
+ name="addressSearch"
1556
+ :label="labelData"
1557
+ :label-align="labelAlign"
1558
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1559
+ readonly
1560
+ is-link
1561
+ :placeholder="placeholder"
1562
+ :rules="[{ required: attr.rule.required === 'true', message: '请选择地址' }]"
1563
+ :required="attr.rule.required === 'true'"
1564
+ @click="readonly ? null : (showAddressPicker = true)"
1565
+ />
1566
+ <VanPopup
1567
+ v-model:show="showAddressPicker"
1568
+ position="bottom"
1569
+ :style="{ height: '80vh' }"
1570
+ teleport="body"
1571
+ overlay-class="date-picker-overlay"
1572
+ >
1573
+ <XLocationPicker
1574
+ :default-center="defaultMapCenter"
1575
+ :service-name="serviceName"
1576
+ @confirm="handleAddressConfirm"
1577
+ />
1578
+ </VanPopup>
1579
+
1580
+ <!-- pc的树形选择框————》 手机端采用 Cascader 级联选择 -->
1581
+ <VanField
1582
+ v-if="attr.type === 'treeSelect' && showItem"
1583
+ v-model="treeValue"
1584
+ name="treeSelect"
1585
+ :label="labelData"
1586
+ :label-align="labelAlign"
1587
+ :input-align="attr.inputAlign ? attr.inputAlign : 'left'"
1588
+ readonly
1589
+ is-link
1590
+ :placeholder="attr.placeholder ? attr.placeholder : `请选择${attr.name}`"
1591
+ :rules="[{ required: attr.rule.required === 'true', message: `请选择${attr.name}` }]"
1592
+ :required="attr.rule.required === 'true'"
1593
+ @click="readonly ? null : (showTreeSelect = true)"
1594
+ />
1595
+ <VanPopup
1596
+ v-model:show="showTreeSelect"
1597
+ position="bottom"
1598
+ teleport="body"
1599
+ overlay-class="date-picker-overlay"
1600
+ >
1601
+ <VanCascader
1602
+ :options="cleanEmptyChildren(option, attr.customFieldName ? attr.customFieldName : { text: 'label', value: 'value', children: 'children' })"
1603
+ :field-names="attr.customFieldName ? attr.customFieldName : { text: 'label', value: 'value', children: 'children' }"
1604
+ :title="attr.name"
1605
+ :closeable="true"
1606
+ @close="showTreeSelect = false"
1607
+ @finish="onTreeSelectFinish"
1608
+ />
1609
+ </VanPopup>
1610
+ </div>
1611
+ </template>
1612
+
1613
+ <style scoped>
1614
+ .date-picker-overlay {
1615
+ background-color: rgba(0, 0, 0, 0.2); /* 设置为半透明的黑色 */
1616
+ }
1617
+ .action-btn {
1618
+ border-radius: 10px;
1619
+ margin-left: 8px;
1620
+ min-width: 4rem;
1621
+ max-width: 6rem;
1622
+ }
1623
+
1624
+ /* 扫码/NFC按钮特殊样式 */
1625
+ .action-btn.scan-nfc {
1626
+ background-color: transparent;
1627
+ border: 1px dashed #aca8a8;
1628
+ color: #1989fa;
1629
+ }
1630
+
1631
+ /* 空提示样式 */
1632
+ .empty-tip {
1633
+ color: #969799;
1634
+ font-size: 14px;
1635
+ text-align: center;
1636
+ padding: 16px 0;
1637
+ }
1638
+ </style>