|
1 | 1 | <template>
|
2 | 2 | <nav>
|
3 | 3 | <h1>Vue SFC Playground</h1>
|
| 4 | + |
| 5 | + <button class="share" @click="copyLink"> |
| 6 | + <svg width="1.4em" height="1.4em" viewBox="0 0 24 24"> |
| 7 | + <g fill="none" stroke="#626262" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 8 | + <circle cx="18" cy="5" r="3"/> |
| 9 | + <circle cx="6" cy="12" r="3"/> |
| 10 | + <circle cx="18" cy="19" r="3"/> |
| 11 | + <path d="M8.59 13.51l6.83 3.98"/> |
| 12 | + <path d="M15.41 6.51l-6.82 3.98"/> |
| 13 | + </g> |
| 14 | + </svg> |
| 15 | + </button> |
| 16 | + |
| 17 | + <button class="download" @click="downloadProject"> |
| 18 | + <svg width="1.7em" height="1.7em" viewBox="0 0 24 24"> |
| 19 | + <g fill="#626262"> |
| 20 | + <rect x="4" y="18" width="16" height="2" rx="1" ry="1"/> |
| 21 | + <rect x="3" y="17" width="4" height="2" rx="1" ry="1" transform="rotate(-90 5 18)"/> |
| 22 | + <rect x="17" y="17" width="4" height="2" rx="1" ry="1" transform="rotate(-90 19 18)"/> |
| 23 | + <path d="M12 15a1 1 0 0 1-.58-.18l-4-2.82a1 1 0 0 1-.24-1.39a1 1 0 0 1 1.4-.24L12 12.76l3.4-2.56a1 1 0 0 1 1.2 1.6l-4 3a1 1 0 0 1-.6.2z"/><path d="M12 13a1 1 0 0 1-1-1V4a1 1 0 0 1 2 0v8a1 1 0 0 1-1 1z"/> |
| 24 | + </g> |
| 25 | + </svg> |
| 26 | + </button> |
4 | 27 | </nav>
|
5 | 28 | </template>
|
6 | 29 |
|
| 30 | +<script setup lang="ts"> |
| 31 | +import { exportFiles } from './store' |
| 32 | +import { saveAs } from 'file-saver' |
| 33 | +
|
| 34 | +function copyLink() { |
| 35 | + navigator.clipboard.writeText(location.href) |
| 36 | + alert('Sharable URL has been copied to clipboard.') |
| 37 | +} |
| 38 | +
|
| 39 | +async function downloadProject() { |
| 40 | + const { default: JSZip } = await import('jszip') |
| 41 | + const zip = new JSZip() |
| 42 | +
|
| 43 | + // basic structure |
| 44 | +
|
| 45 | + // project src |
| 46 | + const src = zip.folder('src')! |
| 47 | + const files = exportFiles() |
| 48 | + for (const file in files) { |
| 49 | + src.file(file, files[file]) |
| 50 | + } |
| 51 | +
|
| 52 | + const blob = await zip.generateAsync({ type: 'blob' }) |
| 53 | + saveAs(blob, 'vue-project.zip') |
| 54 | +} |
| 55 | +</script> |
| 56 | + |
7 | 57 | <style>
|
8 | 58 | nav {
|
9 | 59 | height: var(--nav-height);
|
|
20 | 70 | line-height: var(--nav-height);
|
21 | 71 | font-weight: 500;
|
22 | 72 | }
|
| 73 | +
|
| 74 | +.share { |
| 75 | + position: absolute; |
| 76 | + top: 14px; |
| 77 | + right: 56px; |
| 78 | +} |
| 79 | +
|
| 80 | +.download { |
| 81 | + position: absolute; |
| 82 | + top: 13px; |
| 83 | + right: 16px; |
| 84 | +} |
23 | 85 | </style>
|
0 commit comments