leisure-core 0.5.65 → 0.5.67
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/le-list-form/src/main.vue +50 -0
- package/package.json +1 -1
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
class="compontClass"
|
|
30
30
|
:class="{ 'radio-group-class': item.type === 'radio' }"
|
|
31
31
|
:key="`component-${index}-${item.prop}-${item.type}`"
|
|
32
|
+
:ref="(el) => setFieldRef(item.ref, el, item.prop)"
|
|
32
33
|
>
|
|
33
34
|
<template v-if="item.type === 'radio'">
|
|
34
35
|
<el-radio
|
|
@@ -153,6 +154,7 @@ export default {
|
|
|
153
154
|
return {
|
|
154
155
|
formPop: {},
|
|
155
156
|
options: {},
|
|
157
|
+
fieldComponents: {},
|
|
156
158
|
};
|
|
157
159
|
},
|
|
158
160
|
computed: {
|
|
@@ -213,10 +215,58 @@ export default {
|
|
|
213
215
|
setFieldValue: this.setFieldValue,
|
|
214
216
|
getFormData: this.getFormData,
|
|
215
217
|
initFormData: this.initFormData,
|
|
218
|
+
getFieldComponent: this.getFieldComponent, // 暴露获取字段组件的方法
|
|
219
|
+
getAllFieldComponents: this.getAllFieldComponents, // 暴露获取所有字段组件的方法
|
|
216
220
|
});
|
|
217
221
|
});
|
|
218
222
|
},
|
|
219
223
|
methods: {
|
|
224
|
+
// 设置字段组件引用
|
|
225
|
+
setFieldRef(refName, el, propName) {
|
|
226
|
+
if (el) {
|
|
227
|
+
// 组件挂载时,el 是组件实例
|
|
228
|
+
if (refName) {
|
|
229
|
+
// 如果有自定义 ref 名称,使用它
|
|
230
|
+
this.fieldComponents[refName] = el;
|
|
231
|
+
this.$refs[refName] = el; // 同时设置到 $refs 上
|
|
232
|
+
} else {
|
|
233
|
+
// 如果没有自定义 ref,使用 prop 名称作为默认 ref
|
|
234
|
+
const defaultRef = `field_${propName}`;
|
|
235
|
+
this.fieldComponents[defaultRef] = el;
|
|
236
|
+
this.$refs[defaultRef] = el;
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
// 组件销毁时,el 为 null,清除引用
|
|
240
|
+
if (refName) {
|
|
241
|
+
delete this.fieldComponents[refName];
|
|
242
|
+
delete this.$refs[refName];
|
|
243
|
+
} else {
|
|
244
|
+
const defaultRef = `field_${propName}`;
|
|
245
|
+
delete this.fieldComponents[defaultRef];
|
|
246
|
+
delete this.$refs[defaultRef];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
// 获取特定字段的组件实例
|
|
251
|
+
getFieldComponent(refName) {
|
|
252
|
+
// 先从存储的实例中查找
|
|
253
|
+
if (this.fieldComponents[refName]) {
|
|
254
|
+
return this.fieldComponents[refName];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 再从 $refs 中查找
|
|
258
|
+
if (this.$refs[refName]) {
|
|
259
|
+
return this.$refs[refName];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
console.warn(`未找到字段组件: ${refName}`);
|
|
263
|
+
return null;
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
// 获取所有字段组件实例
|
|
267
|
+
getAllFieldComponents() {
|
|
268
|
+
return { ...this.fieldComponents, ...this.$refs };
|
|
269
|
+
},
|
|
220
270
|
componentType(type) {
|
|
221
271
|
if (!this.dynamicComponentMap[type]) {
|
|
222
272
|
return "le-input";
|