@jr-public/jr-upload-ui 1.0.5 → 1.1.0

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/README.md CHANGED
@@ -34,10 +34,54 @@ export default {
34
34
 
35
35
  组件依赖的静态资源路径仍需由前端传入,例如:
36
36
 
37
+ ```vue
38
+ <JrUploadModal :config="config" bucket-name="example-bucket" upload-path="business/files" />
39
+ ```
40
+
41
+ `config.baseUrl` 指向上传服务;授权回调配置见下文。
42
+
43
+ ## 浏览器临时授权
44
+
45
+ Vue2、Vue3 使用相同配置。业务后端签发一次性票据,前端无需上传平台 Token:
46
+
47
+ ```js
48
+ const config = {
49
+ baseUrl: 'https://upload.example.com/publicUpload',
50
+ getUploadTicket: async ({ bucketName, uploadPath }) => {
51
+ const response = await request({
52
+ url: '/cjl/fileAccess/upload-ticket',
53
+ method: 'post',
54
+ data: { scene: 'xxj-source', bucketName, uploadPath }
55
+ })
56
+ return response.data
57
+ }
58
+ }
59
+ ```
60
+
61
+ 组件仍通过 `bucketName`、`uploadPath` 指定原业务桶和目录;授权失败时停止操作。
62
+ 每次打开弹框重新申请票据,短时会话仅保存在内存。临时授权使用受限 STS
63
+ 直传;启用压缩时在浏览器完成,不支持服务端代理上传和 MD5 去重。
64
+ 旧 `config.token` 接入方式保留兼容,新接入使用 `getUploadTicket`。
65
+
66
+ 下载、远程预览可从相应 Vue 入口导入 `getAuthorizedFileUrl`:
67
+
37
68
  ```js
38
- <JrUploadModal :config="{ baseUrl: 'https://xxx.com/upload-ui', token: 'xxx', uploadPath: '/path' }" />
69
+ import { getAuthorizedFileUrl } from '@jr-public/jr-upload-ui/vue2'
70
+
71
+ const url = await getAuthorizedFileUrl(window.JrTransferSDK, {
72
+ baseUrl: config.baseUrl,
73
+ getFileTicket: scope => request({
74
+ url: '/cjl/fileAccess/preview-ticket',
75
+ method: 'post',
76
+ data: { scene: 'xxj-source', ...scope }
77
+ }).then(response => response.data)
78
+ }, { operation: 'PREVIEW', bucketName: 'example-bucket', objectKey: 'business/file.pdf' })
39
79
  ```
40
80
 
81
+ `getFileTicket` 根据操作选择 `download-ticket` 或 `preview-ticket`。
82
+ 该方法需要先加载上传服务的 `jr-transfer-sdk.js`,返回仅绑定当前文件的短时地址。
83
+ 上传列表中对本地文件的预览仍使用浏览器本地对象,无需申请远程授权。
84
+
41
85
  ## 发布
42
86
 
43
87
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jr-public/jr-upload-ui",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "JR upload modal components for Vue2 and Vue3",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -13,6 +13,7 @@
13
13
  "./vue3": "./packages/vue3/src/index.js"
14
14
  },
15
15
  "scripts": {
16
+ "test": "node --test tests/*.test.cjs",
16
17
  "pack": "npm pack",
17
18
  "prepublishOnly": "npm pack",
18
19
  "publish:public": "npm publish --access public"
@@ -0,0 +1,57 @@
1
+ // 两个 Vue 版本共用票据校验,授权失败时不得退回长期 Token。
2
+ function normalizedDirectory(value) {
3
+ return String(value || '').trim().replace(/^\/+|\/+$/g, '')
4
+ }
5
+
6
+ function validateTicket(grant, scope) {
7
+ const now = Date.now()
8
+ if (!grant || !/^[A-Za-z0-9_-]{43}$/.test(grant.ticket || '')
9
+ || grant.operation !== scope.operation
10
+ || !grant.bucketName || (scope.bucketName && grant.bucketName !== scope.bucketName)
11
+ || !Number.isFinite(grant.expiresAt) || grant.expiresAt <= now || grant.expiresAt > now + 120000
12
+ || (scope.operation === 'UPLOAD' && grant.uploadPath !== scope.uploadPath)
13
+ || (scope.operation !== 'UPLOAD' && grant.objectKey !== scope.objectKey)) {
14
+ throw new Error('文件票据无效、已过期或与申请范围不一致')
15
+ }
16
+ }
17
+
18
+ export async function createUploadSdk(Sdk, config, scope) {
19
+ const shortLived = typeof config.getUploadTicket === 'function' || Boolean(config.browserTicket)
20
+ if (!shortLived) return new Sdk({ baseUrl: config.baseUrl, apiToken: config.token })
21
+ const requested = {
22
+ operation: 'UPLOAD',
23
+ bucketName: String(scope.bucketName || '').trim(),
24
+ uploadPath: normalizedDirectory(scope.uploadPath)
25
+ }
26
+ const grant = typeof config.getUploadTicket === 'function'
27
+ ? await config.getUploadTicket(requested)
28
+ : Object.assign({}, requested, { ticket: config.browserTicket, expiresAt: config.expiresAt })
29
+ validateTicket(grant, requested)
30
+ const sdk = new Sdk({ baseUrl: config.baseUrl, browserTicket: grant.ticket })
31
+ const session = await sdk.exchangeBrowserTicket(grant.ticket)
32
+ if (session.operation !== 'UPLOAD' || session.uploadPath !== requested.uploadPath
33
+ || session.bucketName !== grant.bucketName) {
34
+ throw new Error('上传会话与申请范围不一致')
35
+ }
36
+ sdk.browserExpiresAt = session.expiresAt
37
+ return sdk
38
+ }
39
+
40
+ /** 下载、预览按单个对象申请票据;返回短时地址,供调用页面按原交互打开。 */
41
+ export async function getAuthorizedFileUrl(Sdk, config, scope) {
42
+ if (!['DOWNLOAD', 'PREVIEW'].includes(scope.operation) || typeof config.getFileTicket !== 'function') {
43
+ throw new Error('请配置下载或预览授权回调')
44
+ }
45
+ const requested = {
46
+ operation: scope.operation, bucketName: scope.bucketName, objectKey: scope.objectKey
47
+ }
48
+ const grant = await config.getFileTicket(requested)
49
+ validateTicket(grant, requested)
50
+ const sdk = new Sdk({ baseUrl: config.baseUrl, browserTicket: grant.ticket })
51
+ const session = await sdk.exchangeBrowserTicket(grant.ticket)
52
+ if (session.operation !== requested.operation || session.objectKey !== requested.objectKey
53
+ || session.bucketName !== grant.bucketName) {
54
+ throw new Error('文件会话与申请范围不一致')
55
+ }
56
+ return sdk.getBrowserFileUrl()
57
+ }
@@ -257,8 +257,26 @@
257
257
  </div>
258
258
  </template>
259
259
 
260
- <script>
261
- export default {
260
+ <script>
261
+ import { createUploadSdk } from '../../shared/browser-access'
262
+ // 组件统一允许的单文件最大值,maxSize 对外单位保持为 KB
263
+ const MAX_UPLOAD_SIZE_KB = 10 * 1024 * 1024
264
+
265
+ // 组件内置业务后缀白名单,统一使用不带点号的小写形式。
266
+ const DEFAULT_UPLOAD_EXTENSIONS = [
267
+ 'aqtf', 'hftf', 'gef', 'tb_dg_gef', 'nsxtf', 'sxt2', 'gbq7', 'jmbs',
268
+ 'ujyzbx', 'zkzf', 'nzktf', 'zgzs', 'zgzf', 'zgsf', 'zgtf', 'zgcs', 'zgcf', 'tbsx', 'sgef', 'czr', 'zytf',
269
+ 'nzjy', 'zsf', 'gscs', 'gscf', 'zbxs', 'zbwj', 'zyzf', 'gszs', 'gszf', 'zbjy',
270
+ 'zbsx', 'gctb', 'fwtb', 'nzytf', 'mtbjy', 'gstf', 'dxtf', 'gssf',
271
+ 'qbcg', 'jtb4', 'jzb4', 'xml', 'ydbx', 'ydjc', 'sxzb', 'sxtb', 'sxxj',
272
+ 'hebzbx', 'hebkzjx', 'hebtbx'
273
+ ]
274
+
275
+ // 统一处理前导点、空格和大小写,确保 accept 配置与真实文件后缀可直接比较。
276
+ const normalizeFileExtension = (value) =>
277
+ String(value || '').trim().toLowerCase().replace(/^\.+/, '')
278
+
279
+ export default {
262
280
  name: 'JrUploadModal',
263
281
 
264
282
  props: {
@@ -304,7 +322,7 @@ export default {
304
322
 
305
323
  // 文件限制
306
324
  accept: { type: String, default: '' },
307
- maxSize: { type: Number, default: 50 * 1024 }, // KB
325
+ maxSize: { type: Number, default: MAX_UPLOAD_SIZE_KB }, // KB,默认最大10GB
308
326
  maxCount: { type: Number, default: 10 },
309
327
  multiple: { type: Boolean, default: true },
310
328
 
@@ -384,21 +402,22 @@ export default {
384
402
  computed: {
385
403
  fileRestrictions() {
386
404
  const allowedExtensions = this.accept ? this.accept.split(',').map(ext => {
387
- const trimmed = ext.trim()
388
- return trimmed.startsWith('.') ? trimmed : '.' + trimmed
389
- }) : null
405
+ const normalized = normalizeFileExtension(ext)
406
+ return normalized ? '.' + normalized : ''
407
+ }).filter(Boolean) : null
390
408
 
391
409
  if (allowedExtensions) {
392
- ['.aqtf', '.hftf', '.gef', '.tb_dg_gef', '.nsxtf', '.sxt2', '.gbq7', '.jmbs'].forEach(ext => {
393
- if (!allowedExtensions.some(item => item.toLowerCase() === ext)) {
394
- allowedExtensions.push(ext)
410
+ DEFAULT_UPLOAD_EXTENSIONS.forEach(ext => {
411
+ if (!allowedExtensions.some(item => normalizeFileExtension(item) === ext)) {
412
+ allowedExtensions.push('.' + ext)
395
413
  }
396
414
  })
397
415
  }
398
416
 
399
417
  return {
400
418
  allowedExtensions,
401
- maxSizeBytes: this.maxSize && this.maxSize > 0 ? this.maxSize * 1024 : null,
419
+ // 业务可以设置更小的限制,但不能突破组件统一的10GB单文件上限
420
+ maxSizeBytes: Math.min(this.maxSize && this.maxSize > 0 ? this.maxSize : MAX_UPLOAD_SIZE_KB, MAX_UPLOAD_SIZE_KB) * 1024,
402
421
  maxFileCount: this.maxCount && this.maxCount > 0 ? this.maxCount : null,
403
422
  multiple: this.multiple,
404
423
  showFileTypeInfo: this.showFileTypeInfo,
@@ -449,7 +468,7 @@ export default {
449
468
  watch: {
450
469
  visible(newVal) {
451
470
  if (newVal) {
452
- this.initializeComponent()
471
+ this.initializeComponent().catch(error => this.showError(error.message))
453
472
  // append-to-body: 弹框显示时将根元素移动到document.body
454
473
  if (this.appendToBody) {
455
474
  this.$nextTick(() => {
@@ -521,15 +540,16 @@ export default {
521
540
  * 判断文件后缀是否允许上传,投标成果类后缀兼容包含 gef 或 sxt 的扩展名。
522
541
  */
523
542
  isAllowedFileExtension(fileExt, allowedExtensions) {
524
- const normalizedExt = (fileExt || '').toLowerCase()
543
+ const normalizedExt = normalizeFileExtension(fileExt)
525
544
  if (!normalizedExt) return false
526
545
 
527
- if (['.aqtf', '.hftf', '.gef', '.tb_dg_gef', '.nsxtf', '.sxt2', '.gbq7', '.jmbs'].includes(normalizedExt)
546
+ if (DEFAULT_UPLOAD_EXTENSIONS.includes(normalizedExt)
528
547
  || normalizedExt.includes('gef') || normalizedExt.includes('sxt')) {
529
548
  return true
530
549
  }
531
550
 
532
- return allowedExtensions.some(ext => ext.toLowerCase() === normalizedExt)
551
+ return Array.isArray(allowedExtensions)
552
+ && allowedExtensions.some(ext => normalizeFileExtension(ext) === normalizedExt)
533
553
  },
534
554
 
535
555
  async initializeComponent() {
@@ -573,17 +593,11 @@ export default {
573
593
 
574
594
  // 初始化Transfer SDK
575
595
  if (window.JrTransferSDK) {
576
- this.sdkInstance = new window.JrTransferSDK({
577
- baseUrl: this.config.baseUrl,
578
- apiToken: this.config.token,
596
+ this.sdkInstance = await createUploadSdk(window.JrTransferSDK, this.config, {
597
+ bucketName: this.bucketName,
598
+ uploadPath: this.uploadPath || this.config.uploadPath
579
599
  })
580
600
 
581
- this.$emit('sdk-initialized', {
582
- success: true,
583
- timestamp: Date.now()
584
- })
585
-
586
- console.log('✅ Transfer SDK初始化成功')
587
601
  } else {
588
602
  throw new Error('JrTransferSDK未加载')
589
603
  }
@@ -592,13 +606,19 @@ export default {
592
606
  if (this.enableCompression) {
593
607
  await this.loadCompressionConfig()
594
608
  }
609
+ this.$emit('sdk-initialized', {
610
+ success: true,
611
+ timestamp: Date.now()
612
+ })
595
613
  } catch (error) {
614
+ this.sdkInstance = null
596
615
  console.error('❌ SDK初始化失败:', error)
597
616
  this.$emit('sdk-initialized', {
598
617
  success: false,
599
618
  error: error.message,
600
619
  timestamp: Date.now()
601
620
  })
621
+ throw error
602
622
  }
603
623
  },
604
624
 
@@ -606,12 +626,12 @@ export default {
606
626
  const baseUrl = this.config.baseUrl
607
627
  const dependencies = [
608
628
  `${baseUrl}/js/aliyun-oss-sdk-6.18.0.min.js`,
609
- `${baseUrl}/js/jr-transfer-sdk.js?v=20260814-jmbs`,
629
+ `${baseUrl}/js/jr-transfer-sdk.js?v=20261014-ext`,
610
630
  `${baseUrl}/js/jszip.min.js`
611
631
  ]
612
632
 
613
633
  // 检查是否已加载
614
- if (window.JrTransferSDK && window.JrTransferSDK.SDK_VERSION === '20260814-jmbs' && window.OSS && window.JSZip) {
634
+ if (window.JrTransferSDK && window.JrTransferSDK.SDK_VERSION === '20261014-ext' && window.OSS && window.JSZip) {
615
635
  return Promise.resolve()
616
636
  }
617
637
 
@@ -643,6 +663,8 @@ export default {
643
663
  },
644
664
 
645
665
  cleanup() {
666
+ this.sdkInstance = null
667
+ this.compressionConfig.loaded = false
646
668
  if (this.autoCloseTimer) {
647
669
  clearTimeout(this.autoCloseTimer)
648
670
  this.autoCloseTimer = null
@@ -686,29 +708,21 @@ export default {
686
708
  }
687
709
 
688
710
  try {
689
- const baseUrl = this.config.baseUrl
690
- let apiUrl = `${baseUrl}/api/sts/compression-config?token=${encodeURIComponent(this.config.token)}`
691
-
692
- // 如果提供了bucketName,添加到请求参数中
693
- if (this.bucketName && this.bucketName.trim() !== '') {
694
- apiUrl += `&bucketName=${encodeURIComponent(this.bucketName.trim())}`
695
- }
696
-
697
- console.log('📡 请求压缩配置:', apiUrl)
698
-
699
- const response = await fetch(apiUrl)
700
-
701
- if (!response.ok) {
702
- throw new Error(`HTTP ${response.status}: ${response.statusText}`)
703
- }
704
-
705
- const result = await response.json()
706
-
707
- if (!result.success) {
708
- throw new Error(result.message || '获取压缩配置失败')
711
+ let config
712
+ if (this.sdkInstance && this.sdkInstance.browserAccessMode) {
713
+ config = await this.sdkInstance.getUploadCompressionConfig()
714
+ } else {
715
+ const baseUrl = this.config.baseUrl
716
+ let apiUrl = `${baseUrl}/api/sts/compression-config?token=${encodeURIComponent(this.config.token)}`
717
+ if (this.bucketName && this.bucketName.trim() !== '') {
718
+ apiUrl += `&bucketName=${encodeURIComponent(this.bucketName.trim())}`
719
+ }
720
+ const response = await fetch(apiUrl)
721
+ if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`)
722
+ const result = await response.json()
723
+ if (!result.success) throw new Error(result.message || '获取压缩配置失败')
724
+ config = result.config
709
725
  }
710
-
711
- const config = result.config
712
726
  this.compressionConfig.level = config.level || 'balanced'
713
727
  this.compressionConfig.mode = config.mode || 'smart'
714
728
  this.compressionConfig.threshold = config.threshold || 10 * 1024 * 1024
@@ -721,6 +735,7 @@ export default {
721
735
  return this.compressionConfig
722
736
 
723
737
  } catch (error) {
738
+ if (typeof this.config.getUploadTicket === 'function' || this.config.browserTicket) throw error
724
739
  console.error('❌ 获取压缩配置失败,使用默认配置:', error)
725
740
  // 使用默认配置
726
741
  this.compressionConfig.enabled = this.enableCompression
@@ -770,6 +785,8 @@ export default {
770
785
  if (!this.enableCompression) {
771
786
  return 'none'
772
787
  }
788
+ // 受限 STS 使用浏览器直传,压缩在当前页面完成。
789
+ if (this.sdkInstance && this.sdkInstance.browserAccessMode) return 'frontend'
773
790
 
774
791
  await this.loadCompressionConfig()
775
792
 
@@ -1610,6 +1627,49 @@ export default {
1610
1627
  'sxt2': 'application/octet-stream',
1611
1628
  'gbq7': 'application/octet-stream',
1612
1629
  'jmbs': 'application/octet-stream',
1630
+ 'ujyzbx': 'application/octet-stream',
1631
+ 'zkzf': 'application/octet-stream',
1632
+ 'nzktf': 'application/octet-stream',
1633
+ 'zgzs': 'application/octet-stream',
1634
+ 'zgzf': 'application/octet-stream',
1635
+ 'zgsf': 'application/octet-stream',
1636
+ 'zgtf': 'application/octet-stream',
1637
+ 'zgcs': 'application/octet-stream',
1638
+ 'zgcf': 'application/octet-stream',
1639
+ 'tbsx': 'application/octet-stream',
1640
+ 'sgef': 'application/octet-stream',
1641
+ 'czr': 'application/octet-stream',
1642
+ 'zytf': 'application/octet-stream',
1643
+ 'nzjy': 'application/octet-stream',
1644
+ 'zsf': 'application/octet-stream',
1645
+ 'gscs': 'application/octet-stream',
1646
+ 'gscf': 'application/octet-stream',
1647
+ 'zbxs': 'application/octet-stream',
1648
+ 'zbwj': 'application/octet-stream',
1649
+ 'zyzf': 'application/octet-stream',
1650
+ 'gszs': 'application/octet-stream',
1651
+ 'gszf': 'application/octet-stream',
1652
+ 'zbjy': 'application/octet-stream',
1653
+ 'zbsx': 'application/octet-stream',
1654
+ 'gctb': 'application/octet-stream',
1655
+ 'fwtb': 'application/octet-stream',
1656
+ 'nzytf': 'application/octet-stream',
1657
+ 'mtbjy': 'application/octet-stream',
1658
+ 'gstf': 'application/octet-stream',
1659
+ 'dxtf': 'application/octet-stream',
1660
+ 'gssf': 'application/octet-stream',
1661
+ 'qbcg': 'application/octet-stream',
1662
+ 'jtb4': 'application/octet-stream',
1663
+ 'jzb4': 'application/octet-stream',
1664
+ 'xml': 'application/xml',
1665
+ 'ydbx': 'application/octet-stream',
1666
+ 'ydjc': 'application/octet-stream',
1667
+ 'sxzb': 'application/octet-stream',
1668
+ 'sxtb': 'application/octet-stream',
1669
+ 'sxxj': 'application/octet-stream',
1670
+ 'hebzbx': 'application/octet-stream',
1671
+ 'hebkzjx': 'application/octet-stream',
1672
+ 'hebtbx': 'application/octet-stream',
1613
1673
  'ppt': 'application/vnd.ms-powerpoint',
1614
1674
  'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
1615
1675
  'txt': 'text/plain',
@@ -2027,6 +2087,10 @@ export default {
2027
2087
  })
2028
2088
 
2029
2089
  try {
2090
+ if (typeof this.config.getUploadTicket === 'function'
2091
+ && this.sdkInstance.browserExpiresAt <= Date.now() + 30000) {
2092
+ await this.initializeSDK()
2093
+ }
2030
2094
  // 决定压缩策略
2031
2095
  const compressionStrategy = await this.determineCompressionStrategy(fileObj.file)
2032
2096
  let fileToUpload = fileObj.file
@@ -1,4 +1,5 @@
1
1
  import JrUploadModal from './JrUploadModal.vue'
2
2
 
3
3
  export { JrUploadModal }
4
+ export { getAuthorizedFileUrl } from '../../shared/browser-access'
4
5
  export default JrUploadModal
@@ -257,10 +257,28 @@
257
257
  </div>
258
258
  </template>
259
259
 
260
- <script>
261
- import { ref, reactive, computed, watch, onMounted, onBeforeUnmount, defineEmits, defineProps, nextTick, getCurrentInstance } from 'vue'
262
-
263
- export default {
260
+ <script>
261
+ import { ref, reactive, computed, watch, onMounted, onBeforeUnmount, defineEmits, defineProps, nextTick, getCurrentInstance } from 'vue'
262
+ import { createUploadSdk } from '../../shared/browser-access'
263
+
264
+ // 组件统一允许的单文件最大值,maxSize 对外单位保持为 KB
265
+ const MAX_UPLOAD_SIZE_KB = 10 * 1024 * 1024
266
+
267
+ // 组件内置业务后缀白名单,统一使用不带点号的小写形式。
268
+ const DEFAULT_UPLOAD_EXTENSIONS = [
269
+ 'aqtf', 'hftf', 'gef', 'tb_dg_gef', 'nsxtf', 'sxt2', 'gbq7', 'jmbs',
270
+ 'ujyzbx', 'zkzf', 'nzktf', 'zgzs', 'zgzf', 'zgsf', 'zgtf', 'zgcs', 'zgcf', 'tbsx', 'sgef', 'czr', 'zytf',
271
+ 'nzjy', 'zsf', 'gscs', 'gscf', 'zbxs', 'zbwj', 'zyzf', 'gszs', 'gszf', 'zbjy',
272
+ 'zbsx', 'gctb', 'fwtb', 'nzytf', 'mtbjy', 'gstf', 'dxtf', 'gssf',
273
+ 'qbcg', 'jtb4', 'jzb4', 'xml', 'ydbx', 'ydjc', 'sxzb', 'sxtb', 'sxxj',
274
+ 'hebzbx', 'hebkzjx', 'hebtbx'
275
+ ]
276
+
277
+ // 统一处理前导点、空格和大小写,确保 accept 配置与真实文件后缀可直接比较。
278
+ const normalizeFileExtension = (value) =>
279
+ String(value || '').trim().toLowerCase().replace(/^\.+/, '')
280
+
281
+ export default {
264
282
  name: 'JrUploadModalVue3',
265
283
 
266
284
  props: {
@@ -306,7 +324,7 @@ export default {
306
324
 
307
325
  // 文件限制
308
326
  accept: { type: String, default: '' },
309
- maxSize: { type: Number, default: 50 * 1024 }, // KB
327
+ maxSize: { type: Number, default: MAX_UPLOAD_SIZE_KB }, // KB,默认最大10GB
310
328
  maxCount: { type: Number, default: 10 },
311
329
  multiple: { type: Boolean, default: true },
312
330
 
@@ -406,21 +424,22 @@ export default {
406
424
  // 计算属性
407
425
  const fileRestrictions = computed(() => {
408
426
  const allowedExtensions = props.accept ? props.accept.split(',').map(ext => {
409
- const trimmed = ext.trim()
410
- return trimmed.startsWith('.') ? trimmed : '.' + trimmed
411
- }) : null
427
+ const normalized = normalizeFileExtension(ext)
428
+ return normalized ? '.' + normalized : ''
429
+ }).filter(Boolean) : null
412
430
 
413
431
  if (allowedExtensions) {
414
- ['.aqtf', '.hftf', '.gef', '.tb_dg_gef', '.nsxtf', '.sxt2', '.gbq7', '.jmbs'].forEach(ext => {
415
- if (!allowedExtensions.some(item => item.toLowerCase() === ext)) {
416
- allowedExtensions.push(ext)
432
+ DEFAULT_UPLOAD_EXTENSIONS.forEach(ext => {
433
+ if (!allowedExtensions.some(item => normalizeFileExtension(item) === ext)) {
434
+ allowedExtensions.push('.' + ext)
417
435
  }
418
436
  })
419
437
  }
420
438
 
421
439
  return {
422
440
  allowedExtensions,
423
- maxSizeBytes: props.maxSize && props.maxSize > 0 ? props.maxSize * 1024 : null,
441
+ // 业务可以设置更小的限制,但不能突破组件统一的10GB单文件上限
442
+ maxSizeBytes: Math.min(props.maxSize && props.maxSize > 0 ? props.maxSize : MAX_UPLOAD_SIZE_KB, MAX_UPLOAD_SIZE_KB) * 1024,
424
443
  maxFileCount: props.maxCount && props.maxCount > 0 ? props.maxCount : null,
425
444
  multiple: props.multiple,
426
445
  showFileTypeInfo: props.showFileTypeInfo,
@@ -470,7 +489,7 @@ export default {
470
489
  // watch监听器
471
490
  watch(() => props.visible, async (newVal) => {
472
491
  if (newVal) {
473
- await initializeComponent()
492
+ await initializeComponent().catch(error => showError(error.message))
474
493
  // append-to-body: 弹框显示时将根元素移动到document.body
475
494
  if (props.appendToBody && instance && instance.vnode.el) {
476
495
  await nextTick()
@@ -544,15 +563,16 @@ export default {
544
563
  * 判断文件后缀是否允许上传,投标成果类后缀兼容包含 gef 或 sxt 的扩展名。
545
564
  */
546
565
  const isAllowedFileExtension = (fileExt, allowedExtensions) => {
547
- const normalizedExt = (fileExt || '').toLowerCase()
566
+ const normalizedExt = normalizeFileExtension(fileExt)
548
567
  if (!normalizedExt) return false
549
568
 
550
- if (['.aqtf', '.hftf', '.gef', '.tb_dg_gef', '.nsxtf', '.sxt2', '.gbq7', '.jmbs'].includes(normalizedExt)
569
+ if (DEFAULT_UPLOAD_EXTENSIONS.includes(normalizedExt)
551
570
  || normalizedExt.includes('gef') || normalizedExt.includes('sxt')) {
552
571
  return true
553
572
  }
554
573
 
555
- return allowedExtensions.some(ext => ext.toLowerCase() === normalizedExt)
574
+ return Array.isArray(allowedExtensions)
575
+ && allowedExtensions.some(ext => normalizeFileExtension(ext) === normalizedExt)
556
576
  }
557
577
 
558
578
  const initializeComponent = async () => {
@@ -596,17 +616,11 @@ export default {
596
616
 
597
617
  // 初始化Transfer SDK
598
618
  if (window.JrTransferSDK) {
599
- sdkInstance.value = new window.JrTransferSDK({
600
- baseUrl: props.config.baseUrl,
601
- apiToken: props.config.token,
602
- })
603
-
604
- emit('sdk-initialized', {
605
- success: true,
606
- timestamp: Date.now()
619
+ sdkInstance.value = await createUploadSdk(window.JrTransferSDK, props.config, {
620
+ bucketName: props.bucketName,
621
+ uploadPath: props.uploadPath || props.config.uploadPath
607
622
  })
608
623
 
609
- console.log('✅ Transfer SDK初始化成功')
610
624
  } else {
611
625
  throw new Error('JrTransferSDK未加载')
612
626
  }
@@ -615,13 +629,19 @@ export default {
615
629
  if (props.enableCompression) {
616
630
  await loadCompressionConfig()
617
631
  }
632
+ emit('sdk-initialized', {
633
+ success: true,
634
+ timestamp: Date.now()
635
+ })
618
636
  } catch (error) {
637
+ sdkInstance.value = null
619
638
  console.error('❌ SDK初始化失败:', error)
620
639
  emit('sdk-initialized', {
621
640
  success: false,
622
641
  error: error.message,
623
642
  timestamp: Date.now()
624
643
  })
644
+ throw error
625
645
  }
626
646
  }
627
647
 
@@ -629,12 +649,12 @@ export default {
629
649
  const baseUrl = props.config.baseUrl
630
650
  const dependencies = [
631
651
  `${baseUrl}/js/aliyun-oss-sdk-6.18.0.min.js`,
632
- `${baseUrl}/js/jr-transfer-sdk.js?v=20260814-jmbs`,
652
+ `${baseUrl}/js/jr-transfer-sdk.js?v=20261014-ext`,
633
653
  `${baseUrl}/js/jszip.min.js`
634
654
  ]
635
655
 
636
656
  // 检查是否已加载
637
- if (window.JrTransferSDK && window.JrTransferSDK.SDK_VERSION === '20260814-jmbs' && window.OSS && window.JSZip) {
657
+ if (window.JrTransferSDK && window.JrTransferSDK.SDK_VERSION === '20261014-ext' && window.OSS && window.JSZip) {
638
658
  return Promise.resolve()
639
659
  }
640
660
 
@@ -666,6 +686,8 @@ export default {
666
686
  }
667
687
 
668
688
  const cleanup = () => {
689
+ sdkInstance.value = null
690
+ compressionConfig.loaded = false
669
691
  if (autoCloseTimer.value) {
670
692
  clearTimeout(autoCloseTimer.value)
671
693
  autoCloseTimer.value = null
@@ -711,29 +733,21 @@ export default {
711
733
  }
712
734
 
713
735
  try {
714
- const baseUrl = props.config.baseUrl
715
- let apiUrl = `${baseUrl}/api/sts/compression-config?token=${encodeURIComponent(props.config.token)}`
716
-
717
- // 如果提供了bucketName,添加到请求参数中
718
- if (props.bucketName && props.bucketName.trim() !== '') {
719
- apiUrl += `&bucketName=${encodeURIComponent(props.bucketName.trim())}`
720
- }
721
-
722
- console.log('📡 请求压缩配置:', apiUrl)
723
-
724
- const response = await fetch(apiUrl)
725
-
726
- if (!response.ok) {
727
- throw new Error(`HTTP ${response.status}: ${response.statusText}`)
728
- }
729
-
730
- const result = await response.json()
731
-
732
- if (!result.success) {
733
- throw new Error(result.message || '获取压缩配置失败')
736
+ let config
737
+ if (sdkInstance.value && sdkInstance.value.browserAccessMode) {
738
+ config = await sdkInstance.value.getUploadCompressionConfig()
739
+ } else {
740
+ const baseUrl = props.config.baseUrl
741
+ let apiUrl = `${baseUrl}/api/sts/compression-config?token=${encodeURIComponent(props.config.token)}`
742
+ if (props.bucketName && props.bucketName.trim() !== '') {
743
+ apiUrl += `&bucketName=${encodeURIComponent(props.bucketName.trim())}`
744
+ }
745
+ const response = await fetch(apiUrl)
746
+ if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`)
747
+ const result = await response.json()
748
+ if (!result.success) throw new Error(result.message || '获取压缩配置失败')
749
+ config = result.config
734
750
  }
735
-
736
- const config = result.config
737
751
  compressionConfig.level = config.level || 'balanced'
738
752
  compressionConfig.mode = config.mode || 'smart'
739
753
  compressionConfig.threshold = config.threshold || 10 * 1024 * 1024
@@ -746,6 +760,7 @@ export default {
746
760
  return compressionConfig
747
761
 
748
762
  } catch (error) {
763
+ if (typeof props.config.getUploadTicket === 'function' || props.config.browserTicket) throw error
749
764
  console.error('❌ 获取压缩配置失败,使用默认配置:', error)
750
765
  // 使用默认配置
751
766
  compressionConfig.enabled = props.enableCompression
@@ -795,6 +810,8 @@ export default {
795
810
  if (!props.enableCompression) {
796
811
  return 'none'
797
812
  }
813
+ // 受限 STS 使用浏览器直传,压缩在当前页面完成。
814
+ if (sdkInstance.value && sdkInstance.value.browserAccessMode) return 'frontend'
798
815
 
799
816
  await loadCompressionConfig()
800
817
 
@@ -1635,6 +1652,49 @@ export default {
1635
1652
  'sxt2': 'application/octet-stream',
1636
1653
  'gbq7': 'application/octet-stream',
1637
1654
  'jmbs': 'application/octet-stream',
1655
+ 'ujyzbx': 'application/octet-stream',
1656
+ 'zkzf': 'application/octet-stream',
1657
+ 'nzktf': 'application/octet-stream',
1658
+ 'zgzs': 'application/octet-stream',
1659
+ 'zgzf': 'application/octet-stream',
1660
+ 'zgsf': 'application/octet-stream',
1661
+ 'zgtf': 'application/octet-stream',
1662
+ 'zgcs': 'application/octet-stream',
1663
+ 'zgcf': 'application/octet-stream',
1664
+ 'tbsx': 'application/octet-stream',
1665
+ 'sgef': 'application/octet-stream',
1666
+ 'czr': 'application/octet-stream',
1667
+ 'zytf': 'application/octet-stream',
1668
+ 'nzjy': 'application/octet-stream',
1669
+ 'zsf': 'application/octet-stream',
1670
+ 'gscs': 'application/octet-stream',
1671
+ 'gscf': 'application/octet-stream',
1672
+ 'zbxs': 'application/octet-stream',
1673
+ 'zbwj': 'application/octet-stream',
1674
+ 'zyzf': 'application/octet-stream',
1675
+ 'gszs': 'application/octet-stream',
1676
+ 'gszf': 'application/octet-stream',
1677
+ 'zbjy': 'application/octet-stream',
1678
+ 'zbsx': 'application/octet-stream',
1679
+ 'gctb': 'application/octet-stream',
1680
+ 'fwtb': 'application/octet-stream',
1681
+ 'nzytf': 'application/octet-stream',
1682
+ 'mtbjy': 'application/octet-stream',
1683
+ 'gstf': 'application/octet-stream',
1684
+ 'dxtf': 'application/octet-stream',
1685
+ 'gssf': 'application/octet-stream',
1686
+ 'qbcg': 'application/octet-stream',
1687
+ 'jtb4': 'application/octet-stream',
1688
+ 'jzb4': 'application/octet-stream',
1689
+ 'xml': 'application/xml',
1690
+ 'ydbx': 'application/octet-stream',
1691
+ 'ydjc': 'application/octet-stream',
1692
+ 'sxzb': 'application/octet-stream',
1693
+ 'sxtb': 'application/octet-stream',
1694
+ 'sxxj': 'application/octet-stream',
1695
+ 'hebzbx': 'application/octet-stream',
1696
+ 'hebkzjx': 'application/octet-stream',
1697
+ 'hebtbx': 'application/octet-stream',
1638
1698
  'ppt': 'application/vnd.ms-powerpoint',
1639
1699
  'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
1640
1700
  'txt': 'text/plain',
@@ -2030,9 +2090,9 @@ export default {
2030
2090
  } finally {
2031
2091
  isUploading.value = false
2032
2092
  }
2033
- },
2034
-
2035
- const uploadSingleFile = async (fileObj) => {
2093
+ }
2094
+
2095
+ const uploadSingleFile = async (fileObj) => {
2036
2096
  console.log('📤 上传文件:', fileObj.name)
2037
2097
 
2038
2098
  if (!sdkInstance.value) {
@@ -2052,6 +2112,10 @@ export default {
2052
2112
  })
2053
2113
 
2054
2114
  try {
2115
+ if (typeof props.config.getUploadTicket === 'function'
2116
+ && sdkInstance.value.browserExpiresAt <= Date.now() + 30000) {
2117
+ await initializeSDK()
2118
+ }
2055
2119
  // 决定压缩策略
2056
2120
  const compressionStrategy = await determineCompressionStrategy(fileObj.file)
2057
2121
  let fileToUpload = fileObj.file
@@ -2224,9 +2288,9 @@ export default {
2224
2288
  }, 8000)
2225
2289
  }
2226
2290
  }
2227
- },
2228
-
2229
- // 文件压缩判断
2291
+ }
2292
+
2293
+ // 文件压缩判断
2230
2294
  const shouldCompressFile = (file) => {
2231
2295
  if (!props.enableCompression) return false
2232
2296
 
@@ -1,4 +1,5 @@
1
1
  import JrUploadModalVue3 from './JrUploadModalVUE3.vue'
2
2
 
3
3
  export { JrUploadModalVue3 }
4
+ export { getAuthorizedFileUrl } from '../../shared/browser-access'
4
5
  export default JrUploadModalVue3
package/vue2/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // vue2 入口文件 - 转发到实际的源文件
2
- export { default, JrUploadModal } from '../packages/vue2/src/index.js'
2
+ export { default, JrUploadModal, getAuthorizedFileUrl } from '../packages/vue2/src/index.js'
package/vue3/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // vue3 入口文件 - 转发到实际的源文件
2
- export { default, JrUploadModalVue3 } from '../packages/vue3/src/index.js'
2
+ export { default, JrUploadModalVue3, getAuthorizedFileUrl } from '../packages/vue3/src/index.js'