From a8d626be8aa4407e020e43da75e09e58ea6a4b6d Mon Sep 17 00:00:00 2001 From: Helloworld <1326521+LYZhelloworld@users.noreply.github.com> Date: Sun, 21 Aug 2022 16:17:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9C=A8=E8=AF=BB=E5=8F=96=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E6=96=87=E4=BB=B6=E6=97=B6=E4=B9=9F=E8=83=BD=E5=93=8D?= =?UTF-8?q?=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/JsonComponent.vue | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/CopilotDesinger/copilot-designer/src/components/JsonComponent.vue b/tools/CopilotDesinger/copilot-designer/src/components/JsonComponent.vue index ae527dd3ea..1eb2f9393b 100644 --- a/tools/CopilotDesinger/copilot-designer/src/components/JsonComponent.vue +++ b/tools/CopilotDesinger/copilot-designer/src/components/JsonComponent.vue @@ -23,7 +23,9 @@ export default defineComponent({ }, methods: { beforeUploadJson() { - (this.$refs.jsonFile as HTMLInputElement).click(); + const jsonFile = this.$refs.jsonFile as HTMLInputElement; + jsonFile.value = ""; + jsonFile.click(); }, uploadJson(e: Event) { const files = (e.target as HTMLInputElement).files; @@ -31,11 +33,17 @@ export default defineComponent({ const f = files[0]; const reader = new FileReader(); reader.onload = () => { - const newData = JSON.parse(reader.result as string); - this.$emit("loadData", { - ...createEmptyCopilotData(), - ...newData, - } as CopilotData); + try { + const newData = JSON.parse(reader.result as string); + this.$emit("loadData", { + ...createEmptyCopilotData(), + ...newData, + } as CopilotData); + } catch (e) { + if (e instanceof Error) { + window.alert("读取 JSON 时发生错误:\n" + e.message); + } + } }; reader.readAsText(f); },