mirror of
https://github.com/jekip/naive-ui-admin.git
synced 2026-02-04 13:42:27 +08:00
Table组件columns增加泛型
This commit is contained in:
@@ -4,7 +4,7 @@ import { provide, inject, ComputedRef } from 'vue';
|
|||||||
|
|
||||||
const key = Symbol('s-table');
|
const key = Symbol('s-table');
|
||||||
|
|
||||||
type Instance = TableActionType & {
|
type Instance = TableActionType<{}> & {
|
||||||
wrapRef: Ref<Nullable<HTMLElement>>;
|
wrapRef: Ref<Nullable<HTMLElement>>;
|
||||||
getBindValues: ComputedRef<Recordable>;
|
getBindValues: ComputedRef<Recordable>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { TableBaseColumn } from 'naive-ui/lib/data-table/src/interface';
|
import type { TableBaseColumn } from 'naive-ui/lib/data-table/src/interface';
|
||||||
import { ComponentType } from './componentType';
|
import { ComponentType } from './componentType';
|
||||||
export interface BasicColumn extends TableBaseColumn {
|
export interface BasicColumn<T> extends TableBaseColumn<T> {
|
||||||
//编辑表格
|
//编辑表格
|
||||||
edit?: boolean;
|
edit?: boolean;
|
||||||
editRow?: boolean;
|
editRow?: boolean;
|
||||||
@@ -13,16 +13,16 @@ export interface BasicColumn extends TableBaseColumn {
|
|||||||
// 权限编码控制是否显示
|
// 权限编码控制是否显示
|
||||||
auth?: string[];
|
auth?: string[];
|
||||||
// 业务控制是否显示
|
// 业务控制是否显示
|
||||||
ifShow?: boolean | ((column: BasicColumn) => boolean);
|
ifShow?: boolean | ((column: BasicColumn<T>) => boolean);
|
||||||
// 控制是否支持拖拽,默认支持
|
// 控制是否支持拖拽,默认支持
|
||||||
draggable?: boolean;
|
draggable?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableActionType {
|
export interface TableActionType<T> {
|
||||||
reload: (opt) => Promise<void>;
|
reload: (opt) => Promise<void>;
|
||||||
emit?: any;
|
emit?: any;
|
||||||
getColumns: (opt?) => BasicColumn[];
|
getColumns: (opt?) => BasicColumn<T>[];
|
||||||
setColumns: (columns: BasicColumn[] | string[]) => void;
|
setColumns: (columns: BasicColumn<T>[] | string[]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BasicTableProps {
|
export interface BasicTableProps {
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
import { h } from 'vue';
|
import { h } from 'vue';
|
||||||
import { NAvatar } from 'naive-ui';
|
import { NAvatar } from 'naive-ui';
|
||||||
|
import { BasicColumn } from '@/components/Table';
|
||||||
export const columns = [
|
export interface ListData {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
avatar: string;
|
||||||
|
address: string;
|
||||||
|
beginTime: string;
|
||||||
|
endTime: string;
|
||||||
|
date: string;
|
||||||
|
}
|
||||||
|
export const columns: BasicColumn<ListData>[] = [
|
||||||
{
|
{
|
||||||
title: 'id',
|
title: 'id',
|
||||||
key: 'id',
|
key: 'id',
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<BasicTable
|
<BasicTable
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:request="loadDataTable"
|
:request="loadDataTable"
|
||||||
:row-key="(row) => row.id"
|
:row-key="(row:ListData) => row.id"
|
||||||
ref="actionRef"
|
ref="actionRef"
|
||||||
:actionColumn="actionColumn"
|
:actionColumn="actionColumn"
|
||||||
@update:checked-row-keys="onCheckedRow"
|
@update:checked-row-keys="onCheckedRow"
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
import { BasicTable, TableAction } from '@/components/Table';
|
import { BasicTable, TableAction } from '@/components/Table';
|
||||||
import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
|
import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
|
||||||
import { getTableList } from '@/api/table/list';
|
import { getTableList } from '@/api/table/list';
|
||||||
import { columns } from './columns';
|
import { columns, ListData } from './columns';
|
||||||
import { PlusOutlined } from '@vicons/antd';
|
import { PlusOutlined } from '@vicons/antd';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { type FormRules } from 'naive-ui';
|
import { type FormRules } from 'naive-ui';
|
||||||
|
|||||||
Reference in New Issue
Block a user