From 7265584351e835963c2f25d6fd9110afc3ba25f5 Mon Sep 17 00:00:00 2001 From: sws <1141121512@qq.com> Date: Thu, 5 Sep 2024 18:38:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A1=A8=E5=8D=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BD=AC=E6=8D=A2=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在form_data_transfor_diy_data函数中,加入try-catch结构,确保在配置转换失败时不会抛出错误。若JSON解析失败,将使用表单默认值作为回退,以保持数据的完整性。 --- src/views/layout/index.vue | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/views/layout/index.vue b/src/views/layout/index.vue index 3ba41e80..bd84b087 100644 --- a/src/views/layout/index.vue +++ b/src/views/layout/index.vue @@ -208,18 +208,33 @@ const diy_data_transfor_form_data = (clone_form: diy_data_item) => { }; const form_data_transfor_diy_data = (clone_form: diyData) => { let temp_config = clone_form.config; - return { - id: clone_form.id, - model: { - logo: clone_form.logo, - name: clone_form.name, - is_enable: clone_form.is_enable, - describe: clone_form.describe, - }, - header: is_obj(temp_config) ? (temp_config as diyConfig).header : JSON.parse(temp_config as string).header, - footer: is_obj(temp_config) ? (temp_config as diyConfig).footer : JSON.parse(temp_config as string).footer, - diy_data: is_obj(temp_config) ? (temp_config as diyConfig).diy_data : JSON.parse(temp_config as string).diy_data, - }; + try { + return { + id: clone_form.id, + model: { + logo: clone_form.logo, + name: clone_form.name, + is_enable: clone_form.is_enable, + describe: clone_form.describe, + }, + header: is_obj(temp_config) ? (temp_config as diyConfig).header : JSON.parse(temp_config as string).header, + footer: is_obj(temp_config) ? (temp_config as diyConfig).footer : JSON.parse(temp_config as string).footer, + diy_data: is_obj(temp_config) ? (temp_config as diyConfig).diy_data : JSON.parse(temp_config as string).diy_data, + }; + } catch (error) { + return { + id: clone_form.id, + model: { + logo: clone_form.logo, + name: clone_form.name, + is_enable: clone_form.is_enable, + describe: clone_form.describe, + }, + header: form.value.header, + footer: form.value.footer, + diy_data: form.value.diy_data, + }; + } }; // 截取document.location.search字符串内id/后面的所有字段