import { useState, useEffect } from 'react'; import { useRequest, useHistory } from '@sensoro/core'; import { Table } from '@sensoro/sensoro-design'; import { isString } from 'lodash'; import useQuery from '../../../hooks/use-query'; import model from './use-list'; export function useDeviceService({ initQuery, config, }: { initQuery: { category?: string; domain: string; }; config: { detailUrl: | string | ((params: { sn: string; [key: string]: any }) => string); }; }) { const history = useHistory(); const { allIds, total, onValuesChange, onRefresh, loading } = useQuery( initQuery, 1, model, ); const table = Table.useTable(total, {}); useEffect(() => { onRefresh(); }, []); useEffect(() => { onValuesChange(table.queryData as any); }, [table.queryData]); const handleToDetail = (id: string, sn: string) => { // history.push( // `/console/device-center/device-system/smart-enter/detail/${id}?sn=${sn}`, // ); history.push( isString(config?.detailUrl) ? config?.detailUrl : config?.detailUrl({ sn, id }), ); }; return { table, allIds, loading, handleToDetail, }; }