@base-stone/hooks 0.9.7 → 1.0.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/dist/design-hooks.es.prod.d.ts +6 -0
- package/dist/design-hooks.es.prod.js +168 -175
- 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 {
|
|
@@ -154,6 +158,8 @@ export declare function useCreateModal<const T extends Record<string, ModalConfi
|
|
|
154
158
|
|
|
155
159
|
export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn): FormSubmitResult;
|
|
156
160
|
|
|
161
|
+
export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
|
|
162
|
+
|
|
157
163
|
export declare function useSelectOptions<T extends string | number = string | number, K extends string = string>(getRequestFn: (params: Record<string, any>) => Promise<any>, selectConfig: SelectConfig<K>): SelectOptionsResult<K, T>;
|
|
158
164
|
|
|
159
165
|
export declare function useTableList<T extends Record<string, any> = Record<string, any>>(getRequestFn: (data: QueryParamsData) => Promise<TableResponse<T>>, initParams?: Record<string, any>): TableListResult<T>;
|
|
@@ -1,265 +1,258 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Empty as
|
|
1
|
+
import { useRef as w, useMemo as F, useState as M, useEffect as D, useId as W, useCallback as q } from "react";
|
|
2
|
+
import { Empty as A, App as X } from "antd";
|
|
3
3
|
import { create as K } from "zustand";
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var k = { exports: {} }, y = {};
|
|
5
|
+
var L;
|
|
6
6
|
function ee() {
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
function
|
|
11
|
-
var
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
for (var
|
|
15
|
-
|
|
16
|
-
} else
|
|
17
|
-
return
|
|
18
|
-
$$typeof:
|
|
7
|
+
if (L) return y;
|
|
8
|
+
L = 1;
|
|
9
|
+
var s = /* @__PURE__ */ Symbol.for("react.transitional.element"), a = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
10
|
+
function o(t, r, n) {
|
|
11
|
+
var d = null;
|
|
12
|
+
if (n !== void 0 && (d = "" + n), r.key !== void 0 && (d = "" + r.key), "key" in r) {
|
|
13
|
+
n = {};
|
|
14
|
+
for (var c in r)
|
|
15
|
+
c !== "key" && (n[c] = r[c]);
|
|
16
|
+
} else n = r;
|
|
17
|
+
return r = n.ref, {
|
|
18
|
+
$$typeof: s,
|
|
19
19
|
type: t,
|
|
20
|
-
key:
|
|
21
|
-
ref:
|
|
22
|
-
props:
|
|
20
|
+
key: d,
|
|
21
|
+
ref: r !== void 0 ? r : null,
|
|
22
|
+
props: n
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return y.Fragment = a, y.jsx = o, y.jsxs = o, y;
|
|
26
26
|
}
|
|
27
|
-
var
|
|
27
|
+
var j;
|
|
28
28
|
function te() {
|
|
29
|
-
return
|
|
29
|
+
return j || (j = 1, k.exports = ee()), k.exports;
|
|
30
30
|
}
|
|
31
31
|
var oe = te();
|
|
32
|
-
|
|
32
|
+
function b(s) {
|
|
33
|
+
const a = w(s);
|
|
34
|
+
a.current = F(() => s, [s]);
|
|
35
|
+
const o = w(void 0);
|
|
36
|
+
return o.current || (o.current = function(...t) {
|
|
37
|
+
return a.current.apply(this, t);
|
|
38
|
+
}), o.current;
|
|
39
|
+
}
|
|
40
|
+
const x = {
|
|
33
41
|
sortField: ["orderType", "orderField"],
|
|
34
42
|
sortOrder: ["ASC", "DESC"],
|
|
35
43
|
pageSize: 10
|
|
36
44
|
};
|
|
37
|
-
function ie(
|
|
38
|
-
Object.keys(
|
|
39
|
-
|
|
45
|
+
function ie(s) {
|
|
46
|
+
Object.keys(s).forEach((a) => {
|
|
47
|
+
x[a] = s[a];
|
|
40
48
|
});
|
|
41
49
|
}
|
|
42
|
-
function le(
|
|
43
|
-
const { rowSelection:
|
|
50
|
+
function le(s, a = {}) {
|
|
51
|
+
const { rowSelection: o, ...t } = a, r = x.pageSize, [n, d] = M({
|
|
44
52
|
pagination: {
|
|
45
53
|
showSizeChanger: !0,
|
|
46
54
|
showQuickJumper: !0,
|
|
47
55
|
total: 0,
|
|
48
|
-
pageSize:
|
|
56
|
+
pageSize: r,
|
|
49
57
|
current: 1
|
|
50
58
|
},
|
|
51
59
|
list: [],
|
|
52
60
|
queryParams: {
|
|
53
61
|
pageNo: 1,
|
|
54
|
-
pageSize:
|
|
62
|
+
pageSize: r,
|
|
55
63
|
...t
|
|
56
64
|
}
|
|
57
|
-
}), { pagination:
|
|
58
|
-
if (
|
|
65
|
+
}), { pagination: c, list: p, queryParams: e } = n, { pageNo: u, pageSize: f } = e, [i, S] = M(!0), g = w(e), [v, E] = M([]), C = F(() => {
|
|
66
|
+
if (o)
|
|
59
67
|
return {
|
|
60
68
|
selectedRowKeys: v,
|
|
61
|
-
onChange: (
|
|
69
|
+
onChange: (l) => E(l)
|
|
62
70
|
};
|
|
63
|
-
}, [
|
|
64
|
-
(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
pageSize: h.pageSize,
|
|
80
|
-
total: P
|
|
81
|
-
}
|
|
82
|
-
}), M(!1);
|
|
83
|
-
},
|
|
84
|
-
[e, t, a, u, n, l]
|
|
85
|
-
), D = S(
|
|
86
|
-
(c) => {
|
|
87
|
-
p({ ...e, ...c, pageNo: 1 });
|
|
88
|
-
},
|
|
89
|
-
[p, e]
|
|
90
|
-
), J = S(
|
|
91
|
-
(c) => {
|
|
92
|
-
p({ ...e, ...c });
|
|
93
|
-
},
|
|
94
|
-
[p, e]
|
|
95
|
-
), F = S(
|
|
96
|
-
(c) => {
|
|
97
|
-
p({ ...c, pageSize: u, pageNo: 1 });
|
|
98
|
-
},
|
|
99
|
-
[p, u]
|
|
100
|
-
), N = S(
|
|
101
|
-
(c, O, h, $) => {
|
|
102
|
-
const { action: z } = $;
|
|
103
|
-
if (["paginate", "sort"].includes(z)) {
|
|
104
|
-
const { current: P, pageSize: G } = c, { field: V, order: _ } = h, [Q, Y] = R.sortField, [Z, B] = R.sortOrder, U = {
|
|
105
|
-
...e,
|
|
106
|
-
[Q]: _ ? _ === "ascend" ? Z : B : void 0,
|
|
107
|
-
[Y]: V,
|
|
108
|
-
pageNo: P,
|
|
109
|
-
pageSize: G
|
|
110
|
-
};
|
|
111
|
-
p(U);
|
|
71
|
+
}, [o, v]), z = b(
|
|
72
|
+
(l) => `共 ${l} 条记录 第 ${u}/${Math.ceil(l / f)} 页 `
|
|
73
|
+
), m = async (l) => {
|
|
74
|
+
const { pageNo: O } = l;
|
|
75
|
+
S(!0);
|
|
76
|
+
const h = { ...t, pageSize: f, ...l };
|
|
77
|
+
l.pageNo === void 0 && (h.pageNo = 1), l.pageSize === void 0 && (h.pageSize = f);
|
|
78
|
+
const { data: $ } = await s(h), { list: P = [], totalCount: T = 0 } = $ || {};
|
|
79
|
+
o && E([]), d({
|
|
80
|
+
list: P,
|
|
81
|
+
queryParams: h,
|
|
82
|
+
pagination: {
|
|
83
|
+
...c,
|
|
84
|
+
current: O,
|
|
85
|
+
pageSize: h.pageSize,
|
|
86
|
+
total: T
|
|
112
87
|
}
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
88
|
+
}), S(!1);
|
|
89
|
+
}, N = (l) => {
|
|
90
|
+
m({ ...e, ...l, pageNo: 1 });
|
|
91
|
+
}, I = (l) => {
|
|
92
|
+
m({ ...e, ...l });
|
|
93
|
+
}, J = (l) => {
|
|
94
|
+
m({ ...l, pageSize: f, pageNo: 1 });
|
|
95
|
+
}, H = (l, O, h, $) => {
|
|
96
|
+
const { action: P } = $;
|
|
97
|
+
if (["paginate", "sort"].includes(P)) {
|
|
98
|
+
const { current: T, pageSize: G } = l, { field: V, order: _ } = h, [Q, Y] = x.sortField, [Z, B] = x.sortOrder, U = {
|
|
99
|
+
...e,
|
|
100
|
+
[Q]: _ ? _ === "ascend" ? Z : B : void 0,
|
|
101
|
+
[Y]: V,
|
|
102
|
+
pageNo: T,
|
|
103
|
+
pageSize: G
|
|
104
|
+
};
|
|
105
|
+
m(U);
|
|
126
106
|
}
|
|
127
|
-
}
|
|
128
|
-
return
|
|
129
|
-
|
|
107
|
+
};
|
|
108
|
+
return D(() => {
|
|
109
|
+
N(g.current);
|
|
130
110
|
}, []), {
|
|
131
111
|
queryParams: e,
|
|
132
|
-
search:
|
|
133
|
-
refresh:
|
|
134
|
-
reset:
|
|
112
|
+
search: b(N),
|
|
113
|
+
refresh: b(I),
|
|
114
|
+
reset: b(J),
|
|
135
115
|
selectedRowKeys: v,
|
|
136
|
-
tableProps:
|
|
116
|
+
tableProps: {
|
|
117
|
+
bordered: !0,
|
|
118
|
+
size: "middle",
|
|
119
|
+
sticky: !0,
|
|
120
|
+
rowSelection: C,
|
|
121
|
+
loading: i,
|
|
122
|
+
dataSource: p,
|
|
123
|
+
pagination: { ...c, showTotal: z },
|
|
124
|
+
onChange: b(H),
|
|
125
|
+
locale: {
|
|
126
|
+
emptyText: i ? "" : /* @__PURE__ */ oe.jsx(A, { image: A.PRESENTED_IMAGE_SIMPLE })
|
|
127
|
+
}
|
|
128
|
+
}
|
|
137
129
|
};
|
|
138
130
|
}
|
|
139
|
-
const
|
|
131
|
+
const R = K((s) => ({
|
|
140
132
|
modals: {},
|
|
141
|
-
toggleModal: (
|
|
142
|
-
const
|
|
133
|
+
toggleModal: (a, o) => s((t) => {
|
|
134
|
+
const n = t.modals[a]?.visible || !1;
|
|
143
135
|
return {
|
|
144
136
|
modals: {
|
|
145
137
|
...t.modals,
|
|
146
|
-
[
|
|
147
|
-
visible: !
|
|
148
|
-
data:
|
|
138
|
+
[a]: {
|
|
139
|
+
visible: !n,
|
|
140
|
+
data: n ? {} : o || {}
|
|
149
141
|
}
|
|
150
142
|
}
|
|
151
143
|
};
|
|
152
144
|
}),
|
|
153
|
-
setModal: (
|
|
145
|
+
setModal: (a, o, t) => s((r) => ({
|
|
154
146
|
modals: {
|
|
155
|
-
...
|
|
156
|
-
[
|
|
157
|
-
visible:
|
|
158
|
-
data:
|
|
147
|
+
...r.modals,
|
|
148
|
+
[a]: {
|
|
149
|
+
visible: o,
|
|
150
|
+
data: o ? t || {} : {}
|
|
159
151
|
}
|
|
160
152
|
}
|
|
161
153
|
})),
|
|
162
|
-
clearModals: (
|
|
163
|
-
const t = { ...
|
|
164
|
-
return
|
|
165
|
-
delete t[
|
|
154
|
+
clearModals: (a) => s((o) => {
|
|
155
|
+
const t = { ...o.modals };
|
|
156
|
+
return a.forEach((r) => {
|
|
157
|
+
delete t[r];
|
|
166
158
|
}), { modals: t };
|
|
167
159
|
})
|
|
168
160
|
}));
|
|
169
|
-
function ce(
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
(e) => `${
|
|
161
|
+
function ce(s) {
|
|
162
|
+
const a = R((e) => e.modals), o = R((e) => e.toggleModal), t = R((e) => e.setModal), r = R((e) => e.clearModals), n = W(), d = w([]), c = Object.keys(s);
|
|
163
|
+
D(() => (d.current = c.map(
|
|
164
|
+
(e) => `${n}-${e}`
|
|
173
165
|
), () => {
|
|
174
|
-
|
|
166
|
+
r(d.current);
|
|
175
167
|
}), []);
|
|
176
|
-
const
|
|
177
|
-
return
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
visible:
|
|
181
|
-
data:
|
|
168
|
+
const p = {};
|
|
169
|
+
return c.forEach((e) => {
|
|
170
|
+
const u = `${n}-${e}`, f = a[u] ?? { visible: !1, data: {} }, i = s[e], S = typeof i.title == "function" ? i.title(f.data) : i.title;
|
|
171
|
+
p[`${e}Modal`] = {
|
|
172
|
+
visible: f.visible,
|
|
173
|
+
data: f.data,
|
|
182
174
|
modalProps: {
|
|
183
175
|
width: i.width,
|
|
184
|
-
title:
|
|
185
|
-
open:
|
|
176
|
+
title: S,
|
|
177
|
+
open: f.visible,
|
|
186
178
|
maskClosable: i.maskClosable ?? !1,
|
|
187
179
|
centered: i.centered ?? !0,
|
|
188
180
|
destroyOnHidden: i.destroyOnHidden ?? !0,
|
|
189
|
-
onCancel: i.onCancel ?? (() => t(
|
|
181
|
+
onCancel: i.onCancel ?? (() => t(u, !1))
|
|
190
182
|
},
|
|
191
183
|
drawerProps: {
|
|
192
184
|
size: i.width,
|
|
193
|
-
title:
|
|
194
|
-
open:
|
|
185
|
+
title: S,
|
|
186
|
+
open: f.visible,
|
|
195
187
|
maskClosable: i.maskClosable ?? !0,
|
|
196
188
|
destroyOnHidden: i.destroyOnHidden ?? !0,
|
|
197
189
|
placement: i.placement ?? "right",
|
|
198
|
-
onClose: i.onClose ?? (() => t(
|
|
190
|
+
onClose: i.onClose ?? (() => t(u, !1))
|
|
199
191
|
},
|
|
200
|
-
toggle: (g) =>
|
|
201
|
-
open: (g) => t(
|
|
202
|
-
close: () => t(
|
|
192
|
+
toggle: (g) => o(u, g),
|
|
193
|
+
open: (g) => t(u, !0, g),
|
|
194
|
+
close: () => t(u, !1)
|
|
203
195
|
};
|
|
204
|
-
}),
|
|
205
|
-
|
|
206
|
-
},
|
|
207
|
-
t(`${
|
|
208
|
-
},
|
|
209
|
-
t(`${
|
|
210
|
-
},
|
|
196
|
+
}), p.toggle = (e, u) => {
|
|
197
|
+
o(`${n}-${e}`, u);
|
|
198
|
+
}, p.open = (e, u) => {
|
|
199
|
+
t(`${n}-${e}`, !0, u);
|
|
200
|
+
}, p.close = (e) => {
|
|
201
|
+
t(`${n}-${e}`, !1);
|
|
202
|
+
}, p;
|
|
211
203
|
}
|
|
212
|
-
const ae = (
|
|
213
|
-
function
|
|
214
|
-
const [
|
|
204
|
+
const ae = (s, a = "value", o = "label") => new Map(s.map((t) => [t[a], t[o]]));
|
|
205
|
+
function ue(s, a) {
|
|
206
|
+
const [o, t] = M({
|
|
215
207
|
options: [],
|
|
216
208
|
mapData: /* @__PURE__ */ new Map()
|
|
217
|
-
}), [
|
|
218
|
-
|
|
219
|
-
const { data:
|
|
220
|
-
if (
|
|
221
|
-
const { label: v, value:
|
|
222
|
-
data:
|
|
223
|
-
label:
|
|
224
|
-
value:
|
|
225
|
-
})),
|
|
226
|
-
t((
|
|
209
|
+
}), [r, n] = M(!0), { params: d, selectKey: c, fieldNames: p } = a, e = async () => {
|
|
210
|
+
n(!0);
|
|
211
|
+
const { data: S } = await s(d), g = S || [];
|
|
212
|
+
if (p) {
|
|
213
|
+
const { label: v, value: E } = p, C = g.map((m) => ({
|
|
214
|
+
data: m,
|
|
215
|
+
label: m[v],
|
|
216
|
+
value: m[E]
|
|
217
|
+
})), z = ae(C);
|
|
218
|
+
t((m) => ({ ...m, options: C, mapData: z }));
|
|
227
219
|
} else
|
|
228
220
|
t((v) => ({ ...v, options: g }));
|
|
229
|
-
|
|
230
|
-
},
|
|
221
|
+
n(!1);
|
|
222
|
+
}, u = q(() => {
|
|
231
223
|
e();
|
|
232
224
|
}, [e]);
|
|
233
|
-
|
|
234
|
-
|
|
225
|
+
D(() => {
|
|
226
|
+
u();
|
|
235
227
|
}, []);
|
|
236
|
-
const { options:
|
|
228
|
+
const { options: f, mapData: i } = o;
|
|
237
229
|
return {
|
|
238
|
-
loading:
|
|
239
|
-
refresh:
|
|
240
|
-
[`${
|
|
241
|
-
[`${
|
|
230
|
+
loading: r,
|
|
231
|
+
refresh: u,
|
|
232
|
+
[`${c}Options`]: f,
|
|
233
|
+
[`${c}Map`]: i
|
|
242
234
|
};
|
|
243
235
|
}
|
|
244
|
-
function
|
|
245
|
-
const [
|
|
236
|
+
function de(s, a) {
|
|
237
|
+
const [o, t] = M(!1), { message: r } = X.useApp(), n = q(async (d) => {
|
|
246
238
|
try {
|
|
247
239
|
t(!0);
|
|
248
|
-
const
|
|
249
|
-
|
|
240
|
+
const c = await s(d), { status: p, info: e } = c;
|
|
241
|
+
p == "success" && (a(c), r.success(e));
|
|
250
242
|
} catch {
|
|
251
243
|
}
|
|
252
244
|
t(!1);
|
|
253
|
-
}, [
|
|
245
|
+
}, [s, a, r]);
|
|
254
246
|
return {
|
|
255
|
-
loading:
|
|
256
|
-
submit:
|
|
247
|
+
loading: o,
|
|
248
|
+
submit: n
|
|
257
249
|
};
|
|
258
250
|
}
|
|
259
251
|
export {
|
|
260
252
|
ie as configureTableOption,
|
|
261
253
|
ce as useCreateModal,
|
|
262
|
-
|
|
263
|
-
|
|
254
|
+
de as useFormSubmit,
|
|
255
|
+
b as useMemoizedFn,
|
|
256
|
+
ue as useSelectOptions,
|
|
264
257
|
le as useTableList
|
|
265
258
|
};
|
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.0",
|
|
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
|
}
|