Skip to content

Commit

Permalink
【issues/7200】basicTable选中后没有选中样式 ---
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangdaiscott committed Sep 24, 2024
1 parent c868d90 commit a3997df
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions jeecgboot-vue3/src/components/Table/src/hooks/useTableStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,40 @@ import type { ComputedRef } from 'vue';
import type { BasicTableProps, TableCustomRecord } from '../types/table';
import { unref } from 'vue';
import { isFunction } from '/@/utils/is';
import { ROW_KEY } from '/@/components/Table/src/const';

export function useTableStyle(propsRef: ComputedRef<BasicTableProps>, prefixCls: string) {
/**
* 2024-09-19
* liaozhiyang
* 【issues/7200】basicTable选中后没有选中样式
* */
const isChecked = (propsRef, record) => {
const getAutoCreateKey = () => {
return unref(propsRef).autoCreateKey && !unref(propsRef).rowKey;
};
const getRowKey = () => {
const { rowKey } = unref(propsRef);
return getAutoCreateKey() ? ROW_KEY : rowKey;
};
// 获取行的key字段数据
const getRecordKey = (record) => {
const key = getRowKey();
if (!key) {
return record[ROW_KEY];
} else if (isFunction(key)) {
return key(record);
} else {
return record[key];
}
};
const { rowSelection } = unref(propsRef);
if (rowSelection?.selectedRowKeys?.length) {
return rowSelection.selectedRowKeys.includes(getRecordKey(record));
}
return false;
};

function getRowClassName(record: TableCustomRecord, index: number) {
const { striped, rowClassName } = unref(propsRef);
const classNames: string[] = [];
Expand All @@ -13,6 +45,11 @@ export function useTableStyle(propsRef: ComputedRef<BasicTableProps>, prefixCls:
if (rowClassName && isFunction(rowClassName)) {
classNames.push(rowClassName(record, index));
}
// update-begin--author:liaozhiyang---date:20240919---for:【issues/7200】basicTable选中后没有选中样式
if (isChecked(propsRef, record)) {
classNames.push('ant-table-row-selected');
}
// update-end--author:liaozhiyang---date:20240919---for:【issues/7200】basicTable选中后没有选中样式
return classNames.filter((cls) => !!cls).join(' ');
}

Expand Down

0 comments on commit a3997df

Please sign in to comment.