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