index.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React from 'react'
  2. import ChartTypes from 'containers/Widget/config/chart/ChartTypes'
  3. import { Icon } from 'antd'
  4. import styles from './style.less'
  5. export interface IDashboardItemMaskProps {
  6. loading: boolean
  7. chartType: ChartTypes
  8. empty: boolean
  9. hasDataConfig: boolean
  10. children?: React.ReactElement<any>
  11. }
  12. function Mask (props: IDashboardItemMaskProps) {
  13. const { chartType, hasDataConfig, children } = props
  14. switch (chartType) {
  15. case ChartTypes.Iframe:
  16. return null
  17. case ChartTypes.RichText:
  18. return hasDataConfig && children
  19. default:
  20. return children
  21. }
  22. }
  23. function Loading (props: IDashboardItemMaskProps) {
  24. const { loading } = props
  25. if (!loading) { return null }
  26. return (
  27. <Mask {...props}>
  28. <div className={styles.mask}>
  29. <Icon type="loading" />
  30. <p>加载中…</p>
  31. </div>
  32. </Mask>
  33. )
  34. }
  35. function Empty (props: IDashboardItemMaskProps) {
  36. const { loading, empty } = props
  37. if (loading || !empty) { return null }
  38. return (
  39. <Mask {...props}>
  40. <div className={styles.mask}>
  41. <Icon type="inbox" className={styles.emptyIcon} />
  42. <p>暂无数据</p>
  43. </div>
  44. </Mask>
  45. )
  46. }
  47. const DashboardItemMask = { Loading, Empty }
  48. export default DashboardItemMask