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