@base-stone/hooks 1.1.5 → 1.1.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.
|
@@ -118,7 +118,7 @@ declare interface SelectConfig<K extends string> {
|
|
|
118
118
|
queryFn: (data: Record<string, any>) => Promise<QueryResponse>;
|
|
119
119
|
params?: Record<string, any>;
|
|
120
120
|
dataKey: K;
|
|
121
|
-
|
|
121
|
+
transform?: (result: QueryResponse) => Record<string, any>[];
|
|
122
122
|
fieldNames?: {
|
|
123
123
|
label: string;
|
|
124
124
|
value: string;
|
|
@@ -200,7 +200,7 @@ export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
|
|
|
200
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
202
|
|
|
203
|
-
export declare function useSelectOptions<T extends string | number = string | number, K extends string = string>({ queryFn, params, dataKey, fieldNames,
|
|
203
|
+
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
204
|
|
|
205
205
|
export declare function useTableList<T extends Record<string, any> = Record<string, any>>({ queryFn, params: initParams, rowSelection }: TableOptions<T>): TableResult<T>;
|
|
206
206
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { useRef as
|
|
1
|
+
import { useRef as O, useMemo as J, useState as S, useEffectEvent as F, useEffect as z, 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 k = { exports: {} }, E = {};
|
|
5
5
|
var L;
|
|
6
6
|
function ee() {
|
|
7
7
|
if (L) return E;
|
|
8
8
|
L = 1;
|
|
9
9
|
var n = /* @__PURE__ */ Symbol.for("react.transitional.element"), o = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
10
10
|
function t(e, s, r) {
|
|
11
|
-
var
|
|
12
|
-
if (r !== void 0 && (
|
|
11
|
+
var d = null;
|
|
12
|
+
if (r !== void 0 && (d = "" + r), s.key !== void 0 && (d = "" + s.key), "key" in s) {
|
|
13
13
|
r = {};
|
|
14
14
|
for (var p in s)
|
|
15
15
|
p !== "key" && (r[p] = s[p]);
|
|
@@ -17,7 +17,7 @@ function ee() {
|
|
|
17
17
|
return s = r.ref, {
|
|
18
18
|
$$typeof: n,
|
|
19
19
|
type: e,
|
|
20
|
-
key:
|
|
20
|
+
key: d,
|
|
21
21
|
ref: s !== void 0 ? s : null,
|
|
22
22
|
props: r
|
|
23
23
|
};
|
|
@@ -26,13 +26,13 @@ function ee() {
|
|
|
26
26
|
}
|
|
27
27
|
var q;
|
|
28
28
|
function te() {
|
|
29
|
-
return q || (q = 1,
|
|
29
|
+
return q || (q = 1, k.exports = ee()), k.exports;
|
|
30
30
|
}
|
|
31
31
|
var oe = te();
|
|
32
32
|
function y(n) {
|
|
33
|
-
const o =
|
|
33
|
+
const o = O(n);
|
|
34
34
|
o.current = J(() => n, [n]);
|
|
35
|
-
const t =
|
|
35
|
+
const t = O(void 0);
|
|
36
36
|
return t.current || (t.current = function(...e) {
|
|
37
37
|
return o.current.apply(this, e);
|
|
38
38
|
}), t.current;
|
|
@@ -66,25 +66,25 @@ function ce({
|
|
|
66
66
|
pageSize: e,
|
|
67
67
|
...o
|
|
68
68
|
}
|
|
69
|
-
}), { pagination:
|
|
69
|
+
}), { pagination: d, list: p, queryParams: l } = s, { pageNo: a, pageSize: i } = l, [f, c] = S(!0), [m, g] = S([]), N = J(() => {
|
|
70
70
|
if (t)
|
|
71
71
|
return {
|
|
72
72
|
selectedRowKeys: m,
|
|
73
|
-
onChange: (
|
|
73
|
+
onChange: (u) => g(u)
|
|
74
74
|
};
|
|
75
75
|
}, [t, m]), b = y(
|
|
76
|
-
(
|
|
77
|
-
), v = async (
|
|
78
|
-
const { pageNo: _ } =
|
|
76
|
+
(u) => `共 ${u} 条记录 第 ${a}/${Math.ceil(u / i)} 页 `
|
|
77
|
+
), v = async (u) => {
|
|
78
|
+
const { pageNo: _ } = u;
|
|
79
79
|
c(!0);
|
|
80
|
-
const M = { ...o, pageSize: i, ...
|
|
81
|
-
|
|
80
|
+
const M = { ...o, pageSize: i, ...u };
|
|
81
|
+
u.pageNo === void 0 && (M.pageNo = 1), u.pageSize === void 0 && (M.pageSize = i);
|
|
82
82
|
const { data: T } = await n(M), { list: D = [], totalCount: P = 0 } = T || {};
|
|
83
83
|
t && g([]), r({
|
|
84
84
|
list: D,
|
|
85
85
|
queryParams: M,
|
|
86
86
|
pagination: {
|
|
87
|
-
...
|
|
87
|
+
...d,
|
|
88
88
|
current: _,
|
|
89
89
|
pageSize: M.pageSize,
|
|
90
90
|
total: P
|
|
@@ -92,16 +92,16 @@ function ce({
|
|
|
92
92
|
}), c(!1);
|
|
93
93
|
}, $ = F(() => {
|
|
94
94
|
v({ ...l, pageNo: 1 });
|
|
95
|
-
}),
|
|
96
|
-
v({ ...l, ...
|
|
97
|
-
}, w = (
|
|
98
|
-
v({ ...l, ...
|
|
99
|
-
}, h = (
|
|
100
|
-
v({ ...
|
|
101
|
-
}, H = (
|
|
95
|
+
}), C = (u) => {
|
|
96
|
+
v({ ...l, ...u, pageNo: 1 });
|
|
97
|
+
}, w = (u) => {
|
|
98
|
+
v({ ...l, ...u });
|
|
99
|
+
}, h = (u) => {
|
|
100
|
+
v({ ...u, pageSize: i, pageNo: 1 });
|
|
101
|
+
}, H = (u, _, M, T) => {
|
|
102
102
|
const { action: D } = T;
|
|
103
103
|
if (["paginate", "sort"].includes(D)) {
|
|
104
|
-
const { current: P, pageSize: I } =
|
|
104
|
+
const { current: P, pageSize: I } = u, { field: G, order: A } = M, [V, Q] = x.sortField, [Y, Z] = x.sortOrder, B = {
|
|
105
105
|
...l,
|
|
106
106
|
[V]: A ? A === "ascend" ? Y : Z : void 0,
|
|
107
107
|
[Q]: G,
|
|
@@ -115,7 +115,7 @@ function ce({
|
|
|
115
115
|
$();
|
|
116
116
|
}, []), {
|
|
117
117
|
queryParams: l,
|
|
118
|
-
search: y(
|
|
118
|
+
search: y(C),
|
|
119
119
|
refresh: y(w),
|
|
120
120
|
reset: y(h),
|
|
121
121
|
selectedRowKeys: m,
|
|
@@ -126,7 +126,7 @@ function ce({
|
|
|
126
126
|
rowSelection: N,
|
|
127
127
|
loading: f,
|
|
128
128
|
dataSource: p,
|
|
129
|
-
pagination: { ...
|
|
129
|
+
pagination: { ...d, showTotal: b },
|
|
130
130
|
onChange: y(H),
|
|
131
131
|
locale: {
|
|
132
132
|
emptyText: f ? "" : /* @__PURE__ */ oe.jsx(j, { image: j.PRESENTED_IMAGE_SIMPLE })
|
|
@@ -134,7 +134,7 @@ function ce({
|
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
|
-
const
|
|
137
|
+
const R = K((n) => ({
|
|
138
138
|
modals: {},
|
|
139
139
|
toggleModal: (o, t) => n((e) => {
|
|
140
140
|
const r = e.modals[o]?.visible || !1;
|
|
@@ -165,11 +165,11 @@ const C = K((n) => ({
|
|
|
165
165
|
})
|
|
166
166
|
}));
|
|
167
167
|
function le(n) {
|
|
168
|
-
const o =
|
|
169
|
-
z(() => (
|
|
168
|
+
const o = R((a) => a.modals), t = R((a) => a.toggleModal), e = R((a) => a.setModal), s = R((a) => a.clearModals), r = U(), d = O([]), p = Object.keys(n);
|
|
169
|
+
z(() => (d.current = p.map(
|
|
170
170
|
(a) => `${r}-${a}`
|
|
171
171
|
), () => {
|
|
172
|
-
s(
|
|
172
|
+
s(d.current);
|
|
173
173
|
}), []);
|
|
174
174
|
const l = {};
|
|
175
175
|
return p.forEach((a) => {
|
|
@@ -208,22 +208,22 @@ function le(n) {
|
|
|
208
208
|
}, l;
|
|
209
209
|
}
|
|
210
210
|
const ae = (n, o = "value", t = "label") => new Map(n.map((e) => [e[o], e[t]]));
|
|
211
|
-
function
|
|
212
|
-
const [r,
|
|
211
|
+
function ue({ queryFn: n, params: o, dataKey: t, fieldNames: e, transform: s }) {
|
|
212
|
+
const [r, d] = S({
|
|
213
213
|
list: [],
|
|
214
214
|
mapData: /* @__PURE__ */ new Map()
|
|
215
215
|
}), [p, l] = S(!0), a = async () => {
|
|
216
216
|
l(!0);
|
|
217
217
|
const g = await n(o), b = (s ? s(g) : g.data) || [];
|
|
218
218
|
if (e) {
|
|
219
|
-
const { label: v, value: $ } = e,
|
|
219
|
+
const { label: v, value: $ } = e, C = b.map((h) => ({
|
|
220
220
|
data: h,
|
|
221
221
|
label: h[v],
|
|
222
222
|
value: h[$]
|
|
223
|
-
})), w = ae(
|
|
224
|
-
|
|
223
|
+
})), w = ae(C);
|
|
224
|
+
d((h) => ({ ...h, list: C, mapData: w }));
|
|
225
225
|
} else
|
|
226
|
-
|
|
226
|
+
d((v) => ({ ...v, list: b }));
|
|
227
227
|
l(!1);
|
|
228
228
|
}, i = F(a), f = y(() => {
|
|
229
229
|
a();
|
|
@@ -239,11 +239,11 @@ function de({ queryFn: n, params: o, dataKey: t, fieldNames: e, successCallback:
|
|
|
239
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 de(n, o) {
|
|
243
|
+
const [t, e] = S(!1), { message: s } = X.useApp(), r = W(async (d) => {
|
|
244
244
|
try {
|
|
245
245
|
e(!0);
|
|
246
|
-
const p = await n(
|
|
246
|
+
const p = await n(d), { status: l, info: a } = p;
|
|
247
247
|
l == "success" && (o(p), s.success(a));
|
|
248
248
|
} catch {
|
|
249
249
|
}
|
|
@@ -261,7 +261,7 @@ function pe({
|
|
|
261
261
|
dataKey: e,
|
|
262
262
|
initialValue: s
|
|
263
263
|
}) {
|
|
264
|
-
const r = s || (t === "Array" ? [] : /* @__PURE__ */ Object.create({})), [
|
|
264
|
+
const r = s || (t === "Array" ? [] : /* @__PURE__ */ Object.create({})), [d, p] = S(r), [l, a] = S(!1), i = async (m) => {
|
|
265
265
|
a(!0);
|
|
266
266
|
const g = await n(m ?? o);
|
|
267
267
|
p(g.data);
|
|
@@ -273,7 +273,7 @@ function pe({
|
|
|
273
273
|
i();
|
|
274
274
|
});
|
|
275
275
|
return {
|
|
276
|
-
[e]:
|
|
276
|
+
[e]: d,
|
|
277
277
|
loading: l,
|
|
278
278
|
refresh: c
|
|
279
279
|
};
|
|
@@ -281,9 +281,9 @@ function pe({
|
|
|
281
281
|
export {
|
|
282
282
|
ie as configureTableOption,
|
|
283
283
|
le as useCreateModal,
|
|
284
|
-
|
|
284
|
+
de as useFormSubmit,
|
|
285
285
|
y as useMemoizedFn,
|
|
286
286
|
pe as useRequestQuery,
|
|
287
|
-
|
|
287
|
+
ue as useSelectOptions,
|
|
288
288
|
ce as useTableList
|
|
289
289
|
};
|