index.tsx 875 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Badge } from 'antd';
  2. import React from 'react';
  3. /**
  4. * 状态色
  5. */
  6. export enum StatusColorEnum {
  7. 'success' = 'success',
  8. 'error' = 'error',
  9. 'processing' = 'processing',
  10. 'warning' = 'warning',
  11. 'default' = 'default',
  12. }
  13. export type StatusColorType = keyof typeof StatusColorEnum;
  14. export interface BadgeStatusProps {
  15. text: string | React.ReactNode;
  16. status: string | number;
  17. /**
  18. * 自定义status值颜色
  19. * @example {
  20. * 1: 'success',
  21. * 0: 'error'
  22. * }
  23. */
  24. statusNames?: Record<string | number, StatusColorType>;
  25. }
  26. export default (props: BadgeStatusProps) => {
  27. const handleStatusColor = (): StatusColorType | undefined => {
  28. if ('statusNames' in props) {
  29. return props.statusNames![props.status];
  30. }
  31. return StatusColorEnum['default'];
  32. };
  33. return <Badge status={handleStatusColor()} text={props.text} />;
  34. };