fix: 产物更新 v1.3.1,修复编辑弹窗「点确定没反应」

对应源码仓库 commit 0692249。UmTableForm 的表单 vnode 改由 render() 创建
(删除 computed.formCom,新增 methods.buildForm),避免 Vue 3.5 在渲染外重算
computed 导致字符串 ref 失去 owner、$refs.formRef 为 null;并新增
getFormInstance() 兜底回捞 ElForm 实例。

消费方实测:旧产物点确定无反应,新产物弹窗正常关闭并提交成功。
This commit is contained in:
2026-09-24 12:06:34 +08:00
parent b8b2c793a7
commit 7da6a5f54b
7 changed files with 97 additions and 55 deletions
+66 -38
View File
@@ -4876,15 +4876,40 @@ const _sfc_main$4 = defineComponent({
}
formModel.value = data;
};
const getFormInstance = () => {
var _a, _b;
const viaRefs = (_b = (_a = instance == null ? void 0 : instance.proxy) == null ? void 0 : _a.$refs) == null ? void 0 : _b.formRef;
if (typeof (viaRefs == null ? void 0 : viaRefs.validate) === "function")
return viaRefs;
let found = null;
const pick = (comp) => (comp == null ? void 0 : comp.exposed) ? comp.exposeProxy || comp.proxy : comp == null ? void 0 : comp.proxy;
const walk = (vnode) => {
var _a2, _b2;
if (!vnode || found || typeof vnode !== "object")
return;
const name = ((_a2 = vnode.type) == null ? void 0 : _a2.name) || ((_b2 = vnode.type) == null ? void 0 : _b2.__name);
if (name === "ElForm" && vnode.component) {
found = pick(vnode.component);
return;
}
if (vnode.component)
walk(vnode.component.subTree);
if (Array.isArray(vnode.children))
vnode.children.forEach(walk);
};
walk(instance == null ? void 0 : instance.subTree);
return found;
};
expose({
setFormModel,
getFormModel: () => unref(formModel),
getFormInstance,
onSubmit: () => {
var _a, _b;
return (_b = (_a = instance == null ? void 0 : instance.proxy) == null ? void 0 : _a.onSubmit) == null ? void 0 : _b.call(_a);
}
});
return { formModel, setFormModel };
return { formModel, setFormModel, getFormInstance };
},
data() {
return {
@@ -4910,13 +4935,19 @@ const _sfc_main$4 = defineComponent({
return this.throttleRefreshForm(v, oldV, needFreshCascadeField);
},
async onSubmit() {
var _a, _b;
const refs = this.$refs;
let valid = false;
try {
valid = await ((_b = (_a = refs.formRef) == null ? void 0 : _a.validate) == null ? void 0 : _b.call(_a));
} catch {
return;
var _a;
const form = (_a = this.getFormInstance) == null ? void 0 : _a.call(this);
let valid = true;
if (typeof (form == null ? void 0 : form.validate) === "function") {
try {
valid = await form.validate();
} catch {
return;
}
} else {
console.warn(
"[funjiaui] UmTableForm \u672A\u80FD\u62FF\u5230 ElForm \u5B9E\u4F8B\uFF0C\u672C\u6B21\u8DF3\u8FC7\u8868\u5355\u6821\u9A8C\u76F4\u63A5\u63D0\u4EA4\uFF0C\u8BF7\u53CD\u9988\u6B64\u95EE\u9898\u3002"
);
}
if (valid)
this.$emit("ok", cloneDeep(this.formModel));
@@ -5278,35 +5309,8 @@ const _sfc_main$4 = defineComponent({
},
initForm(fieldName, value) {
this.formModel = { ...this.formModel, [fieldName]: value };
}
},
watch: {
formModel: {
async handler(v, oldV) {
var _a, _b;
this.initRule(false);
const refs = this.$refs;
let needFreshCascadeField = [];
const editingField = [];
for (const key in v) {
if (!isEqual(v[key], oldV == null ? void 0 : oldV[key])) {
needFreshCascadeField = this.cascadeMap.get(key) || [];
editingField.push(key);
}
}
await this.refreshForm(v, oldV, needFreshCascadeField);
await nextTick();
for (const item of editingField) {
try {
await ((_b = (_a = refs == null ? void 0 : refs.formRef) == null ? void 0 : _a.validateField) == null ? void 0 : _b.call(_a, item));
} catch {
}
}
}
}
},
computed: {
formCom() {
},
buildForm() {
if (!this.formItems)
return null;
return h(
@@ -5324,13 +5328,37 @@ const _sfc_main$4 = defineComponent({
);
}
},
watch: {
formModel: {
async handler(v, oldV) {
var _a, _b, _c;
this.initRule(false);
let needFreshCascadeField = [];
const editingField = [];
for (const key in v) {
if (!isEqual(v[key], oldV == null ? void 0 : oldV[key])) {
needFreshCascadeField = this.cascadeMap.get(key) || [];
editingField.push(key);
}
}
await this.refreshForm(v, oldV, needFreshCascadeField);
await nextTick();
for (const item of editingField) {
try {
await ((_c = (_b = (_a = this.getFormInstance) == null ? void 0 : _a.call(this)) == null ? void 0 : _b.validateField) == null ? void 0 : _c.call(_b, item));
} catch {
}
}
}
}
},
beforeMount() {
this.rules = {};
this.initRule();
this.init();
},
render() {
return this.formCom;
return this.buildForm();
}
});
const cssModules$2 = {