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