import React from 'react'; import { map } from 'lodash'; import { Badge } from 'antd'; import classNames from '@pansy/classnames'; import SensorIcon from '@sensoro/library/lib/components/sensor-icon'; import { useDeviceDictionary, useDictionary } from '@sensoro/core'; import { getTextByList } from '../../../utils'; import { Table, Tag, Empty } from '@sensoro/sensoro-design'; import { useDeviceService } from '../hooks/useDeviceService'; import { DEVICE_STATUS, DEVICE_NETWORK_STATUS } from '../config'; export interface DeviceListProps { className?: string; initQuery: { category?: string; domain: string; }; config: { detailUrl: | string | ((params: { id?: number | string; sn: string; [key: string]: any; }) => string); }; } const DeviceList: React.FC = props => { const { initQuery, config, className } = props; const deviceService = useDeviceService({ initQuery, config }); const { getModelByType } = useDeviceDictionary(); const { getDeviceInfoByIds } = useDictionary(); const categorys = getDeviceInfoByIds(['WATER_QUALITY']); const types = categorys?.[0]?.types; const columns = [ { title: '设备编号', dataIndex: 'sn', key: 'sn', width: 180, fixed: 'left', render: (sn: string, record: any) => ( { deviceService.handleToDetail(record.id, record.sn); }} > {sn} ), }, { title: '设备名称', dataIndex: 'name', key: 'name', width: 200, render: (_, record: any) => { return record?.deployment?.name; }, }, { title: '设备类型', dataIndex: 'category', key: 'category', width: 100, render: (text: string) => , filters: map(categorys, i => { return { text: i.name, value: i.category, }; }), }, { title: '设备型号', dataIndex: 'type', key: 'type', width: 100, render: (text: string) => { return getModelByType(text); }, filters: map(types, i => { return { text: getModelByType(i), value: i, }; }), }, { title: '设备状态', dataIndex: 'status', key: 'status', width: 100, render: (status: boolean) => ( ), filters: DEVICE_STATUS.map(i => ({ text: i.label, value: i.value, })), }, { title: '网络状态', dataIndex: 'networkStatus', key: 'networkStatus', width: 100, render: (status: string) => ( ), filterMultiple: false, filters: [ { text: '在线', value: true }, { text: '离线', value: false }, ], }, { title: '操作', dataIndex: 'option', key: 'option', option: true, width: 80, fixed: 'right', render: (text: string, record: any) => ( { deviceService.handleToDetail(record.id, record.sn); }} > 详情 ), }, ]; return ( ), }} searchProps={{ placeholder: '请输入设备名称/设备编号查询', style: { width: 280 }, }} table={deviceService.table} /> ); }; export default DeviceList;