异步数据导致渲染过早无法加载监控

This commit is contained in:
aixianling
2024-07-16 14:46:04 +08:00
parent a6af330500
commit 9b7b1283a8

View File

@@ -86,27 +86,28 @@ export default {
this.component = config.custom this.component = config.custom
this.meta = config?.meta || {} this.meta = config?.meta || {}
} else { } else {
this.componentList = JSON.parse(res.data.config).config const layers = JSON.parse(res.data.config).config
this.dashboard = JSON.parse(res.data.config).dashboard this.dashboard = JSON.parse(res.data.config).dashboard
Promise.all(layers.map(item => Promise.resolve().then(() => {
this.componentList.forEach((item, index) => {
if (item.dataType !== 'staticData' && ((item.type.indexOf('Chart') > -1) || ['display', 'table', 'map', 'summary', 'AiRanking', 'AiDvTable'].includes(item.type))) { if (item.dataType !== 'staticData' && ((item.type.indexOf('Chart') > -1) || ['display', 'table', 'map', 'summary', 'AiRanking', 'AiDvTable'].includes(item.type))) {
this.getSourceData(item, index) return this.getSourceData(item, index)
} }
if (item.type === 'monitor' && item.monitorType === 'cmcc') { if (item.type === 'monitor' && item.monitorType === 'cmcc') {
item.moniterId && this.instance.post(`${this.urlPrefix}/appzyvideoequipment/getWebSdkUrl?deviceId=${item.moniterId}`).then(res => { return item.moniterId && this.instance.post(`${this.urlPrefix}/appzyvideoequipment/getWebSdkUrl?deviceId=${item.moniterId}`).then(res => {
if (res.code == 0) { if (res.code == 0) {
this.$set(this.componentList[index], 'src', JSON.parse(res.data).url) return item.src = JSON.parse(res.data).url
} }
}) })
} }
if (item.type === 'monitor' && item.monitorType === 'slw') { if (item.type === 'monitor' && item.monitorType === 'slw') {
item.moniterId && this.instance.post(`${this.urlPrefix}/appzyvideoequipment/getWebSdkUrl?deviceId=${item.moniterId}`).then(res => { return item.moniterId && this.instance.post(`${this.urlPrefix}/appzyvideoequipment/getWebSdkUrl?deviceId=${item.moniterId}`).then(res => {
if (res.code == 0) { if (res.code == 0) {
this.$set(this.componentList[index], 'src', res.data) return item.src = res.data
} }
}) })
} }
}))).then(() => {
this.componentList = layers
}) })
} }
} }
@@ -114,7 +115,7 @@ export default {
}, },
getSourceData(item, index) { getSourceData(item, index) {
const api = item.dataType === 'apiData' ? item.api : `${this.urlPrefix}/appdiylargescreen/statisticsByLsid?id=${item.sourceDataId}` const api = item.dataType === 'apiData' ? item.api : `${this.urlPrefix}/appdiylargescreen/statisticsByLsid?id=${item.sourceDataId}`
this.instance.post(api).then(res => { return this.instance.post(api).then(res => {
if (res?.data) { if (res?.data) {
if (res.data.length) { if (res.data.length) {
const keys = Object.keys(res.data[0]) const keys = Object.keys(res.data[0])