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