@jr-public/jr-upload-ui 1.0.6 → 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 +45 -1
- package/package.json +2 -1
- package/packages/shared/browser-access.js +57 -0
- package/packages/vue2/src/JrUploadModal.vue +103 -43
- package/packages/vue2/src/index.js +1 -0
- package/packages/vue3/src/JrUploadModalVUE3.vue +109 -49
- package/packages/vue3/src/index.js +1 -0
- package/vue2/index.js +1 -1
- package/vue3/index.js +1 -1
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
|
-
|
|
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
|
|
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
|
+
}
|
|
@@ -258,9 +258,24 @@
|
|
|
258
258
|
</template>
|
|
259
259
|
|
|
260
260
|
<script>
|
|
261
|
+
import { createUploadSdk } from '../../shared/browser-access'
|
|
261
262
|
// 组件统一允许的单文件最大值,maxSize 对外单位保持为 KB
|
|
262
263
|
const MAX_UPLOAD_SIZE_KB = 10 * 1024 * 1024
|
|
263
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
|
+
|
|
264
279
|
export default {
|
|
265
280
|
name: 'JrUploadModal',
|
|
266
281
|
|
|
@@ -387,14 +402,14 @@ export default {
|
|
|
387
402
|
computed: {
|
|
388
403
|
fileRestrictions() {
|
|
389
404
|
const allowedExtensions = this.accept ? this.accept.split(',').map(ext => {
|
|
390
|
-
const
|
|
391
|
-
return
|
|
392
|
-
}) : null
|
|
405
|
+
const normalized = normalizeFileExtension(ext)
|
|
406
|
+
return normalized ? '.' + normalized : ''
|
|
407
|
+
}).filter(Boolean) : null
|
|
393
408
|
|
|
394
409
|
if (allowedExtensions) {
|
|
395
|
-
|
|
396
|
-
if (!allowedExtensions.some(item => item
|
|
397
|
-
allowedExtensions.push(ext)
|
|
410
|
+
DEFAULT_UPLOAD_EXTENSIONS.forEach(ext => {
|
|
411
|
+
if (!allowedExtensions.some(item => normalizeFileExtension(item) === ext)) {
|
|
412
|
+
allowedExtensions.push('.' + ext)
|
|
398
413
|
}
|
|
399
414
|
})
|
|
400
415
|
}
|
|
@@ -453,7 +468,7 @@ export default {
|
|
|
453
468
|
watch: {
|
|
454
469
|
visible(newVal) {
|
|
455
470
|
if (newVal) {
|
|
456
|
-
this.initializeComponent()
|
|
471
|
+
this.initializeComponent().catch(error => this.showError(error.message))
|
|
457
472
|
// append-to-body: 弹框显示时将根元素移动到document.body
|
|
458
473
|
if (this.appendToBody) {
|
|
459
474
|
this.$nextTick(() => {
|
|
@@ -525,15 +540,16 @@ export default {
|
|
|
525
540
|
* 判断文件后缀是否允许上传,投标成果类后缀兼容包含 gef 或 sxt 的扩展名。
|
|
526
541
|
*/
|
|
527
542
|
isAllowedFileExtension(fileExt, allowedExtensions) {
|
|
528
|
-
const normalizedExt = (fileExt
|
|
543
|
+
const normalizedExt = normalizeFileExtension(fileExt)
|
|
529
544
|
if (!normalizedExt) return false
|
|
530
545
|
|
|
531
|
-
if (
|
|
546
|
+
if (DEFAULT_UPLOAD_EXTENSIONS.includes(normalizedExt)
|
|
532
547
|
|| normalizedExt.includes('gef') || normalizedExt.includes('sxt')) {
|
|
533
548
|
return true
|
|
534
549
|
}
|
|
535
550
|
|
|
536
|
-
return
|
|
551
|
+
return Array.isArray(allowedExtensions)
|
|
552
|
+
&& allowedExtensions.some(ext => normalizeFileExtension(ext) === normalizedExt)
|
|
537
553
|
},
|
|
538
554
|
|
|
539
555
|
async initializeComponent() {
|
|
@@ -577,17 +593,11 @@ export default {
|
|
|
577
593
|
|
|
578
594
|
// 初始化Transfer SDK
|
|
579
595
|
if (window.JrTransferSDK) {
|
|
580
|
-
this.sdkInstance =
|
|
581
|
-
|
|
582
|
-
|
|
596
|
+
this.sdkInstance = await createUploadSdk(window.JrTransferSDK, this.config, {
|
|
597
|
+
bucketName: this.bucketName,
|
|
598
|
+
uploadPath: this.uploadPath || this.config.uploadPath
|
|
583
599
|
})
|
|
584
600
|
|
|
585
|
-
this.$emit('sdk-initialized', {
|
|
586
|
-
success: true,
|
|
587
|
-
timestamp: Date.now()
|
|
588
|
-
})
|
|
589
|
-
|
|
590
|
-
console.log('✅ Transfer SDK初始化成功')
|
|
591
601
|
} else {
|
|
592
602
|
throw new Error('JrTransferSDK未加载')
|
|
593
603
|
}
|
|
@@ -596,13 +606,19 @@ export default {
|
|
|
596
606
|
if (this.enableCompression) {
|
|
597
607
|
await this.loadCompressionConfig()
|
|
598
608
|
}
|
|
609
|
+
this.$emit('sdk-initialized', {
|
|
610
|
+
success: true,
|
|
611
|
+
timestamp: Date.now()
|
|
612
|
+
})
|
|
599
613
|
} catch (error) {
|
|
614
|
+
this.sdkInstance = null
|
|
600
615
|
console.error('❌ SDK初始化失败:', error)
|
|
601
616
|
this.$emit('sdk-initialized', {
|
|
602
617
|
success: false,
|
|
603
618
|
error: error.message,
|
|
604
619
|
timestamp: Date.now()
|
|
605
620
|
})
|
|
621
|
+
throw error
|
|
606
622
|
}
|
|
607
623
|
},
|
|
608
624
|
|
|
@@ -610,12 +626,12 @@ export default {
|
|
|
610
626
|
const baseUrl = this.config.baseUrl
|
|
611
627
|
const dependencies = [
|
|
612
628
|
`${baseUrl}/js/aliyun-oss-sdk-6.18.0.min.js`,
|
|
613
|
-
`${baseUrl}/js/jr-transfer-sdk.js?v=
|
|
629
|
+
`${baseUrl}/js/jr-transfer-sdk.js?v=20261014-ext`,
|
|
614
630
|
`${baseUrl}/js/jszip.min.js`
|
|
615
631
|
]
|
|
616
632
|
|
|
617
633
|
// 检查是否已加载
|
|
618
|
-
if (window.JrTransferSDK && window.JrTransferSDK.SDK_VERSION === '
|
|
634
|
+
if (window.JrTransferSDK && window.JrTransferSDK.SDK_VERSION === '20261014-ext' && window.OSS && window.JSZip) {
|
|
619
635
|
return Promise.resolve()
|
|
620
636
|
}
|
|
621
637
|
|
|
@@ -647,6 +663,8 @@ export default {
|
|
|
647
663
|
},
|
|
648
664
|
|
|
649
665
|
cleanup() {
|
|
666
|
+
this.sdkInstance = null
|
|
667
|
+
this.compressionConfig.loaded = false
|
|
650
668
|
if (this.autoCloseTimer) {
|
|
651
669
|
clearTimeout(this.autoCloseTimer)
|
|
652
670
|
this.autoCloseTimer = null
|
|
@@ -690,29 +708,21 @@ export default {
|
|
|
690
708
|
}
|
|
691
709
|
|
|
692
710
|
try {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
apiUrl
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
const result = await response.json()
|
|
710
|
-
|
|
711
|
-
if (!result.success) {
|
|
712
|
-
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
|
|
713
725
|
}
|
|
714
|
-
|
|
715
|
-
const config = result.config
|
|
716
726
|
this.compressionConfig.level = config.level || 'balanced'
|
|
717
727
|
this.compressionConfig.mode = config.mode || 'smart'
|
|
718
728
|
this.compressionConfig.threshold = config.threshold || 10 * 1024 * 1024
|
|
@@ -725,6 +735,7 @@ export default {
|
|
|
725
735
|
return this.compressionConfig
|
|
726
736
|
|
|
727
737
|
} catch (error) {
|
|
738
|
+
if (typeof this.config.getUploadTicket === 'function' || this.config.browserTicket) throw error
|
|
728
739
|
console.error('❌ 获取压缩配置失败,使用默认配置:', error)
|
|
729
740
|
// 使用默认配置
|
|
730
741
|
this.compressionConfig.enabled = this.enableCompression
|
|
@@ -774,6 +785,8 @@ export default {
|
|
|
774
785
|
if (!this.enableCompression) {
|
|
775
786
|
return 'none'
|
|
776
787
|
}
|
|
788
|
+
// 受限 STS 使用浏览器直传,压缩在当前页面完成。
|
|
789
|
+
if (this.sdkInstance && this.sdkInstance.browserAccessMode) return 'frontend'
|
|
777
790
|
|
|
778
791
|
await this.loadCompressionConfig()
|
|
779
792
|
|
|
@@ -1614,6 +1627,49 @@ export default {
|
|
|
1614
1627
|
'sxt2': 'application/octet-stream',
|
|
1615
1628
|
'gbq7': 'application/octet-stream',
|
|
1616
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',
|
|
1617
1673
|
'ppt': 'application/vnd.ms-powerpoint',
|
|
1618
1674
|
'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
1619
1675
|
'txt': 'text/plain',
|
|
@@ -2031,6 +2087,10 @@ export default {
|
|
|
2031
2087
|
})
|
|
2032
2088
|
|
|
2033
2089
|
try {
|
|
2090
|
+
if (typeof this.config.getUploadTicket === 'function'
|
|
2091
|
+
&& this.sdkInstance.browserExpiresAt <= Date.now() + 30000) {
|
|
2092
|
+
await this.initializeSDK()
|
|
2093
|
+
}
|
|
2034
2094
|
// 决定压缩策略
|
|
2035
2095
|
const compressionStrategy = await this.determineCompressionStrategy(fileObj.file)
|
|
2036
2096
|
let fileToUpload = fileObj.file
|
|
@@ -259,10 +259,25 @@
|
|
|
259
259
|
|
|
260
260
|
<script>
|
|
261
261
|
import { ref, reactive, computed, watch, onMounted, onBeforeUnmount, defineEmits, defineProps, nextTick, getCurrentInstance } from 'vue'
|
|
262
|
+
import { createUploadSdk } from '../../shared/browser-access'
|
|
262
263
|
|
|
263
264
|
// 组件统一允许的单文件最大值,maxSize 对外单位保持为 KB
|
|
264
265
|
const MAX_UPLOAD_SIZE_KB = 10 * 1024 * 1024
|
|
265
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
|
+
|
|
266
281
|
export default {
|
|
267
282
|
name: 'JrUploadModalVue3',
|
|
268
283
|
|
|
@@ -409,14 +424,14 @@ export default {
|
|
|
409
424
|
// 计算属性
|
|
410
425
|
const fileRestrictions = computed(() => {
|
|
411
426
|
const allowedExtensions = props.accept ? props.accept.split(',').map(ext => {
|
|
412
|
-
const
|
|
413
|
-
return
|
|
414
|
-
}) : null
|
|
427
|
+
const normalized = normalizeFileExtension(ext)
|
|
428
|
+
return normalized ? '.' + normalized : ''
|
|
429
|
+
}).filter(Boolean) : null
|
|
415
430
|
|
|
416
431
|
if (allowedExtensions) {
|
|
417
|
-
|
|
418
|
-
if (!allowedExtensions.some(item => item
|
|
419
|
-
allowedExtensions.push(ext)
|
|
432
|
+
DEFAULT_UPLOAD_EXTENSIONS.forEach(ext => {
|
|
433
|
+
if (!allowedExtensions.some(item => normalizeFileExtension(item) === ext)) {
|
|
434
|
+
allowedExtensions.push('.' + ext)
|
|
420
435
|
}
|
|
421
436
|
})
|
|
422
437
|
}
|
|
@@ -474,7 +489,7 @@ export default {
|
|
|
474
489
|
// watch监听器
|
|
475
490
|
watch(() => props.visible, async (newVal) => {
|
|
476
491
|
if (newVal) {
|
|
477
|
-
await initializeComponent()
|
|
492
|
+
await initializeComponent().catch(error => showError(error.message))
|
|
478
493
|
// append-to-body: 弹框显示时将根元素移动到document.body
|
|
479
494
|
if (props.appendToBody && instance && instance.vnode.el) {
|
|
480
495
|
await nextTick()
|
|
@@ -548,15 +563,16 @@ export default {
|
|
|
548
563
|
* 判断文件后缀是否允许上传,投标成果类后缀兼容包含 gef 或 sxt 的扩展名。
|
|
549
564
|
*/
|
|
550
565
|
const isAllowedFileExtension = (fileExt, allowedExtensions) => {
|
|
551
|
-
const normalizedExt = (fileExt
|
|
566
|
+
const normalizedExt = normalizeFileExtension(fileExt)
|
|
552
567
|
if (!normalizedExt) return false
|
|
553
568
|
|
|
554
|
-
if (
|
|
569
|
+
if (DEFAULT_UPLOAD_EXTENSIONS.includes(normalizedExt)
|
|
555
570
|
|| normalizedExt.includes('gef') || normalizedExt.includes('sxt')) {
|
|
556
571
|
return true
|
|
557
572
|
}
|
|
558
573
|
|
|
559
|
-
return
|
|
574
|
+
return Array.isArray(allowedExtensions)
|
|
575
|
+
&& allowedExtensions.some(ext => normalizeFileExtension(ext) === normalizedExt)
|
|
560
576
|
}
|
|
561
577
|
|
|
562
578
|
const initializeComponent = async () => {
|
|
@@ -600,17 +616,11 @@ export default {
|
|
|
600
616
|
|
|
601
617
|
// 初始化Transfer SDK
|
|
602
618
|
if (window.JrTransferSDK) {
|
|
603
|
-
sdkInstance.value =
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
})
|
|
607
|
-
|
|
608
|
-
emit('sdk-initialized', {
|
|
609
|
-
success: true,
|
|
610
|
-
timestamp: Date.now()
|
|
619
|
+
sdkInstance.value = await createUploadSdk(window.JrTransferSDK, props.config, {
|
|
620
|
+
bucketName: props.bucketName,
|
|
621
|
+
uploadPath: props.uploadPath || props.config.uploadPath
|
|
611
622
|
})
|
|
612
623
|
|
|
613
|
-
console.log('✅ Transfer SDK初始化成功')
|
|
614
624
|
} else {
|
|
615
625
|
throw new Error('JrTransferSDK未加载')
|
|
616
626
|
}
|
|
@@ -619,13 +629,19 @@ export default {
|
|
|
619
629
|
if (props.enableCompression) {
|
|
620
630
|
await loadCompressionConfig()
|
|
621
631
|
}
|
|
632
|
+
emit('sdk-initialized', {
|
|
633
|
+
success: true,
|
|
634
|
+
timestamp: Date.now()
|
|
635
|
+
})
|
|
622
636
|
} catch (error) {
|
|
637
|
+
sdkInstance.value = null
|
|
623
638
|
console.error('❌ SDK初始化失败:', error)
|
|
624
639
|
emit('sdk-initialized', {
|
|
625
640
|
success: false,
|
|
626
641
|
error: error.message,
|
|
627
642
|
timestamp: Date.now()
|
|
628
643
|
})
|
|
644
|
+
throw error
|
|
629
645
|
}
|
|
630
646
|
}
|
|
631
647
|
|
|
@@ -633,12 +649,12 @@ export default {
|
|
|
633
649
|
const baseUrl = props.config.baseUrl
|
|
634
650
|
const dependencies = [
|
|
635
651
|
`${baseUrl}/js/aliyun-oss-sdk-6.18.0.min.js`,
|
|
636
|
-
`${baseUrl}/js/jr-transfer-sdk.js?v=
|
|
652
|
+
`${baseUrl}/js/jr-transfer-sdk.js?v=20261014-ext`,
|
|
637
653
|
`${baseUrl}/js/jszip.min.js`
|
|
638
654
|
]
|
|
639
655
|
|
|
640
656
|
// 检查是否已加载
|
|
641
|
-
if (window.JrTransferSDK && window.JrTransferSDK.SDK_VERSION === '
|
|
657
|
+
if (window.JrTransferSDK && window.JrTransferSDK.SDK_VERSION === '20261014-ext' && window.OSS && window.JSZip) {
|
|
642
658
|
return Promise.resolve()
|
|
643
659
|
}
|
|
644
660
|
|
|
@@ -670,6 +686,8 @@ export default {
|
|
|
670
686
|
}
|
|
671
687
|
|
|
672
688
|
const cleanup = () => {
|
|
689
|
+
sdkInstance.value = null
|
|
690
|
+
compressionConfig.loaded = false
|
|
673
691
|
if (autoCloseTimer.value) {
|
|
674
692
|
clearTimeout(autoCloseTimer.value)
|
|
675
693
|
autoCloseTimer.value = null
|
|
@@ -715,29 +733,21 @@ export default {
|
|
|
715
733
|
}
|
|
716
734
|
|
|
717
735
|
try {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
apiUrl
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
const result = await response.json()
|
|
735
|
-
|
|
736
|
-
if (!result.success) {
|
|
737
|
-
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
|
|
738
750
|
}
|
|
739
|
-
|
|
740
|
-
const config = result.config
|
|
741
751
|
compressionConfig.level = config.level || 'balanced'
|
|
742
752
|
compressionConfig.mode = config.mode || 'smart'
|
|
743
753
|
compressionConfig.threshold = config.threshold || 10 * 1024 * 1024
|
|
@@ -750,6 +760,7 @@ export default {
|
|
|
750
760
|
return compressionConfig
|
|
751
761
|
|
|
752
762
|
} catch (error) {
|
|
763
|
+
if (typeof props.config.getUploadTicket === 'function' || props.config.browserTicket) throw error
|
|
753
764
|
console.error('❌ 获取压缩配置失败,使用默认配置:', error)
|
|
754
765
|
// 使用默认配置
|
|
755
766
|
compressionConfig.enabled = props.enableCompression
|
|
@@ -799,6 +810,8 @@ export default {
|
|
|
799
810
|
if (!props.enableCompression) {
|
|
800
811
|
return 'none'
|
|
801
812
|
}
|
|
813
|
+
// 受限 STS 使用浏览器直传,压缩在当前页面完成。
|
|
814
|
+
if (sdkInstance.value && sdkInstance.value.browserAccessMode) return 'frontend'
|
|
802
815
|
|
|
803
816
|
await loadCompressionConfig()
|
|
804
817
|
|
|
@@ -1639,6 +1652,49 @@ export default {
|
|
|
1639
1652
|
'sxt2': 'application/octet-stream',
|
|
1640
1653
|
'gbq7': 'application/octet-stream',
|
|
1641
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',
|
|
1642
1698
|
'ppt': 'application/vnd.ms-powerpoint',
|
|
1643
1699
|
'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
1644
1700
|
'txt': 'text/plain',
|
|
@@ -2034,9 +2090,9 @@ export default {
|
|
|
2034
2090
|
} finally {
|
|
2035
2091
|
isUploading.value = false
|
|
2036
2092
|
}
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
const uploadSingleFile = async (fileObj) => {
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
const uploadSingleFile = async (fileObj) => {
|
|
2040
2096
|
console.log('📤 上传文件:', fileObj.name)
|
|
2041
2097
|
|
|
2042
2098
|
if (!sdkInstance.value) {
|
|
@@ -2056,6 +2112,10 @@ export default {
|
|
|
2056
2112
|
})
|
|
2057
2113
|
|
|
2058
2114
|
try {
|
|
2115
|
+
if (typeof props.config.getUploadTicket === 'function'
|
|
2116
|
+
&& sdkInstance.value.browserExpiresAt <= Date.now() + 30000) {
|
|
2117
|
+
await initializeSDK()
|
|
2118
|
+
}
|
|
2059
2119
|
// 决定压缩策略
|
|
2060
2120
|
const compressionStrategy = await determineCompressionStrategy(fileObj.file)
|
|
2061
2121
|
let fileToUpload = fileObj.file
|
|
@@ -2228,9 +2288,9 @@ export default {
|
|
|
2228
2288
|
}, 8000)
|
|
2229
2289
|
}
|
|
2230
2290
|
}
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
// 文件压缩判断
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
// 文件压缩判断
|
|
2234
2294
|
const shouldCompressFile = (file) => {
|
|
2235
2295
|
if (!props.enableCompression) return false
|
|
2236
2296
|
|
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'
|