From 4fb2baecbad287a1b31f9600132a475ea1b0eaf4 Mon Sep 17 00:00:00 2001 From: Arvin Huang <1095369685@qq.com> Date: Tue, 27 Feb 2024 18:47:08 +0800 Subject: [PATCH] update: support download yaml Signed-off-by: Arvin Huang <1095369685@qq.com> --- .../packages/fate-tools/lib/toRequest/service.ts | 8 +++++++- resources-front-end/packages/fate-tools/package.json | 1 + resources-front-end/packages/fate-tools/shims.d.ts | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/resources-front-end/packages/fate-tools/lib/toRequest/service.ts b/resources-front-end/packages/fate-tools/lib/toRequest/service.ts index aab8dc92..d966ea21 100644 --- a/resources-front-end/packages/fate-tools/lib/toRequest/service.ts +++ b/resources-front-end/packages/fate-tools/lib/toRequest/service.ts @@ -7,6 +7,7 @@ import axios, { import { ElMessage } from 'element-plus'; import { isBoolean, isNull, isObject, isUndefined } from 'lodash'; import toFile from '../toFile'; +import JSYmal from 'js-yaml'; export interface BasicConfigForParameter extends CreateAxiosDefaults { ConsolePrinting?: boolean; @@ -149,7 +150,12 @@ export default function HTTPRequest( const fileReader: FileReader = new FileReader(); fileReader.addEventListener('loadend', function () { - const result = JSON.parse(fileReader.result); + let result + if (filename.match(/json/i)) { + result = JSON.parse(fileReader.result); + } else { + result = JSYmal.load(fileReader.result) + } if (result.code !== undefined) { resolve(bodyExplain(result)); } else { diff --git a/resources-front-end/packages/fate-tools/package.json b/resources-front-end/packages/fate-tools/package.json index c8824ea4..c4f602e4 100644 --- a/resources-front-end/packages/fate-tools/package.json +++ b/resources-front-end/packages/fate-tools/package.json @@ -17,6 +17,7 @@ }, "dependencies": { "axios": "^1.6.4", + "js-yaml": "^4.1.0", "encryptlong": "^3.1.4", "file-saver": "^2.0.5" }, diff --git a/resources-front-end/packages/fate-tools/shims.d.ts b/resources-front-end/packages/fate-tools/shims.d.ts index f8844c97..4043b705 100644 --- a/resources-front-end/packages/fate-tools/shims.d.ts +++ b/resources-front-end/packages/fate-tools/shims.d.ts @@ -1,3 +1,4 @@ declare module 'encryptlong'; declare module 'file-saver'; declare module 'lodash-es'; +declare module 'js-yaml';