@base-stone/hooks 1.1.4 → 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.
- package/dist/design-hooks.es.prod.d.ts +2 -1
- package/dist/design-hooks.es.prod.js +111 -111
- package/package.json +1 -1
|
@@ -118,6 +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
|
+
transform?: (result: QueryResponse) => Record<string, any>[];
|
|
121
122
|
fieldNames?: {
|
|
122
123
|
label: string;
|
|
123
124
|
value: string;
|
|
@@ -199,7 +200,7 @@ export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
|
|
|
199
200
|
|
|
200
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>;
|
|
201
202
|
|
|
202
|
-
export declare function useSelectOptions<T extends string | number = string | number, K extends string = string>({ queryFn, params, dataKey, fieldNames }: SelectConfig<K>): SelectOptionsResult<K, T>;
|
|
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>;
|
|
203
204
|
|
|
204
205
|
export declare function useTableList<T extends Record<string, any> = Record<string, any>>({ queryFn, params: initParams, rowSelection }: TableOptions<T>): TableResult<T>;
|
|
205
206
|
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { Empty 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
|
+
import { Empty as j, App as X } from "antd";
|
|
3
3
|
import { create as K } from "zustand";
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var k = { exports: {} }, E = {};
|
|
5
|
+
var L;
|
|
6
6
|
function ee() {
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
function t(e,
|
|
11
|
-
var
|
|
12
|
-
if (r !== void 0 && (
|
|
7
|
+
if (L) return E;
|
|
8
|
+
L = 1;
|
|
9
|
+
var n = /* @__PURE__ */ Symbol.for("react.transitional.element"), o = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
10
|
+
function t(e, s, r) {
|
|
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
|
-
for (var
|
|
15
|
-
|
|
16
|
-
} else r =
|
|
17
|
-
return
|
|
18
|
-
$$typeof:
|
|
14
|
+
for (var p in s)
|
|
15
|
+
p !== "key" && (r[p] = s[p]);
|
|
16
|
+
} else r = s;
|
|
17
|
+
return s = r.ref, {
|
|
18
|
+
$$typeof: n,
|
|
19
19
|
type: e,
|
|
20
|
-
key:
|
|
21
|
-
ref:
|
|
20
|
+
key: d,
|
|
21
|
+
ref: s !== void 0 ? s : null,
|
|
22
22
|
props: r
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return E.Fragment = o, E.jsx = t, E.jsxs = t, E;
|
|
26
26
|
}
|
|
27
|
-
var
|
|
27
|
+
var q;
|
|
28
28
|
function te() {
|
|
29
|
-
return
|
|
29
|
+
return q || (q = 1, k.exports = ee()), k.exports;
|
|
30
30
|
}
|
|
31
31
|
var oe = te();
|
|
32
|
-
function y(
|
|
33
|
-
const o =
|
|
34
|
-
o.current =
|
|
35
|
-
const t =
|
|
32
|
+
function y(n) {
|
|
33
|
+
const o = O(n);
|
|
34
|
+
o.current = J(() => n, [n]);
|
|
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;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
40
|
+
const x = {
|
|
41
41
|
sortField: ["orderType", "orderField"],
|
|
42
42
|
sortOrder: ["ASC", "DESC"],
|
|
43
43
|
pageSize: 10
|
|
44
44
|
};
|
|
45
|
-
function ie(
|
|
46
|
-
Object.keys(
|
|
47
|
-
|
|
45
|
+
function ie(n) {
|
|
46
|
+
Object.keys(n).forEach((o) => {
|
|
47
|
+
x[o] = n[o];
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
function ce({
|
|
51
|
-
queryFn:
|
|
51
|
+
queryFn: n,
|
|
52
52
|
params: o,
|
|
53
53
|
rowSelection: t
|
|
54
54
|
}) {
|
|
55
|
-
const e =
|
|
55
|
+
const e = x.pageSize, [s, r] = S({
|
|
56
56
|
pagination: {
|
|
57
57
|
showSizeChanger: !0,
|
|
58
58
|
showQuickJumper: !0,
|
|
@@ -66,77 +66,77 @@ 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
|
-
}, [t, m]),
|
|
76
|
-
(
|
|
77
|
-
), v = async (
|
|
78
|
-
const { pageNo:
|
|
75
|
+
}, [t, m]), b = y(
|
|
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
|
-
|
|
82
|
-
const { data:
|
|
80
|
+
const M = { ...o, pageSize: i, ...u };
|
|
81
|
+
u.pageNo === void 0 && (M.pageNo = 1), u.pageSize === void 0 && (M.pageSize = i);
|
|
82
|
+
const { data: T } = await n(M), { list: D = [], totalCount: P = 0 } = T || {};
|
|
83
83
|
t && g([]), r({
|
|
84
|
-
list:
|
|
84
|
+
list: D,
|
|
85
85
|
queryParams: M,
|
|
86
86
|
pagination: {
|
|
87
|
-
...
|
|
88
|
-
current:
|
|
87
|
+
...d,
|
|
88
|
+
current: _,
|
|
89
89
|
pageSize: M.pageSize,
|
|
90
|
-
total:
|
|
90
|
+
total: P
|
|
91
91
|
}
|
|
92
92
|
}), c(!1);
|
|
93
|
-
}, $ =
|
|
93
|
+
}, $ = F(() => {
|
|
94
94
|
v({ ...l, pageNo: 1 });
|
|
95
|
-
}),
|
|
96
|
-
v({ ...l, ...
|
|
97
|
-
},
|
|
98
|
-
v({ ...l, ...
|
|
99
|
-
},
|
|
100
|
-
v({ ...
|
|
101
|
-
}, H = (
|
|
102
|
-
const { action:
|
|
103
|
-
if (["paginate", "sort"].includes(
|
|
104
|
-
const { current:
|
|
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
|
+
const { action: D } = T;
|
|
103
|
+
if (["paginate", "sort"].includes(D)) {
|
|
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
|
-
[V]:
|
|
106
|
+
[V]: A ? A === "ascend" ? Y : Z : void 0,
|
|
107
107
|
[Q]: G,
|
|
108
|
-
pageNo:
|
|
108
|
+
pageNo: P,
|
|
109
109
|
pageSize: I
|
|
110
110
|
};
|
|
111
111
|
v(B);
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
|
-
return
|
|
114
|
+
return z(() => {
|
|
115
115
|
$();
|
|
116
116
|
}, []), {
|
|
117
117
|
queryParams: l,
|
|
118
|
-
search: y(
|
|
119
|
-
refresh: y(
|
|
120
|
-
reset: y(
|
|
118
|
+
search: y(C),
|
|
119
|
+
refresh: y(w),
|
|
120
|
+
reset: y(h),
|
|
121
121
|
selectedRowKeys: m,
|
|
122
122
|
tableProps: {
|
|
123
123
|
bordered: !0,
|
|
124
124
|
size: "middle",
|
|
125
125
|
sticky: !0,
|
|
126
|
-
rowSelection:
|
|
126
|
+
rowSelection: N,
|
|
127
127
|
loading: f,
|
|
128
|
-
dataSource:
|
|
129
|
-
pagination: { ...
|
|
128
|
+
dataSource: p,
|
|
129
|
+
pagination: { ...d, showTotal: b },
|
|
130
130
|
onChange: y(H),
|
|
131
131
|
locale: {
|
|
132
|
-
emptyText: f ? "" : /* @__PURE__ */ oe.jsx(
|
|
132
|
+
emptyText: f ? "" : /* @__PURE__ */ oe.jsx(j, { image: j.PRESENTED_IMAGE_SIMPLE })
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
|
-
const
|
|
137
|
+
const R = K((n) => ({
|
|
138
138
|
modals: {},
|
|
139
|
-
toggleModal: (o, t) =>
|
|
139
|
+
toggleModal: (o, t) => n((e) => {
|
|
140
140
|
const r = e.modals[o]?.visible || !1;
|
|
141
141
|
return {
|
|
142
142
|
modals: {
|
|
@@ -148,32 +148,32 @@ const C = K((s) => ({
|
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
150
|
}),
|
|
151
|
-
setModal: (o, t, e) =>
|
|
151
|
+
setModal: (o, t, e) => n((s) => ({
|
|
152
152
|
modals: {
|
|
153
|
-
...
|
|
153
|
+
...s.modals,
|
|
154
154
|
[o]: {
|
|
155
155
|
visible: t,
|
|
156
156
|
data: t ? e || {} : {}
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
})),
|
|
160
|
-
clearModals: (o) =>
|
|
160
|
+
clearModals: (o) => n((t) => {
|
|
161
161
|
const e = { ...t.modals };
|
|
162
|
-
return o.forEach((
|
|
163
|
-
delete e[
|
|
162
|
+
return o.forEach((s) => {
|
|
163
|
+
delete e[s];
|
|
164
164
|
}), { modals: e };
|
|
165
165
|
})
|
|
166
166
|
}));
|
|
167
|
-
function le(
|
|
168
|
-
const o =
|
|
169
|
-
|
|
167
|
+
function le(n) {
|
|
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
|
-
|
|
172
|
+
s(d.current);
|
|
173
173
|
}), []);
|
|
174
174
|
const l = {};
|
|
175
|
-
return
|
|
176
|
-
const i = `${r}-${a}`, f = o[i] ?? { visible: !1, data: {} }, c =
|
|
175
|
+
return p.forEach((a) => {
|
|
176
|
+
const i = `${r}-${a}`, f = o[i] ?? { visible: !1, data: {} }, c = n[a], m = typeof c.title == "function" ? c.title(f.data) : c.title;
|
|
177
177
|
l[`${a}Modal`] = {
|
|
178
178
|
visible: f.visible,
|
|
179
179
|
data: f.data,
|
|
@@ -207,73 +207,73 @@ function le(s) {
|
|
|
207
207
|
e(`${r}-${a}`, !1);
|
|
208
208
|
}, l;
|
|
209
209
|
}
|
|
210
|
-
const ae = (
|
|
211
|
-
function ue({ queryFn:
|
|
212
|
-
const [
|
|
210
|
+
const ae = (n, o = "value", t = "label") => new Map(n.map((e) => [e[o], e[t]]));
|
|
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
|
-
}), [p,
|
|
216
|
-
|
|
217
|
-
const
|
|
215
|
+
}), [p, l] = S(!0), a = async () => {
|
|
216
|
+
l(!0);
|
|
217
|
+
const g = await n(o), b = (s ? s(g) : g.data) || [];
|
|
218
218
|
if (e) {
|
|
219
|
-
const { label:
|
|
219
|
+
const { label: v, value: $ } = e, C = b.map((h) => ({
|
|
220
220
|
data: h,
|
|
221
|
-
label: h[
|
|
222
|
-
value: h[
|
|
223
|
-
})),
|
|
224
|
-
|
|
221
|
+
label: h[v],
|
|
222
|
+
value: h[$]
|
|
223
|
+
})), w = ae(C);
|
|
224
|
+
d((h) => ({ ...h, list: C, mapData: w }));
|
|
225
225
|
} else
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
},
|
|
229
|
-
l();
|
|
230
|
-
});
|
|
231
|
-
x(() => {
|
|
226
|
+
d((v) => ({ ...v, list: b }));
|
|
227
|
+
l(!1);
|
|
228
|
+
}, i = F(a), f = y(() => {
|
|
232
229
|
a();
|
|
230
|
+
});
|
|
231
|
+
z(() => {
|
|
232
|
+
i();
|
|
233
233
|
}, []);
|
|
234
|
-
const { list:
|
|
234
|
+
const { list: c, mapData: m } = r;
|
|
235
235
|
return {
|
|
236
236
|
loading: p,
|
|
237
|
-
refresh:
|
|
238
|
-
[`${t}Options`]:
|
|
239
|
-
[`${t}Map`]:
|
|
237
|
+
refresh: f,
|
|
238
|
+
[`${t}Options`]: c,
|
|
239
|
+
[`${t}Map`]: m
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
|
-
function de(
|
|
243
|
-
const [t, e] = S(!1), { message:
|
|
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
|
|
247
|
-
l == "success" && (o(
|
|
246
|
+
const p = await n(d), { status: l, info: a } = p;
|
|
247
|
+
l == "success" && (o(p), s.success(a));
|
|
248
248
|
} catch {
|
|
249
249
|
}
|
|
250
250
|
e(!1);
|
|
251
|
-
}, [
|
|
251
|
+
}, [n, o, s]);
|
|
252
252
|
return {
|
|
253
253
|
loading: t,
|
|
254
254
|
submit: r
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
257
|
function pe({
|
|
258
|
-
queryFn:
|
|
258
|
+
queryFn: n,
|
|
259
259
|
params: o,
|
|
260
260
|
dataType: t,
|
|
261
261
|
dataKey: e,
|
|
262
|
-
initialValue:
|
|
262
|
+
initialValue: s
|
|
263
263
|
}) {
|
|
264
|
-
const r =
|
|
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
|
-
const g = await
|
|
267
|
-
|
|
268
|
-
}, f =
|
|
269
|
-
|
|
266
|
+
const g = await n(m ?? o);
|
|
267
|
+
p(g.data);
|
|
268
|
+
}, f = F(i);
|
|
269
|
+
z(() => {
|
|
270
270
|
f();
|
|
271
271
|
}, []);
|
|
272
272
|
const c = y(() => {
|
|
273
273
|
i();
|
|
274
274
|
});
|
|
275
275
|
return {
|
|
276
|
-
[e]:
|
|
276
|
+
[e]: d,
|
|
277
277
|
loading: l,
|
|
278
278
|
refresh: c
|
|
279
279
|
};
|