From 47d13d9fafc3a5515b5d9b596de011cffea43d88 Mon Sep 17 00:00:00 2001 From: Den Date: Tue, 26 Nov 2024 19:37:58 +0700 Subject: [PATCH 1/9] feat: add download file --- .../src/components/Simulator/ContractItem.vue | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frontend/src/components/Simulator/ContractItem.vue b/frontend/src/components/Simulator/ContractItem.vue index 8d322b5fc..77ebe4f88 100644 --- a/frontend/src/components/Simulator/ContractItem.vue +++ b/frontend/src/components/Simulator/ContractItem.vue @@ -6,6 +6,7 @@ import { DocumentPlusIcon, PencilSquareIcon, TrashIcon, + ArrowDownOnSquareIcon, } from '@heroicons/vue/16/solid'; import { nextTick } from 'process'; import { ref, onMounted } from 'vue'; @@ -87,6 +88,19 @@ const handleRemoveFile = (id: string) => { title: 'Contract deleted', }); }; + +const handleDownloadFile = (e: Event) => { + e.preventDefault(); + const blob = new Blob([props.contract?.content], { type: 'text/plain' }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = String(props.contract?.name); + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); +};