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