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