From 931f8a712a59f95e698c84535855a5308407bceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E9=B9=B0?= <17kungfuboy@gmail.com> Date: Mon, 15 Aug 2022 10:10:03 +0800 Subject: [PATCH] feat: format form import --- .../components/params-import/params-import.component.ts | 6 +++++- .../src/app/utils/data-transfer/data-transfer.utils.ts | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/workbench/browser/src/app/shared/components/params-import/params-import.component.ts b/src/workbench/browser/src/app/shared/components/params-import/params-import.component.ts index 4a982dfea..a4f02a924 100644 --- a/src/workbench/browser/src/app/shared/components/params-import/params-import.component.ts +++ b/src/workbench/browser/src/app/shared/components/params-import/params-import.component.ts @@ -89,6 +89,10 @@ export class ParamsImportComponent { const json = {}; form2json(this.paramCode).forEach((it) => { const { key, value } = it; + if (key == null || value == null) { + this.message.error($localize`Form format invalid`); + return; + } json[key] = value; }); paramCode = JSON.parse(JSON.stringify(json)); @@ -96,7 +100,7 @@ export class ParamsImportComponent { if (this.contentType === 'xml') { const status = isXML(this.paramCode); if (!status) { - this.message.error('XML格式不合法'); + this.message.error($localize`XML format invalid`); return; } paramCode = JSON.parse(JSON.stringify(xml2UiData(this.paramCode))); diff --git a/src/workbench/browser/src/app/utils/data-transfer/data-transfer.utils.ts b/src/workbench/browser/src/app/utils/data-transfer/data-transfer.utils.ts index a69a199fa..e9d1c950e 100644 --- a/src/workbench/browser/src/app/utils/data-transfer/data-transfer.utils.ts +++ b/src/workbench/browser/src/app/utils/data-transfer/data-transfer.utils.ts @@ -79,7 +79,7 @@ export const form2json = (tmpl) => .map((it) => it.split(':')) .map((it) => { const [key, value] = it; - return { key: key.trim(), value: value.trim() }; + return { key: key?.trim(), value: value?.trim() }; }); export const xml2json = (tmpl) => { @@ -170,7 +170,7 @@ export const xml2UiData = (text) => { * @returns */ export const json2XML: (o: object, tab?) => string = (o, tab) => { - const toXml = function(v, name, ind) { + const toXml = function (v, name, ind) { let xml = ''; if (v instanceof Array) { for (let i = 0, n = v.length; i < n; i++) { @@ -258,7 +258,7 @@ export const text2UiData: (text: string) => uiData = (text) => { * @param inputOptions * @returns */ -export const uiData2Json = function(eoapiArr: ApiEditBody[], inputOptions) { +export const uiData2Json = function (eoapiArr: ApiEditBody[], inputOptions) { inputOptions = inputOptions || {}; const result = {}; const loopFun = (inputArr, inputObject) => {