Commit 45b11bfc authored by 徐乐's avatar 徐乐

perf: 修改设备树组件支持台账字段过滤

parent bceea713
...@@ -12,3 +12,11 @@ export function getEquipmentInfo(data) { ...@@ -12,3 +12,11 @@ export function getEquipmentInfo(data) {
data, data,
}); });
} }
export function GetFieldValueFromTable(params) {
return request({
url: `/PandaWorkFlow/WorkFlow/AccountManage/GetFieldValueFromTable`,
method: REQUEST_METHOD_GET,
params: params,
});
}
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Input, Layout, Spin, Tree, ConfigProvider, Skeleton } from 'antd'; import { Input, Layout, Spin, Tree, ConfigProvider, Skeleton, Select } from 'antd';
// import { SearchOutlined } from '@ant-design/icons'; // import { SearchOutlined } from '@ant-design/icons';
import React, { useCallback, useEffect, useMemo, useRef, useState, useContext } from 'react'; import React, { useCallback, useEffect, useMemo, useRef, useState, useContext } from 'react';
import PandaEmpty from '@wisdom-components/empty'; import PandaEmpty from '@wisdom-components/empty';
import classNames from 'classnames'; import classNames from 'classnames';
import _ from 'lodash'; import _ from 'lodash';
import { getEquipmentInfo } from './apis'; import { getEquipmentInfo, GetFieldValueFromTable } from './apis';
import './index.less'; import './index.less';
import classnames from 'classnames';
// 生成树的数据格式 // 生成树的数据格式
const treeDataGenerator = (origin, currentType, ref) => { const treeDataGenerator = (origin, currentType, ref) => {
...@@ -101,7 +100,7 @@ const DeviceTree = (props) => { ...@@ -101,7 +100,7 @@ const DeviceTree = (props) => {
const prefixCls = getPrefixCls('ec-device-tree-group'); const prefixCls = getPrefixCls('ec-device-tree-group');
const cusProps = _.pick(props, ['onSelect', 'onCheck', 'selectable', 'checkable']); const cusProps = _.pick(props, ['onSelect', 'onCheck', 'selectable', 'checkable']);
const { onSelect, onCheck, keepChecked, singleType = false, selectable, checkable } = props; const { onSelect, onCheck, keepChecked, singleType = false, selectable, checkable, filterName } = props;
const [data, setData] = useState([]); const [data, setData] = useState([]);
const [{ pageIndex, pageSize }, setPagination] = useState({ const [{ pageIndex, pageSize }, setPagination] = useState({
...@@ -111,6 +110,8 @@ const DeviceTree = (props) => { ...@@ -111,6 +110,8 @@ const DeviceTree = (props) => {
const [searchs, setSearchs] = useState(''); const [searchs, setSearchs] = useState('');
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [hasMore, setHasMore] = useState(true); const [hasMore, setHasMore] = useState(true);
const [filterFieldEntries, setFilterFieldEntries] = useState([]); // "筛选字段"可选列表
const [filterValue, setFilterValue] = useState('');
const ref = useRef(); const ref = useRef();
const dataRef = useRef({ const dataRef = useRef({
...@@ -123,7 +124,24 @@ const DeviceTree = (props) => { ...@@ -123,7 +124,24 @@ const DeviceTree = (props) => {
const { currentType, flatData } = dataRef.current; const { currentType, flatData } = dataRef.current;
const [checkedKeys, setCheckedKeys] = useState([]); const [checkedKeys, setCheckedKeys] = useState([]);
const [selectedKeys, setSelectedKeys] = useState([]); const [selectedKeys, setSelectedKeys] = useState([]);
const [first, setFirst] = useState(true);
useEffect(() => {
if (filterName) {
let device = deviceTypes.split(',')[0];
GetFieldValueFromTable({
tableName: '设备_台账_' + device,
fieldName: filterName,
})
.then((res) => {
if (res.code == '0') {
setFilterFieldEntries(res.data);
}
})
.catch((err) => {
setFilterFieldEntries([]);
});
}
}, [filterName]);
const requestQuery = useMemo(() => { const requestQuery = useMemo(() => {
return { return {
...@@ -138,6 +156,12 @@ const DeviceTree = (props) => { ...@@ -138,6 +156,12 @@ const DeviceTree = (props) => {
classField, classField,
direction, direction,
customerName, customerName,
queryWhereParams: [{
column: filterName,
isString: true,
matchingRule: "等于",
columnValue: filterValue
}]
}; };
}, [ }, [
customerName, customerName,
...@@ -149,6 +173,7 @@ const DeviceTree = (props) => { ...@@ -149,6 +173,7 @@ const DeviceTree = (props) => {
searchs, searchs,
sortFields, sortFields,
classField, classField,
filterValue,
]); ]);
useEffect(() => { useEffect(() => {
...@@ -195,6 +220,10 @@ const DeviceTree = (props) => { ...@@ -195,6 +220,10 @@ const DeviceTree = (props) => {
} }
}, [loading, pageIndex, pageSize, hasMore]); }, [loading, pageIndex, pageSize, hasMore]);
const onChangeFilter = (val) => {
setFilterValue(val ? val : '');
}
const onSearch = useCallback( const onSearch = useCallback(
(value) => { (value) => {
setSearchs(value); setSearchs(value);
...@@ -247,8 +276,26 @@ const DeviceTree = (props) => { ...@@ -247,8 +276,26 @@ const DeviceTree = (props) => {
return ( return (
<div className={classNames(prefixCls, 'wkt-scroll-light')}> <div className={classNames(prefixCls, 'wkt-scroll-light')}>
{
filterName ?
<div style={{ display: 'flex', alignItems: 'center', marginBottom: '10px' }}>
<div>{filterName}</div>
<Select
style={{ width: 140 }}
placeholder=""
onChange={onChangeFilter}
allowClear={true}
>
{filterFieldEntries.map((item) => (
<Option key={item}>{item}</Option>
))}
</Select>
</div>
: ''
}
<Input.Search placeholder="搜索设备名称" onSearch={onSearch} allowClear /> <Input.Search placeholder="搜索设备名称" onSearch={onSearch} allowClear />
<div className={classnames(`${prefixCls}-tree-wrap`, 'wkt-scroll-light-plus')} ref={ref}> <div className={classNames(`${prefixCls}-tree-wrap`, 'wkt-scroll-light-plus')} style={{ height: filterName ? 'calc(100% - 90px)' : 'calc(100% - 48px)' }} ref={ref}>
{/* <Spin spinning={loading}> */} {/* <Spin spinning={loading}> */}
{loading || (data && data.length) ? ( {loading || (data && data.length) ? (
<Skeleton loading={loading} active> <Skeleton loading={loading} active>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment