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
if (chart.type == 'customComponent') {
// 为本地G2组件配置添加迭代器
if (!plotSettingsIterator) {
plotSettings[Symbol.iterator] = function * () { plotSettings[Symbol.iterator] = function * () {
const keys = Object.keys(plotSettings) const keys = Object.keys(plotSettings)
for (const k of keys) { for (const k of keys) {
yield [k, plotSettings[k]] yield [k, plotSettings[k]]
} }
} }
for (const [key, value] of plotSettings) { }
if (item.name == value.name) { for (const [key, localPlotSetting] of plotSettings) {
const settings = JSON.parse(JSON.stringify(value.setting)) if (chart.name == localPlotSetting.name) {
item.setting = settings.map((x) => { // 本地配置项
const index = item.setting.findIndex(y => y.field == x.field) const localSettings = JSON.parse(JSON.stringify(localPlotSetting.setting))
x.field = item.setting[index].field chart.setting = localSettings.map((localSet) => {
x.value = item.setting[index].value // 在远程组件配置中找到 与 本地组件的配置项 相同的项索引
return x const index = chart.setting.findIndex(remoteSet => remoteSet.field == localSet.field)
if (index !== -1) {
// 使用远程的值替换本地值
localSet.field = chart.setting[index].field
localSet.value = chart.setting[index].value
}
return localSet
}) })
} }
} }

Loading…
Cancel
Save