@base-stone/hooks 0.9.8 → 1.0.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/dist/design-hooks.es.prod.d.ts +42 -20
- package/dist/design-hooks.es.prod.js +39 -36
- package/package.json +4 -4
|
@@ -64,6 +64,10 @@ export declare interface ModalProps {
|
|
|
64
64
|
onCancel: () => void;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
declare type noop = (this: any, ...args: any[]) => any;
|
|
68
|
+
|
|
69
|
+
declare type PickFunction<T extends noop> = (this: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T>;
|
|
70
|
+
|
|
67
71
|
declare type Placement = 'top' | 'bottom' | 'left' | 'right';
|
|
68
72
|
|
|
69
73
|
export declare interface QueryParamsData {
|
|
@@ -74,6 +78,11 @@ export declare interface QueryParamsData {
|
|
|
74
78
|
[key: string]: any;
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
declare interface QueryResponse {
|
|
82
|
+
status: string;
|
|
83
|
+
data: Record<string, any>[];
|
|
84
|
+
}
|
|
85
|
+
|
|
77
86
|
declare interface RequestFn {
|
|
78
87
|
(val?: unknown): Promise<{
|
|
79
88
|
status: string;
|
|
@@ -81,14 +90,17 @@ declare interface RequestFn {
|
|
|
81
90
|
}>;
|
|
82
91
|
}
|
|
83
92
|
|
|
84
|
-
declare
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
declare interface SelectConfig<K extends string> {
|
|
94
|
+
queryFn: (data: Record<string, any>) => Promise<QueryResponse>;
|
|
95
|
+
options: {
|
|
96
|
+
params?: Record<string, any>;
|
|
97
|
+
selectKey: K;
|
|
98
|
+
fieldNames?: {
|
|
99
|
+
label: string;
|
|
100
|
+
value: string;
|
|
101
|
+
};
|
|
90
102
|
};
|
|
91
|
-
}
|
|
103
|
+
}
|
|
92
104
|
|
|
93
105
|
declare type SelectOption<T extends string | number = string | number> = {
|
|
94
106
|
label: string;
|
|
@@ -109,17 +121,12 @@ declare interface SuccessFn {
|
|
|
109
121
|
(data: Record<string, any>): void;
|
|
110
122
|
}
|
|
111
123
|
|
|
112
|
-
declare interface
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
reset: (params?: Record<string, any>) => void;
|
|
119
|
-
/** 选中的行 keys */
|
|
120
|
-
selectedRowKeys: Key[];
|
|
121
|
-
/** 表格属性 */
|
|
122
|
-
tableProps: TableProps<T>;
|
|
124
|
+
declare interface TableOptions<T, P = Record<string, any>> {
|
|
125
|
+
queryFn: (data: QueryParamsData) => Promise<TableResponse<T>>;
|
|
126
|
+
options?: {
|
|
127
|
+
params: P;
|
|
128
|
+
rowSelection: boolean;
|
|
129
|
+
};
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
export declare interface TableProps<T> {
|
|
@@ -144,6 +151,19 @@ declare interface TableResponse<T> {
|
|
|
144
151
|
};
|
|
145
152
|
}
|
|
146
153
|
|
|
154
|
+
declare interface TableResult<T> {
|
|
155
|
+
/** 查询参数 */
|
|
156
|
+
queryParams: QueryParamsData;
|
|
157
|
+
/** 执行查询方法 */
|
|
158
|
+
search: (params?: Record<string, any>) => void;
|
|
159
|
+
refresh: (params?: Record<string, any>) => void;
|
|
160
|
+
reset: (params?: Record<string, any>) => void;
|
|
161
|
+
/** 选中的行 keys */
|
|
162
|
+
selectedRowKeys: Key[];
|
|
163
|
+
/** 表格属性 */
|
|
164
|
+
tableProps: TableProps<T>;
|
|
165
|
+
}
|
|
166
|
+
|
|
147
167
|
export declare function useCreateModal<const T extends Record<string, ModalConfig>>(configs: T): {
|
|
148
168
|
[K in keyof T as `${string & K}Modal`]: ModalInstance;
|
|
149
169
|
} & {
|
|
@@ -154,8 +174,10 @@ export declare function useCreateModal<const T extends Record<string, ModalConfi
|
|
|
154
174
|
|
|
155
175
|
export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn): FormSubmitResult;
|
|
156
176
|
|
|
157
|
-
export declare function
|
|
177
|
+
export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
|
|
178
|
+
|
|
179
|
+
export declare function useSelectOptions<T extends string | number = string | number, K extends string = string>({ queryFn, options }: SelectConfig<K>): SelectOptionsResult<K, T>;
|
|
158
180
|
|
|
159
|
-
export declare function useTableList<T extends Record<string, any> = Record<string, any>>(
|
|
181
|
+
export declare function useTableList<T extends Record<string, any> = Record<string, any>>({ queryFn, options }: TableOptions<T>): TableResult<T>;
|
|
160
182
|
|
|
161
183
|
export { }
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useRef as w, useMemo as
|
|
1
|
+
import { useRef as w, useMemo as L, useState as y, useEffect as D, useId as U, useCallback as W } from "react";
|
|
2
2
|
import { Empty as A, App as X } from "antd";
|
|
3
3
|
import { create as K } from "zustand";
|
|
4
|
-
var k = { exports: {} },
|
|
5
|
-
var
|
|
4
|
+
var k = { exports: {} }, b = {};
|
|
5
|
+
var j;
|
|
6
6
|
function ee() {
|
|
7
|
-
if (
|
|
8
|
-
|
|
7
|
+
if (j) return b;
|
|
8
|
+
j = 1;
|
|
9
9
|
var s = /* @__PURE__ */ Symbol.for("react.transitional.element"), a = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
10
10
|
function o(t, r, n) {
|
|
11
11
|
var u = null;
|
|
@@ -22,21 +22,22 @@ function ee() {
|
|
|
22
22
|
props: n
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return b.Fragment = a, b.jsx = o, b.jsxs = o, b;
|
|
26
26
|
}
|
|
27
|
-
var
|
|
27
|
+
var F;
|
|
28
28
|
function te() {
|
|
29
|
-
return
|
|
29
|
+
return F || (F = 1, k.exports = ee()), k.exports;
|
|
30
30
|
}
|
|
31
31
|
var oe = te();
|
|
32
|
-
|
|
32
|
+
function M(s) {
|
|
33
33
|
const a = w(s);
|
|
34
|
-
a.current =
|
|
34
|
+
a.current = L(() => s, [s]);
|
|
35
35
|
const o = w(void 0);
|
|
36
36
|
return o.current || (o.current = function(...t) {
|
|
37
37
|
return a.current.apply(this, t);
|
|
38
38
|
}), o.current;
|
|
39
|
-
}
|
|
39
|
+
}
|
|
40
|
+
const x = {
|
|
40
41
|
sortField: ["orderType", "orderField"],
|
|
41
42
|
sortOrder: ["ASC", "DESC"],
|
|
42
43
|
pageSize: 10
|
|
@@ -46,8 +47,11 @@ function ie(s) {
|
|
|
46
47
|
x[a] = s[a];
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
|
-
function le(
|
|
50
|
-
|
|
50
|
+
function le({
|
|
51
|
+
queryFn: s,
|
|
52
|
+
options: a
|
|
53
|
+
}) {
|
|
54
|
+
const { rowSelection: o, params: t } = a || {}, r = x.pageSize, [n, u] = y({
|
|
51
55
|
pagination: {
|
|
52
56
|
showSizeChanger: !0,
|
|
53
57
|
showQuickJumper: !0,
|
|
@@ -61,13 +65,13 @@ function le(s, a = {}) {
|
|
|
61
65
|
pageSize: r,
|
|
62
66
|
...t
|
|
63
67
|
}
|
|
64
|
-
}), { pagination: c, list: p, queryParams: e } = n, { pageNo: d, pageSize: f } = e, [i, S] =
|
|
68
|
+
}), { pagination: c, list: p, queryParams: e } = n, { pageNo: d, pageSize: f } = e, [i, S] = y(!0), g = w(e), [v, E] = y([]), C = L(() => {
|
|
65
69
|
if (o)
|
|
66
70
|
return {
|
|
67
71
|
selectedRowKeys: v,
|
|
68
72
|
onChange: (l) => E(l)
|
|
69
73
|
};
|
|
70
|
-
}, [o, v]), z =
|
|
74
|
+
}, [o, v]), z = M(
|
|
71
75
|
(l) => `共 ${l} 条记录 第 ${d}/${Math.ceil(l / f)} 页 `
|
|
72
76
|
), m = async (l) => {
|
|
73
77
|
const { pageNo: O } = l;
|
|
@@ -87,30 +91,30 @@ function le(s, a = {}) {
|
|
|
87
91
|
}), S(!1);
|
|
88
92
|
}, N = (l) => {
|
|
89
93
|
m({ ...e, ...l, pageNo: 1 });
|
|
90
|
-
},
|
|
94
|
+
}, q = (l) => {
|
|
91
95
|
m({ ...e, ...l });
|
|
92
96
|
}, J = (l) => {
|
|
93
97
|
m({ ...l, pageSize: f, pageNo: 1 });
|
|
94
98
|
}, H = (l, O, h, $) => {
|
|
95
99
|
const { action: P } = $;
|
|
96
100
|
if (["paginate", "sort"].includes(P)) {
|
|
97
|
-
const { current: T, pageSize:
|
|
101
|
+
const { current: T, pageSize: I } = l, { field: G, order: _ } = h, [V, Q] = x.sortField, [Y, Z] = x.sortOrder, B = {
|
|
98
102
|
...e,
|
|
99
|
-
[
|
|
100
|
-
[
|
|
103
|
+
[V]: _ ? _ === "ascend" ? Y : Z : void 0,
|
|
104
|
+
[Q]: G,
|
|
101
105
|
pageNo: T,
|
|
102
|
-
pageSize:
|
|
106
|
+
pageSize: I
|
|
103
107
|
};
|
|
104
|
-
m(
|
|
108
|
+
m(B);
|
|
105
109
|
}
|
|
106
110
|
};
|
|
107
111
|
return D(() => {
|
|
108
112
|
N(g.current);
|
|
109
113
|
}, []), {
|
|
110
114
|
queryParams: e,
|
|
111
|
-
search:
|
|
112
|
-
refresh:
|
|
113
|
-
reset:
|
|
115
|
+
search: M(N),
|
|
116
|
+
refresh: M(q),
|
|
117
|
+
reset: M(J),
|
|
114
118
|
selectedRowKeys: v,
|
|
115
119
|
tableProps: {
|
|
116
120
|
bordered: !0,
|
|
@@ -120,7 +124,7 @@ function le(s, a = {}) {
|
|
|
120
124
|
loading: i,
|
|
121
125
|
dataSource: p,
|
|
122
126
|
pagination: { ...c, showTotal: z },
|
|
123
|
-
onChange:
|
|
127
|
+
onChange: M(H),
|
|
124
128
|
locale: {
|
|
125
129
|
emptyText: i ? "" : /* @__PURE__ */ oe.jsx(A, { image: A.PRESENTED_IMAGE_SIMPLE })
|
|
126
130
|
}
|
|
@@ -158,7 +162,7 @@ const R = K((s) => ({
|
|
|
158
162
|
})
|
|
159
163
|
}));
|
|
160
164
|
function ce(s) {
|
|
161
|
-
const a = R((e) => e.modals), o = R((e) => e.toggleModal), t = R((e) => e.setModal), r = R((e) => e.clearModals), n =
|
|
165
|
+
const a = R((e) => e.modals), o = R((e) => e.toggleModal), t = R((e) => e.setModal), r = R((e) => e.clearModals), n = U(), u = w([]), c = Object.keys(s);
|
|
162
166
|
D(() => (u.current = c.map(
|
|
163
167
|
(e) => `${n}-${e}`
|
|
164
168
|
), () => {
|
|
@@ -201,11 +205,11 @@ function ce(s) {
|
|
|
201
205
|
}, p;
|
|
202
206
|
}
|
|
203
207
|
const ae = (s, a = "value", o = "label") => new Map(s.map((t) => [t[a], t[o]]));
|
|
204
|
-
function de(s, a) {
|
|
205
|
-
const [o, t] =
|
|
206
|
-
|
|
208
|
+
function de({ queryFn: s, options: a }) {
|
|
209
|
+
const [o, t] = y({
|
|
210
|
+
list: [],
|
|
207
211
|
mapData: /* @__PURE__ */ new Map()
|
|
208
|
-
}), [r, n] =
|
|
212
|
+
}), [r, n] = y(!0), { params: u, selectKey: c, fieldNames: p } = a, e = async () => {
|
|
209
213
|
n(!0);
|
|
210
214
|
const { data: S } = await s(u), g = S || [];
|
|
211
215
|
if (p) {
|
|
@@ -218,13 +222,11 @@ function de(s, a) {
|
|
|
218
222
|
} else
|
|
219
223
|
t((v) => ({ ...v, options: g }));
|
|
220
224
|
n(!1);
|
|
221
|
-
}, d =
|
|
222
|
-
e();
|
|
223
|
-
}, [e]);
|
|
225
|
+
}, d = M(void 0);
|
|
224
226
|
D(() => {
|
|
225
|
-
|
|
227
|
+
e();
|
|
226
228
|
}, []);
|
|
227
|
-
const {
|
|
229
|
+
const { list: f, mapData: i } = o;
|
|
228
230
|
return {
|
|
229
231
|
loading: r,
|
|
230
232
|
refresh: d,
|
|
@@ -233,7 +235,7 @@ function de(s, a) {
|
|
|
233
235
|
};
|
|
234
236
|
}
|
|
235
237
|
function ue(s, a) {
|
|
236
|
-
const [o, t] =
|
|
238
|
+
const [o, t] = y(!1), { message: r } = X.useApp(), n = W(async (u) => {
|
|
237
239
|
try {
|
|
238
240
|
t(!0);
|
|
239
241
|
const c = await s(u), { status: p, info: e } = c;
|
|
@@ -251,6 +253,7 @@ export {
|
|
|
251
253
|
ie as configureTableOption,
|
|
252
254
|
ce as useCreateModal,
|
|
253
255
|
ue as useFormSubmit,
|
|
256
|
+
M as useMemoizedFn,
|
|
254
257
|
de as useSelectOptions,
|
|
255
258
|
le as useTableList
|
|
256
259
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base-stone/hooks",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "leafront",
|
|
7
7
|
"email": "leafront@126.com"
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"prettier": "^3.7.4",
|
|
49
49
|
"rollup-plugin-shell": "^1.0.9",
|
|
50
50
|
"typescript": "^5.9.3",
|
|
51
|
-
"typescript-eslint": "^8.
|
|
52
|
-
"vite": "^7.3.
|
|
51
|
+
"typescript-eslint": "^8.52.0",
|
|
52
|
+
"vite": "^7.3.1",
|
|
53
53
|
"vite-plugin-dts": "^4.5.4"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"antd": "^6.1.
|
|
56
|
+
"antd": "^6.1.4",
|
|
57
57
|
"react": "^19.2.3",
|
|
58
58
|
"zustand": "^5.0.9"
|
|
59
59
|
}
|