@ganwei-web/gw-base-components-plus 1.0.53 → 1.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/file-preview/filePreview.vue +26 -3
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<span class="file-preview">
|
|
3
|
+
<span class="file-name">{{ filename }}</span>
|
|
3
4
|
<el-button v-if="isPreview" type="primary" link @click="handlePreview">
|
|
4
5
|
预览
|
|
5
6
|
</el-button>
|
|
@@ -10,7 +11,10 @@
|
|
|
10
11
|
</template>
|
|
11
12
|
|
|
12
13
|
<script setup>
|
|
13
|
-
import {
|
|
14
|
+
import { computed } from 'vue'
|
|
15
|
+
import 'js-base64'
|
|
16
|
+
|
|
17
|
+
const Base64 = window.Base64
|
|
14
18
|
|
|
15
19
|
const props = defineProps({
|
|
16
20
|
// 文件地址
|
|
@@ -35,6 +39,17 @@ const props = defineProps({
|
|
|
35
39
|
}
|
|
36
40
|
})
|
|
37
41
|
|
|
42
|
+
// 从 url 中截取文件名
|
|
43
|
+
const filename = computed(() => {
|
|
44
|
+
const value = props.url || ''
|
|
45
|
+
const raw = value.substring(value.lastIndexOf('/') + 1).split('?')[0]
|
|
46
|
+
try {
|
|
47
|
+
return decodeURIComponent(raw)
|
|
48
|
+
} catch (e) {
|
|
49
|
+
return raw
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
38
53
|
// 从 localStorage.webConfig 读取预览服务域名
|
|
39
54
|
function getPreviewDomain() {
|
|
40
55
|
try {
|
|
@@ -64,10 +79,9 @@ function handlePreview() {
|
|
|
64
79
|
|
|
65
80
|
// 下载
|
|
66
81
|
function handleDownload() {
|
|
67
|
-
const filename = props.url.substring(props.url.lastIndexOf('/') + 1).split('?')[0]
|
|
68
82
|
const link = document.createElement('a')
|
|
69
83
|
link.href = props.url
|
|
70
|
-
link.download = filename
|
|
84
|
+
link.download = filename.value
|
|
71
85
|
document.body.appendChild(link)
|
|
72
86
|
link.click()
|
|
73
87
|
document.body.removeChild(link)
|
|
@@ -78,5 +92,14 @@ function handleDownload() {
|
|
|
78
92
|
.file-preview {
|
|
79
93
|
display: inline-flex;
|
|
80
94
|
align-items: center;
|
|
95
|
+
gap: 4px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.file-name {
|
|
99
|
+
overflow: hidden;
|
|
100
|
+
text-overflow: ellipsis;
|
|
101
|
+
white-space: nowrap;
|
|
102
|
+
max-width: 200px;
|
|
103
|
+
margin-right: 12px;
|
|
81
104
|
}
|
|
82
105
|
</style>
|