Эх сурвалжийг харах

修复表单折叠展开后,数据不一致的问题

ZaiZai 2 жил өмнө
parent
commit
526cbad58a

+ 8 - 4
src/components/table-form/index.vue

@@ -165,12 +165,14 @@ const getExcelHtml = () => {
     if (temp && pkeyId) {
         //渲染表单
         isTableForm.value = true
-        tableFormApp.value = HTableForm.createForm({
+        tableFormApp.value = HTableForm.createForm(excelForm.value, {
             pid: pid,
             template: temp,
-            tableForm: excelForm.value,
             keys: colsKeys.value,
             appId: `#table-form-${pkeyId}`,
+            onFormDataChange: (form) => {
+                excelForm.value = form
+            },
             onRight: (event, KeyName) => {
                 onRightClick(pkeyId, event, KeyName, pid)
             },
@@ -344,13 +346,15 @@ const setTableFormInfoValue = async (key, value) => {
 
 //获取表单数据
 const getFormData = () => {
-    return deepClone(excelForm.value)
+    return excelForm.value
 }
 
 //设置表单数据
 const setFormData = (data) => {
     excelForm.value = deepClone(data)
-    setExcelHtml()
+    //console.log(tableFormApp.value)
+    //tableFormApp.value?.setFormData(data)
+    //setExcelHtml()
 }
 
 //获取表单效验数据

+ 13 - 2
src/plugins/HTableForm.js

@@ -30,7 +30,7 @@ export default class HTableForm {
 
     static tableFormApp = null
 
-    static createForm({template, tableForm, keys, appId, pid, onRight, onBlur, onLeftClick}) {
+    static createForm(tableForm, {template, keys, appId, pid, onRight, onBlur, onLeftClick, onFormDataChange}) {
         const _this = this;
         const app = createApp({
             data() {
@@ -49,16 +49,27 @@ export default class HTableForm {
                     handler(obj) {
                         this.formData = obj
                     },
-                    deep: true
+                    deep: true,
                 },
                 formData: {
                     handler(obj) {
                         tableForm = obj
+                        this.formDataChange(obj)
                     },
                     deep: true
                 },
             },
             methods: {
+                //表单数据改变
+                formDataChange(obj) {
+                    if (onFormDataChange) {
+                        onFormDataChange(obj)
+                    }
+                },
+                //改变表单数据
+                setFormData(obj) {
+                    this.formData = obj
+                },
                 //鼠标右键菜单
                 contextmenuClick(a, b, c, d, e, f, event) {
                     event.preventDefault();