feat(projects): useNaiveTable函数:类型部分

This commit is contained in:
Soybean 2022-07-28 00:30:10 +08:00
parent b32bca4984
commit 02992dc02d
5 changed files with 89 additions and 4 deletions

View File

@ -52,7 +52,7 @@
"ua-parser-js": "^1.0.2", "ua-parser-js": "^1.0.2",
"vditor": "^3.8.15", "vditor": "^3.8.15",
"vue": "3.2.37", "vue": "3.2.37",
"vue-router": "^4.1.2", "vue-router": "^4.1.3",
"wangeditor": "^4.7.15", "wangeditor": "^4.7.15",
"xgplayer": "^2.31.7" "xgplayer": "^2.31.7"
}, },
@ -60,7 +60,7 @@
"@amap/amap-jsapi-types": "^0.0.8", "@amap/amap-jsapi-types": "^0.0.8",
"@commitlint/cli": "^17.0.3", "@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3", "@commitlint/config-conventional": "^17.0.3",
"@iconify/json": "^2.1.83", "@iconify/json": "^2.1.84",
"@iconify/vue": "^3.2.1", "@iconify/vue": "^3.2.1",
"@types/bmapgl": "^0.0.5", "@types/bmapgl": "^0.0.5",
"@types/crypto-js": "^4.1.1", "@types/crypto-js": "^4.1.1",

View 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';
}
]
>
>;

View File

@ -1,7 +1,21 @@
declare namespace TypeUtil { declare namespace TypeUtil {
type Noop = (...args: any) => any; 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 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 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;
} }

View File

@ -2,6 +2,6 @@
<div>权限管理</div> <div>权限管理</div>
</template> </template>
<script setup lang="ts"></script> <script setup lang="tsx"></script>
<style scoped></style> <style scoped></style>

View File

@ -1,5 +1,7 @@
<template> <template>
<div>用户管理</div> <div>
<n-data-table />
</div>
</template> </template>
<script setup lang="ts"></script> <script setup lang="ts"></script>