<div class="btnBox">
<div class="copyTxt" style="opacity: 0; position: absolute; width: 1px; height:1px; overflow: hidden" id="copyTxt"></div>
<div id="copy" class="btn btnRed btnSixeL" onclick="copyLink()">复制链接</div>
<div id="backBtn" class="btn btnYes btnSixeL marTop20" onclick="window.history.back()">返回</div>
</div>
<script type="text/javascript">
function copyLink() {
// 调用后端查询该id的有效链接,无效则后端生成返回
const stockAuthId = $('input[name="radio"]:checked').val();
if(isBlank(stockAuthId)){
return layer.msg("请选择股东", {icon: 2},{time:1000});
}
$.showLoading("正在生成链接");
// 调用后端Api查询linkUrl
const url = pcs.common.path + 后端Api接口;
$.post(url,{},function(data){
if(data.code === 200){
$.hideLoading();
$("#copyTxt").html(data.rs);
copy(data.rs);
}else{
$.hideLoading();
return layer.msg(data.msg, {icon: 2},{time:1000});
}
},'json');
}
function copy(text){
if(navigator.clipboard){
navigator.clipboard.writeText(text).then(function(){
layer.msg("复制成功");
},function(){
copy2(text);
});
}else{
copy2(text);
}
}
function copy2(text){
if((navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))){
const range = document.createRange();
range.selectNode(document.querySelector(".copyTxt"));
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('Copy');
layer.msg("复制成功");
selection.removeAllRanges();
}else {
const input = document.createElement("INPUT");
input.value = text;
input.className = "";
document.body.appendChild(input);
input.select();
if (document.execCommand('copy')) {
document.execCommand('copy');
layer.msg("复制成功");
}
document.body.removeChild(input);
}
}
</script>