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