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