diff --git a/packages/tdesign-uniapp/.changelog/pr-4500.md b/packages/tdesign-uniapp/.changelog/pr-4500.md new file mode 100644 index 000000000..f0f4b2369 --- /dev/null +++ b/packages/tdesign-uniapp/.changelog/pr-4500.md @@ -0,0 +1,6 @@ +--- +pr_number: 4500 +contributor: betavs +--- + +- fix(Table): 修复列配置中的类名选项无效的问题 @betavs ([#4500](https://github.com/Tencent/tdesign-miniprogram/pull/4500)) diff --git a/packages/uniapp-components/table/table.vue b/packages/uniapp-components/table/table.vue index 6cdfd3669..9c9576d87 100644 --- a/packages/uniapp-components/table/table.vue +++ b/packages/uniapp-components/table/table.vue @@ -295,12 +295,27 @@ export default { return styles.join('; '); }, + getCustomClassName(className = '') { + const calcClassName = (name) => { + if (typeof name === 'function') { + return name() || ''; + } + return name; + }; + + if (Array.isArray(className)) { + return className.map(calcClassName); + } + return [calcClassName(className)]; + }, + getThClassName(col, colIndex) { const classes = []; if (col.colKey) classes.push(`${name}__th-${col.colKey}`); if (col.align && col.align !== 'left') classes.push(`${prefix}-align-${col.align}`); if (col.fixed === 'left') classes.push(`${name}__cell--fixed-left`); if (col.fixed === 'right') classes.push(`${name}__cell--fixed-right`); + if (col.className) classes.push(...this.getCustomClassName(col.className)); if (colIndex === this.lastFixedLeftIndex) classes.push(`${name}__cell--fixed-left-last`); if (colIndex === this.firstFixedRightIndex) classes.push(`${name}__cell--fixed-right-first`); return classes.join(' ');