@base-stone/hooks 1.1.0 → 1.1.3

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