fix: 知识卡保存图片流程与配方卡完全一致
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 15s
Test / e2e-test (push) Failing after 53s

html2canvas截图→dataUrl→saveImageFromUrl,跟配方卡片saveImage一模一样。
不再用captureAndSave封装。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 09:17:55 +00:00
parent 26a47aaf23
commit 50756528ee

View File

@@ -727,14 +727,23 @@ function exportPDF() {
setTimeout(() => w.print(), 500)
}
// Save a specific element as image (mobile: share, desktop: download)
// Save element as image — same flow as recipe card:
// 1. html2canvas → dataUrl 2. saveImageFromUrl (share/popup/download)
async function saveElementAsImage(el, name) {
if (!el) { ui.showToast('保存失败'); return }
if (!el) { ui.showToast('找不到卡片'); return }
try {
const { captureAndSave } = await import('../composables/useSaveImage')
const ok = await captureAndSave(el, name)
if (ok) ui.showToast('图片已保存')
} catch {
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 })
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('图片已保存')
} catch (e) {
console.error('saveElementAsImage:', e)
ui.showToast('保存失败')
}
}
@@ -746,7 +755,6 @@ function saveContraImage() {
saveElementAsImage(contraCardRef.value, '精油使用禁忌')
}
function saveCardImage(name) {
// Oil knowledge card modal
const el = document.querySelector('.oil-card-modal')
saveElementAsImage(el, name + '_精油知识卡')
}