@smart100/spu-web-plugin 0.0.15 → 0.0.17
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/dist/spu-web-plugin.mjs +6852 -359
- package/package.json +1 -1
- package/src/apaasSpuTrack.ts +194 -0
- package/src/components/expandexp/index.ts +57 -12
- package/src/components/expandexp/template.ts +4 -3
- package/src/install.ts +7 -47
- package/src/oss/downloadService.ts +43 -17
- package/src/package/apaas-track/apaas-spu/index.js +11 -0
- package/src/package/apaas-track/apaas-spu/index.mjs +4956 -0
- package/src/package/apaas-track/apaas-spu/index.umd.js +11 -0
- package/src/package/apaas-track/apaas-spu/lzma_worker.js +2668 -0
- package/src/storageProxy.ts +2 -0
- package/src/types/shims-lib.d.ts +3 -0
package/package.json
CHANGED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { globalOptions } from './install'
|
|
2
|
+
import { cloneDeep, merge } from 'lodash-es'
|
|
3
|
+
import ApaasSpuTrack from './package/apaas-track/apaas-spu/index.umd.js'
|
|
4
|
+
import login from './login'
|
|
5
|
+
|
|
6
|
+
const getWebInitParams = async () => {
|
|
7
|
+
const user = login.getUser()
|
|
8
|
+
const envname = await login.getEnvname()
|
|
9
|
+
return {
|
|
10
|
+
project: globalOptions.modulename,
|
|
11
|
+
appid: globalOptions.modulekey,
|
|
12
|
+
clientver: globalOptions.moduleversion,
|
|
13
|
+
// anonymousid: '',
|
|
14
|
+
// distinctid: '',
|
|
15
|
+
accountcode: user.accountcode,
|
|
16
|
+
envname: envname,
|
|
17
|
+
tenantcode: user.tenantcode,
|
|
18
|
+
tenantname: user.tenantname,
|
|
19
|
+
positionname: user.positionname,
|
|
20
|
+
mbcode: user.mbcode,
|
|
21
|
+
username: `${user.username1 || ''}|${user.username2 || ''}|${user.username3 || ''}`,
|
|
22
|
+
userinfoname: user.userinfoname
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const getIndextagSync = (params: any) => {
|
|
27
|
+
const result: any = {
|
|
28
|
+
code: '',
|
|
29
|
+
msg: '',
|
|
30
|
+
indextag: ''
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (params.url) {
|
|
34
|
+
const a = params.url.split('indextag=')
|
|
35
|
+
if (a.length > 1) {
|
|
36
|
+
const b = a[1].split('&')
|
|
37
|
+
result.code = 200
|
|
38
|
+
result.indextag = b[0]
|
|
39
|
+
result.msg = '解析成功。'
|
|
40
|
+
} else {
|
|
41
|
+
result.code = 404
|
|
42
|
+
result.msg = '不存在该 url 的 indextag。'
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
result.code = 404
|
|
46
|
+
result.msg = '传入 url 为空。'
|
|
47
|
+
}
|
|
48
|
+
// console.log(result)
|
|
49
|
+
// debugger
|
|
50
|
+
// params.complete && params.complete(result.code, result.indextag, result.msg)
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 兼容开启SPU日志
|
|
55
|
+
const initApaasSpuTrack = () => {
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
if (ApaasSpuTrack && !window.apaasSpuTrack && !window?.aPaaS?.getWebInitParams && !window?.Module?.getIndextagSync) {
|
|
58
|
+
window.aPaaS = {
|
|
59
|
+
getWebInitParams
|
|
60
|
+
}
|
|
61
|
+
window.Module = {
|
|
62
|
+
getIndextagSync
|
|
63
|
+
}
|
|
64
|
+
// if (window.aPaaS && !window.aPaaS.getWebInitParams) {
|
|
65
|
+
// window.aPaaS.getWebInitParams = getWebInitParams
|
|
66
|
+
// } else {
|
|
67
|
+
// window.aPaaS = {
|
|
68
|
+
// getWebInitParams
|
|
69
|
+
// }
|
|
70
|
+
// }
|
|
71
|
+
// if (window.Module && !window.Module.getIndextagSync) {
|
|
72
|
+
// window.Module.getIndextagSync = getIndextagSync
|
|
73
|
+
// } else {
|
|
74
|
+
// window.Module = {
|
|
75
|
+
// getIndextagSync
|
|
76
|
+
// }
|
|
77
|
+
// }
|
|
78
|
+
|
|
79
|
+
ApaasSpuTrack.getApaasSpuTrack({
|
|
80
|
+
url: 'https://log.xtion.net/?project=xw_module',
|
|
81
|
+
zip: false,
|
|
82
|
+
online: true
|
|
83
|
+
}).then((apaasSpuTrack: ApaasSpuTrack) => {
|
|
84
|
+
console.log('apaasSpuTrack', apaasSpuTrack)
|
|
85
|
+
window.apaasSpuTrack = apaasSpuTrack
|
|
86
|
+
|
|
87
|
+
// // 监听关闭事件
|
|
88
|
+
// window.addEventListener('beforeunload', (e) => {
|
|
89
|
+
// // console.log(e)
|
|
90
|
+
// // debugger
|
|
91
|
+
// // window.dispatchEvent(new Event('pagehide'))
|
|
92
|
+
// let beforeunloadCount = window.localStorage.getItem('beforeunloadCount')
|
|
93
|
+
// if (!beforeunloadCount) {
|
|
94
|
+
// beforeunloadCount = 0
|
|
95
|
+
// }
|
|
96
|
+
// window.localStorage.setItem('beforeunloadCount', (Number(beforeunloadCount) + 1).toString())
|
|
97
|
+
// })
|
|
98
|
+
|
|
99
|
+
// // 监听关闭事件
|
|
100
|
+
// window.addEventListener('pagehide', () => {
|
|
101
|
+
// // debugger
|
|
102
|
+
// let pagehideCount = window.localStorage.getItem('pagehideCount')
|
|
103
|
+
// if (!pagehideCount) {
|
|
104
|
+
// pagehideCount = 0
|
|
105
|
+
// }
|
|
106
|
+
// window.localStorage.setItem('pagehideCount', (Number(pagehideCount) + 1).toString())
|
|
107
|
+
// })
|
|
108
|
+
|
|
109
|
+
// 重写 transformLog 底层方法
|
|
110
|
+
let initindextag = ''
|
|
111
|
+
apaasSpuTrack.transformLog = (log: any) => {
|
|
112
|
+
if (log.properties) {
|
|
113
|
+
// 发送所有类型的日志前统一在 properties 对象属性下增加SPU相关属性值:modulekey、modulename、moduleversion、indextag、initindextag、toindextag、fromindextag。
|
|
114
|
+
log.properties.modulekey = log.appid
|
|
115
|
+
log.properties.modulename = log.project
|
|
116
|
+
log.properties.moduleversion = log.clientver
|
|
117
|
+
// debugger
|
|
118
|
+
|
|
119
|
+
const urlParseRes = window.Module.getIndextagSync({
|
|
120
|
+
url: log.url
|
|
121
|
+
})
|
|
122
|
+
log.properties.indextag = urlParseRes.indextag
|
|
123
|
+
|
|
124
|
+
// 初始化时记录 initindextag 之后为每个日志都添加 initindextag
|
|
125
|
+
if (log.types === 'init') {
|
|
126
|
+
initindextag = log.properties.indextag
|
|
127
|
+
}
|
|
128
|
+
log.properties.initindextag = initindextag
|
|
129
|
+
|
|
130
|
+
if (log.types === 'pageview' && log.properties.to) {
|
|
131
|
+
const toParseRes = window.Module.getIndextagSync({
|
|
132
|
+
url: log.properties.to
|
|
133
|
+
})
|
|
134
|
+
log.properties.toindextag = toParseRes.indextag
|
|
135
|
+
}
|
|
136
|
+
if (log.types === 'pageview' && log.properties.from) {
|
|
137
|
+
const fromParseRes = window.Module.getIndextagSync({
|
|
138
|
+
url: log.properties.from
|
|
139
|
+
})
|
|
140
|
+
log.properties.fromindextag = fromParseRes.indextag
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return log
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
apaasSpuTrack.start()
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
}, 2500)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const apaasSpuTrackSendLog = (data: any, end: boolean = false) => {
|
|
153
|
+
if (window.apaasSpuTrack) {
|
|
154
|
+
const logtime = Date.now().toString()
|
|
155
|
+
const baselog = cloneDeep({
|
|
156
|
+
...window.apaasSpuTrack.baseLog,
|
|
157
|
+
logtime: logtime,
|
|
158
|
+
epochnanos: logtime + '000000',
|
|
159
|
+
types: '',
|
|
160
|
+
event: '',
|
|
161
|
+
url: location.href,
|
|
162
|
+
properties: {
|
|
163
|
+
// // 图片导出相关信息
|
|
164
|
+
// // formtype: apaas | litheform | spu
|
|
165
|
+
// formtype: 'spu',
|
|
166
|
+
// // exporttype: 1=普通导出 | 2=后端图片扩展导出 | 3=图片导出SPU
|
|
167
|
+
// exporttype: '3',
|
|
168
|
+
// // pagecode
|
|
169
|
+
// // 当 formtype = apaas 表示低码表单code
|
|
170
|
+
// // 当 formtype = litheform 表示超表表单code
|
|
171
|
+
// // 当 formtype = spu 表示配置的spu页面pagecode
|
|
172
|
+
// pagecode: ''
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
const mergedata = merge(baselog, data)
|
|
176
|
+
// console.log(mergedata)
|
|
177
|
+
// debugger
|
|
178
|
+
window.apaasSpuTrack.addLogToQueue(mergedata, true)
|
|
179
|
+
} else {
|
|
180
|
+
if (!end) {
|
|
181
|
+
console.warn('window.apaasSpuTrack 不存在,导出日志延迟3秒后再次发送。')
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
apaasSpuTrackSendLog(data, true)
|
|
184
|
+
}, 3000)
|
|
185
|
+
} else {
|
|
186
|
+
console.error('apaasTrack 不存在,导出日志发送失败。')
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export {
|
|
192
|
+
initApaasSpuTrack,
|
|
193
|
+
apaasSpuTrackSendLog
|
|
194
|
+
}
|
|
@@ -7,6 +7,7 @@ import { apaasAxios } from '../../axios'
|
|
|
7
7
|
import core, { Module } from '../../core'
|
|
8
8
|
import login from '../../login'
|
|
9
9
|
import { downloadService } from '../../oss'
|
|
10
|
+
import { apaasSpuTrackSendLog } from '../../apaasSpuTrack'
|
|
10
11
|
|
|
11
12
|
export default class SpuExpandexp extends HTMLElement {
|
|
12
13
|
|
|
@@ -340,6 +341,10 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
340
341
|
}
|
|
341
342
|
}
|
|
342
343
|
})
|
|
344
|
+
this.sendLog({
|
|
345
|
+
types: 'exportopenmodal',
|
|
346
|
+
event: 'exportopenmodal'
|
|
347
|
+
})
|
|
343
348
|
} else {
|
|
344
349
|
apaasAxios
|
|
345
350
|
.post('/api/expandexp/global/searchExpGloConfig', {
|
|
@@ -361,6 +366,11 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
361
366
|
.catch((err: Error) => {
|
|
362
367
|
this.data.expandStatus = '1'
|
|
363
368
|
}).finally(() => {
|
|
369
|
+
// 发送日志
|
|
370
|
+
this.sendLog({
|
|
371
|
+
types: 'exportopenmodal',
|
|
372
|
+
event: 'exportopenmodal'
|
|
373
|
+
})
|
|
364
374
|
|
|
365
375
|
if (this.data.expandStatus === '1') {
|
|
366
376
|
this.data.exportcontentArray = ['excel']
|
|
@@ -468,11 +478,22 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
468
478
|
this.data.resultMessage = '网络连接错误'
|
|
469
479
|
this.stopInterval()
|
|
470
480
|
})
|
|
481
|
+
|
|
482
|
+
this.sendLog({
|
|
483
|
+
types: 'exportclickbutton',
|
|
484
|
+
event: 'exportclickbutton',
|
|
485
|
+
properties: {
|
|
486
|
+
bizdata: {
|
|
487
|
+
exportapi: this.props.exportapi,
|
|
488
|
+
params: finallyPost
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
})
|
|
471
492
|
}
|
|
472
493
|
|
|
473
494
|
handleDownload () {
|
|
474
|
-
console.log(this.data)
|
|
475
|
-
console.log(this.data.exportDataItem)
|
|
495
|
+
// console.log(this.data)
|
|
496
|
+
// console.log(this.data.exportDataItem)
|
|
476
497
|
|
|
477
498
|
let fixExportFileUrl = this.data.exportDataItem.exportfileurl[0] === '/' ? this.data.exportDataItem.exportfileurl : '/' + this.data.exportDataItem.exportfileurl
|
|
478
499
|
let exportFileName = this.data.exportDataItem.filename
|
|
@@ -486,12 +507,25 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
486
507
|
// filename: exportFileName
|
|
487
508
|
// })
|
|
488
509
|
|
|
489
|
-
|
|
510
|
+
const params = {
|
|
490
511
|
type: 'att',
|
|
491
512
|
source: fixExportFileUrl,
|
|
492
513
|
datetime: date,
|
|
493
514
|
storagetype: 'storage-1d',
|
|
494
515
|
filename: exportFileName
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
downloadService.downloadFile(params as any)
|
|
519
|
+
|
|
520
|
+
// 发送日志
|
|
521
|
+
this.sendLog({
|
|
522
|
+
types: 'exportdownloadfile',
|
|
523
|
+
event: 'exportdownloadfile',
|
|
524
|
+
properties: {
|
|
525
|
+
bizdata: {
|
|
526
|
+
params: params
|
|
527
|
+
}
|
|
528
|
+
}
|
|
495
529
|
})
|
|
496
530
|
}
|
|
497
531
|
|
|
@@ -614,20 +648,19 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
614
648
|
// this.stopInterval()
|
|
615
649
|
} else if (currentData.exportstate === 'ext_readyrun') {
|
|
616
650
|
this.updateStep('ext_readyrun')
|
|
617
|
-
|
|
618
|
-
this.data.percentage = +currentData.finishRate * 0.5 + 50
|
|
619
|
-
}
|
|
651
|
+
currentData && (this.data.percentage = +currentData.finishRate * 0.5 + 50)
|
|
620
652
|
} else if (currentData.exportstate === 'ext_running') {
|
|
621
653
|
this.updateStep('ext_running')
|
|
622
|
-
|
|
623
|
-
if (currentData) {
|
|
624
|
-
this.data.percentage = +currentData.finishRate * 0.5 + 50
|
|
625
|
-
}
|
|
654
|
+
currentData && (this.data.percentage = +currentData.finishRate * 0.5 + 50)
|
|
626
655
|
} else {
|
|
627
656
|
this.updateStep('running')
|
|
628
657
|
if (currentData) {
|
|
629
|
-
this.data.percentage = +currentData.finishRate
|
|
630
|
-
//
|
|
658
|
+
this.data.percentage = +currentData.finishRate
|
|
659
|
+
// if (this.data.expandStatus = '1') {
|
|
660
|
+
// this.data.percentage = +currentData.finishRate
|
|
661
|
+
// } else {
|
|
662
|
+
// this.data.percentage = +currentData.finishRate * 0.5
|
|
663
|
+
// }
|
|
631
664
|
}
|
|
632
665
|
}
|
|
633
666
|
})
|
|
@@ -649,6 +682,18 @@ export default class SpuExpandexp extends HTMLElement {
|
|
|
649
682
|
}
|
|
650
683
|
}
|
|
651
684
|
|
|
685
|
+
sendLog (data: any) {
|
|
686
|
+
apaasSpuTrackSendLog(merge({
|
|
687
|
+
// types: 'exportdownloadfile',
|
|
688
|
+
// event: 'exportdownloadfile',
|
|
689
|
+
properties: {
|
|
690
|
+
formtype: 'spu',
|
|
691
|
+
exporttype: this.data.expandStatus,
|
|
692
|
+
pagecode: this.props.pagecode
|
|
693
|
+
}
|
|
694
|
+
}, data))
|
|
695
|
+
}
|
|
696
|
+
|
|
652
697
|
removeSelf () {
|
|
653
698
|
this.parentNode!.removeChild(this)
|
|
654
699
|
}
|
|
@@ -159,8 +159,9 @@ export default (ele: SpuExpandexp) => {
|
|
|
159
159
|
}
|
|
160
160
|
.export-file-r {
|
|
161
161
|
display: flex;
|
|
162
|
-
width:
|
|
162
|
+
width: 90px;
|
|
163
163
|
flex-direction: row-reverse;
|
|
164
|
+
align-items: center;
|
|
164
165
|
}
|
|
165
166
|
.export-file-r-download {
|
|
166
167
|
line-height: 26px;
|
|
@@ -177,8 +178,8 @@ export default (ele: SpuExpandexp) => {
|
|
|
177
178
|
border-color: #85ce61;
|
|
178
179
|
}
|
|
179
180
|
.export-file-r-cancel {
|
|
180
|
-
line-height:
|
|
181
|
-
width:
|
|
181
|
+
line-height: 20px;
|
|
182
|
+
width: 20px;
|
|
182
183
|
border-radius: 14px;
|
|
183
184
|
color: #f56c6c;
|
|
184
185
|
background: #fef0f0;
|
package/src/install.ts
CHANGED
|
@@ -3,12 +3,9 @@ import login from './login'
|
|
|
3
3
|
import { initAxios } from './axios'
|
|
4
4
|
import urlquery from './urlquery'
|
|
5
5
|
import { initSpuConfig } from './spuConfig'
|
|
6
|
+
import { initApaasSpuTrack } from './apaasSpuTrack'
|
|
6
7
|
import { merge } from 'lodash-es'
|
|
7
|
-
|
|
8
8
|
import { initTest } from './test'
|
|
9
|
-
// import tenantInfo from './tenantInfo'
|
|
10
|
-
// import { downloadService } from './oss'
|
|
11
|
-
|
|
12
9
|
|
|
13
10
|
const globalOptions: SPUWebPluginOptions = {
|
|
14
11
|
modulekey: 'demospu',
|
|
@@ -17,14 +14,13 @@ const globalOptions: SPUWebPluginOptions = {
|
|
|
17
14
|
router: null
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
let isInstall = false
|
|
21
|
-
|
|
22
17
|
const install = (app: any, options: SPUWebPluginOptions) => {
|
|
23
18
|
// console.log(app)
|
|
24
19
|
// console.log(app.version)
|
|
25
|
-
console.log('@smart100/spu-web-plugin options', options)
|
|
26
20
|
merge(globalOptions, options)
|
|
27
|
-
console.log('@smart100/spu-web-plugin
|
|
21
|
+
console.log('@smart100/spu-web-plugin start!')
|
|
22
|
+
console.log('options', options)
|
|
23
|
+
console.log('globalOptions', globalOptions)
|
|
28
24
|
|
|
29
25
|
// if (install.installed) return
|
|
30
26
|
// install.installed = true
|
|
@@ -40,31 +36,13 @@ const install = (app: any, options: SPUWebPluginOptions) => {
|
|
|
40
36
|
// console.error('This plugin requires Vue App Instance')
|
|
41
37
|
// }
|
|
42
38
|
|
|
43
|
-
|
|
44
39
|
initStorageProxy(globalOptions)
|
|
45
40
|
initAxios(globalOptions)
|
|
46
41
|
initSpuConfig(globalOptions)
|
|
42
|
+
initApaasSpuTrack()
|
|
47
43
|
urlquery.init()
|
|
48
44
|
login.startRefreshtoken()
|
|
49
|
-
|
|
50
|
-
// setTimeout(async () => {
|
|
51
|
-
// const a = await downloadService.getUrl({
|
|
52
|
-
// // source: 'a1b9954a-fb39-4bb2-aa0b-501f4af0d99e.jpeg',
|
|
53
|
-
// // datetime: '1698832693257',
|
|
54
|
-
// // source: '2f7dfe47-1827-4db1-9d99-3ddb08bb7e21.jpg',
|
|
55
|
-
// // datetime: '1698832697897',
|
|
56
|
-
// source: 'e3befbe5-8954-46d2-a368-5f812a5530e5.jpg',
|
|
57
|
-
// datetime: '1699527237567',
|
|
58
|
-
// // cope: {
|
|
59
|
-
// // width: 100
|
|
60
|
-
// // }
|
|
61
|
-
// })
|
|
62
|
-
// console.log(a)
|
|
63
|
-
// console.log(71117)
|
|
64
|
-
// }, 1000)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// tenantInfo.getAndSave()
|
|
45
|
+
initTest(globalOptions)
|
|
68
46
|
|
|
69
47
|
if (globalOptions.router) {
|
|
70
48
|
globalOptions.router.beforeEach(async (to: any, from: any, next: any) => {
|
|
@@ -86,29 +64,11 @@ const install = (app: any, options: SPUWebPluginOptions) => {
|
|
|
86
64
|
}
|
|
87
65
|
})
|
|
88
66
|
} else {
|
|
89
|
-
console.error('
|
|
67
|
+
console.error('@smart100/spu-web-plugin require a vue-router instance.')
|
|
90
68
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
initTest(globalOptions)
|
|
94
|
-
|
|
95
|
-
isInstall = true
|
|
96
|
-
|
|
97
|
-
// Vue.component('xt-engine', components.engine)
|
|
98
|
-
// Vue.prototype.$xtEngine = () => {
|
|
99
|
-
// console.log('$xtEngine')
|
|
100
|
-
// }
|
|
101
|
-
|
|
102
|
-
// const component = options?.component
|
|
103
|
-
// if (component) {
|
|
104
|
-
// for (const x in component) {
|
|
105
|
-
// register(x, component[x])
|
|
106
|
-
// }
|
|
107
|
-
// }
|
|
108
69
|
}
|
|
109
70
|
|
|
110
71
|
export {
|
|
111
72
|
install,
|
|
112
|
-
isInstall,
|
|
113
73
|
globalOptions
|
|
114
74
|
}
|
|
@@ -8,6 +8,7 @@ import ObsClient from '../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.
|
|
|
8
8
|
// const ObsClient = require('../package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js')
|
|
9
9
|
import dayjs from 'dayjs'
|
|
10
10
|
import login from '../login'
|
|
11
|
+
import { apaasAxios } from '../axios'
|
|
11
12
|
// import { get } from 'lodash-es'
|
|
12
13
|
// import qs from 'qs'
|
|
13
14
|
|
|
@@ -193,27 +194,25 @@ const getUrl = async ({
|
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
aElm.innerHTML = filename
|
|
197
|
+
const downloadFileByUrl = (url: string, filename: string) => {
|
|
198
|
+
const aElm = document.createElement('a')
|
|
199
|
+
aElm.innerHTML = filename
|
|
199
200
|
aElm.download = filename
|
|
200
|
-
let href = url
|
|
201
|
-
aElm.href = href
|
|
202
|
-
document.body.appendChild(aElm)
|
|
203
201
|
aElm.target = '_blank'
|
|
202
|
+
aElm.href = url
|
|
203
|
+
document.body.appendChild(aElm)
|
|
204
204
|
let evt = document.createEvent('MouseEvents')
|
|
205
205
|
evt.initEvent('click', false, false)
|
|
206
206
|
aElm.dispatchEvent(evt)
|
|
207
207
|
document.body.removeChild(aElm)
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
aElm.innerHTML = filename
|
|
210
|
+
const downloadFileByBlob = (blob: any, filename: string) => {
|
|
211
|
+
const aElm = document.createElement('a')
|
|
212
|
+
aElm.innerHTML = filename
|
|
213
213
|
aElm.download = filename
|
|
214
214
|
aElm.target = '_blank'
|
|
215
|
-
|
|
216
|
-
aElm.href = href
|
|
215
|
+
aElm.href = window.URL.createObjectURL(blob)
|
|
217
216
|
document.body.appendChild(aElm)
|
|
218
217
|
let evt = document.createEvent('MouseEvents')
|
|
219
218
|
evt.initEvent('click', false, false)
|
|
@@ -233,23 +232,50 @@ const downloadFile = async ({
|
|
|
233
232
|
if (!filename) {
|
|
234
233
|
filename = source
|
|
235
234
|
}
|
|
235
|
+
|
|
236
236
|
const suffix = filename.slice(filename.lastIndexOf('.'))
|
|
237
|
-
|
|
237
|
+
const realFilename = filename.replace(suffix, '') + dayjs(+datetime).format('_YYYYMMDDHHmmssS') + String(Math.floor(Math.random() * 9000) + 1000) + suffix
|
|
238
238
|
|
|
239
239
|
// console.log(filename)
|
|
240
|
-
|
|
241
240
|
const url = await getUrl({
|
|
242
241
|
type,
|
|
243
242
|
source,
|
|
244
243
|
datetime,
|
|
245
244
|
storagetype,
|
|
246
|
-
filename,
|
|
245
|
+
filename: realFilename,
|
|
247
246
|
cope
|
|
248
247
|
})
|
|
248
|
+
// apaasAxios.get(url, {
|
|
249
|
+
// responseType: 'blob',
|
|
250
|
+
// isSendToken: false,
|
|
251
|
+
// isShowErrorMessage: false
|
|
252
|
+
// }).then((response: any) => {
|
|
253
|
+
// // console.log(response)
|
|
254
|
+
// // debugger
|
|
255
|
+
// downloadFileByBlob(response.data, filename)
|
|
256
|
+
// }).catch((e) => {
|
|
257
|
+
// console.log(e)
|
|
258
|
+
// throw Error(e)
|
|
259
|
+
// })
|
|
249
260
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
261
|
+
const isAliYun = CloudServ.isAliyun(storagetype)
|
|
262
|
+
// const isHuawei = CloudServ.isHuawei(storagetype)
|
|
263
|
+
if (isAliYun) {
|
|
264
|
+
downloadFileByUrl(url, filename)
|
|
265
|
+
} else {
|
|
266
|
+
apaasAxios.get(url, {
|
|
267
|
+
responseType: 'blob',
|
|
268
|
+
isSendToken: false,
|
|
269
|
+
isShowErrorMessage: false
|
|
270
|
+
}).then((response: any) => {
|
|
271
|
+
// console.log(response)
|
|
272
|
+
// debugger
|
|
273
|
+
downloadFileByBlob(response.data, filename)
|
|
274
|
+
}).catch((e: any) => {
|
|
275
|
+
console.log(e)
|
|
276
|
+
throw Error(e)
|
|
277
|
+
})
|
|
278
|
+
}
|
|
253
279
|
}
|
|
254
280
|
|
|
255
281
|
export default {
|