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