绿满眶商城微信小程序-uniapp
peng
13 小时以前 a6c950ba797dffec842cf7e923fc439868645766
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
export  function h5Copy(content) {
  
  if (!document.queryCommandSupported('copy')) {
    // 不支持
    return false
  }
  
  let textarea = document.createElement("textarea")
  textarea.value = content
  textarea.readOnly = "readOnly"
  document.body.appendChild(textarea)
  textarea.select() // 选择对象
  textarea.setSelectionRange(0, content.length) //核心
  let result = document.execCommand("copy") // 执行浏览器复制命令
  textarea.remove()
  return result
  
}
 
 
 
/**
 * 获取系统剪贴板内容
 */
 export function getClipboardData() {
  return new Promise((success, fail) => {
    // #ifndef H5
    uni.getClipboardData({
      success: ({ data }) => success(data),
      fail
    })
    // #endif
 
    // #ifdef H5
    try {
      navigator.clipboard.readText().then(success).catch(fail)
    } catch (error) {
      fail(error)
    }
    // #endif
  })
}