修改活动详情在正式环境下复制功能
This commit is contained in:
@@ -253,23 +253,28 @@ function genLink(){
|
||||
hideLoading(layerIndex);
|
||||
if (res.code == 200) {
|
||||
let text = res.data;
|
||||
if (navigator.clipboard) {
|
||||
// 使用 navigator.clipboard API
|
||||
navigator.clipboard.writeText(text)
|
||||
.then(function () {
|
||||
toastMsg(langReplace(localLang.demoModule.Copy_Successfully))
|
||||
})
|
||||
.catch(function (error) {
|
||||
});
|
||||
} else {
|
||||
// 使用 document.execCommand("copy") 作为备用方案
|
||||
var $temp = $("<textarea>");
|
||||
$("body").append($temp);
|
||||
$temp.val(text).select();
|
||||
document.execCommand("copy");
|
||||
$temp.remove();
|
||||
toastMsg(langReplace(localLang.demoModule.Copy_Successfully))
|
||||
}
|
||||
copyText(text);
|
||||
// if (navigator.clipboard) {
|
||||
// console.log('使用 navigator.clipboard API')
|
||||
// // 使用 navigator.clipboard API
|
||||
// navigator.clipboard.writeText(text)
|
||||
// .then(function () {
|
||||
// console.log('复制成功')
|
||||
// toastMsg(langReplace(localLang.demoModule.Copy_Successfully))
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// console.log(error)
|
||||
// });
|
||||
// } else {
|
||||
// console.log('----没诗意')
|
||||
// // 使用 document.execCommand("copy") 作为备用方案
|
||||
// var $temp = $("<textarea>");
|
||||
// $("body").append($temp);
|
||||
// $temp.val(text).select();
|
||||
// document.execCommand("copy");
|
||||
// $temp.remove();
|
||||
// toastMsg(langReplace(localLang.demoModule.Copy_Successfully))
|
||||
// }
|
||||
} else {
|
||||
toastMsg(res.message)
|
||||
}
|
||||
@@ -279,6 +284,56 @@ function genLink(){
|
||||
},
|
||||
})
|
||||
}
|
||||
async function copyText(text) {
|
||||
try {
|
||||
// 尝试 Clipboard API
|
||||
if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
|
||||
await navigator.clipboard.writeText(text);
|
||||
toastMsg(langReplace(localLang.demoModule.Copy_Successfully));
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Clipboard API 复制失败', err);
|
||||
}
|
||||
|
||||
// 回退到 execCommand("copy")
|
||||
fallbackCopyText(text);
|
||||
}
|
||||
|
||||
// execCommand 回退方案
|
||||
function fallbackCopyText(text) {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
textarea.style.position = 'fixed';
|
||||
textarea.style.top = '-9999px';
|
||||
textarea.style.left = '-9999px';
|
||||
textarea.readOnly = true;
|
||||
document.body.appendChild(textarea);
|
||||
|
||||
textarea.select();
|
||||
textarea.setSelectionRange(0, textarea.value.length); // For mobile devices
|
||||
|
||||
let successful = false;
|
||||
|
||||
try {
|
||||
successful = document.execCommand('copy');
|
||||
} catch (e) {
|
||||
successful = false;
|
||||
}
|
||||
|
||||
document.body.removeChild(textarea);
|
||||
|
||||
if (successful) {
|
||||
toastMsg(langReplace(localLang.demoModule.Copy_Successfully));
|
||||
} else {
|
||||
manualCopyFallback(text);
|
||||
}
|
||||
}
|
||||
|
||||
// 手动复制兜底方案
|
||||
function manualCopyFallback(text) {
|
||||
alert('请长按以下内容进行复制:\n\n' + text);
|
||||
}
|
||||
function shareData() {
|
||||
networkRequest({
|
||||
type: "POST",
|
||||
|
Reference in New Issue
Block a user