TextModal.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <script setup>
  2. import { CopyOutlined, DownloadOutlined } from '@ant-design/icons-vue';
  3. import { message } from 'ant-design-vue';
  4. import { ClipboardManager, FileManager } from '@/utils';
  5. // Read-only text modal — used to surface multi-line export blobs
  6. // (subscription URLs, raw inbound JSON, generated share links) the
  7. // way the legacy txtModal did.
  8. defineProps({
  9. open: { type: Boolean, default: false },
  10. title: { type: String, default: '' },
  11. content: { type: String, default: '' },
  12. // When set, surfaces a download button that writes `content` to a
  13. // text file with this name.
  14. fileName: { type: String, default: '' },
  15. });
  16. const emit = defineEmits(['update:open']);
  17. function close() {
  18. emit('update:open', false);
  19. }
  20. async function copy(value) {
  21. const ok = await ClipboardManager.copyText(value || '');
  22. if (ok) {
  23. message.success('Copied');
  24. close();
  25. }
  26. }
  27. function download(content, name) {
  28. if (!name) return;
  29. FileManager.downloadTextFile(content, name);
  30. }
  31. </script>
  32. <template>
  33. <a-modal :open="open" :title="title" :closable="true" @cancel="close">
  34. <a-textarea :value="content" readonly :auto-size="{ minRows: 10, maxRows: 20 }" class="text-modal-content" />
  35. <template #footer>
  36. <a-button v-if="fileName" @click="download(content, fileName)">
  37. <template #icon>
  38. <DownloadOutlined />
  39. </template>
  40. {{ fileName }}
  41. </a-button>
  42. <a-button type="primary" @click="copy(content)">
  43. <template #icon>
  44. <CopyOutlined />
  45. </template>
  46. Copy
  47. </a-button>
  48. </template>
  49. </a-modal>
  50. </template>
  51. <style scoped>
  52. .text-modal-content {
  53. font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  54. font-size: 12px;
  55. overflow-y: auto;
  56. }
  57. </style>