DisplaySettingModal.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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, { useCallback } from 'react'
  21. import {
  22. Modal,
  23. Form,
  24. Card,
  25. Row,
  26. Col,
  27. Checkbox,
  28. InputNumber,
  29. Radio,
  30. Select
  31. } from 'antd'
  32. const FormItem = Form.Item
  33. const RadioGroup = Radio.Group
  34. const { Option } = Select
  35. import { FormComponentProps, FormItemProps } from 'antd/lib/form'
  36. import { IDisplayParams } from 'containers/Viz/types'
  37. import { DefaultDisplayParams } from './constants'
  38. interface IDisplaySettingModalProps extends FormComponentProps<IDisplayParams> {
  39. visible: boolean
  40. displayParams: IDisplayParams
  41. onCancel: () => void
  42. onOk: (params: IDisplayParams) => void
  43. }
  44. const transitionStyleOptions: Array<{
  45. label: string
  46. value: IDisplayParams['transitionStyle']
  47. }> = [
  48. {
  49. label: '无',
  50. value: 'none'
  51. },
  52. {
  53. label: '淡入淡出',
  54. value: 'fade'
  55. },
  56. {
  57. label: '滑动',
  58. value: 'slide'
  59. },
  60. {
  61. label: '凸镜',
  62. value: 'convex'
  63. },
  64. {
  65. label: '凹镜',
  66. value: 'concave'
  67. },
  68. {
  69. label: '缩放',
  70. value: 'zoom'
  71. }
  72. ]
  73. const formItemStyle: Partial<FormItemProps> = {
  74. labelCol: { span: 12 },
  75. wrapperCol: { span: 12 }
  76. }
  77. const DisplaySettingModal: React.FC<IDisplaySettingModalProps> = (props) => {
  78. const { visible, displayParams, form, onCancel, onOk } = props
  79. const { getFieldDecorator } = form
  80. const { autoPlay, autoSlide, transitionStyle, transitionSpeed, grid } =
  81. displayParams || DefaultDisplayParams
  82. const ok = useCallback(() => {
  83. form.validateFieldsAndScroll((err, values) => {
  84. if (err) {
  85. return
  86. }
  87. onOk(values)
  88. })
  89. }, [onOk])
  90. return (
  91. <Modal
  92. visible={visible}
  93. title="大屏设置"
  94. wrapClassName="ant-modal-large"
  95. onCancel={onCancel}
  96. onOk={ok}
  97. >
  98. <Form>
  99. <Row gutter={8}>
  100. <Col span={10}>
  101. <Card title="全局播放设置" size="small">
  102. <FormItem label="自动播放" {...formItemStyle}>
  103. {getFieldDecorator<IDisplayParams>('autoPlay', {
  104. initialValue: autoPlay,
  105. valuePropName: 'checked'
  106. })(<Checkbox />)}
  107. </FormItem>
  108. {form.getFieldValue('autoPlay') === true && (
  109. <FormItem label="每页停留时间(秒)" {...formItemStyle}>
  110. {getFieldDecorator<IDisplayParams>('autoSlide', {
  111. initialValue: autoSlide,
  112. validateFirst: true,
  113. rules: [{ required: true, message: '请输入数字' }]
  114. })(<InputNumber min={3} />)}
  115. </FormItem>
  116. )}
  117. </Card>
  118. </Col>
  119. <Col span={7}>
  120. <Card title="全局动画设置" size="small">
  121. <FormItem label="过渡动画" {...formItemStyle}>
  122. {getFieldDecorator<IDisplayParams>('transitionStyle', {
  123. initialValue: transitionStyle
  124. })(<RadioGroup options={transitionStyleOptions} />)}
  125. </FormItem>
  126. <FormItem label="动画速度" {...formItemStyle}>
  127. {getFieldDecorator<IDisplayParams>('transitionSpeed', {
  128. initialValue: transitionSpeed
  129. })(
  130. <Select>
  131. <Option value="default">默认</Option>
  132. <Option value="fast">快</Option>
  133. <Option value="slow">慢</Option>
  134. </Select>
  135. )}
  136. </FormItem>
  137. </Card>
  138. </Col>
  139. <Col span={7}>
  140. <Card title="拖动栅格设置(像素)" size="small">
  141. <FormItem label="x 轴方向" {...formItemStyle}>
  142. {getFieldDecorator('grid[0]', {
  143. initialValue: grid[0],
  144. rules: [{ required: true, message: '请填入数字' }]
  145. })(<InputNumber min={1} />)}
  146. </FormItem>
  147. <FormItem label="y 轴方向" {...formItemStyle}>
  148. {getFieldDecorator('grid[1]', {
  149. initialValue: grid[1],
  150. rules: [{ required: true, message: '请填入数字' }]
  151. })(<InputNumber min={1} />)}
  152. </FormItem>
  153. </Card>
  154. </Col>
  155. </Row>
  156. </Form>
  157. </Modal>
  158. )
  159. }
  160. export default Form.create<IDisplaySettingModalProps>()(DisplaySettingModal)