@base-stone/hooks 0.9.8 → 1.0.0
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.
|
@@ -64,6 +64,10 @@ export declare interface ModalProps {
|
|
|
64
64
|
onCancel: () => void;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
declare type noop = (this: any, ...args: any[]) => any;
|
|
68
|
+
|
|
69
|
+
declare type PickFunction<T extends noop> = (this: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T>;
|
|
70
|
+
|
|
67
71
|
declare type Placement = 'top' | 'bottom' | 'left' | 'right';
|
|
68
72
|
|
|
69
73
|
export declare interface QueryParamsData {
|
|
@@ -154,6 +158,8 @@ export declare function useCreateModal<const T extends Record<string, ModalConfi
|
|
|
154
158
|
|
|
155
159
|
export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn): FormSubmitResult;
|
|
156
160
|
|
|
161
|
+
export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
|
|
162
|
+
|
|
157
163
|
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>;
|
|
158
164
|
|
|
159
165
|
export declare function useTableList<T extends Record<string, any> = Record<string, any>>(getRequestFn: (data: QueryParamsData) => Promise<TableResponse<T>>, initParams?: Record<string, any>): TableListResult<T>;
|
|
@@ -8,8 +8,8 @@ function ee() {
|
|
|
8
8
|
L = 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 d = null;
|
|
12
|
+
if (n !== void 0 && (d = "" + n), r.key !== void 0 && (d = "" + r.key), "key" in r) {
|
|
13
13
|
n = {};
|
|
14
14
|
for (var c in r)
|
|
15
15
|
c !== "key" && (n[c] = r[c]);
|
|
@@ -17,7 +17,7 @@ function ee() {
|
|
|
17
17
|
return r = n.ref, {
|
|
18
18
|
$$typeof: s,
|
|
19
19
|
type: t,
|
|
20
|
-
key:
|
|
20
|
+
key: d,
|
|
21
21
|
ref: r !== void 0 ? r : null,
|
|
22
22
|
props: n
|
|
23
23
|
};
|
|
@@ -29,14 +29,15 @@ function te() {
|
|
|
29
29
|
return j || (j = 1, k.exports = ee()), k.exports;
|
|
30
30
|
}
|
|
31
31
|
var oe = te();
|
|
32
|
-
|
|
32
|
+
function b(s) {
|
|
33
33
|
const a = w(s);
|
|
34
34
|
a.current = F(() => 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);
|
|
38
38
|
}), o.current;
|
|
39
|
-
}
|
|
39
|
+
}
|
|
40
|
+
const x = {
|
|
40
41
|
sortField: ["orderType", "orderField"],
|
|
41
42
|
sortOrder: ["ASC", "DESC"],
|
|
42
43
|
pageSize: 10
|
|
@@ -47,7 +48,7 @@ function ie(s) {
|
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
function le(s, a = {}) {
|
|
50
|
-
const { rowSelection: o, ...t } = a, r = x.pageSize, [n,
|
|
51
|
+
const { rowSelection: o, ...t } = a, r = x.pageSize, [n, d] = M({
|
|
51
52
|
pagination: {
|
|
52
53
|
showSizeChanger: !0,
|
|
53
54
|
showQuickJumper: !0,
|
|
@@ -61,21 +62,21 @@ function le(s, a = {}) {
|
|
|
61
62
|
pageSize: r,
|
|
62
63
|
...t
|
|
63
64
|
}
|
|
64
|
-
}), { pagination: c, list: p, queryParams: e } = n, { pageNo:
|
|
65
|
+
}), { pagination: c, list: p, queryParams: e } = n, { pageNo: u, pageSize: f } = e, [i, S] = M(!0), g = w(e), [v, E] = M([]), C = F(() => {
|
|
65
66
|
if (o)
|
|
66
67
|
return {
|
|
67
68
|
selectedRowKeys: v,
|
|
68
69
|
onChange: (l) => E(l)
|
|
69
70
|
};
|
|
70
71
|
}, [o, v]), z = b(
|
|
71
|
-
(l) => `共 ${l} 条记录 第 ${
|
|
72
|
+
(l) => `共 ${l} 条记录 第 ${u}/${Math.ceil(l / f)} 页 `
|
|
72
73
|
), m = async (l) => {
|
|
73
74
|
const { pageNo: O } = l;
|
|
74
75
|
S(!0);
|
|
75
76
|
const h = { ...t, pageSize: f, ...l };
|
|
76
77
|
l.pageNo === void 0 && (h.pageNo = 1), l.pageSize === void 0 && (h.pageSize = f);
|
|
77
78
|
const { data: $ } = await s(h), { list: P = [], totalCount: T = 0 } = $ || {};
|
|
78
|
-
o && E([]),
|
|
79
|
+
o && E([]), d({
|
|
79
80
|
list: P,
|
|
80
81
|
queryParams: h,
|
|
81
82
|
pagination: {
|
|
@@ -158,15 +159,15 @@ const R = K((s) => ({
|
|
|
158
159
|
})
|
|
159
160
|
}));
|
|
160
161
|
function ce(s) {
|
|
161
|
-
const a = R((e) => e.modals), o = R((e) => e.toggleModal), t = R((e) => e.setModal), r = R((e) => e.clearModals), n = W(),
|
|
162
|
-
D(() => (
|
|
162
|
+
const a = R((e) => e.modals), o = R((e) => e.toggleModal), t = R((e) => e.setModal), r = R((e) => e.clearModals), n = W(), d = w([]), c = Object.keys(s);
|
|
163
|
+
D(() => (d.current = c.map(
|
|
163
164
|
(e) => `${n}-${e}`
|
|
164
165
|
), () => {
|
|
165
|
-
r(
|
|
166
|
+
r(d.current);
|
|
166
167
|
}), []);
|
|
167
168
|
const p = {};
|
|
168
169
|
return c.forEach((e) => {
|
|
169
|
-
const
|
|
170
|
+
const u = `${n}-${e}`, f = a[u] ?? { visible: !1, data: {} }, i = s[e], S = typeof i.title == "function" ? i.title(f.data) : i.title;
|
|
170
171
|
p[`${e}Modal`] = {
|
|
171
172
|
visible: f.visible,
|
|
172
173
|
data: f.data,
|
|
@@ -177,7 +178,7 @@ function ce(s) {
|
|
|
177
178
|
maskClosable: i.maskClosable ?? !1,
|
|
178
179
|
centered: i.centered ?? !0,
|
|
179
180
|
destroyOnHidden: i.destroyOnHidden ?? !0,
|
|
180
|
-
onCancel: i.onCancel ?? (() => t(
|
|
181
|
+
onCancel: i.onCancel ?? (() => t(u, !1))
|
|
181
182
|
},
|
|
182
183
|
drawerProps: {
|
|
183
184
|
size: i.width,
|
|
@@ -186,28 +187,28 @@ function ce(s) {
|
|
|
186
187
|
maskClosable: i.maskClosable ?? !0,
|
|
187
188
|
destroyOnHidden: i.destroyOnHidden ?? !0,
|
|
188
189
|
placement: i.placement ?? "right",
|
|
189
|
-
onClose: i.onClose ?? (() => t(
|
|
190
|
+
onClose: i.onClose ?? (() => t(u, !1))
|
|
190
191
|
},
|
|
191
|
-
toggle: (g) => o(
|
|
192
|
-
open: (g) => t(
|
|
193
|
-
close: () => t(
|
|
192
|
+
toggle: (g) => o(u, g),
|
|
193
|
+
open: (g) => t(u, !0, g),
|
|
194
|
+
close: () => t(u, !1)
|
|
194
195
|
};
|
|
195
|
-
}), p.toggle = (e,
|
|
196
|
-
o(`${n}-${e}`,
|
|
197
|
-
}, p.open = (e,
|
|
198
|
-
t(`${n}-${e}`, !0,
|
|
196
|
+
}), p.toggle = (e, u) => {
|
|
197
|
+
o(`${n}-${e}`, u);
|
|
198
|
+
}, p.open = (e, u) => {
|
|
199
|
+
t(`${n}-${e}`, !0, u);
|
|
199
200
|
}, p.close = (e) => {
|
|
200
201
|
t(`${n}-${e}`, !1);
|
|
201
202
|
}, p;
|
|
202
203
|
}
|
|
203
204
|
const ae = (s, a = "value", o = "label") => new Map(s.map((t) => [t[a], t[o]]));
|
|
204
|
-
function
|
|
205
|
+
function ue(s, a) {
|
|
205
206
|
const [o, t] = M({
|
|
206
207
|
options: [],
|
|
207
208
|
mapData: /* @__PURE__ */ new Map()
|
|
208
|
-
}), [r, n] = M(!0), { params:
|
|
209
|
+
}), [r, n] = M(!0), { params: d, selectKey: c, fieldNames: p } = a, e = async () => {
|
|
209
210
|
n(!0);
|
|
210
|
-
const { data: S } = await s(
|
|
211
|
+
const { data: S } = await s(d), g = S || [];
|
|
211
212
|
if (p) {
|
|
212
213
|
const { label: v, value: E } = p, C = g.map((m) => ({
|
|
213
214
|
data: m,
|
|
@@ -218,25 +219,25 @@ function de(s, a) {
|
|
|
218
219
|
} else
|
|
219
220
|
t((v) => ({ ...v, options: g }));
|
|
220
221
|
n(!1);
|
|
221
|
-
},
|
|
222
|
+
}, u = q(() => {
|
|
222
223
|
e();
|
|
223
224
|
}, [e]);
|
|
224
225
|
D(() => {
|
|
225
|
-
|
|
226
|
+
u();
|
|
226
227
|
}, []);
|
|
227
228
|
const { options: f, mapData: i } = o;
|
|
228
229
|
return {
|
|
229
230
|
loading: r,
|
|
230
|
-
refresh:
|
|
231
|
+
refresh: u,
|
|
231
232
|
[`${c}Options`]: f,
|
|
232
233
|
[`${c}Map`]: i
|
|
233
234
|
};
|
|
234
235
|
}
|
|
235
|
-
function
|
|
236
|
-
const [o, t] = M(!1), { message: r } = X.useApp(), n = q(async (
|
|
236
|
+
function de(s, a) {
|
|
237
|
+
const [o, t] = M(!1), { message: r } = X.useApp(), n = q(async (d) => {
|
|
237
238
|
try {
|
|
238
239
|
t(!0);
|
|
239
|
-
const c = await s(
|
|
240
|
+
const c = await s(d), { status: p, info: e } = c;
|
|
240
241
|
p == "success" && (a(c), r.success(e));
|
|
241
242
|
} catch {
|
|
242
243
|
}
|
|
@@ -250,7 +251,8 @@ function ue(s, a) {
|
|
|
250
251
|
export {
|
|
251
252
|
ie as configureTableOption,
|
|
252
253
|
ce as useCreateModal,
|
|
253
|
-
|
|
254
|
-
|
|
254
|
+
de as useFormSubmit,
|
|
255
|
+
b as useMemoizedFn,
|
|
256
|
+
ue as useSelectOptions,
|
|
255
257
|
le as useTableList
|
|
256
258
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base-stone/hooks",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "leafront",
|
|
7
7
|
"email": "leafront@126.com"
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"prettier": "^3.7.4",
|
|
49
49
|
"rollup-plugin-shell": "^1.0.9",
|
|
50
50
|
"typescript": "^5.9.3",
|
|
51
|
-
"typescript-eslint": "^8.
|
|
52
|
-
"vite": "^7.3.
|
|
51
|
+
"typescript-eslint": "^8.52.0",
|
|
52
|
+
"vite": "^7.3.1",
|
|
53
53
|
"vite-plugin-dts": "^4.5.4"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"antd": "^6.1.
|
|
56
|
+
"antd": "^6.1.4",
|
|
57
57
|
"react": "^19.2.3",
|
|
58
58
|
"zustand": "^5.0.9"
|
|
59
59
|
}
|