@basestone/hooks 1.3.6 → 1.3.7

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.
@@ -78,6 +78,7 @@ declare interface QueryOptions<K extends string, T = Record<string, any>> {
78
78
  dataType: DataType;
79
79
  dataKey: K;
80
80
  transform?: (data: unknown) => T;
81
+ success?: (data: unknown) => void;
81
82
  initialValue?: Record<string, any> | Record<string, any>[];
82
83
  }
83
84
 
@@ -200,7 +201,7 @@ export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn
200
201
 
201
202
  export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
202
203
 
203
- export declare function useRequestQuery<T = Record<string, any> | Record<string, any>[] | undefined, const K extends string = string>({ queryFn, params, dataType, dataKey, initialValue, transform }: QueryOptions<K, T>): QueryResult<K, T>;
204
+ export declare function useRequestQuery<T = Record<string, any> | Record<string, any>[] | undefined, const K extends string = string>({ queryFn, params, dataType, dataKey, initialValue, transform, success }: QueryOptions<K, T>): QueryResult<K, T>;
204
205
 
205
206
  export declare function useSelectOptions<V extends string | number = string | number, const K extends string = string>({ queryFn, params, dataKey, fieldNames, transform }: SelectConfig<K>): SelectOptionsResult<K, V>;
206
207
 
@@ -1,40 +1,40 @@
1
- import { useRef as j, useMemo as V, useState as h, useEffectEvent as A, useEffect as T, useId as W, useCallback as X } from "react";
1
+ import { useRef as j, useMemo as V, useState as M, useEffectEvent as A, useEffect as T, useId as W, useCallback as X } from "react";
2
2
  import { Empty as J, App as K } from "antd";
3
3
  import { create as ee } from "zustand";
4
- var _ = { exports: {} }, C = {};
4
+ var _ = { exports: {} }, R = {};
5
5
  var H;
6
6
  function te() {
7
- if (H) return C;
7
+ if (H) return R;
8
8
  H = 1;
9
- var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), a = /* @__PURE__ */ Symbol.for("react.fragment");
10
- function o(t, s, n) {
11
- var p = null;
12
- if (n !== void 0 && (p = "" + n), s.key !== void 0 && (p = "" + s.key), "key" in s) {
9
+ var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), s = /* @__PURE__ */ Symbol.for("react.fragment");
10
+ function o(t, a, n) {
11
+ var d = null;
12
+ if (n !== void 0 && (d = "" + n), a.key !== void 0 && (d = "" + a.key), "key" in a) {
13
13
  n = {};
14
- for (var c in s)
15
- c !== "key" && (n[c] = s[c]);
16
- } else n = s;
17
- return s = n.ref, {
14
+ for (var c in a)
15
+ c !== "key" && (n[c] = a[c]);
16
+ } else n = a;
17
+ return a = n.ref, {
18
18
  $$typeof: r,
19
19
  type: t,
20
- key: p,
21
- ref: s !== void 0 ? s : null,
20
+ key: d,
21
+ ref: a !== void 0 ? a : null,
22
22
  props: n
23
23
  };
24
24
  }
25
- return C.Fragment = a, C.jsx = o, C.jsxs = o, C;
25
+ return R.Fragment = s, R.jsx = o, R.jsxs = o, R;
26
26
  }
27
27
  var I;
28
- function se() {
28
+ function ae() {
29
29
  return I || (I = 1, _.exports = te()), _.exports;
30
30
  }
31
- var ae = se();
31
+ var se = ae();
32
32
  function y(r) {
33
- const a = j(r);
34
- a.current = V(() => r, [r]);
33
+ const s = j(r);
34
+ s.current = V(() => r, [r]);
35
35
  const o = j(void 0);
36
36
  return o.current || (o.current = function(...t) {
37
- return a.current.apply(this, t);
37
+ return s.current.apply(this, t);
38
38
  }), o.current;
39
39
  }
40
40
  const w = {
@@ -43,45 +43,45 @@ const w = {
43
43
  pageSize: 10
44
44
  };
45
45
  function ie(r) {
46
- Object.keys(r).forEach((a) => {
47
- w[a] = r[a];
46
+ Object.keys(r).forEach((s) => {
47
+ w[s] = r[s];
48
48
  });
49
49
  }
50
50
  function ce({
51
51
  queryFn: r,
52
- params: a,
52
+ params: s,
53
53
  transform: o,
54
54
  rowSelection: t
55
55
  }) {
56
- const s = w.pageSize, [n, p] = h({
56
+ const a = w.pageSize, [n, d] = M({
57
57
  pagination: {
58
58
  showSizeChanger: !0,
59
59
  showQuickJumper: !0,
60
60
  total: 0,
61
- pageSize: s,
61
+ pageSize: a,
62
62
  current: 1
63
63
  },
64
64
  list: [],
65
65
  queryParams: {
66
66
  pageNo: 1,
67
- pageSize: s,
68
- ...a
67
+ pageSize: a,
68
+ ...s
69
69
  }
70
- }), { pagination: c, list: f, queryParams: e } = n, { pageNo: l, pageSize: d } = e, [i, m] = h(!0), [g, M] = h([]), R = V(() => {
70
+ }), { pagination: c, list: f, queryParams: e } = n, { pageNo: u, pageSize: p } = e, [i, v] = M(!0), [g, S] = M([]), b = V(() => {
71
71
  if (t)
72
72
  return {
73
73
  selectedRowKeys: g,
74
- onChange: (u) => M(u)
74
+ onChange: (l) => S(l)
75
75
  };
76
- }, [t, g]), b = y(
77
- (u) => `共 ${u} 条记录 第 ${l}/${Math.ceil(u / d)} 页 `
78
- ), v = async (u) => {
79
- const { pageNo: L } = u;
80
- m(!0);
81
- const E = { ...a, pageSize: d, ...u };
82
- u.pageNo === void 0 && (E.pageNo = 1), u.pageSize === void 0 && (E.pageSize = d);
76
+ }, [t, g]), C = y(
77
+ (l) => `共 ${l} 条记录 第 ${u}/${Math.ceil(l / p)} 页 `
78
+ ), m = async (l) => {
79
+ const { pageNo: L } = l;
80
+ v(!0);
81
+ const E = { ...s, pageSize: p, ...l };
82
+ l.pageNo === void 0 && (E.pageNo = 1), l.pageSize === void 0 && (E.pageSize = p);
83
83
  const { data: D } = await r(E), N = o ? o(D) : D, { list: O = [], totalCount: F = 0 } = N || {};
84
- t && M([]), p({
84
+ t && S([]), d({
85
85
  list: O,
86
86
  queryParams: E,
87
87
  pagination: {
@@ -90,26 +90,26 @@ function ce({
90
90
  pageSize: E.pageSize,
91
91
  total: F
92
92
  }
93
- }), m(!1);
93
+ }), v(!1);
94
94
  }, P = A(() => {
95
- v({ ...e, pageNo: 1 });
96
- }), x = (u) => {
97
- v({ ...e, ...u, pageNo: 1 });
98
- }, k = (u) => {
99
- v({ ...e, ...u });
100
- }, S = (u) => {
101
- v({ ...u, pageSize: d, pageNo: 1 });
102
- }, z = (u, L, E, D) => {
95
+ m({ ...e, pageNo: 1 });
96
+ }), x = (l) => {
97
+ m({ ...e, ...l, pageNo: 1 });
98
+ }, k = (l) => {
99
+ m({ ...e, ...l });
100
+ }, h = (l) => {
101
+ m({ ...l, pageSize: p, pageNo: 1 });
102
+ }, z = (l, L, E, D) => {
103
103
  const { action: N } = D;
104
104
  if (["paginate", "sort"].includes(N)) {
105
- const { current: O, pageSize: F } = u, { field: G, order: q } = E, [Q, Y] = w.sortField, [Z, B] = w.sortOrder, U = {
105
+ const { current: O, pageSize: F } = l, { field: G, order: q } = E, [Q, Y] = w.sortField, [Z, B] = w.sortOrder, U = {
106
106
  ...e,
107
107
  [Q]: q ? q === "ascend" ? Z : B : void 0,
108
108
  [Y]: G,
109
109
  pageNo: O,
110
110
  pageSize: F
111
111
  };
112
- v(U);
112
+ m(U);
113
113
  }
114
114
  };
115
115
  return T(() => {
@@ -118,139 +118,139 @@ function ce({
118
118
  queryParams: e,
119
119
  search: y(x),
120
120
  refresh: y(k),
121
- reset: y(S),
121
+ reset: y(h),
122
122
  selectedRowKeys: g,
123
123
  tableProps: {
124
124
  bordered: !0,
125
125
  size: "middle",
126
126
  sticky: !0,
127
- rowSelection: R,
127
+ rowSelection: b,
128
128
  loading: i,
129
129
  dataSource: f,
130
- pagination: { ...c, showTotal: b },
130
+ pagination: { ...c, showTotal: C },
131
131
  onChange: y(z),
132
132
  locale: {
133
- emptyText: i ? "" : /* @__PURE__ */ ae.jsx(J, { image: J.PRESENTED_IMAGE_SIMPLE })
133
+ emptyText: i ? "" : /* @__PURE__ */ se.jsx(J, { image: J.PRESENTED_IMAGE_SIMPLE })
134
134
  }
135
135
  }
136
136
  };
137
137
  }
138
138
  const $ = ee((r) => ({
139
139
  modals: {},
140
- toggleModal: (a, o) => r((t) => {
141
- const n = t.modals[a]?.visible || !1;
140
+ toggleModal: (s, o) => r((t) => {
141
+ const n = t.modals[s]?.visible || !1;
142
142
  return {
143
143
  modals: {
144
144
  ...t.modals,
145
- [a]: {
145
+ [s]: {
146
146
  visible: !n,
147
147
  data: n ? {} : o || {}
148
148
  }
149
149
  }
150
150
  };
151
151
  }),
152
- setModal: (a, o, t) => r((s) => ({
152
+ setModal: (s, o, t) => r((a) => ({
153
153
  modals: {
154
- ...s.modals,
155
- [a]: {
154
+ ...a.modals,
155
+ [s]: {
156
156
  visible: o,
157
157
  data: o ? t || {} : {}
158
158
  }
159
159
  }
160
160
  })),
161
- clearModals: (a) => r((o) => {
161
+ clearModals: (s) => r((o) => {
162
162
  const t = { ...o.modals };
163
- return a.forEach((s) => {
164
- delete t[s];
163
+ return s.forEach((a) => {
164
+ delete t[a];
165
165
  }), { modals: t };
166
166
  })
167
167
  }));
168
168
  function le(r) {
169
- const a = $((e) => e.modals), o = $((e) => e.toggleModal), t = $((e) => e.setModal), s = $((e) => e.clearModals), n = W(), p = j([]), c = Object.keys(r);
170
- T(() => (p.current = c.map(
169
+ const s = $((e) => e.modals), o = $((e) => e.toggleModal), t = $((e) => e.setModal), a = $((e) => e.clearModals), n = W(), d = j([]), c = Object.keys(r);
170
+ T(() => (d.current = c.map(
171
171
  (e) => `${n}-${e}`
172
172
  ), () => {
173
- s(p.current);
173
+ a(d.current);
174
174
  }), []);
175
175
  const f = {};
176
176
  return c.forEach((e) => {
177
- const l = `${n}-${e}`, d = a[l] ?? { visible: !1, data: {} }, i = r[e], m = typeof i.title == "function" ? i.title(d.data) : i.title;
177
+ const u = `${n}-${e}`, p = s[u] ?? { visible: !1, data: {} }, i = r[e], v = typeof i.title == "function" ? i.title(p.data) : i.title;
178
178
  f[`${e}Modal`] = {
179
- visible: d.visible,
180
- data: d.data,
179
+ visible: p.visible,
180
+ data: p.data,
181
181
  modalProps: {
182
182
  width: i.width,
183
- title: m,
184
- open: d.visible,
183
+ title: v,
184
+ open: p.visible,
185
185
  maskClosable: i.maskClosable ?? !1,
186
186
  centered: i.centered ?? !0,
187
187
  destroyOnHidden: i.destroyOnHidden ?? !0,
188
- onCancel: i.onCancel ?? (() => t(l, !1))
188
+ onCancel: i.onCancel ?? (() => t(u, !1))
189
189
  },
190
190
  drawerProps: {
191
191
  size: i.width,
192
- title: m,
193
- open: d.visible,
192
+ title: v,
193
+ open: p.visible,
194
194
  maskClosable: i.maskClosable ?? !0,
195
195
  destroyOnHidden: i.destroyOnHidden ?? !0,
196
196
  placement: i.placement ?? "right",
197
- onClose: i.onClose ?? (() => t(l, !1))
197
+ onClose: i.onClose ?? (() => t(u, !1))
198
198
  },
199
- toggle: (g) => o(l, g),
200
- open: (g) => t(l, !0, g),
201
- close: () => t(l, !1)
199
+ toggle: (g) => o(u, g),
200
+ open: (g) => t(u, !0, g),
201
+ close: () => t(u, !1)
202
202
  };
203
- }), f.toggle = (e, l) => {
204
- o(`${n}-${e}`, l);
205
- }, f.open = (e, l) => {
206
- t(`${n}-${e}`, !0, l);
203
+ }), f.toggle = (e, u) => {
204
+ o(`${n}-${e}`, u);
205
+ }, f.open = (e, u) => {
206
+ t(`${n}-${e}`, !0, u);
207
207
  }, f.close = (e) => {
208
208
  t(`${n}-${e}`, !1);
209
209
  }, f;
210
210
  }
211
- function ue({ queryFn: r, params: a, dataKey: o, fieldNames: t, transform: s }) {
212
- const [n, p] = h({
211
+ function ue({ queryFn: r, params: s, dataKey: o, fieldNames: t, transform: a }) {
212
+ const [n, d] = M({
213
213
  list: [],
214
214
  mapData: /* @__PURE__ */ new Map()
215
- }), [c, f] = h(!1), e = async () => {
215
+ }), [c, f] = M(!1), e = async () => {
216
216
  f(!0);
217
- const { data: g, status: M } = await r(a);
218
- if (M === "success") {
219
- const b = (s ? s(g) : g) || [], { label: v, value: P } = t, x = /* @__PURE__ */ new Map([]), k = b.map((S) => {
220
- const z = S[P];
221
- return x.set(z, S[v]), {
222
- label: S[v],
217
+ const { data: g, status: S } = await r(s);
218
+ if (S === "success") {
219
+ const C = (a ? a(g) : g) || [], { label: m, value: P } = t, x = /* @__PURE__ */ new Map([]), k = C.map((h) => {
220
+ const z = h[P];
221
+ return x.set(z, h[m]), {
222
+ label: h[m],
223
223
  value: z,
224
- data: S
224
+ data: h
225
225
  };
226
226
  });
227
- p((S) => ({ ...S, list: k, mapData: x }));
227
+ d((h) => ({ ...h, list: k, mapData: x }));
228
228
  }
229
229
  f(!1);
230
- }, l = A(e), d = y(() => {
230
+ }, u = A(e), p = y(() => {
231
231
  e();
232
232
  });
233
233
  T(() => {
234
- l();
234
+ u();
235
235
  }, []);
236
- const { list: i, mapData: m } = n;
236
+ const { list: i, mapData: v } = n;
237
237
  return {
238
238
  loading: c,
239
- refresh: d,
239
+ refresh: p,
240
240
  [`${o}Options`]: i,
241
- [`${o}Map`]: m
241
+ [`${o}Map`]: v
242
242
  };
243
243
  }
244
- function de(r, a) {
245
- const [o, t] = h(!1), { message: s } = K.useApp(), n = X(async (p) => {
244
+ function de(r, s) {
245
+ const [o, t] = M(!1), { message: a } = K.useApp(), n = X(async (d) => {
246
246
  try {
247
247
  t(!0);
248
- const c = await r(p), { status: f, info: e } = c;
249
- f == "success" && (a(c), s.success(e));
248
+ const c = await r(d), { status: f, info: e } = c;
249
+ f == "success" && (s(c), a.success(e));
250
250
  } catch {
251
251
  }
252
252
  t(!1);
253
- }, [r, a, s]);
253
+ }, [r, s, a]);
254
254
  return {
255
255
  loading: o,
256
256
  submit: n
@@ -258,31 +258,32 @@ function de(r, a) {
258
258
  }
259
259
  function pe({
260
260
  queryFn: r,
261
- params: a,
261
+ params: s,
262
262
  dataType: o,
263
263
  dataKey: t,
264
- initialValue: s,
265
- transform: n
264
+ initialValue: a,
265
+ transform: n,
266
+ success: d
266
267
  }) {
267
- const p = s || (o === "Array" ? [] : /* @__PURE__ */ Object.create({})), [c, f] = h(p), [e, l] = h(!1), d = async (g) => {
268
- l(!0);
269
- const { data: M, status: R } = await r(g ?? a);
270
- if (R === "success") {
271
- const b = n ? n(M) : M;
272
- f(b);
268
+ const c = a || (o === "Array" ? [] : /* @__PURE__ */ Object.create({})), [f, e] = M(c), [u, p] = M(!1), i = async (S) => {
269
+ p(!0);
270
+ const { data: b, status: C } = await r(S ?? s);
271
+ if (C === "success") {
272
+ const m = n ? n(b) : b;
273
+ d && d(b), e(m);
273
274
  }
274
- l(!1);
275
- }, i = A(d);
275
+ p(!1);
276
+ }, v = A(i);
276
277
  T(() => {
277
- i();
278
+ v();
278
279
  }, []);
279
- const m = y((g) => {
280
- d(g);
280
+ const g = y((S) => {
281
+ i(S);
281
282
  });
282
283
  return {
283
- [t]: c,
284
- loading: e,
285
- refresh: m
284
+ [t]: f,
285
+ loading: u,
286
+ refresh: g
286
287
  };
287
288
  }
288
289
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basestone/hooks",
3
3
  "license": "MIT",
4
- "version": "1.3.6",
4
+ "version": "1.3.7",
5
5
  "author": {
6
6
  "name": "leafront",
7
7
  "email": "leafront@126.com"