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