mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 13:32:24 +00:00
refactor: use blob for download file in text modal
This commit is contained in:
parent
0725a084bd
commit
52a3389053
1 changed files with 23 additions and 13 deletions
|
@ -1,20 +1,20 @@
|
|||
{{define "modals/textModal"}}
|
||||
<a-modal id="text-modal" v-model="txtModal.visible" :title="txtModal.title"
|
||||
:closable="true"
|
||||
:class="themeSwitcher.currentTheme">
|
||||
<template slot="footer">
|
||||
<a-button v-if="!ObjectUtil.isEmpty(txtModal.fileName)" icon="download"
|
||||
:href="'data:application/text;charset=utf-8,' + encodeURIComponent(txtModal.content)"
|
||||
:download="txtModal.fileName">[[ txtModal.fileName ]]
|
||||
</a-button>
|
||||
<a-button type="primary" @click="txtModal.copy(txtModal.content)">{{ i18n "copy" }}</a-button>
|
||||
</template>
|
||||
<a-modal id="text-modal" v-model="txtModal.visible" :title="txtModal.title" :closable="true"
|
||||
:class="themeSwitcher.currentTheme">
|
||||
<a-input :style="{ overflowY: 'auto' }" type="textarea" v-model="txtModal.content"
|
||||
:autosize="{ minRows: 10, maxRows: 20}"></a-input>
|
||||
<template slot="footer">
|
||||
<a-button v-if="!ObjectUtil.isEmpty(txtModal.fileName)" icon="download"
|
||||
@click="txtModal.download(txtModal.content, txtModal.fileName)">
|
||||
<span>[[ txtModal.fileName ]]</span>
|
||||
</a-button>
|
||||
<a-button type="primary" icon="copy" @click="txtModal.copy(txtModal.content)">
|
||||
<span>{{ i18n "copy" }}</span>
|
||||
</a-button>
|
||||
</template>
|
||||
</a-modal>
|
||||
|
||||
<script>
|
||||
|
||||
const txtModal = {
|
||||
title: '',
|
||||
content: '',
|
||||
|
@ -35,6 +35,17 @@
|
|||
this.close();
|
||||
})
|
||||
},
|
||||
download: function (content = '', fileName = '') {
|
||||
let link = document.createElement('a');
|
||||
|
||||
link.download = fileName;
|
||||
link.href = URL.createObjectURL(new Blob([content], { type: 'text/plain' }));
|
||||
link.click();
|
||||
|
||||
URL.revokeObjectURL(link.href);
|
||||
|
||||
link.remove();
|
||||
},
|
||||
close: function () {
|
||||
this.visible = false;
|
||||
},
|
||||
|
@ -47,6 +58,5 @@
|
|||
txtModal: txtModal,
|
||||
},
|
||||
});
|
||||
|
||||
</script>
|
||||
{{end}}
|
||||
{{end}}
|
Loading…
Reference in a new issue