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