@smart100/spu-web-plugin 0.0.9 → 0.0.13

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.
@@ -0,0 +1,707 @@
1
+ import { getAttributes } from '../common/index'
2
+ import renderTemplate from './template'
3
+ import { Step } from './step'
4
+ import { cloneDeep, merge } from 'lodash-es'
5
+ import { fixFileName, dealFileSize, dealResultMessage } from './util'
6
+ import { apaasAxios } from '../../axios'
7
+ import core, { Module } from '../../core'
8
+ import login from '../../login'
9
+ import { downloadService } from '../../oss'
10
+
11
+ export default class SpuExpandexp extends HTMLElement {
12
+
13
+ static componentName: string = 'spu-expandexp'
14
+ static register () {
15
+ if (!window.customElements.get(SpuExpandexp.componentName)) {
16
+ window.customElements.define(SpuExpandexp.componentName, SpuExpandexp)
17
+ }
18
+ }
19
+
20
+ shadow!: ShadowRoot
21
+ defaultProps = {
22
+ exportapi: '',
23
+ sheetname: '',
24
+ pagecode: '',
25
+ mergedata: null
26
+ }
27
+ props!: any
28
+ data: any = {}
29
+
30
+ statusTimer: number | null = null
31
+
32
+ constructor () {
33
+ super()
34
+ this.shadow = this.attachShadow({ mode: 'open' })
35
+ }
36
+
37
+ // 当自定义元素第一次被连接到文档DOM时被调用。
38
+ connectedCallback () {
39
+ this.initProps()
40
+ this.shadow.innerHTML = renderTemplate(this)
41
+
42
+ this.initData({
43
+ filetype: '1', // 导出文件类型 1: xls 2: csv 目前spu的导出只实现了xls 因此写死xls
44
+ exportcontent: 'excel', // excel.仅导出单据,link,导出单据和本地链接,photo.导出单据和图片
45
+ filewatermark: '0', // 1.开启文件水印,0.关闭文件水印
46
+ iscompress: '0', // 1.压缩,0.原图
47
+ displaytype: 'horizontal', // horizontal:横向排列 vertical:纵向排列 multi-row:分行展示
48
+ imagetype: 'origin', // 导出图片类型 png jpg origin 默认origin
49
+ imagename: '', // 图片命名规则
50
+ // imagesizepercolumn 和 imageheightcm 为 图片导出SPU新增配置项
51
+ imagesizepercolumn: '5',
52
+ imageheightcm: '2',
53
+
54
+
55
+ expandStatus: '1', // 1普通导出(没有做图片导出服务) 2服务端导出(做了图片导出服务未SPU化) 3安装了图片导出SPU
56
+ filewatermarkGlobalConfig: '0', // 全局文件水印开关
57
+ exportcontentArray: ['excel', 'link', 'photo'], // 当 expandStatus = 2 | 3时才显示导出内容给用户选择
58
+ percentage: 0,
59
+ step: new Step(),
60
+ stepStatus: 0,
61
+ stepName: 'initial',
62
+ stepText: '',
63
+ resultMessage: '',
64
+ exportDataItem: {},
65
+ exportId: '',
66
+ fileName: '',
67
+ fileSize: '',
68
+ runningTaskCount: 0,
69
+ isOldVersionService: false
70
+ }, (key: string, value: any) => {
71
+ const { expandStatus, stepName, stepText, exportcontentArray, exportcontent, isOldVersionService, runningTaskCount, fileName, filetype, fileSize, exportDataItem, percentage, resultMessage } = this.data
72
+
73
+ // debugger
74
+ const $exportSel = this.shadow.querySelector('.export-sel') as any
75
+ const $exportSelCon = this.shadow.querySelector('.export-sel-con') as any
76
+ const $exportSectionWrap = this.shadow.querySelector('.export-section-wrap') as any
77
+ const $exportBtnwrap = this.shadow.querySelector('.export-btnwrap') as any
78
+ const $exportDownload = this.shadow.querySelector('.export-file-r-download') as any
79
+ const $exportCancel = this.shadow.querySelector('.export-file-r-cancel') as any
80
+ const $exportProgress = this.shadow.querySelector('.export-progress') as any
81
+ const $exportProgressInner = this.shadow.querySelector('.export-progress-inner') as any
82
+ const $exportProgressText = this.shadow.querySelector('.export-progress-text') as any
83
+ const $exportTip = this.shadow.querySelector('.export-tip') as any
84
+ const $exportTit = this.shadow.querySelector('.export-tit') as any
85
+ const $exportResult = this.shadow.querySelector('.export-result') as any
86
+ const $fileimg = this.shadow.querySelector('.export-file-l-img') as any
87
+ const $filename = this.shadow.querySelector('.export-file-l-filename') as any
88
+ const $filesize = this.shadow.querySelector('.export-file-l-filesize') as any
89
+ const $wait = this.shadow.querySelector('.export-wait') as any
90
+ const $waitSpan = this.shadow.querySelector('.export-wait span') as any
91
+
92
+ if (key === 'expandStatus' || key === 'stepName') {
93
+ // this.vIf($exportSel, (expandStatus !== '1' && stepName === 'initial'))
94
+ this.vIf($exportSel, (stepName === 'initial'))
95
+ }
96
+ if (key === 'exportcontentArray' || key === 'exportcontent') {
97
+ const mapTitle: any = {
98
+ excel: '仅导出单据',
99
+ link: '导出单据和本地链接',
100
+ photo: '导出单据和图片'
101
+ }
102
+
103
+ const exportcontentOptions = exportcontentArray.map((item: string) => {
104
+ return {
105
+ label: mapTitle[item],
106
+ value: item
107
+ }
108
+ })
109
+
110
+ const html = exportcontentOptions.map((item: any) => {
111
+ return `
112
+ <div class="export-sel-con-item">
113
+ <input type="radio" id="${item.value}" name="exportcontent" value="${item.value}" ${item.value === exportcontent ? 'checked' : ''} />
114
+ <label for="${item.value}">${item.label}</label>
115
+ </div>
116
+ `
117
+ }).join('')
118
+
119
+ $exportSelCon.innerHTML = html
120
+ // set(exportcontent)
121
+ }
122
+
123
+
124
+ // 状态标题
125
+ if (key === 'stepText') {
126
+ this.vText($exportTit, stepText)
127
+ }
128
+
129
+ // 下载按钮显隐
130
+ this.vIf($exportDownload, ((stepName === 'error' || stepName === 'success') && exportDataItem?.exportfileurl))
131
+
132
+ // 取消按钮显隐
133
+ this.vIf($exportCancel, ((stepName === 'running' || stepName === 'ready') && (!exportDataItem?.exportstate || exportDataItem?.exportstate === 'readyrun' || exportDataItem?.exportstate === 'running')))
134
+
135
+ // 进度条
136
+ if (key === 'stepName') {
137
+ this.vIf($exportProgress, (stepName === 'running' || stepName === 'ready' || stepName === 'success' || stepName === 'error' || stepName === 'ext_readyrun' || stepName === 'ext_running'))
138
+ }
139
+ if (key === 'percentage' || key === 'stepName') {
140
+ this.vIf($exportProgressText, percentage < 100)
141
+ if (percentage >= 100) {
142
+ this.vText($exportProgressText, `100%`)
143
+ $exportProgressInner.setAttribute('style', `width: 100%`)
144
+
145
+ if (stepName === 'success') {
146
+ $exportProgressInner.classList.add('success')
147
+ } else if (stepName === 'error') {
148
+ $exportProgressInner.classList.add('error')
149
+ }
150
+ } else {
151
+ this.vText($exportProgressText, `${percentage}%`)
152
+ $exportProgressInner.setAttribute('style', `width: ${percentage}%`)
153
+
154
+ $exportProgressInner.classList.remove('success')
155
+ $exportProgressInner.classList.remove('error')
156
+ }
157
+ }
158
+
159
+
160
+ if (key === 'stepName') {
161
+ this.vIf($exportSectionWrap, stepName !== 'initial')
162
+ this.vIf($exportBtnwrap, stepName === 'initial')
163
+ this.vIf($exportTip, (stepName === 'running' || stepName === 'ready' || stepName === 'ext_readyrun' || stepName === 'ext_running' || stepName === 'success'))
164
+ }
165
+
166
+ if (key === 'resultMessage') {
167
+ this.vIf($exportResult, !!resultMessage)
168
+ this.vText($exportResult, resultMessage)
169
+ }
170
+ if (key === 'stepName') {
171
+ if (stepName === 'success') {
172
+ $exportResult.classList.add('success')
173
+ } else if (stepName === 'error') {
174
+ $exportResult.classList.add('error')
175
+ } else {
176
+ $exportResult.classList.remove('success')
177
+ }
178
+ }
179
+
180
+ if (key === 'exportcontent') {
181
+ if (exportcontent === 'link') {
182
+ $fileimg.classList.add('zip')
183
+ $fileimg.classList.remove('excel')
184
+ } else {
185
+ $fileimg.classList.add('excel')
186
+ $fileimg.classList.remove('zip')
187
+ }
188
+ }
189
+
190
+ if (key === 'fileName' || key === 'filetype' || key === 'exportcontent') {
191
+ const fileNameWithSuffix = fixFileName(fileName, filetype, exportcontent)
192
+ this.vText($filename, fileNameWithSuffix)
193
+ }
194
+ if (key === 'fileSize') {
195
+ this.vText($filesize, fileSize)
196
+ }
197
+
198
+ if (key === 'isOldVersionService' || key === 'runningTaskCount') {
199
+ const flag = !isOldVersionService && runningTaskCount > 0
200
+ this.vIf($wait, flag)
201
+ if (flag) {
202
+ this.vText($waitSpan, runningTaskCount)
203
+ } else {
204
+ this.vText($waitSpan, '')
205
+ }
206
+ }
207
+
208
+
209
+ })
210
+ this.data.fileName = this.props.sheetname
211
+
212
+ this.initEvent()
213
+
214
+ this.getExpandexpConfig()
215
+ }
216
+
217
+ vText (ele: any, text: string) {
218
+ const oldValue = ele.innerHTML || ''
219
+ const newValue = text || ''
220
+ if (oldValue !== newValue) {
221
+ // console.log(newValue)
222
+ ele.innerHTML = newValue
223
+ }
224
+ }
225
+
226
+ vIf (ele: any, flag: boolean) {
227
+ const elc = ele.classList
228
+ if (flag) {
229
+ elc.contains('hide') && elc.remove('hide')
230
+ } else {
231
+ !elc.contains('hide') && elc.add('hide')
232
+ }
233
+ }
234
+
235
+ initData (data: any, setCallback: any) {
236
+ this.data = cloneDeep(data)
237
+ const dataP = cloneDeep(data)
238
+ for (const x in dataP) {
239
+ Object.defineProperty(this.data, x, {
240
+ get: function getter () {
241
+ // console.log('get!')
242
+ return dataP[x]
243
+ },
244
+ set: function getter (value) {
245
+ // console.log('set!')
246
+ dataP[x] = value
247
+ setCallback(x, value)
248
+ }
249
+ })
250
+ // console.log(x)
251
+ this.data[x] = dataP[x]
252
+ }
253
+ }
254
+
255
+ initProps () {
256
+ const attributes = getAttributes(this)
257
+ this.props = {
258
+ ...this.defaultProps,
259
+ ...attributes
260
+ }
261
+ // console.log('attributes', attributes)
262
+ if (this.props.mergedata) {
263
+ this.props.mergedata = JSON.parse(this.props.mergedata)
264
+ }
265
+ console.log('this.props', this.props)
266
+ }
267
+
268
+ initEvent () {
269
+ // this.shadow.querySelector('.spu-expandexp')!.addEventListener('click', (e) => {
270
+ // // console.log(this)
271
+ // // console.log(this.shadow)
272
+ // console.log(e)
273
+ // console.log(e.target)
274
+ // console.log(e.target.nodeName)
275
+ // debugger
276
+
277
+ // this.dispatchEvent(new CustomEvent('click', {
278
+ // detail: {
279
+ // clickMessage: 'Hello from within the Custom Element'
280
+ // }
281
+ // }))
282
+ // }, true)
283
+
284
+ this.shadow.querySelector('.modal-th .close')!.addEventListener('click', () => {
285
+ this.removeSelf()
286
+ })
287
+
288
+ this.shadow.querySelector('.export-file .export-file-r-download')!.addEventListener('click', () => {
289
+ console.log('下载')
290
+ this.handleDownload()
291
+ })
292
+
293
+ this.shadow.querySelector('.export-file .export-file-r-cancel')!.addEventListener('click', () => {
294
+ console.log('取消')
295
+ this.handleCencel()
296
+ })
297
+
298
+ this.shadow.querySelector('.export-btnwrap .btn')!.addEventListener('click', () => {
299
+ console.log('导出')
300
+ this.handleExport()
301
+ // this.data.percentage = this.data.percentage + 20
302
+ // this.data.isOldVersionService = false
303
+ // this.data.runningTaskCount = 1
304
+ // this.data.runningTaskCount = 1
305
+ // this.data.fileSize = dealFileSize('')
306
+ })
307
+ }
308
+
309
+ async getExpandexpConfig () {
310
+ let isInstallexpandexp = await core.checkModule('expandexp')
311
+ // isInstallexpandexp = false
312
+ console.log('isInstallexpandexp', isInstallexpandexp)
313
+
314
+ if (isInstallexpandexp) {
315
+ this.data.expandStatus = '3'
316
+ this.data.filewatermark = '1'
317
+ this.data.iscompress = '1'
318
+
319
+ // 这个单个查询接口返回的filewatermark已经结合了全局水印开关 因此不需要查询全局水印
320
+ Module.apiRequest({
321
+ modulekey: 'expandexp',
322
+ apitag: 'imageConfig-getByPageCode',
323
+ body: {
324
+ pagecode: this.props.pagecode
325
+ },
326
+ complete: (code: any, data: any, msg: any) => {
327
+ // console.log('imageConfig', code, data, msg)
328
+ if (code === 200) {
329
+ this.data.exportcontentArray = data.exportcontent
330
+ // this.data.exportcontentArray = ['photo']
331
+ if (this.data.exportcontentArray?.length > 0) {
332
+ this.data.exportcontent = this.data.exportcontentArray[0]
333
+ } else {
334
+ this.data.exportcontent = 'excel'
335
+ }
336
+ this.data.filewatermarkGlobalConfig = data.filewatermark.toString()
337
+ this.data.filewatermark = data.filewatermark.toString()
338
+ this.data.iscompress = data.iscompress.toString()
339
+ this.data.imagesizepercolumn = data.imagesizepercolumn.toString()
340
+ this.data.imageheightcm = data.imageheightcm.toString()
341
+ }
342
+ }
343
+ })
344
+ } else {
345
+ this.data.filewatermark = '0'
346
+ this.data.iscompress = '0'
347
+ apaasAxios
348
+ .post('/api/expandexp/global/searchExpGloConfig', {
349
+ key: 'export-config-switch',
350
+ tenantcode: login.getUser('tenantcode'),
351
+ productcode: login.getUser('productcode')
352
+ }, {}, {
353
+ isShowLoading: false
354
+ })
355
+ .then((res: any) => {
356
+ // res.data.exttype = '1'
357
+ // res.data.exttype: 2开启了为服务端导出 1为普通导出
358
+ if (res.code === 200 && res?.data?.exttype === '2') {
359
+ this.data.expandStatus = '2'
360
+ } else {
361
+ this.data.expandStatus = '1'
362
+ }
363
+ })
364
+ .catch((err: Error) => {
365
+ this.data.expandStatus = '1'
366
+ }).finally(() => {
367
+
368
+ if (this.data.expandStatus === '1') {
369
+ this.data.exportcontentArray = ['excel']
370
+ this.data.exportcontent = 'excel'
371
+ }
372
+
373
+ // 获取文件水印开关
374
+ apaasAxios
375
+ .post('/api/expandexp/global/searchWatermarkConfig', '', {
376
+ isShowLoading: false
377
+ })
378
+ .then((res: any) => {
379
+ if (res.code === 200 && res?.data?.configjson) {
380
+ this.data.filewatermarkGlobalConfig = JSON.parse(res.data.configjson).isWatermark === '1' ? '1' : '0'
381
+ } else {
382
+ this.data.filewatermarkGlobalConfig = '0'
383
+ }
384
+ })
385
+ .catch(() => {
386
+ this.data.filewatermarkGlobalConfig = '0'
387
+ }).finally(() => {
388
+ this.data.filewatermark = this.data.filewatermarkGlobalConfig === '1' ? '1' : '0'
389
+ })
390
+ })
391
+ }
392
+ }
393
+
394
+ getExportcontentValue () {
395
+ let result = ''
396
+ const eles = this.shadow.querySelectorAll('.export-sel-con input[type=radio][name=exportcontent]') as any
397
+ // console.log(eles)
398
+ for (let i = 0, len = eles.length; i < len; i++) {
399
+ if (eles[i].checked === true) {
400
+ result = eles[i].value
401
+ break
402
+ }
403
+ }
404
+ return result
405
+ }
406
+
407
+ async handleExport () {
408
+ this.updateStep('ready')
409
+ this.data.fileSize = dealFileSize('')
410
+
411
+ const exportcontent = this.getExportcontentValue()
412
+ this.data.exportcontent = exportcontent
413
+
414
+ const mergedata = cloneDeep(this.props.mergedata)
415
+ const post = {
416
+ expfile: {
417
+ pagecode: this.props.pagecode,
418
+ sheetname: this.props.sheetname,
419
+ filename: fixFileName(this.data.fileName, this.data.filetype, this.data.exportcontent),
420
+ filetype: this.data.filetype,
421
+ // exttype 1.普通导出,2.服务端导出
422
+ // 如果为1 或没有这个属性,视为不拓展,前端做兼容
423
+ // 如果是仅导出单据 默认走普通导出 exttype = '1'
424
+ // 因为如果仅导出单据 + 支持水印,又要传 exttype = '2',很麻烦,改为后端处理,如果 expandStatus = 2 | 3 ,exttype就传2,其他情况传1
425
+ // exttype: (config.exportcontentValue === 'excel' || config.expandStatus === '1') ? '1' : '2',
426
+ exttype: this.data.expandStatus === '1' ? '1' : '2',
427
+ // 扩展导出参数
428
+ extconfig: {
429
+ filetype: this.data.filetype,
430
+ exportcontent: exportcontent,
431
+ filewatermark: this.data.filewatermark,
432
+ iscompress: this.data.iscompress,
433
+ displaytype: this.data.displaytype,
434
+ imagetype: this.data.imagetype,
435
+ imagename: this.data.imagename,
436
+ imagesizepercolumn: this.data.imagesizepercolumn,
437
+ imageheightcm: this.data.imageheightcm
438
+ }
439
+ }
440
+ }
441
+ const finallyPost = mergedata ? merge(mergedata, post) : post
442
+ apaasAxios
443
+ .post(this.props.exportapi, finallyPost)
444
+ .then((res: any) => {
445
+ // console.log(res)
446
+ const result = res?.data
447
+ if (result?.code === 200 && result?.data) {
448
+ this.data.exportId = result.data
449
+ this.data.percentage = 0
450
+ // 到ready
451
+ this.updateStep('ready')
452
+ this.statusTimer = window.setInterval(() => {
453
+ this.updateStatus()
454
+ }, 2000)
455
+ } else {
456
+ this.updateStep('error')
457
+ this.data.percentage = 100
458
+ this.data.resultMessage = result?.msg || '网络连接错误'
459
+ this.stopInterval()
460
+ }
461
+ })
462
+ .catch((error: any) => {
463
+ // console.log(error)
464
+ // debugger
465
+ this.updateStep('error')
466
+ this.data.percentage = 100
467
+ this.data.resultMessage = '网络连接错误'
468
+ this.stopInterval()
469
+ })
470
+ }
471
+
472
+ handleDownload () {
473
+ console.log(this.data)
474
+ console.log(this.data.exportDataItem)
475
+
476
+ let fixExportFileUrl = this.data.exportDataItem.exportfileurl[0] === '/' ? this.data.exportDataItem.exportfileurl : '/' + this.data.exportDataItem.exportfileurl
477
+ let exportFileName = this.data.exportDataItem.filename
478
+ let date = this.data.exportDataItem.initdate
479
+
480
+ // console.log({
481
+ // type: 'att',
482
+ // source: fixExportFileUrl,
483
+ // datetime: date,
484
+ // storagetype: 'storage-1d',
485
+ // filename: exportFileName
486
+ // })
487
+
488
+ downloadService.downloadFile({
489
+ type: 'att',
490
+ source: fixExportFileUrl,
491
+ datetime: date,
492
+ storagetype: 'storage-1d',
493
+ filename: exportFileName
494
+ })
495
+ }
496
+
497
+ async handleTest () {
498
+ console.log(this.data)
499
+ console.log(this.data.exportDataItem)
500
+
501
+ // const file = {
502
+ // "fixExportFileUrl": "/23e/att/20240523/1656688/23eea1bb-cb5a-40b7-a411-4b3ef2439b4c.xlsx",
503
+ // "date": "1716458086237",
504
+ // "exportFileName": "终端进离-统计.xlsx",
505
+ // "type": "att",
506
+ // "storage": "storage-1d"
507
+ // }
508
+
509
+ // const imgUrl = await downloadService.downloadFile({
510
+ // type: 'att',
511
+ // // source: file.fixExportFileUrl,
512
+ // source: '23eea1bb-cb5a-40b7-a411-4b3ef2439b4c.xlsx',
513
+ // datetime: '1716458086237',
514
+ // storagetype: 'storage-1d',
515
+ // filename: '终端进离-统计.xlsx'
516
+ // })
517
+ // console.log(imgUrl)
518
+
519
+ // DownloadService.downloadFile(this, fixExportFileUrl, date, exportFileName, 'att', 'storage-1d')
520
+ }
521
+
522
+ handleCencel () {
523
+ // console.log(this.data)
524
+ // console.log(this.data.exportDataItem)
525
+ apaasAxios
526
+ .post('/api/teapi/queue/impexp/cancel', {
527
+ dynamicid: this.data.exportId
528
+ })
529
+ .then((res: any) => {
530
+ if (res?.code === 200 && res?.data) {
531
+ // 取消成功
532
+ this.updateStep('cancel')
533
+ this.data.resultMessage = '任务已取消'
534
+ }
535
+ })
536
+ .catch((error: any) => {
537
+
538
+ })
539
+ }
540
+
541
+ updateStep (statusName: string) {
542
+ if (statusName === 'next') {
543
+ this.data.step.next()
544
+ } else {
545
+ this.data.step.go(statusName)
546
+ }
547
+ this.data.stepStatus = this.data.step.status
548
+ this.data.stepName = this.data.step.statusName
549
+ this.data.stepText = this.data.step.statusText
550
+ }
551
+
552
+ async updateStatus () {
553
+ apaasAxios
554
+ .post(`/api/teapi/queue/impexp/expStatus?dynamicid=${this.data.exportId}`, {}, {
555
+ isShowLoading: false
556
+ })
557
+ .then((res: any) => {
558
+ let responseData = res?.data?.states
559
+ let currentData = null
560
+ if (!responseData) {
561
+ this.data.isOldVersionService = true
562
+ return
563
+ } else {
564
+ if (Array.isArray(responseData)) {
565
+ this.data.isOldVersionService = true
566
+ if (responseData.length > 1) {
567
+ responseData = responseData.filter((item: any) => {
568
+ return item.dynamicid === this.data.exportId
569
+ })
570
+ }
571
+ currentData = responseData[0]
572
+ } else {
573
+ this.data.isOldVersionService = false
574
+ this.data.runningTaskCount = responseData.queuesize
575
+ if (responseData.states && responseData.states.length > 1) {
576
+ responseData.states = responseData.states.filter((item: any) => {
577
+ return item.dynamicid === this.data.exportId
578
+ })
579
+ }
580
+ currentData = responseData.states && responseData.states[0]
581
+ }
582
+ }
583
+ if (!currentData) {
584
+ return
585
+ }
586
+
587
+ if (currentData.exportstate === 'complete') {
588
+ const data = currentData
589
+ this.data.percentage = 100
590
+ if (data.errorfileurl || data.fatalerrormsg) {
591
+ this.updateStep('error')
592
+ } else {
593
+ this.updateStep('success')
594
+ }
595
+ if (data.filesize) {
596
+ // 普通导出服务返回 4000 服务端导出返回 4kb
597
+ // 这里做兼容处理
598
+ this.data.fileSize = dealFileSize(data.filesize)
599
+ }
600
+ this.data.exportDataItem = data
601
+ this.data.resultMessage = dealResultMessage(data)
602
+ this.stopInterval()
603
+ } else if (currentData.exportstate === 'readyrun') {
604
+ this.updateStep('ready')
605
+ } else if (currentData.exportstate === 'fatalerror') {
606
+ this.data.percentage = 100
607
+ this.updateStep('error')
608
+ this.data.resultMessage = dealResultMessage(currentData)
609
+ this.stopInterval()
610
+ } else if (currentData.exportstate === 'cancel') {
611
+ this.updateStep('cancel')
612
+ this.data.resultMessage = '任务取消'
613
+ // this.stopInterval()
614
+ } else if (currentData.exportstate === 'ext_readyrun') {
615
+ this.updateStep('ext_readyrun')
616
+ if (currentData) {
617
+ this.data.percentage = +currentData.finishRate * 0.5 + 50
618
+ }
619
+ } else if (currentData.exportstate === 'ext_running') {
620
+ this.updateStep('ext_running')
621
+ // debugger
622
+ if (currentData) {
623
+ this.data.percentage = +currentData.finishRate * 0.5 + 50
624
+ }
625
+ } else {
626
+ this.updateStep('running')
627
+ if (currentData) {
628
+ this.data.percentage = +currentData.finishRate * 0.5
629
+ // state.percentage = +currentData.finishRate
630
+ }
631
+ }
632
+ })
633
+ .catch((err: any) => {
634
+ console.error(err)
635
+ this.updateStep('error')
636
+ this.data.percentage = 100
637
+ if (err.status === 0) {
638
+ this.data.resultMessage = '网络链接错误'
639
+ this.stopInterval()
640
+ }
641
+ })
642
+ }
643
+
644
+ stopInterval () {
645
+ if (this.statusTimer) {
646
+ window.clearInterval(this.statusTimer)
647
+ this.statusTimer = null
648
+ }
649
+ }
650
+
651
+ removeSelf () {
652
+ this.parentNode!.removeChild(this)
653
+ }
654
+
655
+ attributeChangedCallback (name: any, oldValue: any, newValue: any) {
656
+ console.log('属性变化', name, oldValue, newValue)
657
+ }
658
+
659
+ // 当组件从 DOM 文档移除后调用。
660
+ disconnectedCallback () {
661
+ this.stopInterval()
662
+ // console.log('disconnectedCallback')
663
+ // setTimeout(() => {
664
+ // console.log(this)
665
+ // }, 100)
666
+ }
667
+ }
668
+
669
+ class Expandexp {
670
+ ele!: HTMLElement
671
+ config!: any
672
+
673
+ constructor (config: any) {
674
+ SpuExpandexp.register()
675
+ this.config = config
676
+ this.ele = document.createElement('spu-expandexp')
677
+
678
+ if (this.config) {
679
+ for (const x in this.config) {
680
+ if (x === 'mergedata' && this.config[x]) {
681
+ if (this.config[x]) {
682
+ this.ele.setAttribute(x, JSON.stringify(this.config[x]))
683
+ }
684
+ } else {
685
+ this.ele.setAttribute(x, this.config[x])
686
+ }
687
+ }
688
+ }
689
+
690
+ // console.log(this.ele)
691
+ document.body.appendChild(this.ele)
692
+ }
693
+
694
+ // close () {
695
+ // if (this.ele) {
696
+ // document.body.removeChild(this.ele)
697
+ // }
698
+ // }
699
+ }
700
+
701
+ const expandexp = (config: any) => {
702
+ new Expandexp(config)
703
+ }
704
+
705
+ export {
706
+ expandexp
707
+ }