@amaoaaaaa/search-table 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,118 @@
1
+ import { ProTableProps, TableRow } from '../ProTable/types';
2
+ import { PaginationProps } from 'element-plus';
3
+ import { SortState } from './useTableSort';
4
+ export type SearchTableProps<T extends TableRow = any> = Omit<ProTableProps<T>, 'data' | 'defaultSort'> & {
5
+ /**
6
+ * 是否显示搜索区域
7
+ * @default true
8
+ */
9
+ showSearch?: boolean;
10
+ /**
11
+ * 搜索输入框的提示语
12
+ */
13
+ searchInputPlaceholder?: string;
14
+ /**
15
+ * 是否显示新增按钮
16
+ *
17
+ * @default false
18
+ */
19
+ showAddButton?: boolean;
20
+ /**
21
+ * 是否显示批量删除按钮
22
+ *
23
+ * @default false
24
+ */
25
+ showBatchDeleteButton?: boolean;
26
+ /**
27
+ * 每页条数,不传则自动计算可显示的最大行数
28
+ */
29
+ pageSize?: number;
30
+ /**
31
+ * element-plus 分页组件属性
32
+ */
33
+ elPaginationProps?: Partial<Pick<PaginationProps, 'size' | 'pagerCount'>>;
34
+ /**
35
+ * 默认排序
36
+ */
37
+ defaultSort?: SortState;
38
+ fetchFn: SearchTableFetchFn<T>;
39
+ /**
40
+ * 搜索参数处理函数
41
+ * @param params 当前参数
42
+ * @returns 返回处理后的参数
43
+ */
44
+ searchParamsHandler?: (params: Record<string, any>) => Record<string, any>;
45
+ };
46
+ /**
47
+ * 分页请求参数
48
+ */
49
+ export interface PageParams {
50
+ /**
51
+ * 每页元素数量
52
+ */
53
+ limit?: number;
54
+ /**
55
+ * 当前页起始索引(第一页为0,第n页为(n-1)*limit)
56
+ */
57
+ offset?: number;
58
+ /**
59
+ * 排序顺序,升序还是降序 `asc` or `desc`
60
+ */
61
+ order?: string;
62
+ /**
63
+ * 查询关键词(需要模糊检索时使用)
64
+ */
65
+ search?: string;
66
+ /**
67
+ * 排序字段
68
+ */
69
+ sort?: string;
70
+ [key: string]: any;
71
+ }
72
+ export type SearchTableFetchFn<T = any> = (params?: PageParams, options?: {
73
+ /**
74
+ * 请求中断的信号
75
+ */
76
+ signal?: AbortSignal;
77
+ }) => Promise<PageResp<T>>;
78
+ /**
79
+ * 通用分页响应结构
80
+ */
81
+ export interface PageResp<T = any> {
82
+ /**
83
+ * 请求是否成功
84
+ */
85
+ success: boolean;
86
+ /**
87
+ * 错误代码-0为成功
88
+ */
89
+ code: number;
90
+ /**
91
+ * 错误信息
92
+ */
93
+ message?: string;
94
+ /**
95
+ * 响应数据
96
+ */
97
+ data?: Array<T>;
98
+ /**
99
+ * 开始索引
100
+ */
101
+ offset: number;
102
+ /**
103
+ * 每页数量
104
+ */
105
+ limit: number;
106
+ /**
107
+ * 元素总数
108
+ */
109
+ totalCount: number;
110
+ /**
111
+ * 当前页数(从1开始)
112
+ */
113
+ currPageIndex: number;
114
+ /**
115
+ * 总页数
116
+ */
117
+ pageCount: number;
118
+ }
@@ -0,0 +1,25 @@
1
+ export interface SortState<T extends Record<string, any> = Record<string, any>> {
2
+ /**
3
+ * 排序方式
4
+ */
5
+ order: 'asc' | 'desc';
6
+ /**
7
+ * 排序字段
8
+ */
9
+ sort: keyof T;
10
+ }
11
+ export interface UseTableSortOption {
12
+ defaultSort?: SortState;
13
+ fetchFn: () => void;
14
+ onReset?: () => void;
15
+ }
16
+ export declare function useTableSort({ defaultSort, fetchFn, onReset }: UseTableSortOption): {
17
+ sortState: {
18
+ order: "asc" | "desc";
19
+ sort: string;
20
+ };
21
+ onSortChange: ({ prop, order, }: {
22
+ prop: string;
23
+ order: "ascending" | "descending" | null;
24
+ }) => void;
25
+ };
@@ -0,0 +1,41 @@
1
+ import { Ref } from 'vue';
2
+ /**
3
+ * 创建一个带延迟的布尔 Ref。
4
+ *
5
+ * 当 source 为 true 时,延迟指定时间后才同步为 true;
6
+ * 当 source 为 false 时,立即同步为 false。
7
+ *
8
+ * @param source 源 Ref<boolean>
9
+ * @param delay 延迟时间(毫秒),默认 300ms
10
+ * @returns 延迟后的 Ref<boolean>
11
+ *
12
+ * @example
13
+ * const loading = ref(false);
14
+ * const delayedLoading = useDelayedRef(loading, 500);
15
+ *
16
+ * loading.value = true; // 500ms 后 delayedLoading.value 才变为 true
17
+ * loading.value = false; // 立即变为 false
18
+ */
19
+ export declare function useDelayedRef(source: Ref<boolean>, delay?: number): Ref<boolean>;
20
+ /**
21
+ * 创建一个带延迟的布尔 Ref(对象属性版本)。
22
+ *
23
+ * 当指定对象属性为 true 时,延迟指定时间后才同步为 true;
24
+ * 当为 false 时,立即同步为 false。
25
+ *
26
+ * @typeParam T 源对象类型
27
+ * @typeParam K 属性键(必须是 boolean 类型属性)
28
+ *
29
+ * @param source 源对象
30
+ * @param property 需要监听的属性名
31
+ * @param delay 延迟时间(毫秒),默认 300ms
32
+ * @returns 延迟后的 Ref<boolean>
33
+ *
34
+ * @example
35
+ * const state = reactive({ loading: false });
36
+ * const delayedLoading = useDelayedRef(state, 'loading', 500);
37
+ *
38
+ * state.loading = true; // 500ms 后 delayedLoading.value 才变为 true
39
+ * state.loading = false; // 立即变为 false
40
+ */
41
+ export declare function useDelayedRef<T extends object, K extends keyof T>(source: T, property: K, delay?: number): Ref<boolean>;
@@ -0,0 +1,10 @@
1
+ export { default as SearchTable } from './SearchTable/index.vue';
2
+ export { default as ProTable } from './ProTable/index.vue';
3
+ export type { ProTableInstance } from './ProTable';
4
+ export type { SearchTableProps, SearchTableFetchFn, PageParams, PageResp, } from './SearchTable/types';
5
+ export type { ProTableProps, ProTableColumn, ProTableAction, TableRow, FilterOption, FilterType, ActionButtonVisibility, ApplyFilterPayload, CellEditPayload, } from './ProTable/types';
6
+ export { SelectionStore } from './SearchTable/SelectionStore';
7
+ export { useTableSort } from './SearchTable/useTableSort';
8
+ export type { SortState, UseTableSortOption } from './SearchTable/useTableSort';
9
+ export { useDelayedRef } from './hooks/useDelayedRef';
10
+ export { parseErrorReason } from './utils/parseErrorReason';