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