diff --git a/.vscode/settings.json b/.vscode/settings.json index f65dd72c..ae894318 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,5 +13,6 @@ "i18n-ally.keystyle": "nested", "i18n-ally.localesPaths": ["src/locales/langs"], "prettier.enable": false, - "unocss.root": ["./"] + "unocss.root": ["./"], + "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/packages/hooks/src/use-table.ts b/packages/hooks/src/use-table.ts index 4539f3cf..9507a4c2 100644 --- a/packages/hooks/src/use-table.ts +++ b/packages/hooks/src/use-table.ts @@ -17,22 +17,16 @@ export type TableColumnCheck = { checked: boolean; }; -export type TransformedData = { +export type TransformedData = { data: T[]; pageNum: number; pageSize: number; total: number; }; -export type Transformer = ( - response: Response -) => TransformedData; +export type Transformer = (response: Response) => TransformedData; -export type TableConfig< - A extends ApiFn = ApiFn, - T extends TableData = TableData, - C extends TableColumn = TableColumn -> = { +export type TableConfig = { /** api function to get table data */ apiFn: A; /** api params */ @@ -67,11 +61,7 @@ export type TableConfig< immediate?: boolean; }; -export default function useTable< - A extends ApiFn = ApiFn, - T extends TableData = TableData, - C extends TableColumn = TableColumn ->(config: TableConfig) { +export default function useTable(config: TableConfig) { const { loading, startLoading, endLoading } = useLoading(); const { bool: empty, setBool: setEmpty } = useBoolean(); diff --git a/src/hooks/common/naive-table.ts b/src/hooks/common/naive-table.ts index 02be96cc..6426d7bb 100644 --- a/src/hooks/common/naive-table.ts +++ b/src/hooks/common/naive-table.ts @@ -6,10 +6,10 @@ import { useAppStore } from '@/store/modules/app'; import { $t } from '@/locales'; type TableData = NaiveUI.TableData; +type GetTableData = NaiveUI.GetTableData; +type TableColumn = NaiveUI.TableColumn; -export function useNaiveTable = NaiveUI.TableApiFn>( - config: NaiveUI.NaiveTableConfig -) { +export function useNaiveTable(config: NaiveUI.NaiveTableConfig) { const scope = effectScope(); const appStore = useAppStore(); @@ -28,7 +28,7 @@ export function useNaiveTable>({ + } = useTable, TableColumn>>({ apiFn, apiParams, columns: config.columns, @@ -64,7 +64,7 @@ export function useNaiveTable { - const columnMap = new Map>(); + const columnMap = new Map>>(); cols.forEach(column => { if (isTableColumnHasKey(column)) { @@ -76,7 +76,7 @@ export function useNaiveTable item.checked) - .map(check => columnMap.get(check.key) as NaiveUI.TableColumn); + .map(check => columnMap.get(check.key) as TableColumn>); return filteredColumns; }, @@ -225,8 +225,6 @@ export function getNaiveTableRowKey(row: T) { return row.id; } -function isTableColumnHasKey( - column: NaiveUI.TableColumn -): column is NaiveUI.TableColumnWithKey { +function isTableColumnHasKey(column: TableColumn): column is NaiveUI.TableColumnWithKey { return Boolean((column as NaiveUI.TableColumnWithKey).key); } diff --git a/src/typings/api.d.ts b/src/typings/api.d.ts index 03a70e78..9293e732 100644 --- a/src/typings/api.d.ts +++ b/src/typings/api.d.ts @@ -16,7 +16,7 @@ declare namespace Api { } /** common params of paginating query list data */ - interface PaginatingQueryRecord> extends PaginatingCommonParams { + interface PaginatingQueryRecord extends PaginatingCommonParams { records: T[]; } @@ -29,7 +29,7 @@ declare namespace Api { type EnableStatus = '1' | '2'; /** common record */ - type CommonRecord> = { + type CommonRecord = { /** record id */ id: number; /** record creator */ diff --git a/src/typings/naive-ui.d.ts b/src/typings/naive-ui.d.ts index ee8e50f2..32775180 100644 --- a/src/typings/naive-ui.d.ts +++ b/src/typings/naive-ui.d.ts @@ -16,17 +16,12 @@ declare namespace NaiveUI { type TableData = Api.Common.CommonRecord; - type TableColumnWithKey = - | SetTableColumnKey, T> - | SetTableColumnKey, T>; + type TableColumnWithKey = SetTableColumnKey, T> | SetTableColumnKey, T>; - type TableColumn = - | TableColumnWithKey - | DataTableSelectionColumn - | DataTableExpandColumn; + type TableColumn = TableColumnWithKey | DataTableSelectionColumn | DataTableExpandColumn; - type TableApiFn = ( - params: Api.SystemManage.CommonSearchParams + type TableApiFn = ( + params: R ) => Promise>>; /** @@ -37,8 +32,10 @@ declare namespace NaiveUI { */ type TableOperateType = 'add' | 'edit'; - type NaiveTableConfig = TableApiFn> = Pick< - import('@sa/hooks').TableConfig>, + type GetTableData = A extends TableApiFn ? T : never; + + type NaiveTableConfig = Pick< + import('@sa/hooks').TableConfig, TableColumn>>, 'apiFn' | 'apiParams' | 'columns' | 'immediate' >; } diff --git a/src/views/manage/user/index2.vue b/src/views/manage/user/index2.vue index 6195d52b..c9cd0ac8 100644 --- a/src/views/manage/user/index2.vue +++ b/src/views/manage/user/index2.vue @@ -1,7 +1,4 @@