vome-core 0.0.46 → 0.0.48

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.
@@ -73,9 +73,10 @@
73
73
  v-if="useDownloadAction"
74
74
  type="button"
75
75
  class="vm-file-preview-viewer__link"
76
+ :disabled="downloading"
76
77
  @click="downloadFile"
77
78
  >
78
- 下载
79
+ {{ downloading ? '下载中…' : '下载' }}
79
80
  </button>
80
81
  <button
81
82
  v-else
@@ -238,6 +239,8 @@ const props = withDefaults(
238
239
  radius?: number | string
239
240
  preview?: boolean
240
241
  fit?: 'cover' | 'contain'
242
+ /** 私有文件:点「下载」时先解析可访问短链 */
243
+ resolveDownloadUrl?: (url: string) => Promise<string | undefined>
241
244
  }>(),
242
245
  {
243
246
  embedded: false,
@@ -255,6 +258,7 @@ const emit = defineEmits<{ 'update:open': [v: boolean] }>()
255
258
 
256
259
  const internalOpen = ref(false)
257
260
  const loading = ref(false)
261
+ const downloading = ref(false)
258
262
  const error = ref('')
259
263
  const textContent = ref('')
260
264
  const excelHtml = ref('')
@@ -336,16 +340,28 @@ const useDownloadAction = computed(
336
340
  () => kind.value === 'unsupported' || kind.value === 'office',
337
341
  )
338
342
 
339
- function downloadFile() {
340
- const url = src.value
341
- if (!url) return
342
- const a = document.createElement('a')
343
- a.href = url
344
- a.download = displayName.value || 'download'
345
- a.rel = 'noopener'
346
- document.body.appendChild(a)
347
- a.click()
348
- a.remove()
343
+ async function downloadFile() {
344
+ if (downloading.value) return
345
+ const raw = src.value
346
+ if (!raw) return
347
+ downloading.value = true
348
+ try {
349
+ let url = raw
350
+ if (props.resolveDownloadUrl) {
351
+ const signed = await props.resolveDownloadUrl(raw)
352
+ if (!signed) return
353
+ url = signed
354
+ }
355
+ const a = document.createElement('a')
356
+ a.href = url
357
+ a.download = displayName.value || 'download'
358
+ a.rel = 'noopener'
359
+ document.body.appendChild(a)
360
+ a.click()
361
+ a.remove()
362
+ } finally {
363
+ downloading.value = false
364
+ }
349
365
  }
350
366
 
351
367
  function openInNewWindow() {
@@ -58,33 +58,24 @@
58
58
 
59
59
  <div v-if="previewSrc" class="vm-upload-item__actions">
60
60
  <button
61
- v-if="canInlinePreview"
62
61
  type="button"
63
62
  title="预览"
64
63
  @click.stop="previewOpen = true"
65
64
  >
66
65
  <i class="ri-zoom-in-line" />
67
66
  </button>
68
- <button
69
- v-else
70
- type="button"
71
- title="下载"
72
- :disabled="downloading"
73
- @click.stop="downloadFile"
74
- >
75
- <i class="ri-download-2-line" />
76
- </button>
77
67
  <button v-if="!disabled" type="button" title="删除" @click.stop="emit('remove')">
78
68
  <i class="ri-delete-bin-line" />
79
69
  </button>
80
70
  </div>
81
71
 
82
72
  <vm-preview-viewer
83
- v-if="canInlinePreview"
73
+ v-if="previewSrc"
84
74
  embedded
85
75
  v-model:open="previewOpen"
86
76
  :src="previewSrc"
87
77
  :file-name="item.name || item.url"
78
+ :resolve-download-url="resolveDownloadUrl"
88
79
  />
89
80
  </div>
90
81
  </template>
@@ -92,7 +83,6 @@
92
83
  <script setup lang="ts">
93
84
  import { ref, computed, watch } from 'vue'
94
85
  import { useVideoFrame } from '../../lib/video-frame'
95
- import { getMediaPreviewKind } from '../../lib/file-preview'
96
86
  import { extname, getUploadRule } from '../../lib/upload'
97
87
  import VmPreviewViewer from './vm-preview-viewer.vue'
98
88
  import type { UploadItem } from '../../../../typings/admin/comm/upload'
@@ -104,8 +94,8 @@ const props = withDefaults(
104
94
  item: UploadItem
105
95
  disabled?: boolean
106
96
  showTag?: boolean
107
- /** 私有桶等场景:先解析可访问 URL(如短时签名链)再下载 */
108
- resolveDownloadUrl?: (url: string, item: UploadItem) => Promise<string | undefined>
97
+ /** 私有文件:预览内点「下载」时先解析可访问短链 */
98
+ resolveDownloadUrl?: (url: string) => Promise<string | undefined>
109
99
  }>(),
110
100
  {
111
101
  disabled: false,
@@ -117,55 +107,9 @@ const emit = defineEmits<{ remove: [] }>()
117
107
 
118
108
  const previewOpen = ref(false)
119
109
  const imgBroken = ref(false)
120
- const downloading = ref(false)
121
110
 
122
111
  const previewSrc = computed(() => props.item.preload || props.item.url || '')
123
112
 
124
- const INLINE_KINDS = new Set([
125
- 'image',
126
- 'video',
127
- 'audio',
128
- 'pdf',
129
- 'excel',
130
- 'text',
131
- ])
132
-
133
- /** 可内嵌预览才开浮层;.vome 等直接下载,避免新窗口崩溃 */
134
- const canInlinePreview = computed(() => {
135
- const name = props.item.name || props.item.url || ''
136
- const kind = getMediaPreviewKind(name)
137
- return INLINE_KINDS.has(kind)
138
- })
139
-
140
- async function downloadFile() {
141
- if (downloading.value) return
142
- const raw = previewSrc.value
143
- if (!raw) return
144
- downloading.value = true
145
- try {
146
- let url = raw
147
- if (props.resolveDownloadUrl) {
148
- const signed = await props.resolveDownloadUrl(raw, props.item)
149
- if (!signed) return
150
- url = signed
151
- }
152
- const base =
153
- props.item.name ||
154
- String(url).split('?')[0]?.split('/').pop() ||
155
- 'download'
156
- const a = document.createElement('a')
157
- a.href = url
158
- a.download = base
159
- a.rel = 'noopener'
160
- a.target = '_blank'
161
- document.body.appendChild(a)
162
- a.click()
163
- a.remove()
164
- } finally {
165
- downloading.value = false
166
- }
167
- }
168
-
169
113
  /** 仅上传中显示;失败后隐藏,避免挡住预览/删除 */
170
114
  const showProgress = computed(() => {
171
115
  if (props.item.error) return false
@@ -97,8 +97,8 @@ const props = withDefaults(
97
97
  drag?: boolean
98
98
  prefixPath?: string
99
99
  beforeUpload?: (file: File) => boolean | Promise<boolean>
100
- /** 私有桶等:下载前解析可访问 URL(短时签名链) */
101
- resolveDownloadUrl?: (url: string, item: UploadItem) => Promise<string | undefined>
100
+ /** 私有文件:预览内点「下载」时先解析可访问短链 */
101
+ resolveDownloadUrl?: (url: string) => Promise<string | undefined>
102
102
  }>(),
103
103
  {
104
104
  modelValue: '',
package/dist/index.js CHANGED
@@ -27856,7 +27856,7 @@ init_excel();
27856
27856
  // package.json
27857
27857
  var package_default = {
27858
27858
  name: "vome-core",
27859
- version: "0.0.46",
27859
+ version: "0.0.48",
27860
27860
  description: "Vome framework \u2014 shared + Bun/Elysia server + Vue admin",
27861
27861
  license: "MIT",
27862
27862
  type: "module",
@@ -31168,7 +31168,7 @@ init_excel();
31168
31168
  // package.json
31169
31169
  var package_default = {
31170
31170
  name: "vome-core",
31171
- version: "0.0.46",
31171
+ version: "0.0.48",
31172
31172
  description: "Vome framework \u2014 shared + Bun/Elysia server + Vue admin",
31173
31173
  license: "MIT",
31174
31174
  type: "module",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vome-core",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "description": "Vome framework — shared + Bun/Elysia server + Vue admin",
5
5
  "license": "MIT",
6
6
  "type": "module",