Commit 2ccdf0e5 authored by 李文光's avatar 李文光

feat(offer): 抽取 copyToClipboard 兼容助手,支持非 https/localhost 剪贴板回退 (execCommand)

parent 55cc26ed
......@@ -195,25 +195,46 @@ const reopenOffer = () => {
}
}
const copyMaterials = async () => {
const text = materials.value?.items.map((item) => `${item.label}${item.value}`).join('\n') || ''
// 剪贴板写入需兼容非 https/localhost 等不支持 Clipboard API 的环境
const copyToClipboard = async (text = '') => {
if (!text) return false
if (navigator.clipboard?.writeText) {
try {
await navigator.clipboard.writeText(text)
showToast('审批材料已复制')
return true
} catch {
showToast('复制失败', 'error')
// 权限不足或调用失败,回退到 execCommand
}
}
try {
const textarea = document.createElement('textarea')
textarea.value = text
textarea.style.position = 'fixed'
textarea.style.opacity = '0'
document.body.appendChild(textarea)
textarea.focus()
textarea.select()
const ok = document.execCommand('copy')
document.body.removeChild(textarea)
return ok
} catch {
return false
}
}
const copyMaterials = async () => {
const text = materials.value?.items.map((item) => `${item.label}${item.value}`).join('\n') || ''
const ok = await copyToClipboard(text)
if (ok) showToast('审批材料已复制')
else showToast('复制失败', 'error')
}
const copyMail = async () => {
const text = offer.value?.mailDraft || ''
if (!text) return
try {
await navigator.clipboard.writeText(text)
showToast('邮件草稿已复制')
} catch {
showToast('复制失败', 'error')
}
const ok = await copyToClipboard(text)
if (ok) showToast('邮件草稿已复制')
else showToast('复制失败', 'error')
}
// 当前唯一的「下一步」主操作:放进工作流面板,让页面只有一处突出主 CTA,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment