@amaoaaaaa/search-table 0.3.0 → 0.4.0

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 CHANGED
@@ -103,20 +103,21 @@ const columns = [{ label: '姓名', prop: 'name' }];
103
103
 
104
104
  ### SearchTable Props
105
105
 
106
- | 属性 | 类型 | 默认值 | 说明 |
107
- | ------------------------ | ------------------------------------ | ------------------ | ---------------------------- |
108
- | `columns` | `ProTableColumn[]` | - | 表格列配置 |
109
- | `fetchFn` | `SearchTableFetchFn` | **必填** | 数据请求函数 |
110
- | `showSearch` | `boolean` | `true` | 是否显示搜索区域 |
111
- | `searchInputPlaceholder` | `string` | `"输入搜索关键词"` | 搜索框占位文本 |
112
- | `searchField` | `string` | `"search"` | 搜索框绑定到查询参数的字段名 |
113
- | `showAddButton` | `boolean` | `false` | 是否显示新增按钮 |
114
- | `showBatchDeleteButton` | `boolean` | `false` | 是否显示批量删除按钮 |
115
- | `pageSize` | `number` | 自动计算 | 每页条数 |
116
- | `elPaginationProps` | `Partial<PaginationProps>` | - | 分页组件属性 |
117
- | `defaultSort` | `SortState` | - | 默认排序 |
118
- | `selectable` | `boolean \| (row, index) => boolean` | - | 是否可勾选 |
119
- | `searchParamsHandler` | `(params) => params` | - | 搜索参数处理函数 |
106
+ | 属性 | 类型 | 默认值 | 说明 |
107
+ | ------------------------ | ------------------------------------ | ------------------ | ------------------------------ |
108
+ | `columns` | `ProTableColumn[]` | - | 表格列配置 |
109
+ | `fetchFn` | `SearchTableFetchFn` | **必填** | 数据请求函数 |
110
+ | `showSearch` | `boolean` | `true` | 是否显示搜索区域 |
111
+ | `searchInputPlaceholder` | `string` | `"输入搜索关键词"` | 搜索框占位文本 |
112
+ | `searchButtonText` | `string` | `"搜索"` | 搜索按钮文字(优先于全局配置) |
113
+ | `searchField` | `string` | `"search"` | 搜索框绑定到查询参数的字段名 |
114
+ | `showAddButton` | `boolean` | `false` | 是否显示新增按钮 |
115
+ | `showBatchDeleteButton` | `boolean` | `false` | 是否显示批量删除按钮 |
116
+ | `pageSize` | `number` | 自动计算 | 每页条数 |
117
+ | `elPaginationProps` | `SearchTablePaginationProps` | - | 分页组件视觉配置(见下方说明) |
118
+ | `defaultSort` | `SortState` | - | 默认排序 |
119
+ | `selectable` | `boolean \| (row, index) => boolean` | - | 是否可勾选 |
120
+ | `searchParamsHandler` | `(params) => params` | - | 搜索参数处理函数 |
120
121
 
121
122
  ### SearchTable Events
122
123
 
@@ -172,11 +173,16 @@ const columns = [{ label: '姓名', prop: 'name' }];
172
173
 
173
174
  组件默认按 element-plus 表格的默认尺寸(表头 40px、每行 40px)计算每页条数。
174
175
  如果业务中修改了表格样式,可用 `SearchTableConfigProvider` 统一覆盖,避免分页行数计算错误。
175
- 该组件只提供配置、不渲染额外 DOM,用法类似 `ElConfigProvider`:
176
+ 也可以在全局统一定制分页组件的视觉配置。该组件只提供配置、不渲染额外 DOM,用法类似 `ElConfigProvider`:
176
177
 
177
178
  ```vue
178
179
  <template>
179
- <SearchTableConfigProvider row-height="48" header-height="56px">
180
+ <SearchTableConfigProvider
181
+ row-height="48"
182
+ header-height="56px"
183
+ :pagination-props="{ layout: 'total, prev, pager, next, jumper', pagerCount: 7 }"
184
+ :search-props="{ buttonText: '查询' }"
185
+ >
180
186
  <SearchTable :columns="columns" :fetch-fn="fetchData" />
181
187
  </SearchTableConfigProvider>
182
188
  </template>
@@ -186,23 +192,59 @@ import { SearchTable, SearchTableConfigProvider } from '@amaoaaaaa/search-table'
186
192
  </script>
187
193
  ```
188
194
 
189
- | 属性 | 类型 | 默认值 | 说明 |
190
- | -------------- | ------------------ | ------ | -------------------------------- |
191
- | `rowHeight` | `number \| string` | `40` | 表格行高(px),用于计算每页条数 |
192
- | `headerHeight` | `number \| string` | `40` | 表头高度(px),用于计算每页条数 |
195
+ | 属性 | 类型 | 默认值 | 说明 |
196
+ | ----------------- | ---------------------------- | ------------------------------------------------------------------------- | -------------------------------- |
197
+ | `rowHeight` | `number \| string` | `40` | 表格行高(px),用于计算每页条数 |
198
+ | `headerHeight` | `number \| string` | `40` | 表头高度(px),用于计算每页条数 |
199
+ | `paginationProps` | `SearchTablePaginationProps` | `{ background: true, layout: 'total, sizes, prev, pager, next, jumper' }` | 分页组件视觉配置 |
200
+ | `searchProps` | `SearchTableSearchProps` | `{ buttonText: '搜索' }` | 搜索区域配置 |
193
201
 
194
202
  取值规则:
195
203
 
196
204
  - 支持数字或字符串,字符串只提取前导数字并忽略单位:`48`、`'48'`、`'48px'`、`' 48.5px '` 均可用,`'3rem'` 会被当成 `3`(不做单位换算)。
197
205
  - 解析结果四舍五入为整数:`'48.5px'` 为 `49`,`'48.4'` 为 `48`。
198
206
  - 无法解析或非正数(如 `'abc'`、`''`、`0`、`Infinity`)会回退默认值 `40`。
207
+ - `layout` 与 element-plus 分页组件一致,可按需增减 `total`、`sizes`、`jumper` 等;传空字符串会回退默认布局。
208
+ - 分页配置的优先级:`elPaginationProps`(实例级)> `paginationProps`(全局)> 默认配置;值为 `undefined` 的字段不会覆盖低优先级的值。
209
+ - 搜索区域的配置统一放在 `searchProps` 对象里,当前支持 `buttonText`(搜索按钮文字),后续新增配置直接往对象里加字段即可;优先级:`searchButtonText`(实例级)> `searchProps.buttonText`(全局)> 默认值。
199
210
  - 只影响未显式传入 `pageSize` 的实例;配置在实例挂载时读取一次,运行中修改 props 不会让已挂载实例重新计算。
200
211
 
212
+ `SearchTablePaginationProps` 是从 element-plus `PaginationProps` 中 Pick 出来的子集,保证与 `el-pagination` 类型一致,支持以下字段:
213
+
214
+ | 字段 | 说明 |
215
+ | ------------- | ------------------------------------- |
216
+ | `size` | 分页组件尺寸 |
217
+ | `background` | 是否为分页按钮添加背景色,默认 `true` |
218
+ | `pagerCount` | 页码按钮数量 |
219
+ | `layout` | 组件布局,各元素用逗号分隔 |
220
+ | `popperClass` | 每页条数下拉框的类名 |
221
+ | `popperStyle` | 每页条数下拉框的行内样式 |
222
+ | `prevText` | 替代上一页图标显示的文本 |
223
+ | `prevIcon` | 上一页图标 |
224
+ | `nextText` | 替代下一页图标显示的文本 |
225
+ | `nextIcon` | 下一页图标 |
226
+
227
+ `SearchTable` 的 `elPaginationProps` 与全局的 `paginationProps` 支持完全相同的字段,例如:
228
+
229
+ ```vue
230
+ <SearchTable
231
+ :columns="columns"
232
+ :fetch-fn="fetchData"
233
+ :el-pagination-props="{ background: false, pagerCount: 5, prevText: '上一页' }"
234
+ />
235
+ ```
236
+
237
+ `SearchTableSearchProps` 目前支持以下字段,后续新增搜索区配置会继续往这个对象里加:
238
+
239
+ | 字段 | 说明 |
240
+ | ------------ | ------------------------------------------------------------- |
241
+ | `buttonText` | 搜索按钮文字,默认 `搜索`;实例级可用 `searchButtonText` 覆盖 |
242
+
201
243
  ## 导出清单
202
244
 
203
245
  **组件:** `SearchTable`, `SearchTableConfigProvider`, `ProTable`
204
246
 
205
- **类型:** `SearchTableProps`, `SearchTableFetchFn`, `PageParams`, `PageResp`, `SearchTableConfigProviderProps`, `ProTableProps`, `ProTableColumn`, `ProTableAction`, `TableRow`, `ApplyFilterPayload`, `CellEditPayload`, `SortState`, `ProTableInstance`
247
+ **类型:** `SearchTableProps`, `SearchTablePaginationProps`, `SearchTableSearchProps`, `SearchTableFetchFn`, `PageParams`, `PageResp`, `SearchTableConfigProviderProps`, `ProTableProps`, `ProTableColumn`, `ProTableAction`, `TableRow`, `ApplyFilterPayload`, `CellEditPayload`, `SortState`, `ProTableInstance`
206
248
 
207
249
  **工具:** `SelectionStore`, `useTableSort`, `useDelayedRef`, `parseErrorReason`
208
250
 
@@ -9,8 +9,10 @@ declare function __VLS_template(): {
9
9
  };
10
10
  type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
11
11
  declare const __VLS_component: import('vue').DefineComponent<SearchTableConfigProviderProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<SearchTableConfigProviderProps> & Readonly<{}>, {
12
+ paginationProps: import('./types').SearchTablePaginationProps;
12
13
  rowHeight: number | string;
13
14
  headerHeight: number | string;
15
+ searchProps: import('./types').SearchTableSearchProps;
14
16
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
15
17
  declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
16
18
  export default _default;
@@ -1,4 +1,5 @@
1
1
  import { InjectionKey } from 'vue';
2
+ import { SearchTablePaginationProps, SearchTableSearchProps } from './types';
2
3
  /**
3
4
  * SearchTableConfigProvider 的配置项
4
5
  */
@@ -19,28 +20,60 @@ export interface SearchTableConfigProviderProps {
19
20
  * @default 40
20
21
  */
21
22
  headerHeight?: number | string;
23
+ /**
24
+ * 分页组件的视觉配置
25
+ *
26
+ * 从 element-plus 分页组件的 props 中 Pick 而来,会与 SearchTable 的
27
+ * `elPaginationProps` 合并,后者优先级更高
28
+ *
29
+ * @default { background: true, layout: 'total, sizes, prev, pager, next, jumper' }
30
+ */
31
+ paginationProps?: SearchTablePaginationProps;
32
+ /**
33
+ * 搜索区域的配置
34
+ *
35
+ * 会被 SearchTable 上同名的实例配置覆盖
36
+ *
37
+ * @default { buttonText: '搜索' }
38
+ */
39
+ searchProps?: SearchTableSearchProps;
22
40
  }
23
41
  /**
24
- * 解析后的高度配置
42
+ * 解析后的组件配置
25
43
  */
26
- export interface SearchTableHeightConfig {
44
+ export interface SearchTableConfig {
27
45
  /** 表格行高,正整数 */
28
46
  rowHeight: number;
29
47
  /** 表头高度,正整数 */
30
48
  headerHeight: number;
49
+ /** 分页组件的视觉配置 */
50
+ paginationProps: SearchTablePaginationProps;
51
+ /** 解析后的搜索区域配置 */
52
+ searchProps: Required<SearchTableSearchProps>;
31
53
  }
32
54
  /**
33
- * 默认高度配置,与 element-plus 表格默认样式保持一致
55
+ * 默认配置,高度与 element-plus 表格默认样式保持一致
56
+ */
57
+ export declare const DEFAULT_SEARCH_TABLE_CONFIG: SearchTableConfig;
58
+ /**
59
+ * 合并分页配置
60
+ *
61
+ * @description
62
+ * 越靠后的配置优先级越高;值为 `undefined` 的键视为未传入,
63
+ * 避免某个来源只声明了部分配置时把已有值覆盖掉。
64
+ *
65
+ * @param sources 按优先级从低到高排列的分页配置
66
+ * @returns 合并后的分页配置
34
67
  */
35
- export declare const DEFAULT_SEARCH_TABLE_HEIGHT_CONFIG: SearchTableHeightConfig;
68
+ export declare function mergePaginationProps(...sources: Array<SearchTablePaginationProps | undefined>): SearchTablePaginationProps;
36
69
  /**
37
- * 解析高度配置
70
+ * 解析组件配置
38
71
  *
39
72
  * @param config 原始配置
40
- * @returns 解析后的正整数高度配置
73
+ * @returns 解析后的配置
41
74
  */
42
- export declare function resolveHeightConfig(config?: SearchTableConfigProviderProps): SearchTableHeightConfig;
75
+ export declare function resolveSearchTableConfig(config?: SearchTableConfigProviderProps): SearchTableConfig;
43
76
  /**
44
- * 高度配置的注入 key,由 SearchTableConfigProvider 提供、SearchTable 读取
77
+ * 组件配置的注入 key,由 SearchTableConfigProvider 提供、SearchTable 读取
45
78
  */
46
- export declare const searchTableConfigKey: InjectionKey<SearchTableHeightConfig>;
79
+ export declare const searchTableConfigKey: InjectionKey<SearchTableConfig>;
@@ -1,6 +1,29 @@
1
1
  import { ProTableProps, TableRow } from '../ProTable/types';
2
2
  import { PaginationProps } from 'element-plus';
3
3
  import { SortState } from './useTableSort';
4
+ /**
5
+ * 分页组件的视觉配置
6
+ *
7
+ * @description
8
+ * 直接从 element-plus 的 `PaginationProps` 中 Pick,
9
+ * 保证这里的类型与 `el-pagination` 的 props 始终一致。
10
+ */
11
+ export type SearchTablePaginationProps = Partial<Pick<PaginationProps, 'size' | 'background' | 'pagerCount' | 'layout' | 'popperClass' | 'popperStyle' | 'prevText' | 'prevIcon' | 'nextText' | 'nextIcon'>>;
12
+ /**
13
+ * 搜索区域的配置
14
+ *
15
+ * @description
16
+ * 用对象承载搜索区的可配置项,后续新增配置直接往里加字段,
17
+ * 避免在全局配置上不断堆叠扁平的单项属性。
18
+ */
19
+ export interface SearchTableSearchProps {
20
+ /**
21
+ * 搜索按钮的文字
22
+ *
23
+ * @default '搜索'
24
+ */
25
+ buttonText?: string;
26
+ }
4
27
  export type SearchTableProps<T extends TableRow = any> = Omit<ProTableProps<T>, 'data' | 'defaultSort'> & {
5
28
  /**
6
29
  * 是否显示搜索区域
@@ -9,8 +32,18 @@ export type SearchTableProps<T extends TableRow = any> = Omit<ProTableProps<T>,
9
32
  showSearch?: boolean;
10
33
  /**
11
34
  * 搜索输入框的提示语
35
+ *
36
+ * @default '输入搜索关键词'
12
37
  */
13
38
  searchInputPlaceholder?: string;
39
+ /**
40
+ * 搜索按钮的文字
41
+ *
42
+ * 优先级高于 `SearchTableConfigProvider` 中的 `searchProps.buttonText`
43
+ *
44
+ * @default '搜索'
45
+ */
46
+ searchButtonText?: string;
14
47
  /**
15
48
  * 搜索框绑定到查询参数的字段名
16
49
  *
@@ -34,9 +67,11 @@ export type SearchTableProps<T extends TableRow = any> = Omit<ProTableProps<T>,
34
67
  */
35
68
  pageSize?: number;
36
69
  /**
37
- * element-plus 分页组件属性
70
+ * element-plus 分页组件的视觉配置
71
+ *
72
+ * 优先级高于 `SearchTableConfigProvider` 中的 `paginationProps`
38
73
  */
39
- elPaginationProps?: Partial<Pick<PaginationProps, 'size' | 'pagerCount'>>;
74
+ elPaginationProps?: SearchTablePaginationProps;
40
75
  /**
41
76
  * 默认排序
42
77
  */
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { default as SearchTable } from './SearchTable/index.vue';
2
2
  export { default as SearchTableConfigProvider } from './SearchTable/ConfigProvider.vue';
3
3
  export { default as ProTable } from './ProTable/index.vue';
4
4
  export type { ProTableInstance } from './ProTable';
5
- export type { SearchTableProps, SearchTableFetchFn, PageParams, PageResp, } from './SearchTable/types';
5
+ export type { SearchTableProps, SearchTablePaginationProps, SearchTableSearchProps, SearchTableFetchFn, PageParams, PageResp, } from './SearchTable/types';
6
6
  export type { SearchTableInstance } from './SearchTable';
7
7
  export type { SearchTableConfigProviderProps } from './SearchTable/config';
8
8
  export type { ProTableProps, ProTableColumn, ProTableAction, TableRow, FilterOption, FilterType, ActionButtonVisibility, ApplyFilterPayload, CellEditPayload, ProTableColumn as SearchTableColumn, ProTableAction as SearchTableAction, } from './ProTable/types';