@base-stone/hooks 0.7.5 → 0.7.6

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.
@@ -9,12 +9,19 @@ import { TableProps as TableProps_2 } from 'antd';
9
9
  */
10
10
  export declare function configureTableOption(config: GlobalTableConfig): void;
11
11
 
12
+ declare interface FormSubmitResult {
13
+ loading: boolean;
14
+ submit: (number?: unknown) => void;
15
+ }
16
+
12
17
  declare interface GlobalTableConfig {
13
18
  sortField: string[];
14
19
  sortOrder: string[];
15
20
  pageSize: number;
16
21
  }
17
22
 
23
+ declare type MapData<T extends string | number = string | number> = Map<T, string | number | undefined>;
24
+
18
25
  declare type ModalInstance<T = any> = {
19
26
  visible: boolean;
20
27
  data: T;
@@ -31,6 +38,41 @@ export declare interface QueryParamsData {
31
38
  [key: string]: any;
32
39
  }
33
40
 
41
+ declare interface RequestFn {
42
+ (val?: unknown): Promise<{
43
+ status: string;
44
+ info: string;
45
+ }>;
46
+ }
47
+
48
+ declare interface SelectConfig<K> {
49
+ params?: Record<string, any>;
50
+ selectKey: K;
51
+ fieldNames?: {
52
+ label: string;
53
+ value: string;
54
+ };
55
+ }
56
+
57
+ declare type SelectOption<T extends string | number = string | number> = {
58
+ label: string;
59
+ value: T;
60
+ data?: Record<string, unknown>;
61
+ };
62
+
63
+ declare type SelectOptionsResult<K extends string, T extends string | number> = {
64
+ loading: boolean;
65
+ refresh: () => void;
66
+ } & {
67
+ [P in `${K}Options`]: (SelectOption<T> & Record<string, any>)[];
68
+ } & {
69
+ [P in `${K}Map`]: MapData<T>;
70
+ };
71
+
72
+ declare interface SuccessFn {
73
+ (data: Record<string, any>): void;
74
+ }
75
+
34
76
  declare interface TableListResult<T> {
35
77
  /** 查询参数 */
36
78
  queryParams: QueryParamsData;
@@ -77,6 +119,10 @@ export declare function useCreateModal<T extends readonly string[]>(suffixes: T)
77
119
  close: (type: T[number]) => void;
78
120
  };
79
121
 
122
+ export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn): FormSubmitResult;
123
+
124
+ export declare function useSelectOptions<K extends string = string, T extends string | number = string | number>(getRequestFn: (params: Record<string, any>) => Promise<any>, selectConfig: SelectConfig<K>): SelectOptionsResult<K, T>;
125
+
80
126
  export declare function useTableList<T>(getRequestFn: (data: QueryParamsData) => Promise<TableResponse<T>>, initParams?: Record<string, any>): TableListResult<T>;
81
127
 
82
128
  export { }
@@ -1,200 +1,245 @@
1
- import { useState as z, useRef as I, useMemo as j, useCallback as S, useEffect as J, useId as W } from "react";
2
- import { Empty as q } from "antd";
3
- import { create as X } from "zustand";
4
- var T = { exports: {} }, E = {};
5
- var A;
6
- function K() {
7
- if (A) return E;
8
- A = 1;
9
- var l = /* @__PURE__ */ Symbol.for("react.transitional.element"), i = /* @__PURE__ */ Symbol.for("react.fragment");
10
- function s(r, o, a) {
11
- var p = null;
12
- if (a !== void 0 && (p = "" + a), o.key !== void 0 && (p = "" + o.key), "key" in o) {
13
- a = {};
14
- for (var c in o)
15
- c !== "key" && (a[c] = o[c]);
16
- } else a = o;
17
- return o = a.ref, {
18
- $$typeof: l,
19
- type: r,
20
- key: p,
21
- ref: o !== void 0 ? o : null,
22
- props: a
1
+ import { useState as M, useRef as J, useMemo as j, useCallback as m, useEffect as C, useId as W } from "react";
2
+ import { Empty as q, App as X } from "antd";
3
+ import { create as K } from "zustand";
4
+ var k = { exports: {} }, x = {};
5
+ var D;
6
+ function ee() {
7
+ if (D) return x;
8
+ D = 1;
9
+ var i = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
10
+ function a(e, s, n) {
11
+ var d = null;
12
+ if (n !== void 0 && (d = "" + n), s.key !== void 0 && (d = "" + s.key), "key" in s) {
13
+ n = {};
14
+ for (var l in s)
15
+ l !== "key" && (n[l] = s[l]);
16
+ } else n = s;
17
+ return s = n.ref, {
18
+ $$typeof: i,
19
+ type: e,
20
+ key: d,
21
+ ref: s !== void 0 ? s : null,
22
+ props: n
23
23
  };
24
24
  }
25
- return E.Fragment = i, E.jsx = s, E.jsxs = s, E;
25
+ return x.Fragment = r, x.jsx = a, x.jsxs = a, x;
26
26
  }
27
- var F;
28
- function ee() {
29
- return F || (F = 1, T.exports = K()), T.exports;
27
+ var I;
28
+ function te() {
29
+ return I || (I = 1, k.exports = ee()), k.exports;
30
30
  }
31
- var te = ee();
32
- const v = {
31
+ var oe = te();
32
+ const b = {
33
33
  sortField: ["orderType", "orderField"],
34
34
  sortOrder: ["ASC", "DESC"],
35
35
  pageSize: 15
36
36
  };
37
- function se(l) {
38
- Object.keys(l).forEach((i) => {
39
- v[i] = l[i];
37
+ function ie(i) {
38
+ Object.keys(i).forEach((r) => {
39
+ b[r] = i[r];
40
40
  });
41
41
  }
42
- function ne(l, i = {}) {
43
- const { rowSelection: s, ...r } = i, o = v.pageSize, [a, p] = z({
42
+ function le(i, r = {}) {
43
+ const { rowSelection: a, ...e } = r, s = b.pageSize, [n, d] = M({
44
44
  pagination: {
45
45
  showSizeChanger: !0,
46
46
  showQuickJumper: !0,
47
47
  total: 0,
48
- pageSize: o,
48
+ pageSize: s,
49
49
  current: 1
50
50
  },
51
51
  list: [],
52
52
  queryParams: {
53
53
  pageNo: 1,
54
- pageSize: o,
55
- ...r
54
+ pageSize: s,
55
+ ...e
56
56
  }
57
- }), { pagination: c, list: e, queryParams: t } = a, { pageNo: g, pageSize: u } = t, [f, h] = z(!0), L = I(t), [x, P] = z([]), k = j(() => {
58
- if (s)
57
+ }), { pagination: l, list: o, queryParams: t } = n, { pageNo: p, pageSize: u } = t, [f, R] = M(!0), $ = J(t), [y, h] = M([]), E = j(() => {
58
+ if (a)
59
59
  return {
60
- selectedRowKeys: x,
61
- onChange: (n) => P(n)
60
+ selectedRowKeys: y,
61
+ onChange: (c) => h(c)
62
62
  };
63
- }, [s, x]), C = S(
64
- (n) => `共 ${n} 条记录 第 ${g}/${Math.ceil(n / u)} 页 `,
65
- [g, u]
66
- ), d = S(
67
- async (n) => {
68
- const { pageNo: b } = n;
69
- h(!0);
70
- const m = { ...r, pageSize: u, ...n };
71
- n.pageNo === void 0 && (m.pageNo = 1), n.pageSize === void 0 && (m.pageSize = u);
72
- const { data: R } = await l(m), { list: y = [], totalCount: $ = 0 } = R || {};
73
- s && P([]), p({
74
- list: y,
75
- queryParams: m,
63
+ }, [a, y]), v = m(
64
+ (c) => `共 ${c} 条记录 第 ${p}/${Math.ceil(c / u)} 页 `,
65
+ [p, u]
66
+ ), g = m(
67
+ async (c) => {
68
+ const { pageNo: _ } = c;
69
+ R(!0);
70
+ const S = { ...e, pageSize: u, ...c };
71
+ c.pageNo === void 0 && (S.pageNo = 1), c.pageSize === void 0 && (S.pageSize = u);
72
+ const { data: z } = await i(S), { list: w = [], totalCount: P = 0 } = z || {};
73
+ a && h([]), d({
74
+ list: w,
75
+ queryParams: S,
76
76
  pagination: {
77
- ...c,
78
- current: b,
79
- pageSize: m.pageSize,
80
- total: $
77
+ ...l,
78
+ current: _,
79
+ pageSize: S.pageSize,
80
+ total: P
81
81
  }
82
- }), h(!1);
82
+ }), R(!1);
83
83
  },
84
- [t, r, s, u, l, c]
85
- ), N = S(
86
- (n) => {
87
- d({ ...t, ...n, pageNo: 1 });
84
+ [t, e, a, u, i, l]
85
+ ), L = m(
86
+ (c) => {
87
+ g({ ...t, ...c, pageNo: 1 });
88
88
  },
89
- [d, t]
90
- ), D = S(
91
- (n) => {
92
- d({ ...t, ...n });
89
+ [g, t]
90
+ ), O = m(
91
+ (c) => {
92
+ g({ ...t, ...c });
93
93
  },
94
- [d, t]
95
- ), O = S(
96
- (n) => {
97
- d({ ...n, pageSize: u, pageNo: 1 });
94
+ [g, t]
95
+ ), F = m(
96
+ (c) => {
97
+ g({ ...c, pageSize: u, pageNo: 1 });
98
98
  },
99
- [d, u]
100
- ), _ = S(
101
- (n, b, m, R) => {
102
- const { action: y } = R;
103
- if (["paginate", "sort"].includes(y)) {
104
- const { current: $, pageSize: V } = n, { field: Q, order: w } = m, [Y, Z] = v.sortField, [B, H] = v.sortOrder, U = {
99
+ [g, u]
100
+ ), N = m(
101
+ (c, _, S, z) => {
102
+ const { action: w } = z;
103
+ if (["paginate", "sort"].includes(w)) {
104
+ const { current: P, pageSize: V } = c, { field: Q, order: A } = S, [Y, Z] = b.sortField, [B, H] = b.sortOrder, U = {
105
105
  ...t,
106
- [Y]: w ? w === "ascend" ? B : H : void 0,
106
+ [Y]: A ? A === "ascend" ? B : H : void 0,
107
107
  [Z]: Q,
108
- pageNo: $,
108
+ pageNo: P,
109
109
  pageSize: V
110
110
  };
111
- d(U);
111
+ g(U);
112
112
  }
113
113
  },
114
- [t, d]
114
+ [t, g]
115
115
  ), G = j(() => ({
116
116
  bordered: !0,
117
117
  size: "middle",
118
118
  sticky: !0,
119
- rowSelection: k,
120
- pagination: { ...c, showTotal: C },
119
+ rowSelection: E,
120
+ pagination: { ...l, showTotal: v },
121
121
  loading: f,
122
- dataSource: e,
123
- onChange: _,
122
+ dataSource: o,
123
+ onChange: N,
124
124
  locale: {
125
- emptyText: f ? "" : /* @__PURE__ */ te.jsx(q, { image: q.PRESENTED_IMAGE_SIMPLE })
125
+ emptyText: f ? "" : /* @__PURE__ */ oe.jsx(q, { image: q.PRESENTED_IMAGE_SIMPLE })
126
126
  }
127
- }), [k, c, C, f, e, _]);
128
- return J(() => {
129
- N(L.current);
127
+ }), [E, l, v, f, o, N]);
128
+ return C(() => {
129
+ L($.current);
130
130
  }, []), {
131
131
  queryParams: t,
132
- reload: N,
133
- refresh: D,
134
- reset: O,
135
- selectedRowKeys: x,
132
+ reload: L,
133
+ refresh: O,
134
+ reset: F,
135
+ selectedRowKeys: y,
136
136
  tableProps: G
137
137
  };
138
138
  }
139
- const M = X((l) => ({
139
+ const T = K((i) => ({
140
140
  modals: {},
141
- toggleModal: (i, s) => l((r) => {
142
- const a = r.modals[i]?.visible || !1;
141
+ toggleModal: (r, a) => i((e) => {
142
+ const n = e.modals[r]?.visible || !1;
143
143
  return {
144
144
  modals: {
145
- ...r.modals,
146
- [i]: {
147
- visible: !a,
148
- data: a ? {} : s || {}
145
+ ...e.modals,
146
+ [r]: {
147
+ visible: !n,
148
+ data: n ? {} : a || {}
149
149
  }
150
150
  }
151
151
  };
152
152
  }),
153
- setModal: (i, s, r) => l((o) => ({
153
+ setModal: (r, a, e) => i((s) => ({
154
154
  modals: {
155
- ...o.modals,
156
- [i]: {
157
- visible: s,
158
- data: s ? r || {} : {}
155
+ ...s.modals,
156
+ [r]: {
157
+ visible: a,
158
+ data: a ? e || {} : {}
159
159
  }
160
160
  }
161
161
  })),
162
- clearModals: (i) => l((s) => {
163
- const r = { ...s.modals };
164
- return i.forEach((o) => {
165
- delete r[o];
166
- }), { modals: r };
162
+ clearModals: (r) => i((a) => {
163
+ const e = { ...a.modals };
164
+ return r.forEach((s) => {
165
+ delete e[s];
166
+ }), { modals: e };
167
167
  })
168
168
  }));
169
- function ie(l) {
170
- const i = M((e) => e.modals), s = M((e) => e.toggleModal), r = M((e) => e.setModal), o = M((e) => e.clearModals), a = W(), p = I(l.map((e) => `${a}-${e}`));
171
- J(() => () => {
172
- o(p.current);
169
+ function ce(i) {
170
+ const r = T((o) => o.modals), a = T((o) => o.toggleModal), e = T((o) => o.setModal), s = T((o) => o.clearModals), n = W(), d = J(i.map((o) => `${n}-${o}`));
171
+ C(() => () => {
172
+ s(d.current);
173
173
  }, []);
174
- const c = {};
175
- for (const e of l) {
176
- const t = `${a}-${e}`, u = i[t] ?? { visible: !1, data: {} };
177
- c[`${e}Modal`] = {
174
+ const l = {};
175
+ for (const o of i) {
176
+ const t = `${n}-${o}`, u = r[t] ?? { visible: !1, data: {} };
177
+ l[`${o}Modal`] = {
178
178
  visible: u.visible,
179
179
  data: u.data,
180
- toggle: (f) => s(t, f),
181
- open: (f) => r(t, !0, f),
182
- close: () => r(t, !1)
180
+ toggle: (f) => a(t, f),
181
+ open: (f) => e(t, !0, f),
182
+ close: () => e(t, !1)
183
183
  };
184
184
  }
185
- return c.toggle = (e, t) => {
186
- const g = `${a}-${e}`;
187
- s(g, t);
188
- }, c.open = (e, t) => {
189
- const g = `${a}-${e}`;
190
- r(g, !0, t);
191
- }, c.close = (e) => {
192
- const t = `${a}-${e}`;
193
- r(t, !1);
194
- }, c;
185
+ return l.toggle = (o, t) => {
186
+ const p = `${n}-${o}`;
187
+ a(p, t);
188
+ }, l.open = (o, t) => {
189
+ const p = `${n}-${o}`;
190
+ e(p, !0, t);
191
+ }, l.close = (o) => {
192
+ const t = `${n}-${o}`;
193
+ e(t, !1);
194
+ }, l;
195
+ }
196
+ const se = (i, r = "value", a = "label") => new Map(i.map((e) => [e[r], e[a]]));
197
+ function ue(i, r) {
198
+ const [a, e] = M([]), [s, n] = M(/* @__PURE__ */ new Map()), [d, l] = M(!0), { params: o, selectKey: t, fieldNames: p } = r, u = async () => {
199
+ l(!0);
200
+ const { data: R } = await i(o), $ = R || [];
201
+ if (p) {
202
+ const { label: y, value: h } = p, E = $.map((v) => ({
203
+ data: v,
204
+ label: v[y],
205
+ value: v[h]
206
+ }));
207
+ e(E), n(se(E));
208
+ } else
209
+ e($);
210
+ l(!1);
211
+ }, f = m(() => {
212
+ u();
213
+ }, [u]);
214
+ return C(() => {
215
+ f();
216
+ }, []), {
217
+ loading: d,
218
+ refresh: f,
219
+ [`${t}Options`]: a,
220
+ [`${t}Map`]: s
221
+ };
222
+ }
223
+ function de(i, r) {
224
+ const [a, e] = M(!1), { message: s } = X.useApp(), n = m(async (d) => {
225
+ try {
226
+ const l = await i(d);
227
+ e(!0);
228
+ const { status: o, info: t } = l;
229
+ o == "success" && (r(l), s.success(t));
230
+ } catch {
231
+ }
232
+ e(!1);
233
+ }, [i, r, s]);
234
+ return {
235
+ loading: a,
236
+ submit: n
237
+ };
195
238
  }
196
239
  export {
197
- se as configureTableOption,
198
- ie as useCreateModal,
199
- ne as useTableList
240
+ ie as configureTableOption,
241
+ ce as useCreateModal,
242
+ de as useFormSubmit,
243
+ ue as useSelectOptions,
244
+ le as useTableList
200
245
  };
@@ -1 +1 @@
1
- (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react"),require("antd"),require("zustand")):typeof define=="function"&&define.amd?define(["exports","react","antd","zustand"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.DesignReact={},c.React,c.antd,c.zustand))})(this,(function(c,o,z,A){"use strict";var v={exports:{}},E={};var b;function F(){if(b)return E;b=1;var u=Symbol.for("react.transitional.element"),l=Symbol.for("react.fragment");function r(a,s,n){var g=null;if(n!==void 0&&(g=""+n),s.key!==void 0&&(g=""+s.key),"key"in s){n={};for(var d in s)d!=="key"&&(n[d]=s[d])}else n=s;return s=n.ref,{$$typeof:u,type:a,key:g,ref:s!==void 0?s:null,props:n}}return E.Fragment=l,E.jsx=r,E.jsxs=r,E}var h;function I(){return h||(h=1,v.exports=F()),v.exports}var J=I();const y={sortField:["orderType","orderField"],sortOrder:["ASC","DESC"],pageSize:15};function O(u){Object.keys(u).forEach(l=>{y[l]=u[l]})}function D(u,l={}){const{rowSelection:r,...a}=l,s=y.pageSize,[n,g]=o.useState({pagination:{showSizeChanger:!0,showQuickJumper:!0,total:0,pageSize:s,current:1},list:[],queryParams:{pageNo:1,pageSize:s,...a}}),{pagination:d,list:e,queryParams:t}=n,{pageNo:S,pageSize:p}=t,[m,$]=o.useState(!0),V=o.useRef(t),[T,P]=o.useState([]),N=o.useMemo(()=>{if(r)return{selectedRowKeys:T,onChange:i=>P(i)}},[r,T]),_=o.useCallback(i=>`共 ${i} 条记录 第 ${S}/${Math.ceil(i/p)} 页 `,[S,p]),f=o.useCallback(async i=>{const{pageNo:j}=i;$(!0);const M={...a,pageSize:p,...i};i.pageNo===void 0&&(M.pageNo=1),i.pageSize===void 0&&(M.pageSize=p);const{data:C}=await u(M),{list:k=[],totalCount:x=0}=C||{};r&&P([]),g({list:k,queryParams:M,pagination:{...d,current:j,pageSize:M.pageSize,total:x}}),$(!1)},[t,a,r,p,u,d]),q=o.useCallback(i=>{f({...t,...i,pageNo:1})},[f,t]),Q=o.useCallback(i=>{f({...t,...i})},[f,t]),Y=o.useCallback(i=>{f({...i,pageSize:p,pageNo:1})},[f,p]),w=o.useCallback((i,j,M,C)=>{const{action:k}=C;if(["paginate","sort"].includes(k)){const{current:x,pageSize:B}=i,{field:H,order:L}=M,[U,W]=y.sortField,[X,K]=y.sortOrder,ee={...t,[U]:L?L==="ascend"?X:K:void 0,[W]:H,pageNo:x,pageSize:B};f(ee)}},[t,f]),Z=o.useMemo(()=>({bordered:!0,size:"middle",sticky:!0,rowSelection:N,pagination:{...d,showTotal:_},loading:m,dataSource:e,onChange:w,locale:{emptyText:m?"":J.jsx(z.Empty,{image:z.Empty.PRESENTED_IMAGE_SIMPLE})}}),[N,d,_,m,e,w]);return o.useEffect(()=>{q(V.current)},[]),{queryParams:t,reload:q,refresh:Q,reset:Y,selectedRowKeys:T,tableProps:Z}}const R=A.create(u=>({modals:{},toggleModal:(l,r)=>u(a=>{const n=a.modals[l]?.visible||!1;return{modals:{...a.modals,[l]:{visible:!n,data:n?{}:r||{}}}}}),setModal:(l,r,a)=>u(s=>({modals:{...s.modals,[l]:{visible:r,data:r?a||{}:{}}}})),clearModals:l=>u(r=>{const a={...r.modals};return l.forEach(s=>{delete a[s]}),{modals:a}})}));function G(u){const l=R(e=>e.modals),r=R(e=>e.toggleModal),a=R(e=>e.setModal),s=R(e=>e.clearModals),n=o.useId(),g=o.useRef(u.map(e=>`${n}-${e}`));o.useEffect(()=>()=>{s(g.current)},[]);const d={};for(const e of u){const t=`${n}-${e}`,p=l[t]??{visible:!1,data:{}};d[`${e}Modal`]={visible:p.visible,data:p.data,toggle:m=>r(t,m),open:m=>a(t,!0,m),close:()=>a(t,!1)}}return d.toggle=(e,t)=>{const S=`${n}-${e}`;r(S,t)},d.open=(e,t)=>{const S=`${n}-${e}`;a(S,!0,t)},d.close=e=>{const t=`${n}-${e}`;a(t,!1)},d}c.configureTableOption=O,c.useCreateModal=G,c.useTableList=D,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(d,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("antd"),require("zustand")):typeof define=="function"&&define.amd?define(["exports","react","antd","zustand"],e):(d=typeof globalThis<"u"?globalThis:d||self,e(d.DesignReact={},d.React,d.antd,d.zustand))})(this,(function(d,e,z,O){"use strict";var $={exports:{}},b={};var L;function D(){if(L)return b;L=1;var l=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(t,a,i){var f=null;if(i!==void 0&&(f=""+i),a.key!==void 0&&(f=""+a.key),"key"in a){i={};for(var u in a)u!=="key"&&(i[u]=a[u])}else i=a;return a=i.ref,{$$typeof:l,type:t,key:f,ref:a!==void 0?a:null,props:i}}return b.Fragment=r,b.jsx=n,b.jsxs=n,b}var N;function F(){return N||(N=1,$.exports=D()),$.exports}var I=F();const C={sortField:["orderType","orderField"],sortOrder:["ASC","DESC"],pageSize:15};function J(l){Object.keys(l).forEach(r=>{C[r]=l[r]})}function G(l,r={}){const{rowSelection:n,...t}=r,a=C.pageSize,[i,f]=e.useState({pagination:{showSizeChanger:!0,showQuickJumper:!0,total:0,pageSize:a,current:1},list:[],queryParams:{pageNo:1,pageSize:a,...t}}),{pagination:u,list:o,queryParams:s}=i,{pageNo:g,pageSize:p}=s,[S,T]=e.useState(!0),h=e.useRef(s),[E,k]=e.useState([]),v=e.useMemo(()=>{if(n)return{selectedRowKeys:E,onChange:c=>k(c)}},[n,E]),y=e.useCallback(c=>`共 ${c} 条记录 第 ${g}/${Math.ceil(c/p)} 页 `,[g,p]),m=e.useCallback(async c=>{const{pageNo:q}=c;T(!0);const M={...t,pageSize:p,...c};c.pageNo===void 0&&(M.pageNo=1),c.pageSize===void 0&&(M.pageSize=p);const{data:x}=await l(M),{list:P=[],totalCount:w=0}=x||{};n&&k([]),f({list:P,queryParams:M,pagination:{...u,current:q,pageSize:M.pageSize,total:w}}),T(!1)},[s,t,n,p,l,u]),_=e.useCallback(c=>{m({...s,...c,pageNo:1})},[m,s]),B=e.useCallback(c=>{m({...s,...c})},[m,s]),H=e.useCallback(c=>{m({...c,pageSize:p,pageNo:1})},[m,p]),j=e.useCallback((c,q,M,x)=>{const{action:P}=x;if(["paginate","sort"].includes(P)){const{current:w,pageSize:W}=c,{field:X,order:A}=M,[K,ee]=C.sortField,[te,se]=C.sortOrder,oe={...s,[K]:A?A==="ascend"?te:se:void 0,[ee]:X,pageNo:w,pageSize:W};m(oe)}},[s,m]),U=e.useMemo(()=>({bordered:!0,size:"middle",sticky:!0,rowSelection:v,pagination:{...u,showTotal:y},loading:S,dataSource:o,onChange:j,locale:{emptyText:S?"":I.jsx(z.Empty,{image:z.Empty.PRESENTED_IMAGE_SIMPLE})}}),[v,u,y,S,o,j]);return e.useEffect(()=>{_(h.current)},[]),{queryParams:s,reload:_,refresh:B,reset:H,selectedRowKeys:E,tableProps:U}}const R=O.create(l=>({modals:{},toggleModal:(r,n)=>l(t=>{const i=t.modals[r]?.visible||!1;return{modals:{...t.modals,[r]:{visible:!i,data:i?{}:n||{}}}}}),setModal:(r,n,t)=>l(a=>({modals:{...a.modals,[r]:{visible:n,data:n?t||{}:{}}}})),clearModals:r=>l(n=>{const t={...n.modals};return r.forEach(a=>{delete t[a]}),{modals:t}})}));function V(l){const r=R(o=>o.modals),n=R(o=>o.toggleModal),t=R(o=>o.setModal),a=R(o=>o.clearModals),i=e.useId(),f=e.useRef(l.map(o=>`${i}-${o}`));e.useEffect(()=>()=>{a(f.current)},[]);const u={};for(const o of l){const s=`${i}-${o}`,p=r[s]??{visible:!1,data:{}};u[`${o}Modal`]={visible:p.visible,data:p.data,toggle:S=>n(s,S),open:S=>t(s,!0,S),close:()=>t(s,!1)}}return u.toggle=(o,s)=>{const g=`${i}-${o}`;n(g,s)},u.open=(o,s)=>{const g=`${i}-${o}`;t(g,!0,s)},u.close=o=>{const s=`${i}-${o}`;t(s,!1)},u}const Q=(l,r="value",n="label")=>new Map(l.map(t=>[t[r],t[n]]));function Y(l,r){const[n,t]=e.useState([]),[a,i]=e.useState(new Map),[f,u]=e.useState(!0),{params:o,selectKey:s,fieldNames:g}=r,p=async()=>{u(!0);const{data:T}=await l(o),h=T||[];if(g){const{label:E,value:k}=g,v=h.map(y=>({data:y,label:y[E],value:y[k]}));t(v),i(Q(v))}else t(h);u(!1)},S=e.useCallback(()=>{p()},[p]);return e.useEffect(()=>{S()},[]),{loading:f,refresh:S,[`${s}Options`]:n,[`${s}Map`]:a}}function Z(l,r){const[n,t]=e.useState(!1),{message:a}=z.App.useApp(),i=e.useCallback(async f=>{try{const u=await l(f);t(!0);const{status:o,info:s}=u;o=="success"&&(r(u),a.success(s))}catch{}t(!1)},[l,r,a]);return{loading:n,submit:i}}d.configureTableOption=J,d.useCreateModal=V,d.useFormSubmit=Z,d.useSelectOptions=Y,d.useTableList=G,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@base-stone/hooks",
3
3
  "license": "MIT",
4
- "version": "0.7.5",
4
+ "version": "0.7.6",
5
5
  "author": {
6
6
  "name": "yeliang",
7
7
  "email": "leafront@126.com"