forked from github/dataease
fix(图表): 表格自适应列宽拖拽宽度后未铺满
This commit is contained in:
parent
6f6365e032
commit
eec7f92b86
@ -207,28 +207,24 @@ export class TableInfo extends S2ChartView<TableSheet> {
|
|||||||
newChart.store.set('lastLayoutResult', newChart.facet.layoutResult)
|
newChart.store.set('lastLayoutResult', newChart.facet.layoutResult)
|
||||||
})
|
})
|
||||||
newChart.on(S2Event.LAYOUT_AFTER_HEADER_LAYOUT, (ev: LayoutResult) => {
|
newChart.on(S2Event.LAYOUT_AFTER_HEADER_LAYOUT, (ev: LayoutResult) => {
|
||||||
const status = newChart.store.get('status')
|
|
||||||
if (status === 'default') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const lastLayoutResult = newChart.store.get('lastLayoutResult') as LayoutResult
|
const lastLayoutResult = newChart.store.get('lastLayoutResult') as LayoutResult
|
||||||
if (status === 'expanded' && lastLayoutResult) {
|
if (lastLayoutResult) {
|
||||||
// 拖拽表头定义宽度,和上一次布局对比,保留除已拖拽列之外的宽度
|
// 拖动表头 resize
|
||||||
const widthByFieldValue = newChart.options.style?.colCfg?.widthByFieldValue
|
const widthByFieldValue = newChart.options.style?.colCfg?.widthByFieldValue
|
||||||
const lastLayoutWidthMap: Record<string, number> = lastLayoutResult?.colLeafNodes.reduce(
|
const lastLayoutWidthMap: Record<string, number> =
|
||||||
(p, n) => {
|
lastLayoutResult?.colLeafNodes.reduce((p, n) => {
|
||||||
p[n.value] = widthByFieldValue?.[n.value] ?? n.width
|
p[n.value] = widthByFieldValue?.[n.value] ?? n.width
|
||||||
return p
|
return p
|
||||||
},
|
}, {}) || {}
|
||||||
{}
|
|
||||||
)
|
|
||||||
const totalWidth = ev.colLeafNodes.reduce((p, n) => {
|
const totalWidth = ev.colLeafNodes.reduce((p, n) => {
|
||||||
n.width = lastLayoutWidthMap[n.value]
|
n.width = lastLayoutWidthMap[n.value] || n.width
|
||||||
n.x = p
|
n.x = p
|
||||||
return p + n.width
|
return p + n.width
|
||||||
}, 0)
|
}, 0)
|
||||||
ev.colsHierarchy.width = totalWidth
|
ev.colsHierarchy.width = totalWidth
|
||||||
} else {
|
newChart.store.set('lastLayoutResult', undefined)
|
||||||
|
return
|
||||||
|
}
|
||||||
// 第一次渲染初始化,把图片字段固定为 120 进行计算
|
// 第一次渲染初始化,把图片字段固定为 120 进行计算
|
||||||
const urlFields = fields.filter(field => field.deType === 7).map(f => f.dataeaseName)
|
const urlFields = fields.filter(field => field.deType === 7).map(f => f.dataeaseName)
|
||||||
const totalWidthWithImg = ev.colLeafNodes.reduce((p, n) => {
|
const totalWidthWithImg = ev.colLeafNodes.reduce((p, n) => {
|
||||||
@ -236,7 +232,6 @@ export class TableInfo extends S2ChartView<TableSheet> {
|
|||||||
}, 0)
|
}, 0)
|
||||||
if (containerDom.offsetWidth <= totalWidthWithImg) {
|
if (containerDom.offsetWidth <= totalWidthWithImg) {
|
||||||
// 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,不处理
|
// 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,不处理
|
||||||
newChart.store.set('status', 'default')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 图片字段固定 120, 剩余宽度按比例均摊到其他字段进行扩大
|
// 图片字段固定 120, 剩余宽度按比例均摊到其他字段进行扩大
|
||||||
@ -251,8 +246,6 @@ export class TableInfo extends S2ChartView<TableSheet> {
|
|||||||
return p + n.width
|
return p + n.width
|
||||||
}, 0)
|
}, 0)
|
||||||
ev.colsHierarchy.width = Math.min(containerDom.offsetWidth, totalWidth)
|
ev.colsHierarchy.width = Math.min(containerDom.offsetWidth, totalWidth)
|
||||||
newChart.store.set('status', 'expanded')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// click
|
// click
|
||||||
|
@ -228,32 +228,27 @@ export class TableNormal extends S2ChartView<TableSheet> {
|
|||||||
newChart.store.set('lastLayoutResult', newChart.facet.layoutResult)
|
newChart.store.set('lastLayoutResult', newChart.facet.layoutResult)
|
||||||
})
|
})
|
||||||
newChart.on(S2Event.LAYOUT_AFTER_HEADER_LAYOUT, (ev: LayoutResult) => {
|
newChart.on(S2Event.LAYOUT_AFTER_HEADER_LAYOUT, (ev: LayoutResult) => {
|
||||||
const status = newChart.store.get('status')
|
|
||||||
if (status === 'default') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const lastLayoutResult = newChart.store.get('lastLayoutResult') as LayoutResult
|
const lastLayoutResult = newChart.store.get('lastLayoutResult') as LayoutResult
|
||||||
if (status === 'expanded' && lastLayoutResult) {
|
if (lastLayoutResult) {
|
||||||
// 拖拽表头定义宽度,和上一次布局对比,保留除已拖拽列之外的宽度
|
// 拖动表头 resize
|
||||||
const widthByFieldValue = newChart.options.style?.colCfg?.widthByFieldValue
|
const widthByFieldValue = newChart.options.style?.colCfg?.widthByFieldValue
|
||||||
const lastLayoutWidthMap: Record<string, number> = lastLayoutResult?.colLeafNodes.reduce(
|
const lastLayoutWidthMap: Record<string, number> =
|
||||||
(p, n) => {
|
lastLayoutResult?.colLeafNodes.reduce((p, n) => {
|
||||||
p[n.value] = widthByFieldValue?.[n.value] ?? n.width
|
p[n.value] = widthByFieldValue?.[n.value] ?? n.width
|
||||||
return p
|
return p
|
||||||
},
|
}, {}) || {}
|
||||||
{}
|
|
||||||
)
|
|
||||||
const totalWidth = ev.colLeafNodes.reduce((p, n) => {
|
const totalWidth = ev.colLeafNodes.reduce((p, n) => {
|
||||||
n.width = lastLayoutWidthMap[n.value]
|
n.width = lastLayoutWidthMap[n.value] || n.width
|
||||||
n.x = p
|
n.x = p
|
||||||
return p + n.width
|
return p + n.width
|
||||||
}, 0)
|
}, 0)
|
||||||
ev.colsHierarchy.width = totalWidth
|
ev.colsHierarchy.width = totalWidth
|
||||||
} else {
|
newChart.store.set('lastLayoutResult', undefined)
|
||||||
|
return
|
||||||
|
}
|
||||||
const scale = containerDom.offsetWidth / ev.colsHierarchy.width
|
const scale = containerDom.offsetWidth / ev.colsHierarchy.width
|
||||||
if (scale <= 1) {
|
if (scale <= 1) {
|
||||||
// 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,不处理
|
// 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,不处理
|
||||||
newChart.store.set('status', 'default')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const totalWidth = ev.colLeafNodes.reduce((p, n) => {
|
const totalWidth = ev.colLeafNodes.reduce((p, n) => {
|
||||||
@ -262,8 +257,6 @@ export class TableNormal extends S2ChartView<TableSheet> {
|
|||||||
return p + n.width
|
return p + n.width
|
||||||
}, 0)
|
}, 0)
|
||||||
ev.colsHierarchy.width = Math.min(containerDom.offsetWidth, totalWidth)
|
ev.colsHierarchy.width = Math.min(containerDom.offsetWidth, totalWidth)
|
||||||
newChart.store.set('status', 'expanded')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// click
|
// click
|
||||||
|
Loading…
Reference in New Issue
Block a user