@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.
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # @amaoaaaaa/search-table
2
+
3
+ 基于 [Element Plus](https://element-plus.org/) 的搜索表格 Vue 3 组件,提供开箱即用的分页、排序、筛选、跨页勾选等功能。
4
+
5
+ ## 特性
6
+
7
+ - 🔍 内置搜索框 + 搜索参数管理
8
+ - 📄 自动分页 + 动态计算每页行数
9
+ - ↕️ 列排序支持
10
+ - 🎯 列筛选支持(单选 / 多选 / 时间范围)
11
+ - ☑️ 跨页勾选(手动管理 selection state)
12
+ - ✏️ 单元格内联编辑
13
+ - 🎨 内置 ProTable 组件,可独立使用
14
+ - 📦 图标构建时内联 SVG,零网络请求,离线可用
15
+
16
+ ## 安装
17
+
18
+ ```bash
19
+ npm install @amaoaaaaa/search-table
20
+ ```
21
+
22
+ ### Peer Dependencies
23
+
24
+ 你需要确保项目中已安装以下依赖:
25
+
26
+ ```bash
27
+ npm install vue element-plus axios lodash-es
28
+ # tailwindcss 可选(用于样式类)
29
+ ```
30
+
31
+ ## 使用
32
+
33
+ ### 1. 全局注册图标类型声明(可选)
34
+
35
+ 在 `env.d.ts` 或 `shims-icons.d.ts` 中添加:
36
+
37
+ ```ts
38
+ /// <reference types="unplugin-icons/types/vue" />
39
+ ```
40
+
41
+ > 注意:消费者项目无需安装 `unplugin-icons`,此声明仅用于 IDE 类型提示。图标 SVG 已在构建时内联到组件中。
42
+
43
+ ### 2. 使用 SearchTable
44
+
45
+ ```vue
46
+ <template>
47
+ <SearchTable
48
+ ref="searchTableRef"
49
+ :columns="columns"
50
+ :fetch-fn="fetchData"
51
+ show-add-button
52
+ show-batch-delete-button
53
+ @add="handleAdd"
54
+ @batch-delete="handleBatchDelete"
55
+ />
56
+ </template>
57
+
58
+ <script setup lang="ts">
59
+ import { ref } from 'vue';
60
+ import { SearchTable } from '@amaoaaaaa/search-table';
61
+ import type { SearchTableProps, PageParams, PageResp } from '@amaoaaaaa/search-table';
62
+
63
+ const searchTableRef = ref();
64
+
65
+ const columns = [
66
+ { label: '姓名', prop: 'name' },
67
+ { label: '年龄', prop: 'age', sortable: true },
68
+ { label: '操作', actions: [{ text: '编辑', handler: (row) => console.log(row) }] },
69
+ ];
70
+
71
+ async function fetchData(params?: PageParams): Promise<PageResp<any>> {
72
+ const res = await fetch('/api/list', { method: 'POST', body: JSON.stringify(params) });
73
+ return res.json();
74
+ }
75
+
76
+ function handleAdd() {
77
+ console.log('新增');
78
+ }
79
+
80
+ function handleBatchDelete(rows: any[]) {
81
+ console.log('批量删除', rows);
82
+ }
83
+ </script>
84
+ ```
85
+
86
+ ### 3. 使用 ProTable(独立使用)
87
+
88
+ ```vue
89
+ <template>
90
+ <ProTable :data="tableData" :columns="columns" />
91
+ </template>
92
+
93
+ <script setup lang="ts">
94
+ import { ProTable } from '@amaoaaaaa/search-table';
95
+
96
+ const tableData = [{ id: 1, name: '张三' }];
97
+
98
+ const columns = [{ label: '姓名', prop: 'name' }];
99
+ </script>
100
+ ```
101
+
102
+ ## API
103
+
104
+ ### SearchTable Props
105
+
106
+ | 属性 | 类型 | 默认值 | 说明 |
107
+ | ------------------------ | ------------------------------------ | ------------------ | -------------------- |
108
+ | `columns` | `ProTableColumn[]` | - | 表格列配置 |
109
+ | `fetchFn` | `SearchTableFetchFn` | **必填** | 数据请求函数 |
110
+ | `showSearch` | `boolean` | `true` | 是否显示搜索区域 |
111
+ | `searchInputPlaceholder` | `string` | `"输入搜索关键词"` | 搜索框占位文本 |
112
+ | `showAddButton` | `boolean` | `false` | 是否显示新增按钮 |
113
+ | `showBatchDeleteButton` | `boolean` | `false` | 是否显示批量删除按钮 |
114
+ | `pageSize` | `number` | 自动计算 | 每页条数 |
115
+ | `elPaginationProps` | `Partial<PaginationProps>` | - | 分页组件属性 |
116
+ | `defaultSort` | `SortState` | - | 默认排序 |
117
+ | `selectable` | `boolean \| (row, index) => boolean` | - | 是否可勾选 |
118
+ | `searchParamsHandler` | `(params) => params` | - | 搜索参数处理函数 |
119
+
120
+ ### SearchTable Events
121
+
122
+ | 事件名 | 参数 | 说明 |
123
+ | -------------- | ----------------- | ---------------- |
124
+ | `add` | - | 点击新增按钮 |
125
+ | `batch-delete` | `rows: any[]` | 点击批量删除按钮 |
126
+ | `cell-edit` | `CellEditPayload` | 单元格编辑完成 |
127
+
128
+ ### SearchTable Expose
129
+
130
+ | 方法/属性 | 类型 | 说明 |
131
+ | ------------------ | ---------------------------- | -------------- |
132
+ | `refresh` | `() => Promise<void>` | 刷新当前页 |
133
+ | `selectedRows` | `Ref<TableRow[]>` | 已勾选的行 |
134
+ | `getSelectionRows` | `() => TableRow[]` | 获取已勾选的行 |
135
+ | `selectRows` | `(rows: TableRow[]) => void` | 勾选指定行 |
136
+
137
+ ## 导出清单
138
+
139
+ **组件:** `SearchTable`, `ProTable`
140
+
141
+ **类型:** `SearchTableProps`, `SearchTableFetchFn`, `PageParams`, `PageResp`, `ProTableProps`, `ProTableColumn`, `ProTableAction`, `TableRow`, `ApplyFilterPayload`, `CellEditPayload`, `SortState`, `ProTableInstance`
142
+
143
+ **工具:** `SelectionStore`, `useTableSort`, `useDelayedRef`, `parseErrorReason`
144
+
145
+ ## License
146
+
147
+ MIT
@@ -0,0 +1,9 @@
1
+ import { ProTableColumn } from '../types';
2
+ type __VLS_Props = {
3
+ col: ProTableColumn;
4
+ row: any;
5
+ column: any;
6
+ index: number;
7
+ };
8
+ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
9
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { default as ProTable } from './index.vue';
2
+ export type ProTableInstance = InstanceType<typeof ProTable>;