@ganwei-web/gw-base-components-plus 1.0.54 → 1.0.56

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.
@@ -1,91 +1,96 @@
1
1
  <template>
2
2
  <span class="file-preview">
3
- <span class="file-name">{{ filename }}</span>
3
+ <span class="file-name">{{ showFileName ? filename : $t("login.framePro.label.attachment") }}</span>
4
4
  <el-button v-if="isPreview" type="primary" link @click="handlePreview">
5
- 预览
5
+ {{$t("login.framePro.label.preview")}}
6
6
  </el-button>
7
7
  <el-button v-if="isDownload" type="primary" link @click="handleDownload">
8
- 下载
8
+ {{$t("login.framePro.label.download")}}
9
9
  </el-button>
10
10
  </span>
11
11
  </template>
12
12
 
13
- <script setup>
14
- import { computed } from 'vue'
13
+ <script>
15
14
  import 'js-base64'
16
15
 
17
16
  const Base64 = window.Base64
18
17
 
19
- const props = defineProps({
20
- // 文件地址
21
- url: {
22
- type: String,
23
- required: true
18
+ export default {
19
+ props: {
20
+ // 文件地址
21
+ url: {
22
+ type: String,
23
+ required: true
24
+ },
25
+ // 文件地址的域名前缀,未传入时默认使用当前站点 origin
26
+ fileDomain: {
27
+ type: String,
28
+ default: ''
29
+ },
30
+ // 是否显示预览按钮
31
+ isPreview: {
32
+ type: Boolean,
33
+ default: true
34
+ },
35
+ // 是否显示下载按钮
36
+ isDownload: {
37
+ type: Boolean,
38
+ default: true
39
+ },
40
+ // 是否显示文件名,false 时显示“附件”
41
+ showFileName: {
42
+ type: Boolean,
43
+ default: true
44
+ }
24
45
  },
25
- // 文件地址的域名前缀,未传入时默认使用当前站点 origin
26
- fileDomain: {
27
- type: String,
28
- default: ''
46
+ computed: {
47
+ // 从 url 中截取文件名
48
+ filename() {
49
+ const value = this.url || ''
50
+ const raw = value.substring(value.lastIndexOf('/') + 1).split('?')[0]
51
+ try {
52
+ return decodeURIComponent(raw)
53
+ } catch (e) {
54
+ return raw
55
+ }
56
+ }
29
57
  },
30
- // 是否显示预览按钮
31
- isPreview: {
32
- type: Boolean,
33
- default: false
34
- },
35
- // 是否显示下载按钮
36
- isDownload: {
37
- type: Boolean,
38
- default: false
39
- }
40
- })
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
-
53
- // 从 localStorage.webConfig 读取预览服务域名
54
- function getPreviewDomain() {
55
- try {
56
- const webConfig = JSON.parse(localStorage.getItem('webConfig') || '{}')
57
- return webConfig?.httpConfig?.configPreviewDomain || ''
58
- } catch (e) {
59
- return ''
58
+ methods: {
59
+ // 从 localStorage.webConfig 读取预览服务域名
60
+ getPreviewDomain() {
61
+ try {
62
+ const webConfig = JSON.parse(localStorage.getItem('webConfig') || '{}')
63
+ return webConfig?.httpConfig?.configPreviewDomain || ''
64
+ } catch (e) {
65
+ return ''
66
+ }
67
+ },
68
+ // 预览:使用预览服务器打开文件
69
+ handlePreview() {
70
+ const domain = this.getPreviewDomain().replace(/\/+$/, '') || ''
71
+ if (!domain) {
72
+ console.warn('[file-preview] 未配置预览服务域名')
73
+ return
74
+ }
75
+ // 文件地址需带上域名:优先使用外部传入的域名,否则使用当前站点 origin
76
+ const fileDomain = (this.fileDomain || window.location.origin).replace(/\/+$/, '')
77
+ const fileUrl = /^https?:\/\//i.test(this.url)
78
+ ? this.url
79
+ : `${fileDomain}/${String(this.url).replace(/^\/+/, '')}`
80
+ const previewUrl = `${domain}/onlinePreview?url=${encodeURIComponent(Base64.encode(fileUrl))}`
81
+ window.open(previewUrl)
82
+ },
83
+ // 下载
84
+ handleDownload() {
85
+ const link = document.createElement('a')
86
+ link.href = this.url
87
+ link.download = this.filename
88
+ document.body.appendChild(link)
89
+ link.click()
90
+ document.body.removeChild(link)
91
+ }
60
92
  }
61
93
  }
62
-
63
- // 预览:使用预览服务器打开文件
64
- function handlePreview() {
65
- const domain = getPreviewDomain().replace(/\/+$/, '') || ""
66
- if (!domain) {
67
- console.warn('[file-preview] 未配置预览服务域名')
68
- return
69
- }
70
- // 文件地址需带上域名:优先使用外部传入的域名,否则使用当前站点 origin
71
- const fileDomain = (props.fileDomain || window.location.origin).replace(/\/+$/, '')
72
- const fileUrl = /^https?:\/\//i.test(props.url)
73
- ? props.url
74
- : `${fileDomain}/${String(props.url).replace(/^\/+/, '')}`
75
- console.log('fileUrl', fileUrl)
76
- const previewUrl = `${domain}/onlinePreview?url=${encodeURIComponent(Base64.encode(fileUrl))}`
77
- window.open(previewUrl)
78
- }
79
-
80
- // 下载
81
- function handleDownload() {
82
- const link = document.createElement('a')
83
- link.href = props.url
84
- link.download = filename.value
85
- document.body.appendChild(link)
86
- link.click()
87
- document.body.removeChild(link)
88
- }
89
94
  </script>
90
95
 
91
96
  <style scoped>
@@ -101,5 +106,6 @@ function handleDownload() {
101
106
  white-space: nowrap;
102
107
  max-width: 200px;
103
108
  margin-right: 12px;
109
+ line-height: 16px;
104
110
  }
105
111
  </style>
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@ganwei-web/gw-base-components-plus",
3
- "version": "1.0.54",
3
+ "version": "1.0.56",
4
4
  "description": "components",
5
5
  "main": "./dist/index.es.js",
6
+ "dependencies": {
7
+ "js-base64": "^2.6.4"
8
+ },
6
9
  "scripts": {
7
10
  "test": "echo \"Error: no test specified\" && exit 1"
8
11
  },