LogicPanel.jsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {styled} from 'styled-components'
  2. import {ProFormList, ProFormSelect, ProFormText,ProFormGroup,ProFormSegmented} from '@ant-design/pro-components'
  3. import {memo, useState, forwardRef} from 'react'
  4. import { LOGIC_TYPE} from "../pages/IndexDefine/constants";
  5. import useI18NPrefix from "../hooks/useI18NPrefix";
  6. const component = forwardRef(({
  7. type,
  8. options,
  9. value
  10. },ref) => {
  11. const t = useI18NPrefix('global');
  12. const [count,setCount]=useState(0);
  13. const joinLogic=(index)=>{
  14. const display = ( index !== (count-1) )
  15. if (display){
  16. return <ProFormSegmented
  17. name="relation"
  18. fieldProps={{style:{marginLeft:"50%"}}}
  19. initialValue="AND"
  20. valueEnum={{
  21. AND: t('operation.and'),
  22. OR: t('operation.or'),
  23. }}
  24. />
  25. }
  26. }
  27. return (
  28. <Container ref={ref}>
  29. <CustomFromList
  30. name="filters"
  31. wrapperCol={{span:24}}
  32. initialValue={value}
  33. creatorButtonProps={{
  34. creatorButtonText: t("operation.attributes")
  35. }}
  36. onAfterAdd={(e,s,c)=>setCount(c)}
  37. onAfterRemove={(e,c)=>setCount(c)}
  38. itemContainerRender={(doms,{index})=> {
  39. return <>
  40. {doms}
  41. {joinLogic(index)}
  42. </>
  43. }}
  44. >
  45. <ProFormGroup key="group">
  46. <ProFormSelect
  47. width="sm"
  48. name="bizName"
  49. placeholder={t("placeholder.fields")}
  50. rules={[{ required: true }]}
  51. options={options}
  52. />
  53. <ProFormSelect
  54. width="sm"
  55. name="operator"
  56. placeholder={t("placeholder.logic")}
  57. rules={[{ required: true }]}
  58. valueEnum={LOGIC_TYPE}
  59. />
  60. <ProFormText
  61. width={250}
  62. name="value"
  63. placeholder={t("placeholder.value")}
  64. rules={[{ required: true }]}
  65. />
  66. </ProFormGroup>
  67. </CustomFromList>
  68. </Container>
  69. )
  70. })
  71. export const LogicPanel = memo(component)
  72. const CustomFromList=styled(ProFormList)`
  73. .ant-form-item {
  74. margin-bottom: 5px;
  75. }
  76. .ant-pro-form-list-action{
  77. margin-block-end: 0;
  78. line-height: 0;
  79. height: 29px;
  80. }
  81. `
  82. const Container = styled.div`
  83. width: 95%;
  84. padding-block-end: 1px;
  85. padding-block-start: 15px;
  86. padding-inline-end: 20px;
  87. padding-inline-start: 20px;
  88. background-color: #f5f5f5;
  89. min-height: 68px;
  90. `