mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): useNaiveTable函数:类型部分
This commit is contained in:
69
src/hooks/business/useNaiveTable.ts
Normal file
69
src/hooks/business/useNaiveTable.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import type { DataTableColumn } from 'naive-ui';
|
||||
|
||||
type UnionColumn<T> = T extends DataTableColumn[] ? TypeUtil.ArrayToUnion<T> : never;
|
||||
|
||||
type ColumnKey = 'key';
|
||||
|
||||
type InterfaceArray = {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
type ColumnKeyData = {
|
||||
key: unknown;
|
||||
};
|
||||
|
||||
type ExcludeArrayByKey<T extends InterfaceArray[]> = T extends [infer First, ...infer Rest]
|
||||
? First extends ColumnKeyData
|
||||
? Rest extends InterfaceArray[]
|
||||
? [First, ...ExcludeArrayByKey<Rest>]
|
||||
: [First]
|
||||
: Rest extends InterfaceArray[]
|
||||
? ExcludeArrayByKey<Rest>
|
||||
: []
|
||||
: [];
|
||||
|
||||
type GetUnionColumnKey<T extends InterfaceArray[]> = ColumnKey extends keyof UnionColumn<T>
|
||||
? UnionColumn<T>[ColumnKey]
|
||||
: never;
|
||||
|
||||
export const columns: DataTableColumn[] = [
|
||||
{
|
||||
type: 'selection'
|
||||
},
|
||||
{
|
||||
title: 'Name',
|
||||
key: 'name',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: 'Age',
|
||||
key: 'age'
|
||||
},
|
||||
{
|
||||
title: 'Address',
|
||||
key: 'address'
|
||||
}
|
||||
];
|
||||
|
||||
export type UnionColumnKey = GetUnionColumnKey<
|
||||
ExcludeArrayByKey<
|
||||
[
|
||||
{
|
||||
type: 'selection';
|
||||
},
|
||||
{
|
||||
title: 'Name';
|
||||
key: 'name';
|
||||
align: 'center';
|
||||
},
|
||||
{
|
||||
title: 'Age';
|
||||
key: 'age';
|
||||
},
|
||||
{
|
||||
title: 'Address';
|
||||
key: 'address';
|
||||
}
|
||||
]
|
||||
>
|
||||
>;
|
Reference in New Issue
Block a user