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