Browse Source

添加 复制 插件

王飞 1 year ago
parent
commit
6ba67f4327
3 changed files with 30 additions and 6 deletions
  1. 2 0
      package.json
  2. 14 3
      src/views/Manage/File/FilePage.vue
  3. 14 3
      src/views/Manage/Img/ImgPage.vue

+ 2 - 0
package.json

@@ -34,6 +34,7 @@
     "@zxcvbn-ts/core": "^3.0.3",
     "animate.css": "^4.1.1",
     "axios": "^1.4.0",
+    "clipboard": "^2.0.11",
     "dayjs": "^1.11.9",
     "echarts": "^5.4.3",
     "echarts-wordcloud": "^2.1.0",
@@ -50,6 +51,7 @@
     "sortablejs": "^1.15.0",
     "url": "^0.11.1",
     "vue": "3.3.4",
+    "vue-clipboard3": "^2.0.0",
     "vue-i18n": "9.2.2",
     "vue-router": "^4.2.4",
     "vue-types": "^5.1.1"

+ 14 - 3
src/views/Manage/File/FilePage.vue

@@ -376,13 +376,24 @@ const downloadFile = (row: FileData) => {
   window.open(row.virtualPath)
 }
 
-const onCopy = (row: FileData) => {
-  navigator.clipboard.writeText(row.virtualPath).then(() => {
+import useClipboard from 'vue-clipboard3'
+
+const { toClipboard } = useClipboard()
+
+const onCopy = async (row: FileData) => {
+  try {
+    await toClipboard(row.virtualPath)
     ElMessage({
       message: '复制成功!',
       type: 'success'
     })
-  })
+  } catch (error) {
+    console.log(error)
+    ElMessage({
+      message: '复制失败!',
+      type: 'error'
+    })
+  }
 }
 
 const handleAdd = () => {

+ 14 - 3
src/views/Manage/Img/ImgPage.vue

@@ -339,13 +339,24 @@ const downloadFile = (row: ImgData) => {
   window.open(row.bannerUrl)
 }
 
-const onCopy = (row: ImgData) => {
-  navigator.clipboard.writeText(row.bannerUrl).then(() => {
+import useClipboard from 'vue-clipboard3'
+
+const { toClipboard } = useClipboard()
+
+const onCopy = async (row: ImgData) => {
+  try {
+    await toClipboard(row.bannerUrl)
     ElMessage({
       message: '复制成功!',
       type: 'success'
     })
-  })
+  } catch (error) {
+    console.log(error)
+    ElMessage({
+      message: '复制失败!',
+      type: 'error'
+    })
+  }
 }
 
 const handleAdd = () => {