fix: 优化页面加载时,对于G2组件的配置项兼容处理

main
hong.yang 1 year ago
parent e48f2572b5
commit 3930a8c13e

@ -17,32 +17,41 @@ export default {
// 配置兼容 // 配置兼容
const pageInfo = handleResData(data) const pageInfo = handleResData(data)
// 兼容边框配置 // 兼容边框配置
pageInfo.chartList.forEach((item) => { pageInfo.chartList.forEach((chart) => {
if (item.dataSource) { if (chart.dataSource) {
item.dataSource.source = item.dataSource?.source || 'dataset' chart.dataSource.source = chart.dataSource?.source || 'dataset'
} }
if (!item.border) { if (!chart.border) {
item.border = { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [0, 0, 0, 0] } chart.border = { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [0, 0, 0, 0] }
} }
if (!item.border.padding) { if (!chart.border.padding) {
item.border.padding = [0, 0, 0, 0] chart.border.padding = [0, 0, 0, 0]
} }
if (item.type == 'customComponent') { let plotSettingsIterator = false
plotSettings[Symbol.iterator] = function * () { if (chart.type == 'customComponent') {
const keys = Object.keys(plotSettings) // 为本地G2组件配置添加迭代器
for (const k of keys) { if (!plotSettingsIterator) {
yield [k, plotSettings[k]] plotSettings[Symbol.iterator] = function * () {
const keys = Object.keys(plotSettings)
for (const k of keys) {
yield [k, plotSettings[k]]
}
} }
} }
for (const [key, value] of plotSettings) { for (const [key, localPlotSetting] of plotSettings) {
if (item.name == value.name) { if (chart.name == localPlotSetting.name) {
const settings = JSON.parse(JSON.stringify(value.setting)) // 本地配置项
item.setting = settings.map((x) => { const localSettings = JSON.parse(JSON.stringify(localPlotSetting.setting))
const index = item.setting.findIndex(y => y.field == x.field) chart.setting = localSettings.map((localSet) => {
x.field = item.setting[index].field // 在远程组件配置中找到 与 本地组件的配置项 相同的项索引
x.value = item.setting[index].value const index = chart.setting.findIndex(remoteSet => remoteSet.field == localSet.field)
return x if (index !== -1) {
// 使用远程的值替换本地值
localSet.field = chart.setting[index].field
localSet.value = chart.setting[index].value
}
return localSet
}) })
} }
} }

Loading…
Cancel
Save