, { field: 'id', title: '活动二维码', width: 140,align:'center',templet: function (d) { return '<a href="#" lay-event="copy"><img src="'+d.qcode+'" height="100" width="100"><br>点击复制转发</a>'; } } case 'copy':
const text = '📢 活动报名:\n名称:'+data.title+'\n网址:'+data.qcodeurl+'\n说明:请复制网址到浏览器中,或扫码报名';
copyTextAndImage(text, data.qcode);
break;
function copyTextAndImage(text, base64Img) {
const html = `<div>${text.replace(/\n/g,'<br>')}<br><img src="${base64Img}" width="150" height="150" /></div>`;
const blob = new Blob([html], { type: 'text/html' });
const item = new ClipboardItem({ 'text/html': blob });
navigator.clipboard.write([item]).then(() => {
layer.msg('复制成功,请转发');
}).catch(err => {
layer.msg('复制失败:' + err);
});
}
function base64ToBlob(base64) {
const arr = base64.split(',');
const mime = arr[0].match(/:(.*?);/)[1];
const bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });
}