fix: 知识卡保存图片参数与配方卡完全一致,去掉长按fallback
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 6s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 53s
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 6s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 53s
- html2canvas 参数: backgroundColor=null, scale=3, allowTaint=false (与 RecipeDetailOverlay.generateCardImage 完全一致) - useSaveImage 精简为只有 share + download 两条路径 - 截图失败时显示具体错误信息便于调试 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -727,24 +727,33 @@ function exportPDF() {
|
||||
setTimeout(() => w.print(), 500)
|
||||
}
|
||||
|
||||
// Save element as image — same flow as recipe card:
|
||||
// 1. html2canvas → dataUrl 2. saveImageFromUrl (share/popup/download)
|
||||
// Save element as image — identical to recipe card flow
|
||||
async function saveElementAsImage(el, name) {
|
||||
if (!el) { ui.showToast('找不到卡片'); return }
|
||||
const html2canvas = (await import('html2canvas')).default
|
||||
const { saveImageFromUrl } = await import('../composables/useSaveImage')
|
||||
|
||||
// Hide buttons during capture
|
||||
const btns = el.querySelectorAll('button')
|
||||
btns.forEach(b => { b._d = b.style.display; b.style.display = 'none' })
|
||||
|
||||
try {
|
||||
const html2canvas = (await import('html2canvas')).default
|
||||
const { saveImageFromUrl } = await import('../composables/useSaveImage')
|
||||
// Hide buttons during capture
|
||||
const btns = el.querySelectorAll('button')
|
||||
btns.forEach(b => { b._d = b.style.display; b.style.display = 'none' })
|
||||
const canvas = await html2canvas(el, { scale: 2, backgroundColor: '#fff', useCORS: true })
|
||||
// Same params as recipe card's generateCardImage
|
||||
const canvas = await html2canvas(el, {
|
||||
backgroundColor: null,
|
||||
scale: 3,
|
||||
useCORS: true,
|
||||
allowTaint: false,
|
||||
})
|
||||
btns.forEach(b => b.style.display = b._d || '')
|
||||
|
||||
const dataUrl = canvas.toDataURL('image/png')
|
||||
const result = await saveImageFromUrl(dataUrl, name)
|
||||
if (result === 'shared' || result === 'downloaded') ui.showToast('图片已保存')
|
||||
await saveImageFromUrl(dataUrl, name)
|
||||
ui.showToast('图片已保存')
|
||||
} catch (e) {
|
||||
console.error('saveElementAsImage:', e)
|
||||
ui.showToast('保存失败')
|
||||
btns.forEach(b => b.style.display = b._d || '')
|
||||
console.error('saveElementAsImage failed:', e)
|
||||
ui.showToast('截图失败: ' + (e.message || '未知错误'))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user