From eec7f92b86077701c4b5f3325f323baa3527cc97 Mon Sep 17 00:00:00 2001 From: wisonic Date: Sat, 12 Oct 2024 20:21:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94=E5=88=97=E5=AE=BD=E6=8B=96=E6=8B=BD?= =?UTF-8?q?=E5=AE=BD=E5=BA=A6=E5=90=8E=E6=9C=AA=E9=93=BA=E6=BB=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/charts/table/table-info.ts | 65 +++++++++---------- .../js/panel/charts/table/table-normal.ts | 45 ++++++------- 2 files changed, 48 insertions(+), 62 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts index 9ea25e826f..b5f60ed47a 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts @@ -207,52 +207,45 @@ export class TableInfo extends S2ChartView { newChart.store.set('lastLayoutResult', newChart.facet.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 - if (status === 'expanded' && lastLayoutResult) { - // 拖拽表头定义宽度,和上一次布局对比,保留除已拖拽列之外的宽度 + if (lastLayoutResult) { + // 拖动表头 resize const widthByFieldValue = newChart.options.style?.colCfg?.widthByFieldValue - const lastLayoutWidthMap: Record = lastLayoutResult?.colLeafNodes.reduce( - (p, n) => { + const lastLayoutWidthMap: Record = + lastLayoutResult?.colLeafNodes.reduce((p, n) => { p[n.value] = widthByFieldValue?.[n.value] ?? n.width return p - }, - {} - ) + }, {}) || {} const totalWidth = ev.colLeafNodes.reduce((p, n) => { - n.width = lastLayoutWidthMap[n.value] + n.width = lastLayoutWidthMap[n.value] || n.width n.x = p return p + n.width }, 0) ev.colsHierarchy.width = totalWidth - } else { - // 第一次渲染初始化,把图片字段固定为 120 进行计算 - const urlFields = fields.filter(field => field.deType === 7).map(f => f.dataeaseName) - const totalWidthWithImg = ev.colLeafNodes.reduce((p, n) => { - return p + (urlFields.includes(n.field) ? 120 : n.width) - }, 0) - if (containerDom.offsetWidth <= totalWidthWithImg) { - // 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,不处理 - newChart.store.set('status', 'default') - return - } - // 图片字段固定 120, 剩余宽度按比例均摊到其他字段进行扩大 - const totalWidthWithoutImg = ev.colLeafNodes.reduce((p, n) => { - return p + (urlFields.includes(n.field) ? 0 : n.width) - }, 0) - const restWidth = containerDom.offsetWidth - urlFields.length * 120 - const scale = restWidth / totalWidthWithoutImg - const totalWidth = ev.colLeafNodes.reduce((p, n) => { - n.width = urlFields.includes(n.field) ? 120 : n.width * scale - n.x = p - return p + n.width - }, 0) - ev.colsHierarchy.width = Math.min(containerDom.offsetWidth, totalWidth) - newChart.store.set('status', 'expanded') + newChart.store.set('lastLayoutResult', undefined) + return } + // 第一次渲染初始化,把图片字段固定为 120 进行计算 + const urlFields = fields.filter(field => field.deType === 7).map(f => f.dataeaseName) + const totalWidthWithImg = ev.colLeafNodes.reduce((p, n) => { + return p + (urlFields.includes(n.field) ? 120 : n.width) + }, 0) + if (containerDom.offsetWidth <= totalWidthWithImg) { + // 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,不处理 + return + } + // 图片字段固定 120, 剩余宽度按比例均摊到其他字段进行扩大 + const totalWidthWithoutImg = ev.colLeafNodes.reduce((p, n) => { + return p + (urlFields.includes(n.field) ? 0 : n.width) + }, 0) + const restWidth = containerDom.offsetWidth - urlFields.length * 120 + const scale = restWidth / totalWidthWithoutImg + const totalWidth = ev.colLeafNodes.reduce((p, n) => { + n.width = urlFields.includes(n.field) ? 120 : n.width * scale + n.x = p + return p + n.width + }, 0) + ev.colsHierarchy.width = Math.min(containerDom.offsetWidth, totalWidth) }) } // click diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts index a5fbcf4053..1ac9e543af 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts @@ -228,42 +228,35 @@ export class TableNormal extends S2ChartView { newChart.store.set('lastLayoutResult', newChart.facet.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 - if (status === 'expanded' && lastLayoutResult) { - // 拖拽表头定义宽度,和上一次布局对比,保留除已拖拽列之外的宽度 + if (lastLayoutResult) { + // 拖动表头 resize const widthByFieldValue = newChart.options.style?.colCfg?.widthByFieldValue - const lastLayoutWidthMap: Record = lastLayoutResult?.colLeafNodes.reduce( - (p, n) => { + const lastLayoutWidthMap: Record = + lastLayoutResult?.colLeafNodes.reduce((p, n) => { p[n.value] = widthByFieldValue?.[n.value] ?? n.width return p - }, - {} - ) + }, {}) || {} const totalWidth = ev.colLeafNodes.reduce((p, n) => { - n.width = lastLayoutWidthMap[n.value] + n.width = lastLayoutWidthMap[n.value] || n.width n.x = p return p + n.width }, 0) ev.colsHierarchy.width = totalWidth - } else { - const scale = containerDom.offsetWidth / ev.colsHierarchy.width - if (scale <= 1) { - // 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,不处理 - newChart.store.set('status', 'default') - return - } - const totalWidth = ev.colLeafNodes.reduce((p, n) => { - n.width = n.width * scale - n.x = p - return p + n.width - }, 0) - ev.colsHierarchy.width = Math.min(containerDom.offsetWidth, totalWidth) - newChart.store.set('status', 'expanded') + newChart.store.set('lastLayoutResult', undefined) + return } + const scale = containerDom.offsetWidth / ev.colsHierarchy.width + if (scale <= 1) { + // 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,不处理 + return + } + const totalWidth = ev.colLeafNodes.reduce((p, n) => { + n.width = n.width * scale + n.x = p + return p + n.width + }, 0) + ev.colsHierarchy.width = Math.min(containerDom.offsetWidth, totalWidth) }) } // click