import { Button } from 'antd-mobile'; import React from 'react'; import { useState } from 'react'; export function useDataGrip( loadData: any, actions: Array, condition: string, ) { const [pageNo, setPageNo] = useState(2); const [list, setList] = useState({}); const [visible, setVisible] = useState(false); /** * 加载更多 */ const loadMore = async () => { await loadData(condition, pageNo); setPageNo((pageNo) => pageNo + 1); }; /** * * @param val 传入按钮数据展示 * @returns */ const getActions = (val: any): React.ReactNode[] => { if (actions) { if (actions.length === 1) { return [ <>, <>, , ]; } else if (actions.length === 2) { return [ <>,
actions[1]?.callBack(val, e)} key={actions[1].name} > {actions[1].name}
,
actions[0]?.callBack(val, e)} key={actions[0].name} > {actions[0].name}
, ]; } else if (actions.length === 3) { return [
actions[0]?.callBack(val, e)} key={actions[0].name} > {actions[0].name}
,
actions[1]?.callBack(val, e)} > {actions[1].name}
,
actions[2]?.callBack(val, e)} > {actions[2].name}
, ]; } else { return []; } } else { return []; } }; /** * * @param query 传入一个row数据展示详情 */ const showDetails = (query: any) => { setList(query); setVisible(true); }; return { list, visible, pageNo, setVisible, loadMore, getActions, showDetails, }; }