@base-stone/hooks 1.1.9 → 1.2.1

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