fix(app): screenshot copy button copies image; add copy link

This commit is contained in:
2025-12-14 00:59:02 +08:00
parent b4c7a3eac9
commit 8931ad5d7f
16 changed files with 45 additions and 32 deletions

View File

@@ -98,13 +98,25 @@ async function copyLink(item) {
async function copyImage(item) {
const url = buildUrl(item.filename)
if (
!navigator.clipboard ||
typeof navigator.clipboard.write !== 'function' ||
typeof window.ClipboardItem === 'undefined'
) {
ElMessage.warning('当前环境不支持复制图片(建议使用 Chrome/Edge 并通过 HTTPS 访问);可用“复制链接/下载”。')
return
}
try {
const resp = await fetch(url, { credentials: 'include' })
if (!resp.ok) throw new Error('fetch_failed')
const blob = await resp.blob()
const mime = blob.type || ''
if (!mime.startsWith('image/')) throw new Error('not_image')
await navigator.clipboard.write([new ClipboardItem({ [blob.type]: blob })])
ElMessage.success('图片已复制')
} catch {
await copyLink(item)
ElMessage.warning('复制图片失败:请确认允许剪贴板权限;可用“复制链接/下载”。')
}
}
@@ -142,6 +154,7 @@ onMounted(load)
<div class="shot-meta app-muted">{{ item.created || '' }}</div>
<div class="shot-actions">
<el-button size="small" text type="primary" @click="copyImage(item)">复制图片</el-button>
<el-button size="small" text @click="copyLink(item)">复制链接</el-button>
<el-button size="small" text @click="download(item)">下载</el-button>
<el-button size="small" text type="danger" @click="onDelete(item)">删除</el-button>
</div>