Skip to content

Commit

Permalink
feat: 添加下载链接计算属性
Browse files Browse the repository at this point in the history
  • Loading branch information
Coooolfan committed Nov 1, 2024
1 parent 7a6348f commit 30fddc8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/views/FileShareView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ const titleStringMobile = computed(() => {
return descIsEmpty.value ? '' : '附言:'
})
const downloadUrl = computed(() => {
return `/file/${shareCode}/${fileRecord.value.file_name}?pw=${passwordInput.value}`
})
async function downloadHandler() {
// 构建一个下载请求
let a = document.createElement('a')
a.style.display = 'none'
a.href = `/file/${shareCode}/${fileRecord.value.file_name}?pw=${passwordInput.value}`
a.href = downloadUrl.value
a.download = fileRecord.value.file_name
console.log(a.href)
a.click()
Expand Down Expand Up @@ -90,14 +94,19 @@ async function downloadHandler() {
/>
<Button
severity="contrast"
label="下载"
@click="downloadHandler"
:class="{
'w-20': fileRecord.permission.toString() === '3',
'w-full': fileRecord.permission.toString() !== '3'
}"
:disabled="fileRecord.file_name === '文件不存在'"
></Button>
>
<!-- 使用单独的a标签以允许在浏览器右键复制下载链接 -->
<a v-if="fileRecord.file_name === '文件不存在'" class="pointer-events-none"
>文件不存在</a
>
<a v-else :href="downloadUrl">下载</a>
</Button>
</div>
</div>
<div class="p-2 h-96 hidden md:block -translate-y-8">
Expand Down

0 comments on commit 30fddc8

Please sign in to comment.