From d0bb1d0206803504d621e7285204d3eced998649 Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Thu, 18 Dec 2025 18:31:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E6=8D=A2=E8=A1=8C=E5=90=8E=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E8=A1=A8=E5=A4=B4=E5=AF=B9=E9=BD=90=E6=96=B9=E5=BC=8F=E5=8F=91?= =?UTF-8?q?=E7=94=9F=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/common/common_table.ts | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts b/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts index ac47a1ebd6..522c28254d 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts @@ -6,8 +6,8 @@ import { isTransparent, parseJson, resetRgbOpacity, - safeDecimalSum, - safeDecimalMean + safeDecimalMean, + safeDecimalSum } from '../..//util' import { DEFAULT_BASIC_STYLE, @@ -50,17 +50,13 @@ import { filter, find, intersection, + isNumber, keys, map, maxBy, - meanBy, merge, minBy, - repeat, - sumBy, - size, - sum, - isNumber + repeat } from 'lodash-es' import { createVNode, render } from 'vue' import TableTooltip from '@/views/chart/components/editor/common/TableTooltip.vue' @@ -2198,7 +2194,7 @@ export class CustomDataCell extends TableDataCell { * @protected */ protected drawTextShape() { - if(this.meta.isMergedCell) { + if (this.meta.isMergedCell) { return } if (this.meta.autoWrap) { @@ -2242,7 +2238,8 @@ const drawTextShape = (cell, isHeader) => { // 单元格文本 const { formattedValue } = cell.getFormattedFieldValue() // 获取文本样式 - const textStyle = cell.getTextStyle() + const textStyle = cloneDeep(cell.getTextStyle()) + textStyle.textAlign = undefined // 宽度能放几个字符,就放几个,放不下就换行 let wrapText = getWrapText( formattedValue ? formattedValue?.toString() : emptyPlaceholder, @@ -2298,7 +2295,8 @@ const drawTextShape = (cell, isHeader) => { cell.actualTextWidth = cell.spreadsheet.measureTextWidth(wrapText, textStyle) // 获取文本位置并渲染文本 - const { x, y } = cell.getTextAndIconPosition()?.text || cell.getTextPosition() + const { y } = cell.getTextAndIconPosition()?.text || cell.getTextPosition() + const x = getTextStartX(cell, textStyle) // 绘制文本 cell.textShape = renderText(cell, [cell.textShape], x, y, wrapText, textStyle, { fontSize: extraStyleFontSize @@ -2308,6 +2306,33 @@ const drawTextShape = (cell, isHeader) => { cell.textShapes.push(cell.textShape) } +/** + * 计算文本起始X位置 + * @param cell + * @param textStyle + */ +function getTextStartX(cell, textStyle) { + // 获取单元格区域 + const area = cell.getCellArea() + // 计算文本宽度,只计算第一行宽度 + const textWidth = cell.spreadsheet.measureTextWidthRoughly( + cell.actualText.split('\n')[0], + textStyle + ) + const padding = cell.theme.colCell?.cell?.padding ?? { left: 0, right: 0 } + const align = cell.getTextStyle()?.textAlign ?? 'left' + switch (align) { + case 'left': + return area.x + (padding.left || 0) + case 'center': + return area.x + (area.width - textWidth) / 2 + case 'right': + return area.x + area.width - textWidth - (padding.right || 0) + default: + return area.x + (padding.left || 0) + } +} + /** * 计算表头高度 * @param info 单元格信息