index.tsx 830 B

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