index.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. import type { ISchema } from '@formily/json-schema';
  2. import { createSchemaField } from '@formily/react';
  3. import {
  4. ArrayItems,
  5. DatePicker,
  6. Form,
  7. FormGrid,
  8. FormItem,
  9. FormTab,
  10. Input,
  11. NumberPicker,
  12. PreviewText,
  13. Select,
  14. Space,
  15. TreeSelect,
  16. } from '@formily/antd';
  17. import type { Field, FieldDataSource } from '@formily/core';
  18. import { createForm, onFieldReact, onFieldValueChange } from '@formily/core';
  19. import GroupNameControl from '@/components/SearchComponent/GroupNameControl';
  20. import {
  21. DeleteOutlined,
  22. DoubleRightOutlined,
  23. ReloadOutlined,
  24. SaveOutlined,
  25. SearchOutlined,
  26. } from '@ant-design/icons';
  27. import { Button, Card, Dropdown, Empty, Menu, Popover, Typography } from 'antd';
  28. import { useEffect, useMemo, useRef, useState } from 'react';
  29. import type { ProColumns } from '@jetlinks/pro-table';
  30. import type { EnumData } from '@/utils/typings';
  31. import styles from './index.less';
  32. import Service from '@/components/SearchComponent/service';
  33. import _ from 'lodash';
  34. import { useIntl } from '@@/plugin-locale/localeExports';
  35. import classnames from 'classnames';
  36. import { onlyMessage, randomString } from '@/utils/util';
  37. import { useHistory, useLocation } from 'umi';
  38. const ui2Server = (source: SearchTermsUI): SearchTermsServer => [
  39. { terms: source.terms1 },
  40. { terms: source.terms2, type: source.type },
  41. ];
  42. const server2Ui = (source: SearchTermsServer): SearchTermsUI => ({
  43. terms1: source[0].terms,
  44. terms2: source[1]?.terms,
  45. type: source[0]?.type || 'and',
  46. });
  47. interface Props<T> {
  48. /** @name "搜索条件" */
  49. field: ProColumns<T>[];
  50. onSearch: (params: { terms: SearchTermsServer }) => void;
  51. target?: string;
  52. /**
  53. * @name "固定查询参数"
  54. * eg: 1: {[{ column: 'test', value: 'admin' }]}
  55. * 2: {[
  56. * {
  57. * terms: [{ column: 'parentId$isnull', value: '' }, { column: 'parentId$not', value: 'test', type: 'or' }],
  58. * },
  59. * {
  60. * terms: [{ column: 'id$not', value: 'test', type: 'and' }],
  61. * },
  62. * ]}
  63. * */
  64. defaultParam?: SearchTermsServer | Term[];
  65. /**
  66. * @name "搜索组件模式"
  67. * simple 限制只支持一组搜索条件,用于小弹窗搜索时使用
  68. */
  69. model?: 'simple' | 'advance';
  70. enableSave?: boolean;
  71. initParam?: SearchTermsServer;
  72. }
  73. const termType = [
  74. { label: '=', value: 'eq' },
  75. { label: '!=', value: 'not' },
  76. { label: '包含', value: 'like' },
  77. { label: '不包含', value: 'nlike' },
  78. { label: '>', value: 'gt' },
  79. { label: '>=', value: 'gte' },
  80. { label: '<', value: 'lt' },
  81. { label: '<=', value: 'lte' },
  82. { label: '属于', value: 'in' },
  83. { label: '不属于', value: 'nin' },
  84. ];
  85. const service = new Service();
  86. const SchemaField = createSchemaField({
  87. components: {
  88. FormItem,
  89. FormTab,
  90. Input,
  91. Select,
  92. NumberPicker,
  93. FormGrid,
  94. ArrayItems,
  95. DatePicker,
  96. PreviewText,
  97. GroupNameControl,
  98. Space,
  99. TreeSelect,
  100. },
  101. });
  102. /**
  103. * 搜索字段排序
  104. * @param field
  105. */
  106. const sortField = (field: ProColumns[]) => {
  107. let _temp = false;
  108. field.forEach((item) => {
  109. if (item.index) {
  110. _temp = true;
  111. return;
  112. }
  113. });
  114. if (!_temp) {
  115. // 如果没有index 就默认name字段最第一个
  116. field.map((item) => {
  117. if (item.dataIndex === 'name') {
  118. item.index = 0;
  119. return item;
  120. } else {
  121. return item;
  122. }
  123. });
  124. }
  125. // index排序
  126. return _.sortBy(field, (i) => i.index);
  127. };
  128. // 保存历史记录
  129. // 过滤不参与搜索的列数据 ==> 字段排序
  130. // 场景一:简单模式
  131. // 默认搜索参数,根据Index 来判断,或者默认name为第一组条件
  132. // 场景二:高级模式
  133. // 默认六组搜索条件。根据字段index排序
  134. // const nodeFor = <T extends Record<string, any>>(props: Props<T>, ref) => {
  135. // console.log(props,ref)
  136. // return (<></>)
  137. // }
  138. //
  139. // export const node = forwardRef(nodeFor) as <RecordType extends Record<string, any>>(props: Props<RecordType>, ref?: React.Ref<HTMLDivElement>) => React.ReactElement
  140. const SearchComponent = <T extends Record<string, any>>(props: Props<T>) => {
  141. const { field, target, onSearch, defaultParam, enableSave = true, initParam, model } = props;
  142. const _history = useHistory();
  143. const _location = useLocation();
  144. /**
  145. * 过滤不参与搜索的数据 ?
  146. * TODO Refactor 依赖透明?
  147. */
  148. const filterSearchTerm = (): ProColumns<any>[] =>
  149. field
  150. .filter((item) => item.dataIndex)
  151. .filter((item) => !item.hideInSearch)
  152. .filter((item) => !['index', 'option'].includes(item.dataIndex as string));
  153. /**
  154. * 根据dataIndex 过滤不参与查询的参数
  155. *
  156. * @param _field 查询的列
  157. * @param excludes 过滤的字段名称
  158. */
  159. // const filterSearchTerm2 = (_field: ProColumns<T>[] = [], excludes: string[] = []) =>
  160. // _field.filter(item => item.dataIndex)
  161. // .filter(item => !item.hideInSearch)
  162. // .filter(item => !excludes.includes(item.dataIndex as string))
  163. // 处理后的搜索条件
  164. const processedField = sortField(filterSearchTerm());
  165. const defaultTerms = (index: number) =>
  166. ({
  167. termType: 'like',
  168. column: (processedField[index]?.dataIndex as string) || null,
  169. type: 'or',
  170. } as Partial<Term>);
  171. const intl = useIntl();
  172. const [expand, setExpand] = useState<boolean>(true);
  173. const initForm = server2Ui(initParam || [{ terms: [defaultTerms(0)] }]);
  174. const [aliasVisible, setAliasVisible] = useState<boolean>(false);
  175. const [initParams, setInitParams] = useState<SearchTermsUI>(initForm);
  176. const [history, setHistory] = useState([]);
  177. const [logVisible, setLogVisible] = useState<boolean>(false);
  178. const uiParamRef = useRef(initParam);
  179. const form = useMemo(
  180. () =>
  181. createForm<SearchTermsUI>({
  182. validateFirst: true,
  183. initialValues: initParams,
  184. effects() {
  185. onFieldReact('*.*.column', async (typeFiled, f) => {
  186. // if ((typeFiled as Field).modified) {
  187. const isModified = (typeFiled as Field).modified;
  188. const _column = (typeFiled as Field).value;
  189. const _field = field.find((item) => item.dataIndex === _column);
  190. if (_column === 'id') {
  191. if (isModified) {
  192. f.setFieldState(typeFiled.query('.termType'), async (state) => {
  193. state.value = 'eq';
  194. });
  195. }
  196. f.setFieldState(typeFiled.query('.value'), async (state) => {
  197. state.componentType = 'Input';
  198. state.componentProps = { allowClear: true };
  199. });
  200. } else {
  201. switch (_field?.valueType) {
  202. case 'select':
  203. let __option: { label: any; value: any }[] | FieldDataSource | undefined = [];
  204. if (_field?.valueEnum) {
  205. __option = Object.values(_field?.valueEnum || {}).map((item) => ({
  206. label: item.text,
  207. value: item.status,
  208. }));
  209. } else if (_field?.request) {
  210. __option = await _field.request();
  211. }
  212. if (isModified) {
  213. f.setFieldState(typeFiled.query('.termType'), async (state) => {
  214. state.value = 'eq';
  215. });
  216. }
  217. f.setFieldState(typeFiled.query('.value'), async (state) => {
  218. console.log(state.value);
  219. state.componentType = 'Select';
  220. state.dataSource = __option;
  221. state.componentProps = {
  222. allowClear: true,
  223. showSearch: true,
  224. filterOption: (input: string, option: any) =>
  225. option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0,
  226. };
  227. });
  228. break;
  229. case 'treeSelect':
  230. let _option: { label: any; value: any }[] | FieldDataSource | undefined = [];
  231. if (_field?.valueEnum) {
  232. _option = Object.values(_field?.valueEnum || {}).map((item) => ({
  233. label: item.text,
  234. value: item.status,
  235. }));
  236. } else if (_field?.request) {
  237. _option = await _field.request();
  238. }
  239. if (isModified) {
  240. f.setFieldState(typeFiled.query('.termType'), (_state) => {
  241. _state.value = 'eq';
  242. });
  243. }
  244. f.setFieldState(typeFiled.query('.value'), (state) => {
  245. state.componentType = 'TreeSelect';
  246. state.dataSource = _option;
  247. state.componentProps = {
  248. ..._field.fieldProps,
  249. allowClear: true,
  250. showSearch: true,
  251. treeNodeFilterProp: 'name',
  252. filterOption: (input: string, option: any) =>
  253. option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0,
  254. };
  255. });
  256. break;
  257. case 'digit':
  258. f.setFieldState(typeFiled.query('.value'), async (state) => {
  259. state.componentType = 'NumberPicker';
  260. state.componentProps = { allowClear: true };
  261. });
  262. if (isModified) {
  263. f.setFieldState(typeFiled.query('.termType'), async (state) => {
  264. state.value = 'eq';
  265. });
  266. }
  267. break;
  268. case 'dateTime':
  269. f.setFieldState(typeFiled.query('.value'), async (state) => {
  270. state.componentType = 'DatePicker';
  271. state.componentProps = { showTime: true, allowClear: true };
  272. });
  273. if (isModified) {
  274. f.setFieldState(typeFiled.query('.termType'), async (state) => {
  275. state.value = 'gte';
  276. });
  277. }
  278. break;
  279. default:
  280. if (isModified) {
  281. f.setFieldState(typeFiled.query('.termType'), async (state) => {
  282. state.value = 'like';
  283. });
  284. }
  285. f.setFieldState(typeFiled.query('.value'), async (state) => {
  286. state.componentType = 'Input';
  287. state.componentProps = { allowClear: true };
  288. });
  289. break;
  290. }
  291. }
  292. // }
  293. });
  294. onFieldValueChange('*.*.column', (field1, form1) => {
  295. form1.setFieldState(field1.query('.value'), (state1) => {
  296. if (field1.modified) {
  297. state1.value = undefined;
  298. }
  299. });
  300. });
  301. },
  302. }),
  303. [target, expand],
  304. );
  305. const historyForm = createForm();
  306. const queryHistory = async () => {
  307. const response = await service.history.query(`${target}-search`);
  308. if (response.status === 200) {
  309. setHistory(response.result);
  310. }
  311. };
  312. const createGroup = (name: string): ISchema => ({
  313. 'x-decorator': 'FormItem',
  314. 'x-decorator-props': {
  315. gridSpan: 4,
  316. },
  317. 'x-component': 'ArrayItems',
  318. type: 'array',
  319. 'x-value': new Array(expand ? 1 : 3).fill({ termType: 'like' }),
  320. items: {
  321. type: 'object',
  322. 'x-component': 'FormGrid',
  323. 'x-component-props': {
  324. minColumns: 14,
  325. maxColumns: 14,
  326. columnGap: 24,
  327. // rowGap: 1,
  328. },
  329. properties: {
  330. type: {
  331. 'x-decorator': 'FormItem',
  332. 'x-component': 'GroupNameControl',
  333. 'x-decorator-props': {
  334. gridSpan: 3,
  335. },
  336. default: 'or',
  337. 'x-component-props': {
  338. name: name,
  339. },
  340. 'x-visible': !expand,
  341. },
  342. column: {
  343. type: 'string',
  344. 'x-decorator': 'FormItem',
  345. 'x-component': 'Select',
  346. 'x-decorator-props': {
  347. gridSpan: 3,
  348. },
  349. 'x-component-props': {
  350. placeholder: '请选择',
  351. },
  352. enum: filterSearchTerm().map((i) => ({ label: i.title, value: i.dataIndex } as EnumData)),
  353. },
  354. termType: {
  355. type: 'enum',
  356. 'x-decorator': 'FormItem',
  357. 'x-component': 'Select',
  358. 'x-decorator-props': {
  359. gridSpan: 3,
  360. },
  361. default: 'like',
  362. enum: termType,
  363. },
  364. value: {
  365. 'x-decorator-props': {
  366. gridSpan: 6,
  367. },
  368. 'x-decorator': 'FormItem',
  369. 'x-component': 'Input',
  370. },
  371. },
  372. },
  373. });
  374. const schema: ISchema = {
  375. type: 'object',
  376. properties: {
  377. layout: {
  378. type: 'void',
  379. 'x-component': 'FormGrid',
  380. 'x-component-props': {
  381. minColumns: 9,
  382. maxColumns: 9,
  383. },
  384. properties: {
  385. terms1: createGroup('第一组'),
  386. type: {
  387. 'x-decorator': 'FormItem',
  388. 'x-component': 'Select',
  389. 'x-decorator-props': {
  390. gridSpan: 1,
  391. style: {
  392. display: 'flex',
  393. alignItems: 'center',
  394. marginTop: '-22px',
  395. padding: '0 30px',
  396. },
  397. },
  398. default: 'and',
  399. enum: [
  400. { label: '并且', value: 'and' },
  401. { label: '或者', value: 'or' },
  402. ],
  403. },
  404. terms2: createGroup('第二组'),
  405. },
  406. },
  407. },
  408. };
  409. const handleForm = (_expand?: boolean) => {
  410. const value = form.values;
  411. const __expand = _expand !== undefined ? _expand : expand;
  412. // 第一组条件值
  413. const _terms1 = _.cloneDeep(value.terms1?.[0]);
  414. const uiParam = uiParamRef.current;
  415. // 判断一下条件。。是否展开。
  416. if (__expand) {
  417. value.terms1 = [
  418. uiParam?.[0]?.terms?.[0] || _terms1 || defaultTerms(0),
  419. uiParam?.[0]?.terms?.[1] || defaultTerms(1),
  420. uiParam?.[0]?.terms?.[2] || defaultTerms(2),
  421. ];
  422. value.terms2 = [
  423. uiParam?.[1]?.terms?.[0] || defaultTerms(3),
  424. uiParam?.[1]?.terms?.[1] || defaultTerms(4),
  425. uiParam?.[1]?.terms?.[2] || defaultTerms(5),
  426. ];
  427. } else {
  428. value.terms1 = [uiParam?.[0]?.terms?.[0] || _terms1 || defaultTerms(0)];
  429. value.terms2 = [];
  430. }
  431. setInitParams(value);
  432. };
  433. const handleExpand = () => {
  434. handleForm();
  435. setExpand(!expand);
  436. };
  437. useEffect(() => {
  438. // 1、一组条件时的表单值
  439. // 2、六组条件时的表单值
  440. // 3、拥有默认条件时的表单值
  441. // 合并初始化的值
  442. //expand false 6组条件 true 1组条件
  443. if (initParam && initParam[0].terms && initParam[0].terms.length > 1) {
  444. handleExpand();
  445. }
  446. }, [initParam]);
  447. const simpleSchema: ISchema = {
  448. type: 'object',
  449. properties: {
  450. terms1: createGroup('第一组'),
  451. },
  452. };
  453. const handleHistory = (item: SearchHistory) => {
  454. const log = JSON.parse(item.content) as SearchTermsUI;
  455. setLogVisible(false);
  456. uiParamRef.current = ui2Server(log);
  457. const _expand =
  458. !!(log.terms1 && log.terms1.length > 1) || !!(log.terms2 && log.terms2.length > 1);
  459. if (_expand) {
  460. setExpand(false);
  461. }
  462. handleForm(_expand);
  463. };
  464. const historyDom = (
  465. <Menu className={styles.history}>
  466. {history.length > 0 ? (
  467. history.map((item: SearchHistory) => (
  468. <Menu.Item onClick={() => handleHistory(item)} key={item.id || randomString(9)}>
  469. <div className={styles.list}>
  470. <Typography.Text ellipsis={{ tooltip: item.name }}>{item.name}</Typography.Text>
  471. <DeleteOutlined
  472. onClick={async (e) => {
  473. e?.stopPropagation();
  474. const response = await service.history.remove(`${target}-search`, item.key);
  475. if (response.status === 200) {
  476. onlyMessage('操作成功');
  477. const temp = history.filter((h: any) => h.key !== item.key);
  478. setHistory(temp);
  479. }
  480. }}
  481. />
  482. </div>
  483. </Menu.Item>
  484. ))
  485. ) : (
  486. <Menu.Item>
  487. <div
  488. style={{
  489. display: 'flex',
  490. justifyContent: 'center',
  491. alignItems: 'center',
  492. width: '148px',
  493. }}
  494. >
  495. <Empty />
  496. </div>
  497. </Menu.Item>
  498. )}
  499. </Menu>
  500. );
  501. const formatValue = (value: SearchTermsUI): SearchTermsServer => {
  502. let _value = ui2Server(value);
  503. // 处理默认查询参数
  504. if (defaultParam && defaultParam?.length > 0) {
  505. if ('terms' in defaultParam[0]) {
  506. _value = _value.concat(defaultParam as SearchTermsServer);
  507. } else if ('value' in defaultParam[0]) {
  508. _value = _value.concat([{ terms: defaultParam }]);
  509. }
  510. }
  511. return _value
  512. .filter((i) => i.terms && i.terms?.length > 0)
  513. .map((_term) => {
  514. _term.terms = _term.terms
  515. ?.filter((term) => term.value !== '')
  516. .map((item) => {
  517. if (item.termType === 'like' && item.value && item.value !== '') {
  518. item.value = `%${item.value}%`;
  519. return item;
  520. }
  521. return item;
  522. });
  523. return _term;
  524. });
  525. };
  526. const handleSearchValue = (
  527. data: SearchTermsServer,
  528. fields: ProColumns<T>[],
  529. ): SearchTermsServer => {
  530. return data.map((item) => {
  531. item.terms?.forEach((termsItem) => {
  532. const _fieldItem = fields.find((fieldItem) => fieldItem.dataIndex === termsItem.column);
  533. if (
  534. _fieldItem &&
  535. _fieldItem.search &&
  536. _fieldItem.search.transform &&
  537. _.isFunction(_fieldItem.search.transform)
  538. ) {
  539. termsItem.value = _fieldItem.search.transform(termsItem.value, '', '');
  540. }
  541. });
  542. return item;
  543. });
  544. };
  545. const handleSearch = async (type: boolean = true) => {
  546. const value = form.values;
  547. const filterTerms = (data: Partial<Term>[] | undefined) =>
  548. data && data.filter((item) => item.column != null).filter((item) => item.value !== undefined);
  549. const _terms = _.cloneDeep(value);
  550. _terms.terms1 = filterTerms(_terms.terms1);
  551. _terms.terms2 = filterTerms(_terms.terms2);
  552. const _temp = formatValue(_terms);
  553. if (
  554. (_terms.terms1 && _terms.terms1.length > 1) ||
  555. (_terms.terms2 && _terms.terms2.length > 1)
  556. ) {
  557. // 展开高级搜索
  558. uiParamRef.current = ui2Server(value);
  559. setExpand(false);
  560. handleForm(true);
  561. }
  562. const params = new URLSearchParams(_location.search);
  563. params.delete('q');
  564. params.delete('target');
  565. if (
  566. (value.terms1 && value.terms1.length && value.terms1?.some((item) => item.value)) ||
  567. (value.terms2 && value.terms2.length && value.terms2?.some((item) => item.value))
  568. ) {
  569. if (type) {
  570. params.append('q', JSON.stringify(value));
  571. if (props.target) {
  572. params.append('target', props.target);
  573. }
  574. _history.push({
  575. hash: _location.hash,
  576. search: '?' + params.toString(),
  577. });
  578. // setUrl({ q: JSON.stringify(value), target: props.target });
  579. }
  580. } else {
  581. _history.push({
  582. hash: _location.hash,
  583. search: '?' + params.toString(),
  584. });
  585. }
  586. const newTemp = handleSearchValue(_.cloneDeep(_temp), props.field);
  587. onSearch({ terms: newTemp });
  588. };
  589. useEffect(() => {
  590. // 防止页面下多个TabsTabPane中的查询组件共享路由中的参数
  591. const params = new URLSearchParams(_location.search);
  592. const q = params.get('q');
  593. const _target = params.get('target');
  594. if (q && props.model !== 'simple') {
  595. if (_target) {
  596. if (props.target && _target === props.target) {
  597. form.setValues(JSON.parse(q));
  598. handleSearch(false);
  599. }
  600. return;
  601. }
  602. form.setValues(JSON.parse(q));
  603. handleSearch(false);
  604. }
  605. }, [_location, props.target]);
  606. useEffect(() => {
  607. if (defaultParam) {
  608. handleSearch(!(props.model === 'simple'));
  609. }
  610. }, []);
  611. const handleSaveLog = async () => {
  612. const value = await form.submit<SearchTermsUI>();
  613. const value2 = await historyForm.submit<{ alias: string }>();
  614. const response = await service.history.save(`${target}-search`, {
  615. name: value2.alias,
  616. content: JSON.stringify(value),
  617. });
  618. if (response.status === 200) {
  619. onlyMessage('保存成功!');
  620. } else {
  621. onlyMessage('保存失败', 'error');
  622. }
  623. setAliasVisible(!aliasVisible);
  624. };
  625. const resetForm = async (type: boolean) => {
  626. const value = form.values;
  627. if (!expand) {
  628. value.terms1 = [defaultTerms(0), defaultTerms(1), defaultTerms(2)];
  629. value.terms2 = [defaultTerms(3), defaultTerms(4), defaultTerms(5)];
  630. } else {
  631. value.terms1 = [defaultTerms(0)];
  632. value.terms2 = [];
  633. }
  634. setInitParams(value);
  635. await handleSearch(type);
  636. };
  637. const SearchBtn = {
  638. simple: (
  639. <>
  640. {
  641. // @ts-ignore
  642. <Button
  643. icon={<SearchOutlined />}
  644. onClick={() => {
  645. handleSearch(false);
  646. }}
  647. type="primary"
  648. >
  649. 搜索
  650. </Button>
  651. }
  652. </>
  653. ),
  654. advance: (
  655. <Dropdown.Button
  656. icon={<SearchOutlined />}
  657. placement={'bottomLeft'}
  658. destroyPopupOnHide
  659. // @ts-ignore
  660. onClick={handleSearch}
  661. visible={logVisible}
  662. onVisibleChange={async (visible) => {
  663. setLogVisible(visible);
  664. if (visible) {
  665. await queryHistory();
  666. }
  667. }}
  668. type="primary"
  669. overlay={historyDom}
  670. >
  671. 搜索
  672. </Dropdown.Button>
  673. ),
  674. };
  675. const SaveBtn = (
  676. <Popover
  677. content={
  678. <Form style={{ width: '217px' }} form={historyForm}>
  679. <SchemaField
  680. schema={{
  681. type: 'object',
  682. properties: {
  683. alias: {
  684. 'x-decorator': 'FormItem',
  685. 'x-component': 'Input.TextArea',
  686. 'x-validator': [
  687. {
  688. max: 64,
  689. message: '最多可输入64个字符',
  690. },
  691. {
  692. required: true,
  693. message: '请输入名称',
  694. },
  695. ],
  696. },
  697. },
  698. }}
  699. />
  700. <Button onClick={handleSaveLog} type="primary" className={styles.saveLog}>
  701. 保存
  702. </Button>
  703. </Form>
  704. }
  705. visible={aliasVisible}
  706. onVisibleChange={setAliasVisible}
  707. title="搜索名称"
  708. trigger="click"
  709. >
  710. <Button icon={<SaveOutlined />} block>
  711. {intl.formatMessage({
  712. id: 'pages.data.option.save',
  713. defaultMessage: '保存',
  714. })}
  715. </Button>
  716. </Popover>
  717. );
  718. return (
  719. <Card bordered={false} className={styles.container}>
  720. <Form form={form} className={styles.form} labelCol={4} wrapperCol={18}>
  721. <div className={expand && styles.simple}>
  722. <SchemaField schema={expand ? simpleSchema : schema} />
  723. <div className={styles.action} style={{ marginTop: expand ? 0 : -12 }}>
  724. <Space>
  725. {enableSave ? SearchBtn.advance : SearchBtn.simple}
  726. {enableSave && SaveBtn}
  727. <Button
  728. icon={<ReloadOutlined />}
  729. block
  730. onClick={() => {
  731. resetForm(model !== 'simple');
  732. }}
  733. >
  734. 重置
  735. </Button>
  736. </Space>
  737. {model !== 'simple' && (
  738. <div className={classnames(styles.more, !expand ? styles.simple : styles.advance)}>
  739. <Button type="link" onClick={handleExpand}>
  740. 更多筛选
  741. <DoubleRightOutlined style={{ marginLeft: 32 }} rotate={expand ? 90 : -90} />
  742. </Button>
  743. </div>
  744. )}
  745. </div>
  746. </div>
  747. </Form>
  748. </Card>
  749. );
  750. };
  751. export default SearchComponent;