t20-common-lib 0.15.9 → 0.15.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "t20-common-lib",
3
- "version": "0.15.9",
3
+ "version": "0.15.10",
4
4
  "description": "T20",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -68,6 +68,8 @@
68
68
  * 3. A 控制 B 可编辑 — setFieldEditable
69
69
  * 4. A 控制 B 值/名称回显或下拉项 — setFieldValue、setFieldLabelValue、setFieldOptions
70
70
  * 5. A 控制 B 渲染哪种组件 — setFieldElementType(须为 elementTypeChange 中已配置的枚举)
71
+ *
72
+ * fieldControlList:与 dynamicData 同时传入,仅在收到模版时按 fieldNo 与 elements[].prop 合并一次 isShow、showName→label、isRequired;之后渲染均以合并后的 mergedTemplateBase 为唯一数据源。
71
73
  */
72
74
  // 复用 Demo 中的字段组件,按模板的 elementType 动态渲染
73
75
  const context = require.context('./components/', true, /\.vue$/)
@@ -100,6 +102,11 @@ export default {
100
102
  linkageMethod: {
101
103
  type: Function,
102
104
  default: null
105
+ },
106
+ /** 字段控制配置,与 dynamicData 一并传入;仅整合一次 */
107
+ fieldControlList: {
108
+ type: Array,
109
+ default: () => []
103
110
  }
104
111
  },
105
112
  data() {
@@ -109,9 +116,11 @@ export default {
109
116
  // 右侧锚点当前定位项
110
117
  action: '',
111
118
  formAttrs: {},
119
+ // dynamicData + fieldControlList 合并后的模版快照;applyFieldStates 均从此克隆,不再直接用原始 dynamicData
120
+ mergedTemplateBase: null,
112
121
  // 运行时模板(动态表单渲染与联动状态都基于它)
113
122
  runtimeTemplate: { units: [] },
114
- // 联动写入的 options / elementType:每次从 dynamicData 克隆模板后会合并回来,避免被重置清空
123
+ // 联动写入的 options / elementType:每次从 mergedTemplateBase 克隆后会合并回来,避免被重置清空
115
124
  linkageFieldOverrides: {},
116
125
  // 避免联动写值导致 watch 循环触发
117
126
  isApplyingLinkage: false,
@@ -205,10 +214,40 @@ export default {
205
214
  this.$emit('input', { ...this.formData })
206
215
  }
207
216
  },
217
+ /**
218
+ * 将 fieldControlList 合并进模版克隆(fieldNo 对应 elements[].prop)
219
+ */
220
+ mergeFieldControlIntoTemplate(templateClone) {
221
+ const list = this.fieldControlList
222
+ if (!templateClone?.units || !Array.isArray(list) || list.length === 0) return templateClone
223
+ const byFieldNo = Object.create(null)
224
+ list.forEach(row => {
225
+ if (row && row.fieldNo != null && row.fieldNo !== '') byFieldNo[row.fieldNo] = row
226
+ })
227
+ ;(templateClone.units || []).forEach(group => {
228
+ ;(group.elements || []).forEach(item => {
229
+ if (!item.prop) return
230
+ const cfg = byFieldNo[item.prop]
231
+ if (!cfg) return
232
+ if (cfg.isShow !== undefined && cfg.isShow !== null) {
233
+ item.isShow = this.templateShowOrEditable(cfg.isShow)
234
+ }
235
+ if (cfg.showName != null && String(cfg.showName).trim() !== '') {
236
+ item.label = cfg.showName
237
+ }
238
+ if (cfg.isRequired !== undefined && cfg.isRequired !== null) {
239
+ item.isRequired = this.templateRequired(cfg.isRequired)
240
+ }
241
+ })
242
+ })
243
+ return templateClone
244
+ },
208
245
  // 基于模板初始化:分组锚点、默认值、必填规则
209
246
  initializeFromTemplate() {
210
247
  this.linkageFieldOverrides = {}
211
- this.runtimeTemplate = JSON.parse(JSON.stringify(this.dynamicData || { units: [] }))
248
+ const raw = JSON.parse(JSON.stringify(this.dynamicData || { units: [] }))
249
+ this.mergedTemplateBase = this.mergeFieldControlIntoTemplate(raw)
250
+ this.runtimeTemplate = JSON.parse(JSON.stringify(this.mergedTemplateBase))
212
251
  this.action = this.formGroups.length > 0 ? this.formGroups[0].prop : ''
213
252
  this.ensureFormDataShape()
214
253
  this.formGroups.forEach(group => {
@@ -328,7 +367,7 @@ export default {
328
367
  const prev = this.linkageFieldOverrides[groupProp][fieldProp] || {}
329
368
  this.$set(this.linkageFieldOverrides[groupProp], fieldProp, { ...prev, ...patch })
330
369
  },
331
- /** 模板每次从 dynamicData 克隆后,把联动里改过的 options / elementType 写回对应字段 */
370
+ /** 模板每次从 mergedTemplateBase 克隆后,把联动里改过的 options / elementType 写回对应字段 */
332
371
  applyLinkageOverrides() {
333
372
  Object.keys(this.linkageFieldOverrides || {}).forEach(groupProp => {
334
373
  const fields = this.linkageFieldOverrides[groupProp]
@@ -369,9 +408,9 @@ export default {
369
408
  this.$emit('linkage', linkageApi)
370
409
  },
371
410
  applyFieldStates() {
372
- if (!this.dynamicData?.units) return
411
+ if (!this.mergedTemplateBase?.units) return
373
412
  this.isApplyingLinkage = true
374
- const nextTemplate = JSON.parse(JSON.stringify(this.dynamicData))
413
+ const nextTemplate = JSON.parse(JSON.stringify(this.mergedTemplateBase))
375
414
  this.rules = {}
376
415
  ;(nextTemplate.units || []).forEach(group => {
377
416
  group.isShow = this.templateShowOrEditable(group.isShow)