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