index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 from 'react'
  21. import DownloadList from '../DownloadList'
  22. import { Icon, Button } from 'antd'
  23. import { IDownloadRecord } from 'app/containers/App/types'
  24. const styles = require('./EditorHeader.less')
  25. const utilStyles = require('assets/less/util.less')
  26. interface IEditorHeaderProps {
  27. currentType: string
  28. name: string
  29. description: string
  30. placeholder?: {
  31. name: string
  32. description: string
  33. }
  34. className: string
  35. loading?: boolean
  36. downloadList?: IDownloadRecord[]
  37. onNameChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
  38. onDescriptionChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
  39. onSave?: () => void
  40. onCancel: () => void
  41. onSetting?: () => void
  42. onLoadDownloadList?: () => void
  43. onDownloadFile?: (id) => void
  44. }
  45. export function EditorHeader (props: IEditorHeaderProps) {
  46. const {
  47. currentType,
  48. name,
  49. description,
  50. className,
  51. loading,
  52. downloadList,
  53. onNameChange,
  54. onDescriptionChange,
  55. onSave,
  56. onCancel,
  57. onSetting,
  58. onLoadDownloadList,
  59. onDownloadFile
  60. } = props
  61. const placeholder = props.placeholder || {
  62. name: '请输入名称',
  63. description: '请输入描述…'
  64. }
  65. return (
  66. <div className={`${styles.editorHeader} ${className}`}>
  67. <Icon type="left" className={styles.back} onClick={onCancel} />
  68. <div className={styles.title}>
  69. <div className={styles.name}>
  70. <input
  71. type="text"
  72. placeholder={placeholder.name}
  73. value={name}
  74. onChange={onNameChange}
  75. readOnly={currentType === 'dashboard'}
  76. />
  77. <span>{name || placeholder.name}</span>
  78. </div>
  79. <div className={styles.desc}>
  80. <input
  81. type="text"
  82. placeholder={currentType === 'dashboard' ? '' : placeholder.description}
  83. value={description}
  84. onChange={onDescriptionChange}
  85. readOnly={currentType === 'dashboard'}
  86. />
  87. <span>{description || placeholder.description}</span>
  88. </div>
  89. </div>
  90. {
  91. currentType === 'dashboard'
  92. ? (
  93. <ul className={styles.tools}>
  94. <li>
  95. <DownloadList
  96. downloadList={downloadList}
  97. onLoadDownloadList={onLoadDownloadList}
  98. onDownloadFile={onDownloadFile}
  99. />
  100. </li>
  101. </ul>
  102. )
  103. : (
  104. <div className={`${currentType === 'dashboard' ? utilStyles.hide : styles.actions}`}>
  105. <Button onClick={onSetting}>设置</Button>
  106. <Button
  107. type="primary"
  108. loading={loading}
  109. disabled={loading}
  110. onClick={onSave}
  111. >
  112. 保存
  113. </Button>
  114. </div>
  115. )
  116. }
  117. </div>
  118. )
  119. }
  120. export default EditorHeader