UNPKG

@antdp/fuzzy-query

Version:

基于antd封装的组件 模糊查询 自定义提示

70 lines 1.86 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; var _excluded = ["value", "width", "onClick", "mode", "labelInValue", "ValueField"]; import React from "react"; import { Table } from "antd"; import "./index.css"; import { jsx as _jsx } from "react/jsx-runtime"; var getCheck = (item, value, mode, labelInValue, ValueField) => { if (["tags", "multiple"].includes(mode) && Array.isArray(value)) { var fig = value.find(it => { if (labelInValue && it) { return it[ValueField] === item[ValueField]; } return it === value; }); if (fig) { return true; } } else { if (labelInValue && value) { return value[ValueField] === item[ValueField]; } else { return value === item[ValueField]; } } return false; }; export default props => { var { value, width, onClick: _onClick, mode, labelInValue, ValueField } = props, rest = _objectWithoutPropertiesLoose(props, _excluded); var getCheckMome = React.useCallback(getCheck, [JSON.stringify(value)]); var onRow = record => { var check = getCheckMome(record, value, mode, labelInValue, ValueField); return { onClick: () => _onClick(record, !check), style: check && { background: "#e6f7ff" } || {} }; }; return /*#__PURE__*/_jsx("div", { className: "fuzzy-query-table", children: /*#__PURE__*/_jsx(Table, _extends({ rowKey: ValueField, onRow: onRow, size: "small", pagination: false, style: { width }, scroll: { y: 300 }, columns: [{ dataIndex: "label", title: "名称" }, { dataIndex: "value", title: "编号" }] }, rest)) }); };