perf: 移动端添加复制下载链接的选项

This commit is contained in:
jmal 2024-01-29 17:16:21 +08:00
parent e757a19737
commit b08c7446ac

View File

@ -285,6 +285,7 @@ import VideoPreview from "@/components/preview/VideoPreview";
import SimTextPreview from "@/components/preview/SimTextPreview";
import {suffix} from "@/utils/file-type";
import OfficePreview from "@/components/preview/OfficePreview";
import Clipboard from "clipboard";
let pinyin = require("pinyin");
@ -342,8 +343,7 @@ export default {
newFolderName: '新建文件夹',
Loop: null,
isJustHideMenus: false,
menus: [
// { iconClass: 'menu-open', label: '打开', operation: 'open' },
singleMenus: [
{iconClass: 'menu-select', label: '选择', operation: 'select'},
{iconClass: 'menu-favorite', label: '收藏', operation: 'favorite'},
{iconClass: 'menu-rename', label: '重命名', operation: 'rename'},
@ -351,6 +351,7 @@ export default {
{iconClass: 'menu-download', label: '下载', operation: 'download'},
{iconClass: 'menu-remove', label: '删除', operation: 'remove'}
],
menus: [],
rowContextData: {},
selectRowData: [],
checkboxGroup: [],
@ -479,6 +480,7 @@ export default {
},
// 长按事件
rowContextmenu(row, target, touchClientX) {
this.menus = JSON.parse(JSON.stringify(this.singleMenus));
// 改变菜单
if (this.selectStatus && this.selectIndexList.includes(row.index)) {
if (this.selectIndexList.includes(row.index)) {
@ -490,6 +492,11 @@ export default {
this.menus.splice(0, 1, item)
}
if (row.isShare && !row.isPrivacy) {
// 添加复制下载链接选项
this.menus.splice(-2, 0, { iconClass: "menu-fuzhi", label: "复制下载链接", operation: "copyDownloadLink" })
}
this.preliminaryRowData(row)
// 长按选择的数据
const offsetTop = getElementToPageTop(target) - row.scrollY
@ -547,6 +554,10 @@ export default {
case 'download':
this.downloadFile()
break
case "copyDownloadLink":
// 复制下载链接
this.copyDownloadLink(this.rowContextData)
break;
case 'remove':
this.deleteFile()
break
@ -630,6 +641,25 @@ export default {
});
}
},
// 复制下载链接
copyDownloadLink(row) {
let url = window.location.origin + fileConfig.previewUrl(this.$store.getters.name, row, undefined, undefined)
let clipboard = new Clipboard('.newFileMenu', {
text: function () {
return url
}
})
clipboard.on('success', e => {
this.$message({message: '复制成功', type: 'success', duration: 1000});
// 释放内存
clipboard.destroy()
})
clipboard.on('error', e => {
// 不支持复制
this.$message({message: '该浏览器不支持自动复制', type: 'warning', duration: 1000});
clipboard.destroy()
})
},
// 收藏/取消收藏
favoriteOperating(isFavorite) {
this.rowContextData.isFavorite = isFavorite