@wangcheng051/plugin-kit 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +275 -2
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +320 -0
- package/dist/index.js +787 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +8 -0
- package/dist/index.umd.cjs.map +1 -0
- package/dist/style.css +1 -0
- package/package.json +98 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wangcheng051/plugin-kit 类型声明
|
|
3
|
+
*
|
|
4
|
+
* 本包为纯 JS/JSX 实现,此文件为手写声明,用于给 TypeScript 使用方提供类型提示。
|
|
5
|
+
* 手写声明不会随源码自动更新,改动 src 的导出后请同步本文件;
|
|
6
|
+
* `npm run build` / `npm run verify:types` 会校验两者是否一致。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type * as React from 'react';
|
|
10
|
+
import type { ThemeConfig } from 'antd';
|
|
11
|
+
|
|
12
|
+
/* ------------------------------------------------------------------ *
|
|
13
|
+
* 单元格渲染器相关类型
|
|
14
|
+
* ------------------------------------------------------------------ */
|
|
15
|
+
|
|
16
|
+
/** 标签列的选项 */
|
|
17
|
+
export interface TagOption {
|
|
18
|
+
label: React.ReactNode;
|
|
19
|
+
value: string | number | boolean;
|
|
20
|
+
color?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 操作列的按钮 */
|
|
24
|
+
export interface ColumnAction {
|
|
25
|
+
key: string;
|
|
26
|
+
text: React.ReactNode;
|
|
27
|
+
onClick?: (action: ColumnAction, record?: any) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* ------------------------------------------------------------------ *
|
|
31
|
+
* 单元格渲染器
|
|
32
|
+
* ------------------------------------------------------------------ */
|
|
33
|
+
|
|
34
|
+
export interface CellProps {
|
|
35
|
+
value?: any;
|
|
36
|
+
record?: any;
|
|
37
|
+
color?: string;
|
|
38
|
+
options?: TagOption[];
|
|
39
|
+
digits?: number;
|
|
40
|
+
showSymbol?: boolean;
|
|
41
|
+
percent?: boolean;
|
|
42
|
+
length?: number;
|
|
43
|
+
actions?: ColumnAction[];
|
|
44
|
+
onClick?: (value: any) => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 文本渲染(默认) */
|
|
48
|
+
export function TextCell(props: CellProps): React.ReactElement;
|
|
49
|
+
|
|
50
|
+
/** 金额渲染(负数标红) */
|
|
51
|
+
export function MoneyCell(props: CellProps): React.ReactElement;
|
|
52
|
+
|
|
53
|
+
/** 数字渲染(自动千分位) */
|
|
54
|
+
export function NumberCell(props: CellProps): React.ReactElement;
|
|
55
|
+
|
|
56
|
+
/** 标签渲染 */
|
|
57
|
+
export function TagCell(props: CellProps): React.ReactElement;
|
|
58
|
+
|
|
59
|
+
/** 长文本省略 + tooltip */
|
|
60
|
+
export function EllipsisCell(props: CellProps): React.ReactElement;
|
|
61
|
+
|
|
62
|
+
/** 链接单元格 */
|
|
63
|
+
export function LinkCell(props: CellProps): React.ReactElement;
|
|
64
|
+
|
|
65
|
+
/** 操作列渲染(按钮组) */
|
|
66
|
+
export function ActionCell(props: CellProps): React.ReactElement;
|
|
67
|
+
|
|
68
|
+
/* ------------------------------------------------------------------ *
|
|
69
|
+
* 主题
|
|
70
|
+
* ------------------------------------------------------------------ */
|
|
71
|
+
|
|
72
|
+
/** ag-grid 经典主题名 */
|
|
73
|
+
export type AgGridTheme =
|
|
74
|
+
| 'alpine'
|
|
75
|
+
| 'balham'
|
|
76
|
+
| 'material'
|
|
77
|
+
| 'quartz'
|
|
78
|
+
| 'classic';
|
|
79
|
+
|
|
80
|
+
/** 行高密度 */
|
|
81
|
+
export type TableDensity = 'compact' | 'normal' | 'relaxed';
|
|
82
|
+
|
|
83
|
+
/** antd 5 主题配置 */
|
|
84
|
+
export const crmTheme: ThemeConfig;
|
|
85
|
+
|
|
86
|
+
/** 状态预设 */
|
|
87
|
+
export const STATUS_PRESETS: Record<
|
|
88
|
+
string,
|
|
89
|
+
{ color: string; text: string }
|
|
90
|
+
>;
|
|
91
|
+
|
|
92
|
+
/** 字典状态常见色值映射 */
|
|
93
|
+
export const DICT_COLOR_MAP: Record<string, string>;
|
|
94
|
+
|
|
95
|
+
/** v31 可用的经典主题名 */
|
|
96
|
+
export const AG_GRID_THEMES: AgGridTheme[];
|
|
97
|
+
|
|
98
|
+
/** 默认主题 */
|
|
99
|
+
export const DEFAULT_AG_GRID_THEME: AgGridTheme;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 生成 ag-grid 容器所需的 className。
|
|
103
|
+
*/
|
|
104
|
+
export function agGridClass(
|
|
105
|
+
theme?: AgGridTheme,
|
|
106
|
+
extra?: string,
|
|
107
|
+
): string;
|
|
108
|
+
|
|
109
|
+
/** 行高预设(compact / normal / relaxed) */
|
|
110
|
+
export const ROW_HEIGHT_PRESETS: Record<TableDensity, number>;
|
|
111
|
+
|
|
112
|
+
/* ------------------------------------------------------------------ *
|
|
113
|
+
* 工具函数
|
|
114
|
+
* ------------------------------------------------------------------ */
|
|
115
|
+
|
|
116
|
+
/** 空值判断:null / undefined / '' / NaN / 空数组 */
|
|
117
|
+
export function isEmpty(value: any): boolean;
|
|
118
|
+
|
|
119
|
+
/** 安全取值,path 支持 'a.b.c' 形式 */
|
|
120
|
+
export function get<T = any>(obj: any, path: string, defaultValue?: T): T;
|
|
121
|
+
|
|
122
|
+
/** 数字千分位格式化 */
|
|
123
|
+
export function formatNumber(value: number | string | null | undefined, digits?: number): string;
|
|
124
|
+
|
|
125
|
+
/** 金额格式化(人民币) */
|
|
126
|
+
export function formatMoney(
|
|
127
|
+
value: number | string | null | undefined,
|
|
128
|
+
options?: {
|
|
129
|
+
digits?: number;
|
|
130
|
+
symbol?: string;
|
|
131
|
+
showSymbol?: boolean;
|
|
132
|
+
showZeroZero?: boolean;
|
|
133
|
+
},
|
|
134
|
+
): string;
|
|
135
|
+
|
|
136
|
+
/** 百分比格式化,0.1234 -> '12.34%' */
|
|
137
|
+
export function formatPercent(
|
|
138
|
+
value: number | string | null | undefined,
|
|
139
|
+
digits?: number,
|
|
140
|
+
): string;
|
|
141
|
+
|
|
142
|
+
/** 数组按键分组,返回 { key: item[] } */
|
|
143
|
+
export function groupBy<T = any>(
|
|
144
|
+
list: T[],
|
|
145
|
+
keyFn: string | ((item: T) => string | number),
|
|
146
|
+
): Record<string, T[]>;
|
|
147
|
+
|
|
148
|
+
/** 过滤对象中的空值字段 */
|
|
149
|
+
export function omitEmpty<T extends Record<string, any>>(obj: T): Partial<T>;
|
|
150
|
+
|
|
151
|
+
/** 防抖 */
|
|
152
|
+
export function debounce<T extends (...args: any[]) => any>(
|
|
153
|
+
fn: T,
|
|
154
|
+
wait?: number,
|
|
155
|
+
): (...args: Parameters<T>) => void;
|
|
156
|
+
|
|
157
|
+
/** 类名拼接 */
|
|
158
|
+
export function cx(...args: any[]): string;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 按 key 生成 Map,便于 O(1) 查找。
|
|
162
|
+
* key 优先取 obj[key],取不到时回退到 obj.id。
|
|
163
|
+
*/
|
|
164
|
+
export function MayList<T = any>(
|
|
165
|
+
objectsArray?: T[],
|
|
166
|
+
key?: string,
|
|
167
|
+
): Map<string | number, T>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* 深拷贝(保留函数引用)。
|
|
171
|
+
* 遇到函数时返回原引用而非复制 —— 列配置里的 render 组件函数必须保留引用。
|
|
172
|
+
*/
|
|
173
|
+
export function deepClone<T>(value: T): T;
|
|
174
|
+
|
|
175
|
+
/* ------------------------------------------------------------------ *
|
|
176
|
+
* CRM 业务列表组件
|
|
177
|
+
* ------------------------------------------------------------------ */
|
|
178
|
+
|
|
179
|
+
/** 列配置项(业务列表用,字段较 ag-grid 版更宽松) */
|
|
180
|
+
export interface BusinessColumnConfig {
|
|
181
|
+
field: string;
|
|
182
|
+
key?: string;
|
|
183
|
+
cnDisplay?: string;
|
|
184
|
+
enDisplay?: string;
|
|
185
|
+
/** 是否默认显示 */
|
|
186
|
+
visible?: boolean;
|
|
187
|
+
/** 是否隐藏 */
|
|
188
|
+
hide?: boolean;
|
|
189
|
+
/** 锁定位置(合计行不统计) */
|
|
190
|
+
lockPosition?: boolean;
|
|
191
|
+
/** 自定义渲染 */
|
|
192
|
+
render?: (params: any) => React.ReactNode;
|
|
193
|
+
[key: string]: any;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** 列表接口请求方法 */
|
|
197
|
+
export type TableRequest = (
|
|
198
|
+
params: any,
|
|
199
|
+
url?: string,
|
|
200
|
+
) => Promise<{ response: any }>;
|
|
201
|
+
|
|
202
|
+
/** 列配置查询接口 */
|
|
203
|
+
export type GetColConfigRequest = (
|
|
204
|
+
configKey?: string,
|
|
205
|
+
) => Promise<{ response: any }>;
|
|
206
|
+
|
|
207
|
+
/** 列配置保存接口 */
|
|
208
|
+
export type SaveColConfigRequest = (params: any) => void | Promise<any>;
|
|
209
|
+
|
|
210
|
+
/** 排序状态 */
|
|
211
|
+
export interface SortInfo {
|
|
212
|
+
colId?: string;
|
|
213
|
+
sort?: 'asc' | 'desc' | null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** useTableModule 的入参 */
|
|
217
|
+
export interface UseTableModuleProps {
|
|
218
|
+
/** sessionStorage 存储 key */
|
|
219
|
+
sessionKey?: string;
|
|
220
|
+
/** 自定义单元格渲染,如 { companyName: (params) => node } */
|
|
221
|
+
renderKey?: Record<string, (params: any) => React.ReactNode>;
|
|
222
|
+
/** 自定义请求参数转换 */
|
|
223
|
+
setParamsList?: (params: any) => any;
|
|
224
|
+
/** 列配置的业务标识 */
|
|
225
|
+
configKey?: string;
|
|
226
|
+
/** 列表接口地址 */
|
|
227
|
+
tableUrl?: string;
|
|
228
|
+
/** 列表接口请求方法 */
|
|
229
|
+
tableRequest?: TableRequest;
|
|
230
|
+
/** 查询列配置接口 */
|
|
231
|
+
getColConfigRequest?: GetColConfigRequest;
|
|
232
|
+
/** 保存列配置接口 */
|
|
233
|
+
saveColConfigRequest?: SaveColConfigRequest;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** useTableModule 返回值 */
|
|
237
|
+
export interface UseTableModuleResult {
|
|
238
|
+
/** 列设置按钮渲染函数 */
|
|
239
|
+
SettingTableRender: (props?: any) => React.ReactElement;
|
|
240
|
+
/** 表格渲染函数 */
|
|
241
|
+
TableListRender: (props?: any) => React.ReactElement;
|
|
242
|
+
/** 重新拉取列表 */
|
|
243
|
+
getTableData: () => Promise<any> | void;
|
|
244
|
+
/** 重新拉取列配置 */
|
|
245
|
+
getColConfig: () => void;
|
|
246
|
+
/** 保存列配置 */
|
|
247
|
+
saveColConfig: () => void;
|
|
248
|
+
/** 重置搜索条件 */
|
|
249
|
+
resetSesstion: () => void;
|
|
250
|
+
/** 当前列表数据 */
|
|
251
|
+
tableData: any[];
|
|
252
|
+
/** 设置 loading */
|
|
253
|
+
setloading: (loading: boolean) => void;
|
|
254
|
+
/** 当前 loading 状态 */
|
|
255
|
+
loading: boolean;
|
|
256
|
+
/** 当前列定义 */
|
|
257
|
+
columnDefs: BusinessColumnConfig[];
|
|
258
|
+
/** 当前请求参数(ref) */
|
|
259
|
+
paramsCurrent: { current: any };
|
|
260
|
+
/** 分页总条数 */
|
|
261
|
+
total?: number;
|
|
262
|
+
/** 当前筛选条件 */
|
|
263
|
+
filterKey: any[];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* CRM 列表 Hook:统一管理列配置、排序、分页、高级搜索与 session 持久化。
|
|
268
|
+
*
|
|
269
|
+
* 所有业务接口均需注入,插件包不依赖任何业务工程。
|
|
270
|
+
*/
|
|
271
|
+
export function useTableModule(
|
|
272
|
+
props?: UseTableModuleProps,
|
|
273
|
+
defaultProps?: UseTableModuleProps,
|
|
274
|
+
): UseTableModuleResult;
|
|
275
|
+
|
|
276
|
+
/** TableList 属性 */
|
|
277
|
+
export interface TableListProps {
|
|
278
|
+
columnDefs?: BusinessColumnConfig[];
|
|
279
|
+
loading?: boolean;
|
|
280
|
+
customBottomTotal?: boolean;
|
|
281
|
+
onChange?: (params: any) => void;
|
|
282
|
+
tableRef?: React.MutableRefObject<any>;
|
|
283
|
+
tableData?: any[];
|
|
284
|
+
pagination?: boolean | { current?: number; pageSize?: number; total?: number };
|
|
285
|
+
reset?: Record<string, any>;
|
|
286
|
+
customColumn?: any[];
|
|
287
|
+
filterSearchRender?: Record<string, any>;
|
|
288
|
+
setfilterKey?: (keys: any[]) => void;
|
|
289
|
+
filterKey?: any[];
|
|
290
|
+
[key: string]: any;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** 表格组件 */
|
|
294
|
+
export function TableList(props: TableListProps): React.ReactElement;
|
|
295
|
+
|
|
296
|
+
/** 列设置组件 */
|
|
297
|
+
export function SettingTable(props: {
|
|
298
|
+
onChange?: (params: any) => void;
|
|
299
|
+
columRef?: React.MutableRefObject<any>;
|
|
300
|
+
[key: string]: any;
|
|
301
|
+
}): React.ReactElement;
|
|
302
|
+
|
|
303
|
+
/** 自定义表头组件 */
|
|
304
|
+
export function CustomHeader(props: any): React.ReactElement;
|
|
305
|
+
|
|
306
|
+
/** 列表页自定义搜索插槽 */
|
|
307
|
+
export function OtherSlot(props: {
|
|
308
|
+
dataIndex?: string;
|
|
309
|
+
language?: boolean;
|
|
310
|
+
onChange?: (value: any) => void;
|
|
311
|
+
value?: any;
|
|
312
|
+
[key: string]: any;
|
|
313
|
+
}): React.ReactElement;
|
|
314
|
+
|
|
315
|
+
/** 升序图标 */
|
|
316
|
+
export const SortAscending: React.ComponentType<any>;
|
|
317
|
+
/** 降序图标 */
|
|
318
|
+
export const SortDescending: React.ComponentType<any>;
|
|
319
|
+
/** 未排序图标 */
|
|
320
|
+
export const SortUnSort: React.ComponentType<any>;
|