Skip to content

Commit

Permalink
feat(components): 新增对外暴露 getColumns
Browse files Browse the repository at this point in the history
Change-Id: Ife37e207ae5c9606df2c49a99516bb13536a263d
  • Loading branch information
njikm2010 committed Jun 25, 2024
1 parent 25ec230 commit f2faf0b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 36 deletions.
49 changes: 26 additions & 23 deletions packages/components/src/fat-table/fat-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,29 @@ const FatTableInner = declareComponent({
const doLayout = () => tableRef.value?.doLayout();
const gotoPage = (page: number) => handlePageCurrentChange(page);

/**
* 表格列
*/
const tableColumns = computed(() => {
const columns: FatTableColumn<any>[] = (props.columns ?? NoopArray).filter(i => i.type !== 'query');

// 注入选择行
if (props.enableSelect && !isSelectionColumnDefined) {
columns.unshift({
type: 'selection',
width: '40',
selectable: props.selectable,
className: 'fat-table__selection-cell',
});
}

return columns.map(i => {
const columnKey = getColumnKey(i) ?? i.type;

return { ...i, columnKey };
});
});

const tableInstance: FatTableMethods<any, any> = {
get tableRef() {
return tableRef.value;
Expand Down Expand Up @@ -784,6 +807,9 @@ const FatTableInner = declareComponent({
refresh: fetch,
reset,
getRequestParams,
getColumns() {
return tableColumns.value;
},
};

expose(tableInstance);
Expand Down Expand Up @@ -812,29 +838,6 @@ const FatTableInner = declareComponent({

const queryable = computed(() => props.enableQuery && props.columns.some(isQueryable));

/**
* 表格列
*/
const tableColumns = computed(() => {
const columns: FatTableColumn<any>[] = (props.columns ?? NoopArray).filter(i => i.type !== 'query');

// 注入选择行
if (props.enableSelect && !isSelectionColumnDefined) {
columns.unshift({
type: 'selection',
width: '40',
selectable: props.selectable,
className: 'fat-table__selection-cell',
});
}

return columns.map(i => {
const columnKey = getColumnKey(i) ?? i.type;

return { ...i, columnKey };
});
});

const tableConfigurableColumns = computed(() => {
return tableColumns.value.filter(i => i.type !== 'selection' && i.type !== 'expand');
});
Expand Down
35 changes: 23 additions & 12 deletions packages/components/src/fat-table/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Ref } from '@wakeadmin/demi';
import {
ButtonProps,
ClassValue,
CommonProps,
FilterList,
PaginationProps,
SortOrder,
TableProps,
StyleValue,
ClassValue,
PaginationProps,
TableMethods,
ButtonProps,
CommonProps,
TableProps,
} from '@wakeadmin/element-adapter';
import type { Ref } from '@wakeadmin/demi';

import { GetAtomicProps } from '../atomic';
import { FatFormItemProps, FatFormMethods, FatFormMode } from '../fat-form';
Expand Down Expand Up @@ -204,6 +204,11 @@ export interface FatTableMethods<Item extends {}, Query extends {}> {
* 获取 request 参数
*/
getRequestParams: () => FatTableRequestParams<Item, Query>;

/**
* 获取 Columns
*/
getColumns: () => FatTableColumn<any>[];
}

/**
Expand Down Expand Up @@ -731,12 +736,18 @@ export interface FatTableColumn<
FatTableColumnSelect<T> {
/**
* 列类型
* index 索引
* selection 选择器
* expand 展开
* actions 表单操作
* query 纯表单字段, 该列不会出现在表格中
* default 默认
*
* `index` 索引
*
* `selection` 选择器
*
* `expand` 展开
*
* `actions` 表单操作
*
* `query` 纯表单字段, 该列不会出现在表格中
*
* `default` 默认
*/
type?: 'index' | 'selection' | 'expand' | 'actions' | 'default' | 'query';

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/utils/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export class Vue3Portal<T extends {} = any> extends BasePortal<T> {
*/
export const Portal = (isVue2 ? Vue2Portal : Vue3Portal) as unknown as new <T>(
component: () => any,
options: {
options?: {
/**
* 挂载目标
*
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,7 @@ export type GetParameterInSet<S extends Set<any>> = S extends Set<infer F extend

type Without<T> = { [K in keyof T]?: never };
export type XOR<T, U> = (Without<T> & U) | (Without<U> & T);

export type Prettify<T> = {
[K in keyof T]: T[K];
} & {};
Binary file modified packages/doc/docs/fat-table/images/fat-table-methods.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/doc/xmind/fat-table-methods.xmind
Binary file not shown.

0 comments on commit f2faf0b

Please sign in to comment.