wui-components-v2 1.2.5 → 1.2.7

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.
@@ -129,8 +129,10 @@ function initFormData() {
129
129
  // 开关:归一化为 "是"/"否" 字符串,避免 wd-switch 在 onBeforeMount 校验时
130
130
  // 因 modelValue 非 active/inactive 值(如 ''、布尔、数字)被强制重置为未选中
131
131
  if (ControlTypeSupportor.getControlType(item, props.entity && props.entity[item.sourceId]) === 'yes-no-switch') {
132
- const def = (props.entity && props.entity[item.sourceId]) ?? item.transDefaultValue
133
- const isYes = def === '是' || def === true || def === 1 || def === 'true' || def === '1'
132
+ const defRaw = (props.entity && props.entity[item.sourceId]) ?? item.transDefaultValue
133
+ // def 运行时可能是 string / boolean / number,统一转字符串再比较,避免与字面量类型比较的 TS 报错
134
+ const defStr = defRaw === null || defRaw === undefined ? '' : String(defRaw)
135
+ const isYes = defStr === '是' || defStr === 'true' || defStr === '1'
134
136
  return (models[item.sourceId] = isYes ? '是' : '否')
135
137
  }
136
138
 
@@ -388,37 +390,67 @@ watch(
388
390
  )
389
391
  //-e subRelValueField 联动
390
392
 
391
- // 存储变化后的数据,{ [fieldKey]: newValue, ... }
393
+ // 按「当前项 sourceId」分组存储联动参数:
394
+ // { [当前项sourceId]: { relValueField: 指向字段的表单值, relValueField3: 指向字段的表单值 } }
392
395
  const changedData = ref<Record<string, any>>({})
393
- const initialModel = ref<Record<string, any>>({})
394
396
 
395
- // 监听 shouldMonitor 中 relValueField / relValueField3 对应的 model 字段
397
+ // 监听 shouldMonitor 中 relValueField / relValueField3 对象下 id 对应的 model 字段,
398
+ // 把这两个 id 对应的表单值作为参数回传给「当前项」(按当前项 sourceId 分组,避免多字段互相覆盖)
396
399
  watch(
397
400
  () => {
401
+ // 按当前项 sourceId 分别记录其 relValueField / relValueField3 指向字段的当前值
398
402
  const snapshot: Record<string, any> = {}
399
403
  shouldMonitor.value?.forEach((item: any) => {
400
- if (item.relValueField) snapshot.relValueField = model.value[item.relValueField]
401
- if (item.relValueField3) snapshot.relValueField3 = model.value[item.relValueField3]
404
+ snapshot[item.id] = {
405
+ relValueField: item.relValueField ? model.value[item.relValueField] : undefined,
406
+ relValueField3: item.relValueField3 ? model.value[item.relValueField3] : undefined,
407
+ }
402
408
  })
403
409
  return snapshot
404
410
  },
405
- newVal => {
406
- // 只存储与初始值不同的字段(表单变化的值)
411
+ (newVal, oldVal) => {
412
+ // 当 relValueField / relValueField3 指向的字段值发生变化时,清空「当前项」自身的数据
413
+ // (oldVal 为 undefined 表示首次执行,跳过清空,避免初始化时误清)
414
+ if (oldVal) {
415
+ shouldMonitor.value?.forEach((item: any) => {
416
+ const oldSnap = oldVal[item.id] || {}
417
+ const newSnap = newVal[item.id] || {}
418
+ const relChanged =
419
+ item.relValueField && oldSnap.relValueField !== newSnap.relValueField
420
+ const rel3Changed =
421
+ item.relValueField3 && oldSnap.relValueField3 !== newSnap.relValueField3
422
+ if (relChanged || rel3Changed) {
423
+ model.value[item.id] = ''
424
+ }
425
+ })
426
+ }
427
+
428
+ // 当前项存在 relValueField / relValueField3 时,把其 id 对应的表单值作为联动参数带上
407
429
  const changed: Record<string, any> = {}
408
430
  shouldMonitor.value?.forEach((item: any) => {
409
- if (item.relValueField && newVal.relValueField !== initialModel.value[item.relValueField]) {
410
- changed.relValueField = newVal.relValueField
411
- }
412
- if (item.relValueField3 && newVal.relValueField3 !== initialModel.value[item.relValueField3]) {
413
- changed.relValueField3 = newVal.relValueField3
414
- }
431
+ const snap = newVal[item.id] || {}
432
+ const entry: Record<string, any> = {}
433
+ if (item.relValueField) entry.relValueField = snap.relValueField
434
+ if (item.relValueField3) entry.relValueField3 = snap.relValueField3
435
+ changed[item.id] = entry
415
436
  })
416
437
  changedData.value = changed
417
438
 
418
- // 当所有被监听的字段都有值时,存入缓存供 select-list 页面读取
419
- const values = Object.values(newVal)
420
- const allExist = values.length > 0 && values.every(v => v !== null && v !== undefined && v !== '')
421
- if (allExist) {
439
+ // 任一被监听字段有值时即写入缓存,供对应字段的 select 弹窗按 sourceId 读取自己的联动参数
440
+ const hasValue = shouldMonitor.value?.some((item: any) => {
441
+ const snap = newVal[item.id] || {}
442
+ return (
443
+ (item.relValueField &&
444
+ snap.relValueField !== undefined &&
445
+ snap.relValueField !== null &&
446
+ snap.relValueField !== '') ||
447
+ (item.relValueField3 &&
448
+ snap.relValueField3 !== undefined &&
449
+ snap.relValueField3 !== null &&
450
+ snap.relValueField3 !== '')
451
+ )
452
+ })
453
+ if (shouldMonitor.value?.length && hasValue) {
422
454
  uni.setStorageSync('paramsData', {
423
455
  changedData: changedData.value,
424
456
  rawData: shouldMonitor.value,
@@ -434,7 +466,6 @@ action.value = uni.getStorageSync('BASE_URL')
434
466
  hydrocarbonProgramToken.value = uni.getStorageSync('HYDROCARBON_PROGRAM_TOKEN')
435
467
  token.value = uni.getStorageSync('TOKEN')
436
468
  initFormData()
437
- initialModel.value = JSON.parse(JSON.stringify(model.value))
438
469
 
439
470
  // 小程序端 setData 异步:wd-switch 在 popup 内延迟挂载时,onBeforeMount 可能读到
440
471
  // 初始(未同步)的 modelValue,被组件校正逻辑强制重置为 inactiveValue("否")。
@@ -539,7 +570,8 @@ function submit() {
539
570
  })
540
571
  }
541
572
  }
542
- resolve({ ...clearValueMap, ...data })
573
+ console.log('data', { ...data, ...clearValueMap }, clearValueMap, data)
574
+ resolve({ ...data, ...clearValueMap })
543
575
  } else {
544
576
  reject(valid)
545
577
  }
@@ -557,7 +589,9 @@ defineExpose({
557
589
  })
558
590
  const clearValueMap = fields.value.reduce(
559
591
  (acc, field) => {
560
- acc[field.id] = field.clearValueOnHidden ? '' : (field.defaultValue ?? null)
592
+ if (field.clearValueOnHidden == true) {
593
+ acc[field.id] = ''
594
+ }
561
595
  return acc
562
596
  },
563
597
  {} as Record<string, any>
@@ -241,7 +241,8 @@ async function queryList(pageNo: number, pageSize: number) {
241
241
  }
242
242
 
243
243
  // 步骤2:构建查询参数
244
- const search = uni.getStorageSync('paramsData')?.changedData || {}
244
+ // 按当前字段 sourceId 读取其专属联动参数(relValueField / relValueField3 指向字段的表单值)
245
+ const search = uni.getStorageSync('paramsData')?.changedData?.[props.sourceId] || {}
245
246
  const newParams = {
246
247
  thirdCriterion: search.relValueField3 || '',
247
248
  secondCriterion: search.relValueField?.toString() || '',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",