@base-stone/hooks 0.7.4 → 0.7.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.
|
@@ -15,6 +15,14 @@ declare interface GlobalTableConfig {
|
|
|
15
15
|
pageSize: number;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
declare type ModalInstance<T = any> = {
|
|
19
|
+
visible: boolean;
|
|
20
|
+
data: T;
|
|
21
|
+
toggle: (data?: T) => void;
|
|
22
|
+
open: (data?: T) => void;
|
|
23
|
+
close: () => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
18
26
|
export declare interface QueryParamsData {
|
|
19
27
|
pageNo: number;
|
|
20
28
|
pageSize: number;
|
|
@@ -58,6 +66,17 @@ declare interface TableResponse<T> {
|
|
|
58
66
|
};
|
|
59
67
|
}
|
|
60
68
|
|
|
69
|
+
/**
|
|
70
|
+
* 批量创建多个模态框 hook
|
|
71
|
+
* @param suffixes 模态框后缀数组
|
|
72
|
+
* @returns 包含所有模态框实例的对象,以及统一的 toggle/open/close 函数
|
|
73
|
+
*/
|
|
74
|
+
export declare function useCreateModal<T extends readonly string[]>(suffixes: T): Record<`${T[number]}Modal`, ModalInstance> & {
|
|
75
|
+
toggle: (type: T[number], data?: any) => void;
|
|
76
|
+
open: (type: T[number], data?: any) => void;
|
|
77
|
+
close: (type: T[number]) => void;
|
|
78
|
+
};
|
|
79
|
+
|
|
61
80
|
export declare function useTableList<T>(getRequestFn: (data: QueryParamsData) => Promise<TableResponse<T>>, initParams?: Record<string, any>): TableListResult<T>;
|
|
62
81
|
|
|
63
82
|
export { }
|
|
@@ -1,141 +1,200 @@
|
|
|
1
|
-
import { useState as z, useRef as
|
|
2
|
-
import { Empty as
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
return
|
|
25
|
+
return E.Fragment = i, E.jsx = s, E.jsxs = s, E;
|
|
25
26
|
}
|
|
26
|
-
var
|
|
27
|
-
function
|
|
28
|
-
return
|
|
27
|
+
var F;
|
|
28
|
+
function ee() {
|
|
29
|
+
return F || (F = 1, T.exports = K()), T.exports;
|
|
29
30
|
}
|
|
30
|
-
var
|
|
31
|
-
const
|
|
31
|
+
var te = ee();
|
|
32
|
+
const v = {
|
|
32
33
|
sortField: ["orderType", "orderField"],
|
|
33
34
|
sortOrder: ["ASC", "DESC"],
|
|
34
35
|
pageSize: 15
|
|
35
36
|
};
|
|
36
|
-
function
|
|
37
|
-
Object.keys(
|
|
38
|
-
|
|
37
|
+
function se(l) {
|
|
38
|
+
Object.keys(l).forEach((i) => {
|
|
39
|
+
v[i] = l[i];
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
|
-
function
|
|
42
|
-
const { rowSelection:
|
|
42
|
+
function ne(l, i = {}) {
|
|
43
|
+
const { rowSelection: s, ...r } = i, o = v.pageSize, [a, p] = z({
|
|
43
44
|
pagination: {
|
|
44
45
|
showSizeChanger: !0,
|
|
45
46
|
showQuickJumper: !0,
|
|
46
47
|
total: 0,
|
|
47
|
-
pageSize:
|
|
48
|
+
pageSize: o,
|
|
48
49
|
current: 1
|
|
49
50
|
},
|
|
50
51
|
list: [],
|
|
51
52
|
queryParams: {
|
|
52
53
|
pageNo: 1,
|
|
53
|
-
pageSize:
|
|
54
|
-
...
|
|
54
|
+
pageSize: o,
|
|
55
|
+
...r
|
|
55
56
|
}
|
|
56
|
-
}), { pagination:
|
|
57
|
-
if (
|
|
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)
|
|
58
59
|
return {
|
|
59
|
-
selectedRowKeys:
|
|
60
|
-
onChange: (
|
|
60
|
+
selectedRowKeys: x,
|
|
61
|
+
onChange: (n) => P(n)
|
|
61
62
|
};
|
|
62
|
-
}, [
|
|
63
|
-
(
|
|
64
|
-
[
|
|
65
|
-
),
|
|
66
|
-
async (
|
|
67
|
-
const { pageNo:
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const { data:
|
|
72
|
-
|
|
73
|
-
list:
|
|
74
|
-
queryParams:
|
|
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,
|
|
75
76
|
pagination: {
|
|
76
|
-
...
|
|
77
|
-
current:
|
|
78
|
-
pageSize:
|
|
79
|
-
total:
|
|
77
|
+
...c,
|
|
78
|
+
current: b,
|
|
79
|
+
pageSize: m.pageSize,
|
|
80
|
+
total: $
|
|
80
81
|
}
|
|
81
|
-
}),
|
|
82
|
+
}), h(!1);
|
|
82
83
|
},
|
|
83
|
-
[
|
|
84
|
-
),
|
|
85
|
-
(
|
|
86
|
-
|
|
84
|
+
[t, r, s, u, l, c]
|
|
85
|
+
), N = S(
|
|
86
|
+
(n) => {
|
|
87
|
+
d({ ...t, ...n, pageNo: 1 });
|
|
87
88
|
},
|
|
88
|
-
[
|
|
89
|
-
),
|
|
90
|
-
(
|
|
91
|
-
|
|
89
|
+
[d, t]
|
|
90
|
+
), D = S(
|
|
91
|
+
(n) => {
|
|
92
|
+
d({ ...t, ...n });
|
|
92
93
|
},
|
|
93
|
-
[
|
|
94
|
-
),
|
|
95
|
-
(
|
|
96
|
-
|
|
94
|
+
[d, t]
|
|
95
|
+
), O = S(
|
|
96
|
+
(n) => {
|
|
97
|
+
d({ ...n, pageSize: u, pageNo: 1 });
|
|
97
98
|
},
|
|
98
|
-
[
|
|
99
|
-
),
|
|
100
|
-
(
|
|
101
|
-
const { action:
|
|
102
|
-
if (["paginate", "sort"].includes(
|
|
103
|
-
const { current:
|
|
104
|
-
...
|
|
105
|
-
[
|
|
106
|
-
[
|
|
107
|
-
pageNo:
|
|
108
|
-
pageSize:
|
|
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 = {
|
|
105
|
+
...t,
|
|
106
|
+
[Y]: w ? w === "ascend" ? B : H : void 0,
|
|
107
|
+
[Z]: Q,
|
|
108
|
+
pageNo: $,
|
|
109
|
+
pageSize: V
|
|
109
110
|
};
|
|
110
|
-
|
|
111
|
+
d(U);
|
|
111
112
|
}
|
|
112
113
|
},
|
|
113
|
-
[
|
|
114
|
-
),
|
|
114
|
+
[t, d]
|
|
115
|
+
), G = j(() => ({
|
|
115
116
|
bordered: !0,
|
|
116
117
|
size: "middle",
|
|
117
118
|
sticky: !0,
|
|
118
|
-
rowSelection:
|
|
119
|
-
pagination: { ...
|
|
120
|
-
loading:
|
|
121
|
-
dataSource:
|
|
122
|
-
onChange:
|
|
119
|
+
rowSelection: k,
|
|
120
|
+
pagination: { ...c, showTotal: C },
|
|
121
|
+
loading: f,
|
|
122
|
+
dataSource: e,
|
|
123
|
+
onChange: _,
|
|
123
124
|
locale: {
|
|
124
|
-
emptyText:
|
|
125
|
+
emptyText: f ? "" : /* @__PURE__ */ te.jsx(q, { image: q.PRESENTED_IMAGE_SIMPLE })
|
|
125
126
|
}
|
|
126
|
-
}), [
|
|
127
|
-
return
|
|
128
|
-
|
|
127
|
+
}), [k, c, C, f, e, _]);
|
|
128
|
+
return J(() => {
|
|
129
|
+
N(L.current);
|
|
129
130
|
}, []), {
|
|
130
|
-
queryParams:
|
|
131
|
-
reload:
|
|
132
|
-
refresh:
|
|
133
|
-
reset:
|
|
134
|
-
selectedRowKeys:
|
|
135
|
-
tableProps:
|
|
131
|
+
queryParams: t,
|
|
132
|
+
reload: N,
|
|
133
|
+
refresh: D,
|
|
134
|
+
reset: O,
|
|
135
|
+
selectedRowKeys: x,
|
|
136
|
+
tableProps: G
|
|
136
137
|
};
|
|
137
138
|
}
|
|
139
|
+
const M = X((l) => ({
|
|
140
|
+
modals: {},
|
|
141
|
+
toggleModal: (i, s) => l((r) => {
|
|
142
|
+
const a = r.modals[i]?.visible || !1;
|
|
143
|
+
return {
|
|
144
|
+
modals: {
|
|
145
|
+
...r.modals,
|
|
146
|
+
[i]: {
|
|
147
|
+
visible: !a,
|
|
148
|
+
data: a ? {} : s || {}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}),
|
|
153
|
+
setModal: (i, s, r) => l((o) => ({
|
|
154
|
+
modals: {
|
|
155
|
+
...o.modals,
|
|
156
|
+
[i]: {
|
|
157
|
+
visible: s,
|
|
158
|
+
data: s ? r || {} : {}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
})),
|
|
162
|
+
clearModals: (i) => l((s) => {
|
|
163
|
+
const r = { ...s.modals };
|
|
164
|
+
return i.forEach((o) => {
|
|
165
|
+
delete r[o];
|
|
166
|
+
}), { modals: r };
|
|
167
|
+
})
|
|
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);
|
|
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`] = {
|
|
178
|
+
visible: u.visible,
|
|
179
|
+
data: u.data,
|
|
180
|
+
toggle: (f) => s(t, f),
|
|
181
|
+
open: (f) => r(t, !0, f),
|
|
182
|
+
close: () => r(t, !1)
|
|
183
|
+
};
|
|
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;
|
|
195
|
+
}
|
|
138
196
|
export {
|
|
139
|
-
|
|
140
|
-
|
|
197
|
+
se as configureTableOption,
|
|
198
|
+
ie as useCreateModal,
|
|
199
|
+
ne as useTableList
|
|
141
200
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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"})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base-stone/hooks",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.5",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "yeliang",
|
|
7
7
|
"email": "leafront@126.com"
|
|
@@ -36,9 +36,10 @@
|
|
|
36
36
|
"lint:js": "npm run eslint && npm run prettier"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
+
"@eslint/js": "^9.39.2",
|
|
39
40
|
"@types/node": "^25.0.3",
|
|
40
41
|
"@types/react": "^19.2.7",
|
|
41
|
-
"@
|
|
42
|
+
"@vitejs/plugin-react-swc": "^4.2.2",
|
|
42
43
|
"classnames": "^2.5.1",
|
|
43
44
|
"eslint": "^9.39.2",
|
|
44
45
|
"eslint-plugin-prettier": "^5.5.4",
|
|
@@ -46,14 +47,14 @@
|
|
|
46
47
|
"eslint-plugin-react-refresh": "^0.4.26",
|
|
47
48
|
"prettier": "^3.7.4",
|
|
48
49
|
"rollup-plugin-shell": "^1.0.9",
|
|
49
|
-
"@vitejs/plugin-react-swc": "^4.2.2",
|
|
50
50
|
"typescript": "^5.9.3",
|
|
51
|
+
"typescript-eslint": "^8.50.0",
|
|
51
52
|
"vite": "^7.3.0",
|
|
52
|
-
"vite-plugin-dts": "^4.5.4"
|
|
53
|
-
"typescript-eslint": "^8.50.0"
|
|
53
|
+
"vite-plugin-dts": "^4.5.4"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"antd": "^6.1.1",
|
|
57
|
-
"react": "^19.2.3"
|
|
57
|
+
"react": "^19.2.3",
|
|
58
|
+
"zustand": "^5.0.9"
|
|
58
59
|
}
|
|
59
60
|
}
|