Browse Source

[Fix][UI Next][V1.0.0-Beta] Fix bug where name copy is invalid (#9684)

Devosend 3 years ago
parent
commit
99678c097c
1 changed files with 5 additions and 7 deletions
  1. 5 7
      dolphinscheduler-ui-next/src/utils/clipboard.ts

+ 5 - 7
dolphinscheduler-ui-next/src/utils/clipboard.ts

@@ -16,16 +16,14 @@
  */
 
 export const copy = (text: string): boolean => {
-  const range = document.createRange()
-  const node = document.createTextNode(text)
-  document.body.append(node)
-  range.selectNode(node)
-  window.getSelection()?.addRange(range)
+  const inp = document.createElement('input')
+  document.body.appendChild(inp)
+  inp.value = text
+  inp.select()
   let result = false
   try {
     result = document.execCommand('copy')
   } catch (err) {}
-  window.getSelection()?.removeAllRanges()
-  document.body.removeChild(node)
+  inp.remove()
   return result
 }