1234567891011121314151617181920212223242526272829303132333435363738 |
- /**
- * 复制文本到剪贴板
- * @param {string} text - 要复制的文本内容
- * @param {string} successMsg - 复制成功时的提示信息
- * @param {string} failMsg - 复制失败时的提示信息
- */
- export const copyToClipboard = (text, successMsg = '复制成功', failMsg = '复制失败') => {
- // #ifdef H5
- const input = document.createElement('input')
- input.value = text
- document.body.appendChild(input)
- input.select()
- document.execCommand('copy')
- document.body.removeChild(input)
- uni.showToast({
- title: successMsg,
- icon: 'success'
- })
- // #endif
- // #ifdef APP-PLUS || MP
- uni.setClipboardData({
- data: text,
- success: () => {
- uni.showToast({
- title: successMsg,
- icon: 'success'
- })
- },
- fail: () => {
- uni.showToast({
- title: failMsg,
- icon: 'none'
- })
- }
- })
- // #endif
- }
|