@base-stone/hooks 0.7.6 → 0.7.8
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.
|
@@ -113,16 +113,16 @@ declare interface TableResponse<T> {
|
|
|
113
113
|
* @param suffixes 模态框后缀数组
|
|
114
114
|
* @returns 包含所有模态框实例的对象,以及统一的 toggle/open/close 函数
|
|
115
115
|
*/
|
|
116
|
-
export declare function useCreateModal<T extends readonly string[]>(suffixes: T): Record<`${T[number]}Modal`, ModalInstance> & {
|
|
117
|
-
toggle: (type:
|
|
118
|
-
open: (type:
|
|
119
|
-
close: (type:
|
|
116
|
+
export declare function useCreateModal<const T extends readonly string[] = readonly string[]>(suffixes: T): Record<`${T[number]}Modal`, ModalInstance> & {
|
|
117
|
+
toggle: (type: string, data?: any) => void;
|
|
118
|
+
open: (type: string, data?: any) => void;
|
|
119
|
+
close: (type: string) => void;
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn): FormSubmitResult;
|
|
123
123
|
|
|
124
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
125
|
|
|
126
|
-
export declare function useTableList<T>(getRequestFn: (data: QueryParamsData) => Promise<TableResponse<T>>, initParams?: Record<string, any>): TableListResult<T>;
|
|
126
|
+
export declare function useTableList<T extends Record<string, any> = Record<string, any>>(getRequestFn: (data: QueryParamsData) => Promise<TableResponse<T>>, initParams?: Record<string, any>): TableListResult<T>;
|
|
127
127
|
|
|
128
128
|
export { }
|
|
@@ -1 +1 @@
|
|
|
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:
|
|
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:10};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"})}));
|