This commit is contained in:
2025-12-16 20:20:53 +07:00
commit 2e651f1c89
315 changed files with 33529 additions and 0 deletions

View 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
}));
}