优化记录值复制功能 (#266)
1、修复无法复制包含双引号的 TXT 记录值 2、调整 MX 记录值的复制按钮到右侧,因为复制不需要复制优先级。
This commit is contained in:
@@ -290,12 +290,16 @@ $(document).ready(function(){
|
||||
field: 'Value',
|
||||
title: '记录值',
|
||||
formatter: function(value, row, index) {
|
||||
var display = value;
|
||||
if(row.Type == 'MX') display = value + ' | ' + row.MX;
|
||||
var copyId = 'copy-value-' + row.RecordId;
|
||||
// 只允许安全字符,避免引号问题
|
||||
var safeValue = (value+'').replace(/'/g, "'").replace(/\\/g, "\\\\");
|
||||
return '<span id="'+copyId+'">'+display+'</span><a href="javascript:void(0);" title="复制记录值" onclick="copyToClipboard(\''+safeValue+'\', \'#'+copyId+'\')" style="padding-left:6px;"><i class=\"fa fa-copy\"></i></a>';
|
||||
if(row.Type == 'MX') {
|
||||
// 只复制 mx.yandex.net,按钮在其右侧,优先级单独显示
|
||||
return '<span id="'+copyId+'" data-value="'+htmlEscape(value)+'">'+value+'</span>'
|
||||
+ '<a href="javascript:void(0);" title="复制记录值" onclick="copyToClipboard(null, \'#'+copyId+'\')" style="padding-left:6px;"><i class=\"fa fa-copy\"></i></a>'
|
||||
+ '<span class="mx-priority"> | '+row.MX+'</span>';
|
||||
} else {
|
||||
return '<span id="'+copyId+'" data-value="'+htmlEscape(value)+'">'+value+'</span>'
|
||||
+ '<a href="javascript:void(0);" title="复制记录值" onclick="copyToClipboard(null, \'#'+copyId+'\')" style="padding-left:6px;"><i class=\"fa fa-copy\"></i></a>';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -728,23 +732,38 @@ function advanceSearch(){
|
||||
}
|
||||
}
|
||||
function copyToClipboard(text, selector) {
|
||||
var tempInput = document.createElement('input');
|
||||
tempInput.style.position = 'absolute';
|
||||
tempInput.style.left = '-9999px';
|
||||
tempInput.value = text;
|
||||
document.body.appendChild(tempInput);
|
||||
tempInput.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(tempInput);
|
||||
if(selector){
|
||||
var icon = document.querySelector(selector + ' + a i');
|
||||
if(icon){
|
||||
var oldClass = icon.className;
|
||||
icon.className = 'fa fa-check';
|
||||
setTimeout(function(){ icon.className = oldClass; }, 1000);
|
||||
}
|
||||
}
|
||||
layer.msg('已复制到剪贴板', {icon: 1, time: 600});
|
||||
if (!text && selector) {
|
||||
var el = document.querySelector(selector);
|
||||
if (el) {
|
||||
text = el.getAttribute('data-value');
|
||||
}
|
||||
}
|
||||
var tempInput = document.createElement('input');
|
||||
tempInput.style.position = 'absolute';
|
||||
tempInput.style.left = '-9999px';
|
||||
tempInput.value = text;
|
||||
document.body.appendChild(tempInput);
|
||||
tempInput.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(tempInput);
|
||||
if(selector){
|
||||
var icon = document.querySelector(selector + ' + a i');
|
||||
if(icon){
|
||||
var oldClass = icon.className;
|
||||
icon.className = 'fa fa-check';
|
||||
setTimeout(function(){ icon.className = oldClass; }, 1000);
|
||||
}
|
||||
}
|
||||
layer.msg('已复制到剪贴板', {icon: 1, time: 600});
|
||||
}
|
||||
// 工具函数:HTML转义,防止XSS
|
||||
function htmlEscape(str) {
|
||||
return String(str)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
</script>
|
||||
{/block}
|
||||
Reference in New Issue
Block a user