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