From 3aeb9dd5d3a7afbb13d90b499d43ff316d433c06 Mon Sep 17 00:00:00 2001 From: jmal Date: Sat, 15 Jun 2024 20:03:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=81=E5=AF=86=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=B3=E9=94=AE"=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5"=E7=9A=84=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/file-api.js | 8 +++++ src/components/ShowFile/ShowFile.vue | 53 +++++++++++++++++----------- src/icons/svg/file-glb.svg | 1 + src/sse/SSEClient.js | 5 ++- src/utils/file-config.js | 5 +-- src/utils/file-type.js | 4 +-- 6 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 src/icons/svg/file-glb.svg diff --git a/src/api/file-api.js b/src/api/file-api.js index 81e5f8e..9b59fed 100644 --- a/src/api/file-api.js +++ b/src/api/file-api.js @@ -189,6 +189,14 @@ export default { data: data }) }, + // 生成shareToken + generateShareToken: function(params) { + return request({ + url: '/share/generate/share-token', + method: 'get', + params + }) + }, // 取消分享 cancelShareLink: function(params) { return request({ diff --git a/src/components/ShowFile/ShowFile.vue b/src/components/ShowFile/ShowFile.vue index c72731c..02b7798 100644 --- a/src/components/ShowFile/ShowFile.vue +++ b/src/components/ShowFile/ShowFile.vue @@ -1056,6 +1056,7 @@ export default { isJustHideMenus: false, menusIsMultiple: false, menus: [], + shareToken: undefined, contextmenuDisabled: false, rowContextData: {}, tableLoading: true, @@ -3336,27 +3337,43 @@ export default { this.menus.splice(index, 1) } } - if (row.isShare && !row.isPrivacy) { - // 添加复制下载链接选项 - this.menus.splice(-2, 0, { - iconClass: 'menu-fuzhi', - label: '复制下载链接', - operation: 'copyDownloadLink', - }) - } + this.setMenusCopyDownLoadLinks(row) } this.preliminaryRowData(row) }, + setMenusCopyDownLoadLinks(row) { + if (row.isShare) { + // 获取this.menus中download的索引 + const downloadIndex = this.menus.findIndex( + item => item.operation === 'download' + ) + this.shareToken = undefined + // 在download之前添加复制下载链接选项 + if (row.isPrivacy) { + // 如果是私密分享需要先获取shareToken + api.generateShareToken({fileId: row.id}).then(res => { + this.shareToken = res.data + this.addMenusCopyDownLoadLinks(downloadIndex) + }) + } else { + this.addMenusCopyDownLoadLinks(downloadIndex) + } + } + }, + addMenusCopyDownLoadLinks(index) { + this.menus.splice(index, 0, { + iconClass: 'menu-fuzhi', + label: '复制下载链接', + operation: 'copyDownloadLink', + }) + }, setMenusByPermission(file) { const reservations = ['open', 'download'] // 删除this.menus中不要的菜单, 仅保留reservations中的菜单 this.menus = this.menus.filter(item => reservations.includes(item.operation) ) - if ( - file.operationPermissionList && - file.operationPermissionList.length > 0 - ) { + if (file.operationPermissionList && file.operationPermissionList.length > 0) { if (file.operationPermissionList.indexOf('PUT') > -1) { this.menus.splice(this.menus.length - 1, 0, { iconClass: 'menu-rename', @@ -3382,6 +3399,7 @@ export default { }) } } + this.setMenusCopyDownLoadLinks(file) }, // 更多操作(单选) moreClick(row, event) { @@ -3961,16 +3979,9 @@ export default { }, // 复制下载链接 copyDownloadLink(row) { - let url = - window.location.origin + - fileConfig.previewUrl( - this.$store.getters.name, - row, - undefined, - undefined - ) + let url = window.location.origin + fileConfig.previewUrl(this.$store.getters.name, row, undefined, this.shareToken) if (row.isFolder) { - url = fileConfig.packageDownloadUrl(row.id, row.name + '.zip') + url = fileConfig.packageDownloadUrl(row.id, row.name + '.zip', this.shareToken) } let clipboard = new Clipboard('.newFileMenu', { text: function() { diff --git a/src/icons/svg/file-glb.svg b/src/icons/svg/file-glb.svg new file mode 100644 index 0000000..846cae6 --- /dev/null +++ b/src/icons/svg/file-glb.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/sse/SSEClient.js b/src/sse/SSEClient.js index 92ad32b..4deacce 100644 --- a/src/sse/SSEClient.js +++ b/src/sse/SSEClient.js @@ -10,7 +10,10 @@ const uuid = generateUUID(); const throttledConnectSSE = _.throttle((username) => { if (typeof EventSource !== 'undefined') { - connectToSSE(username); + // 判断cookie中是否有token + if (store.getters.name) { + connectToSSE(username); + } } else { console.error('EventSource is not supported by the browser'); } diff --git a/src/utils/file-config.js b/src/utils/file-config.js index 65936cd..552e05e 100644 --- a/src/utils/file-config.js +++ b/src/utils/file-config.js @@ -112,7 +112,8 @@ export default { return window.location.origin + `${this.baseUrl}/public/s/packageDownload?fileIds=${fileIds}${queryShareId}${queryShareToken}` }, // 文件打包下载Url - packageDownloadUrl: function(fileId, downloadName) { - return window.location.origin + `${this.baseUrl}/public/s/${fileId}/packageDownload/${downloadName}` + packageDownloadUrl: function(fileId, downloadName, shareToken) { + const queryShareToken = shareToken ? `?share-token=${shareToken}` : '' + return window.location.origin + `${this.baseUrl}/public/s/${fileId}/packageDownload/${downloadName}${queryShareToken}` }, } diff --git a/src/utils/file-type.js b/src/utils/file-type.js index d5ae518..e2fa90e 100644 --- a/src/utils/file-type.js +++ b/src/utils/file-type.js @@ -88,5 +88,5 @@ iconClass.set('yml','file-yml') iconClass.set('yaml','file-yml') iconClass.set('plist','file-plist') iconClass.set('iso','file-iso') -iconClass.set('glb','glb') -iconClass.set('gltf','glb') +iconClass.set('glb','file-glb') +iconClass.set('gltf','file-glb')