init
This commit is contained in:
50
src/components/table/index.ts
Normal file
50
src/components/table/index.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { h } from 'vue';
|
||||
import type { ButtonProps, DataTableColumns } from 'naive-ui';
|
||||
import { NButton, NSpace } from 'naive-ui';
|
||||
import type { TableColumn } from 'naive-ui/es/data-table/src/interface';
|
||||
import type { safeClient } from '@/service/api';
|
||||
import type TableBase from './table-base.vue';
|
||||
|
||||
export type TableBaseColumns<T = any> = Array<
|
||||
TableColumn<T> & {
|
||||
operations?: (row: T) => Array<Partial<ButtonProps> & { contentText: string }>;
|
||||
key: string;
|
||||
title: string;
|
||||
}
|
||||
>;
|
||||
|
||||
export type TableInst = InstanceType<typeof TableBase>;
|
||||
|
||||
export interface Pagination {
|
||||
limit: number;
|
||||
offset: number;
|
||||
}
|
||||
|
||||
export type TableFetchData = (page: Pagination) => ReturnType<typeof safeClient>;
|
||||
|
||||
export function transformColumns<T = any>(columns: TableBaseColumns<T>): DataTableColumns<T> {
|
||||
return columns.map(col => {
|
||||
return {
|
||||
...col,
|
||||
render: col.operations
|
||||
? (row: T) =>
|
||||
h(NSpace, null, {
|
||||
default: () => col.operations!(row).map(item => h(NButton, item, { default: () => item.contentText }))
|
||||
})
|
||||
: undefined
|
||||
} as TableColumn<T>;
|
||||
});
|
||||
}
|
||||
|
||||
export function transformHeaderColumns<T = any>(columns: TableBaseColumns<T>): NaiveUI.TableColumnCheck[] {
|
||||
return columns
|
||||
.filter(col => {
|
||||
return !col.fixed;
|
||||
})
|
||||
.map(col => ({
|
||||
key: col.key,
|
||||
title: col.title,
|
||||
checked: true,
|
||||
visible: true
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user