fix: 部分仪表板导出模板失败

This commit is contained in:
wangjiahao 2022-04-29 10:35:00 +08:00
parent 1c551ae3cc
commit 6fe299c5c9

View File

@ -266,35 +266,40 @@ export default {
downloadToTemplate() { downloadToTemplate() {
const _this = this const _this = this
_this.dataLoading = true _this.dataLoading = true
_this.findStaticSource(function(staticResource) { try {
html2canvas(document.getElementById('canvasInfoTemp')).then(canvas => { _this.findStaticSource(function(staticResource) {
_this.dataLoading = false html2canvas(document.getElementById('canvasInfoTemp')).then(canvas => {
const snapshot = canvas.toDataURL('image/jpeg', 0.1) // 0.1 _this.dataLoading = false
if (snapshot !== '') { const snapshot = canvas.toDataURL('image/jpeg', 0.1) // 0.1
_this.templateInfo = { if (snapshot !== '') {
name: _this.$store.state.panel.panelInfo.name, _this.templateInfo = {
templateType: 'self', name: _this.$store.state.panel.panelInfo.name,
snapshot: snapshot, templateType: 'self',
panelStyle: JSON.stringify(_this.canvasStyleData), snapshot: snapshot,
panelData: JSON.stringify(_this.componentData), panelStyle: JSON.stringify(_this.canvasStyleData),
dynamicData: JSON.stringify(_this.panelViewDetailsInfo), panelData: JSON.stringify(_this.componentData),
staticResource: JSON.stringify(staticResource || {}) dynamicData: JSON.stringify(_this.panelViewDetailsInfo),
staticResource: JSON.stringify(staticResource || {})
}
const blob = new Blob([JSON.stringify(_this.templateInfo)], { type: '' })
FileSaver.saveAs(blob, _this.$store.state.panel.panelInfo.name + '-TEMPLATE.DET')
} }
const blob = new Blob([JSON.stringify(_this.templateInfo)], { type: '' }) })
FileSaver.saveAs(blob, _this.$store.state.panel.panelInfo.name + '-TEMPLATE.DET')
}
}) })
}) } catch (e) {
console.error(e)
_this.dataLoading = false
}
}, },
// //
findStaticSource(callBack) { findStaticSource(callBack) {
const staticResource = [] const staticResource = []
// //
if (this.canvasStyleData.panel.imageUrl && this.canvasStyleData.panel.imageUrl.indexOf('static-resource') > -1) { if (typeof this.canvasStyleData.panel.imageUrl === 'string' && this.canvasStyleData.panel.imageUrl.indexOf('static-resource') > -1) {
staticResource.push(this.canvasStyleData.panel.imageUrl) staticResource.push(this.canvasStyleData.panel.imageUrl)
} }
this.componentData.forEach(item => { this.componentData.forEach(item => {
if (item.commonBackground && item.commonBackground.outerImage && item.commonBackground.outerImage.indexOf('static-resource') > -1) { if (typeof item.commonBackground.outerImage === 'string' && item.commonBackground.outerImage.indexOf('static-resource') > -1) {
staticResource.push(item.commonBackground.outerImage) staticResource.push(item.commonBackground.outerImage)
} }
}) })
@ -308,7 +313,9 @@ export default {
callBack() callBack()
} }
} else { } else {
callBack() setTimeout(() => {
callBack()
}, 0)
} }
}, },