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