@base-stone/hooks 1.0.0 → 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 +27 -15
- package/dist/design-hooks.es.prod.js +168 -166
- 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,15 @@ declare interface RequestFn {
|
|
|
85
90
|
}>;
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
declare
|
|
93
|
+
declare interface SelectConfig<K extends string> {
|
|
94
|
+
queryFn: (data: Record<string, any>) => Promise<QueryResponse>;
|
|
89
95
|
params?: Record<string, any>;
|
|
90
96
|
selectKey: K;
|
|
91
97
|
fieldNames?: {
|
|
92
98
|
label: string;
|
|
93
99
|
value: string;
|
|
94
100
|
};
|
|
95
|
-
}
|
|
101
|
+
}
|
|
96
102
|
|
|
97
103
|
declare type SelectOption<T extends string | number = string | number> = {
|
|
98
104
|
label: string;
|
|
@@ -113,17 +119,10 @@ declare interface SuccessFn {
|
|
|
113
119
|
(data: Record<string, any>): void;
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
declare interface
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
search: (params?: Record<string, any>) => void;
|
|
121
|
-
refresh: (params?: Record<string, any>) => void;
|
|
122
|
-
reset: (params?: Record<string, any>) => void;
|
|
123
|
-
/** 选中的行 keys */
|
|
124
|
-
selectedRowKeys: Key[];
|
|
125
|
-
/** 表格属性 */
|
|
126
|
-
tableProps: TableProps<T>;
|
|
122
|
+
declare interface TableOptions<T, P = Record<string, any>> {
|
|
123
|
+
queryFn: (data: QueryParamsData) => Promise<TableResponse<T>>;
|
|
124
|
+
params?: P;
|
|
125
|
+
rowSelection?: boolean;
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
export declare interface TableProps<T> {
|
|
@@ -148,6 +147,19 @@ declare interface TableResponse<T> {
|
|
|
148
147
|
};
|
|
149
148
|
}
|
|
150
149
|
|
|
150
|
+
declare interface TableResult<T> {
|
|
151
|
+
/** 查询参数 */
|
|
152
|
+
queryParams: QueryParamsData;
|
|
153
|
+
/** 执行查询方法 */
|
|
154
|
+
search: (params?: Record<string, any>) => void;
|
|
155
|
+
refresh: (params?: Record<string, any>) => void;
|
|
156
|
+
reset: (params?: Record<string, any>) => void;
|
|
157
|
+
/** 选中的行 keys */
|
|
158
|
+
selectedRowKeys: Key[];
|
|
159
|
+
/** 表格属性 */
|
|
160
|
+
tableProps: TableProps<T>;
|
|
161
|
+
}
|
|
162
|
+
|
|
151
163
|
export declare function useCreateModal<const T extends Record<string, ModalConfig>>(configs: T): {
|
|
152
164
|
[K in keyof T as `${string & K}Modal`]: ModalInstance;
|
|
153
165
|
} & {
|
|
@@ -160,8 +172,8 @@ export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn
|
|
|
160
172
|
|
|
161
173
|
export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
|
|
162
174
|
|
|
163
|
-
export declare function useSelectOptions<T extends string | number = string | number, K extends string = string>(
|
|
175
|
+
export declare function useSelectOptions<T extends string | number = string | number, K extends string = string>({ queryFn, params, selectKey, fieldNames }: SelectConfig<K>): SelectOptionsResult<K, T>;
|
|
164
176
|
|
|
165
|
-
export declare function useTableList<T extends Record<string, any> = Record<string, any>>(
|
|
177
|
+
export declare function useTableList<T extends Record<string, any> = Record<string, any>>({ queryFn, params: initParams, rowSelection }: TableOptions<T>): TableResult<T>;
|
|
166
178
|
|
|
167
179
|
export { }
|
|
@@ -1,258 +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
|
|
25
|
+
return b.Fragment = o, b.jsx = t, b.jsxs = t, b;
|
|
26
26
|
}
|
|
27
27
|
var j;
|
|
28
|
-
function
|
|
29
|
-
return j || (j = 1,
|
|
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
|
|
51
|
-
|
|
50
|
+
function ie({
|
|
51
|
+
queryFn: s,
|
|
52
|
+
params: o,
|
|
53
|
+
rowSelection: t
|
|
54
|
+
}) {
|
|
55
|
+
const e = R.pageSize, [r, n] = M({
|
|
52
56
|
pagination: {
|
|
53
57
|
showSizeChanger: !0,
|
|
54
58
|
showQuickJumper: !0,
|
|
55
59
|
total: 0,
|
|
56
|
-
pageSize:
|
|
60
|
+
pageSize: e,
|
|
57
61
|
current: 1
|
|
58
62
|
},
|
|
59
63
|
list: [],
|
|
60
64
|
queryParams: {
|
|
61
65
|
pageNo: 1,
|
|
62
|
-
pageSize:
|
|
63
|
-
...
|
|
66
|
+
pageSize: e,
|
|
67
|
+
...o
|
|
64
68
|
}
|
|
65
|
-
}), { pagination:
|
|
66
|
-
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)
|
|
67
71
|
return {
|
|
68
|
-
selectedRowKeys:
|
|
69
|
-
onChange: (
|
|
72
|
+
selectedRowKeys: f,
|
|
73
|
+
onChange: (u) => y(u)
|
|
70
74
|
};
|
|
71
|
-
}, [
|
|
72
|
-
(
|
|
73
|
-
),
|
|
74
|
-
const { pageNo: O } =
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const { data: $ } = await s(
|
|
79
|
-
|
|
80
|
-
list:
|
|
81
|
-
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,
|
|
82
86
|
pagination: {
|
|
83
|
-
...
|
|
87
|
+
...p,
|
|
84
88
|
current: O,
|
|
85
|
-
pageSize:
|
|
86
|
-
total:
|
|
89
|
+
pageSize: S.pageSize,
|
|
90
|
+
total: w
|
|
87
91
|
}
|
|
88
|
-
}),
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
},
|
|
96
|
-
const { action:
|
|
97
|
-
if (["paginate", "sort"].includes(
|
|
98
|
-
const { current:
|
|
99
|
-
...
|
|
100
|
-
[
|
|
101
|
-
[
|
|
102
|
-
pageNo:
|
|
103
|
-
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
|
|
104
108
|
};
|
|
105
|
-
|
|
109
|
+
g(Z);
|
|
106
110
|
}
|
|
107
111
|
};
|
|
108
|
-
return
|
|
109
|
-
|
|
112
|
+
return k(() => {
|
|
113
|
+
D(v.current);
|
|
110
114
|
}, []), {
|
|
111
|
-
queryParams:
|
|
112
|
-
search:
|
|
113
|
-
refresh:
|
|
114
|
-
reset:
|
|
115
|
-
selectedRowKeys:
|
|
115
|
+
queryParams: l,
|
|
116
|
+
search: h(D),
|
|
117
|
+
refresh: h(L),
|
|
118
|
+
reset: h(q),
|
|
119
|
+
selectedRowKeys: f,
|
|
116
120
|
tableProps: {
|
|
117
121
|
bordered: !0,
|
|
118
122
|
size: "middle",
|
|
119
123
|
sticky: !0,
|
|
120
|
-
rowSelection:
|
|
121
|
-
loading:
|
|
122
|
-
dataSource:
|
|
123
|
-
pagination: { ...
|
|
124
|
-
onChange:
|
|
124
|
+
rowSelection: E,
|
|
125
|
+
loading: m,
|
|
126
|
+
dataSource: d,
|
|
127
|
+
pagination: { ...p, showTotal: z },
|
|
128
|
+
onChange: h(J),
|
|
125
129
|
locale: {
|
|
126
|
-
emptyText:
|
|
130
|
+
emptyText: m ? "" : /* @__PURE__ */ te.jsx(N, { image: N.PRESENTED_IMAGE_SIMPLE })
|
|
127
131
|
}
|
|
128
132
|
}
|
|
129
133
|
};
|
|
130
134
|
}
|
|
131
|
-
const
|
|
135
|
+
const C = X((s) => ({
|
|
132
136
|
modals: {},
|
|
133
|
-
toggleModal: (
|
|
134
|
-
const n =
|
|
137
|
+
toggleModal: (o, t) => s((e) => {
|
|
138
|
+
const n = e.modals[o]?.visible || !1;
|
|
135
139
|
return {
|
|
136
140
|
modals: {
|
|
137
|
-
...
|
|
138
|
-
[
|
|
141
|
+
...e.modals,
|
|
142
|
+
[o]: {
|
|
139
143
|
visible: !n,
|
|
140
|
-
data: n ? {} :
|
|
144
|
+
data: n ? {} : t || {}
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
147
|
};
|
|
144
148
|
}),
|
|
145
|
-
setModal: (
|
|
149
|
+
setModal: (o, t, e) => s((r) => ({
|
|
146
150
|
modals: {
|
|
147
151
|
...r.modals,
|
|
148
|
-
[
|
|
149
|
-
visible:
|
|
150
|
-
data:
|
|
152
|
+
[o]: {
|
|
153
|
+
visible: t,
|
|
154
|
+
data: t ? e || {} : {}
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
157
|
})),
|
|
154
|
-
clearModals: (
|
|
155
|
-
const
|
|
156
|
-
return
|
|
157
|
-
delete
|
|
158
|
-
}), { modals:
|
|
158
|
+
clearModals: (o) => s((t) => {
|
|
159
|
+
const e = { ...t.modals };
|
|
160
|
+
return o.forEach((r) => {
|
|
161
|
+
delete e[r];
|
|
162
|
+
}), { modals: e };
|
|
159
163
|
})
|
|
160
164
|
}));
|
|
161
|
-
function
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
(
|
|
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}`
|
|
165
169
|
), () => {
|
|
166
|
-
r(
|
|
170
|
+
r(p.current);
|
|
167
171
|
}), []);
|
|
168
|
-
const
|
|
169
|
-
return
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
visible:
|
|
173
|
-
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,
|
|
174
178
|
modalProps: {
|
|
175
179
|
width: i.width,
|
|
176
|
-
title:
|
|
177
|
-
open:
|
|
180
|
+
title: v,
|
|
181
|
+
open: m.visible,
|
|
178
182
|
maskClosable: i.maskClosable ?? !1,
|
|
179
183
|
centered: i.centered ?? !0,
|
|
180
184
|
destroyOnHidden: i.destroyOnHidden ?? !0,
|
|
181
|
-
onCancel: i.onCancel ?? (() =>
|
|
185
|
+
onCancel: i.onCancel ?? (() => e(c, !1))
|
|
182
186
|
},
|
|
183
187
|
drawerProps: {
|
|
184
188
|
size: i.width,
|
|
185
|
-
title:
|
|
186
|
-
open:
|
|
189
|
+
title: v,
|
|
190
|
+
open: m.visible,
|
|
187
191
|
maskClosable: i.maskClosable ?? !0,
|
|
188
192
|
destroyOnHidden: i.destroyOnHidden ?? !0,
|
|
189
193
|
placement: i.placement ?? "right",
|
|
190
|
-
onClose: i.onClose ?? (() =>
|
|
194
|
+
onClose: i.onClose ?? (() => e(c, !1))
|
|
191
195
|
},
|
|
192
|
-
toggle: (
|
|
193
|
-
open: (
|
|
194
|
-
close: () =>
|
|
196
|
+
toggle: (f) => t(c, f),
|
|
197
|
+
open: (f) => e(c, !0, f),
|
|
198
|
+
close: () => e(c, !1)
|
|
195
199
|
};
|
|
196
|
-
}),
|
|
197
|
-
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
},
|
|
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;
|
|
203
207
|
}
|
|
204
|
-
const
|
|
205
|
-
function
|
|
206
|
-
const [
|
|
207
|
-
|
|
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({
|
|
211
|
+
list: [],
|
|
208
212
|
mapData: /* @__PURE__ */ new Map()
|
|
209
|
-
}), [
|
|
210
|
-
|
|
211
|
-
const { data:
|
|
212
|
-
if (
|
|
213
|
-
const { label:
|
|
214
|
-
data:
|
|
215
|
-
label:
|
|
216
|
-
value:
|
|
217
|
-
})), z =
|
|
218
|
-
|
|
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 }));
|
|
219
223
|
} else
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
},
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
D(() => {
|
|
226
|
-
u();
|
|
224
|
+
n((f) => ({ ...f, options: v }));
|
|
225
|
+
d(!1);
|
|
226
|
+
}, a = h(void 0);
|
|
227
|
+
k(() => {
|
|
228
|
+
l();
|
|
227
229
|
}, []);
|
|
228
|
-
const {
|
|
230
|
+
const { list: c, mapData: m } = r;
|
|
229
231
|
return {
|
|
230
|
-
loading:
|
|
231
|
-
refresh:
|
|
232
|
-
[`${
|
|
233
|
-
[`${
|
|
232
|
+
loading: p,
|
|
233
|
+
refresh: a,
|
|
234
|
+
[`${t}Options`]: c,
|
|
235
|
+
[`${t}Map`]: m
|
|
234
236
|
};
|
|
235
237
|
}
|
|
236
|
-
function
|
|
237
|
-
const [
|
|
238
|
+
function ue(s, o) {
|
|
239
|
+
const [t, e] = M(!1), { message: r } = W.useApp(), n = U(async (p) => {
|
|
238
240
|
try {
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
|
|
241
|
+
e(!0);
|
|
242
|
+
const d = await s(p), { status: l, info: a } = d;
|
|
243
|
+
l == "success" && (o(d), r.success(a));
|
|
242
244
|
} catch {
|
|
243
245
|
}
|
|
244
|
-
|
|
245
|
-
}, [s,
|
|
246
|
+
e(!1);
|
|
247
|
+
}, [s, o, r]);
|
|
246
248
|
return {
|
|
247
|
-
loading:
|
|
249
|
+
loading: t,
|
|
248
250
|
submit: n
|
|
249
251
|
};
|
|
250
252
|
}
|
|
251
253
|
export {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
254
|
+
ne as configureTableOption,
|
|
255
|
+
le as useCreateModal,
|
|
256
|
+
ue as useFormSubmit,
|
|
257
|
+
h as useMemoizedFn,
|
|
258
|
+
ce as useSelectOptions,
|
|
259
|
+
ie as useTableList
|
|
258
260
|
};
|