FullScreen.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { FC, memo, useMemo, useCallback } from 'react'
  21. import classnames from 'classnames'
  22. import ControlComponent from '../../Control'
  23. import { Row, Col, Button } from 'antd'
  24. import { IRenderTreeItem, IMapControlOptions, IControl } from '../../types'
  25. import { ControlQueryMode } from '../../constants'
  26. import { getControlVisibility } from '../../util'
  27. import styles from './Layouts.less'
  28. interface IFullScreenControlPanelLayoutProps {
  29. queryMode: ControlQueryMode
  30. renderTree: IRenderTreeItem[]
  31. formValues: object
  32. mapOptions: IMapControlOptions
  33. onChange: (control: IControl, val: any) => void
  34. onSearch: (changedValues?: object) => void
  35. onReset: () => void
  36. }
  37. const FullScreenControlPanelLayout: FC<IFullScreenControlPanelLayoutProps> = ({
  38. queryMode,
  39. renderTree,
  40. formValues,
  41. mapOptions,
  42. onChange,
  43. onSearch,
  44. onReset
  45. }) => {
  46. const renderControlComponents = useCallback(
  47. (controlRenderTreeItems: IRenderTreeItem[], parents?: IControl[]) => {
  48. let components = []
  49. controlRenderTreeItems.forEach((control) => {
  50. const { key, width, children, ...rest } = control
  51. if (getControlVisibility(renderTree, control, formValues)) {
  52. const controlValue = formValues && formValues[`${control.key}`]
  53. components = components.concat(
  54. <Col key={key} span={12}>
  55. <ControlComponent
  56. queryMode={queryMode}
  57. control={control}
  58. value={controlValue}
  59. currentOptions={mapOptions[key]}
  60. onChange={onChange}
  61. onSearch={onSearch}
  62. />
  63. </Col>
  64. )
  65. if (children) {
  66. const controlWithOutChildren = { key, width, ...rest }
  67. components = components.concat(
  68. renderControlComponents(
  69. children,
  70. parents
  71. ? parents.concat(controlWithOutChildren)
  72. : [controlWithOutChildren]
  73. )
  74. )
  75. }
  76. }
  77. })
  78. return components
  79. },
  80. [renderTree, formValues, mapOptions]
  81. )
  82. const panelClassNames = useMemo(
  83. () =>
  84. classnames({
  85. [styles.fullscreenControlPanel]: true,
  86. [styles.empty]: !renderTree.filter((r) =>
  87. getControlVisibility(renderTree, r, formValues)
  88. ).length
  89. }),
  90. [renderTree]
  91. )
  92. const manualSearch = useCallback(() => {
  93. onSearch()
  94. }, [onSearch])
  95. return (
  96. <div className={panelClassNames}>
  97. <div className={styles.controls}>
  98. <Row gutter={8}>{renderControlComponents(renderTree)}</Row>
  99. </div>
  100. {queryMode === ControlQueryMode.Manually && (
  101. <div className={styles.actions}>
  102. <Button type="primary" icon="search" onClick={manualSearch}>
  103. 查询
  104. </Button>
  105. <Button icon="reload" onClick={onReset}>
  106. 重置
  107. </Button>
  108. </div>
  109. )}
  110. </div>
  111. )
  112. }
  113. export default memo(FullScreenControlPanelLayout)