|
|
@ -104,19 +104,27 @@ layui.define(['lay', 'util', 'element', 'form'], function(exports){ |
|
|
|
className: 'file-b', |
|
|
|
className: 'file-b', |
|
|
|
title: ['复制代码'], |
|
|
|
title: ['复制代码'], |
|
|
|
event: function(el, type){ |
|
|
|
event: function(el, type){ |
|
|
|
typeof options.onCopy === 'function' ? options.onCopy(finalCode) : function(){ |
|
|
|
var text = util.unescape(finalCode); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
navigator.clipboard.writeText(text).then(function(){ |
|
|
|
|
|
|
|
layer.msg('已复制', {icon: 1}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} catch(e) { |
|
|
|
|
|
|
|
var textarea = document.createElement('textarea'); |
|
|
|
|
|
|
|
textarea.value = text; |
|
|
|
|
|
|
|
textarea.style.position = 'absolute'; |
|
|
|
|
|
|
|
textarea.style.opacity = '0'; |
|
|
|
|
|
|
|
document.body.appendChild(textarea); |
|
|
|
|
|
|
|
textarea.select(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
navigator.clipboard.writeText(util.unescape(finalCode)).then(function(){ |
|
|
|
document.execCommand('copy'); |
|
|
|
layer.msg('已复制', { |
|
|
|
layer.msg('已复制', {icon: 1}); |
|
|
|
icon: 1 |
|
|
|
} catch(err) { |
|
|
|
}); |
|
|
|
layer.msg('复制失败', {icon: 2}); |
|
|
|
}); |
|
|
|
|
|
|
|
} catch(e) { |
|
|
|
|
|
|
|
layer.msg('复制失败', { |
|
|
|
|
|
|
|
icon: 2 |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}(); |
|
|
|
textarea.remove(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
typeof options.onCopy === 'function' && options.onCopy(text); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -369,4 +377,4 @@ layui.define(['lay', 'util', 'element', 'form'], function(exports){ |
|
|
|
// 若为源码版,则自动加载该组件依赖的 css 文件
|
|
|
|
// 若为源码版,则自动加载该组件依赖的 css 文件
|
|
|
|
if(!layui['layui.all']){ |
|
|
|
if(!layui['layui.all']){ |
|
|
|
layui.addcss('modules/code.css?v=3', 'skincodecss'); |
|
|
|
layui.addcss('modules/code.css?v=3', 'skincodecss'); |
|
|
|
} |
|
|
|
} |
|
|
|