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