-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(projects): useNaiveTable函数:类型部分
- Loading branch information
1 parent
b32bca4
commit 02992dc
Showing
5 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
] | ||
> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
declare namespace TypeUtil { | ||
type Noop = (...args: any) => any; | ||
|
||
type UnionInclude<T, K extends keyof T> = K extends keyof T ? true : false; | ||
|
||
type GetFunArgs<F extends Noop> = F extends (...args: infer P) => any ? P : never; | ||
|
||
type GetFunReturn<F extends Noop> = F extends (...args: any) => infer R ? R : never; | ||
|
||
type FirstOfArray<T extends any[]> = T extends [infer First, ...infer _Rest] ? First : never; | ||
|
||
type LastOfArray<T extends any[]> = T extends [...infer _Rest, infer Last] ? Last : never; | ||
|
||
type ArrayToUnion<T extends any[]> = T extends [infer First, ...infer Rest] | ||
? First extends any | ||
? Rest extends any[] | ||
? FirstOfArray<[First]> | ArrayToUnion<Rest> | ||
: [First] | ||
: never | ||
: never; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<template> | ||
<div>用户管理</div> | ||
<div> | ||
<n-data-table /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"></script> | ||
|
02992dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
soybean-admin – ./
soybean-admin.vercel.app
soybean-admin-git-main-honghuangdc.vercel.app
www.soybean.pro
soybean.pro
soybean-admin-honghuangdc.vercel.app