mirror of
https://github.com/dataease/dataease.git
synced 2026-05-14 21:12:33 +08:00
fix(图表): 恢复修复明细表换行后设置表头对齐方式发生异常的代码
This commit is contained in:
committed by
jianneng-fit2cloud
parent
1732678344
commit
9b37ee8a60
@@ -53,13 +53,9 @@ import {
|
||||
keys,
|
||||
map,
|
||||
maxBy,
|
||||
meanBy,
|
||||
merge,
|
||||
minBy,
|
||||
repeat,
|
||||
sumBy,
|
||||
size,
|
||||
sum,
|
||||
isNumber
|
||||
} from 'lodash-es'
|
||||
import { createVNode, render } from 'vue'
|
||||
@@ -2256,7 +2252,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,
|
||||
@@ -2312,7 +2309,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
|
||||
@@ -2322,6 +2320,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 单元格信息
|
||||
|
||||
Reference in New Issue
Block a user