You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.1 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. import icon_check_s from '../assets/icon_check_s_s.svg';
  2. import icon_check_u from '../assets/icon_check_s_u.svg';
  3. import icon_arr from '../assets/icon_arr_p_r.svg';
  4. import icon_pending from '../assets/icon_upload_0.svg';
  5. import icon_uploading from '../assets/icon_upload_1.svg';
  6. import icon_uploaded from '../assets/icon_upload_2.svg';
  7. import { Measurement } from '../services/apiTypes';
  8. import { XB_CODES } from '../utils/constant';
  9. export type UpdateState = 'idle' | 'pending' | 'uploading' | 'uploaded';
  10. export default function MeasureItem({
  11. item,
  12. onDetail,
  13. }: {
  14. item: Measurement;
  15. onDetail?: () => void;
  16. }) {
  17. const stateText = () => {
  18. if (item.syncStatus === 'wait') {
  19. return <span className="text-[#A3ACC0] text-xs"></span>;
  20. } else if (item.syncStatus === 'fail') {
  21. return <span className="text-[red] text-xs"></span>;
  22. } else if (item.syncStatus === 'finish') {
  23. return <span className="text-[#04CA17] text-xs"></span>;
  24. }
  25. return null;
  26. };
  27. const direct = XB_CODES.find((dire) => dire.value === item.direction);
  28. return (
  29. <div className="flex mx-2 gap-3">
  30. <main className="flex-1">
  31. <header className="flex items-center gap-2">
  32. <h1 className="text-[15px] font-medium ">{item.name}</h1>
  33. {stateText()}
  34. </header>
  35. <main className="flex my-2">
  36. <p className="flex-1 text-sm ">{`${item.lineName}`}</p>
  37. <p className="flex-1 text-sm ">{`${item.location}`}</p>
  38. <p className="flex-1 text-sm ">{`${direct?.label}方向`}</p>
  39. </main>
  40. <footer>
  41. <span className="text-sm text-[#b7b7b7]">{item.createTime}</span>
  42. </footer>
  43. </main>
  44. <aside className="flex items-center" onClick={onDetail}>
  45. <span className="mr-2 text-sm text-primary font-medium"></span>
  46. <img src={icon_arr} alt="arr" className="h-[10px]" />
  47. </aside>
  48. </div>
  49. );
  50. }
  51. export function MeasureItemEx(props: {
  52. item: Measurement;
  53. selected: boolean;
  54. uploadState: UpdateState;
  55. onSelected?: () => void;
  56. onDetail?: () => void;
  57. }) {
  58. const stateImg = () => {
  59. if (props.uploadState === 'idle') {
  60. if (props.selected) {
  61. return <img src={icon_check_s} alt="icon" />;
  62. } else {
  63. return <img src={icon_check_u} alt="icon" />;
  64. }
  65. } else if (props.uploadState === 'pending') {
  66. return <img src={icon_pending} alt="icon" />;
  67. } else if (props.uploadState === 'uploading') {
  68. return <img src={icon_uploading} alt="icon" />;
  69. } else if (props.uploadState === 'uploaded') {
  70. return <img src={icon_uploaded} alt="icon" />;
  71. }
  72. return null;
  73. };
  74. const stateText = () => {
  75. if (props.uploadState === 'pending') {
  76. return <span className="text-[#A3ACC0] text-xs"></span>;
  77. } else if (props.uploadState === 'uploading') {
  78. return <span className="text-primary text-xs"></span>;
  79. } else if (props.uploadState === 'uploaded') {
  80. return <span className="text-[#04CA17] text-xs"></span>;
  81. }
  82. return null;
  83. };
  84. return (
  85. <div
  86. className="relative flex mx-2 gap-3"
  87. onClick={props.uploadState === 'idle' ? props.onSelected : undefined}
  88. >
  89. <main className="flex-1">
  90. <header className="flex items-center gap-2">
  91. {stateImg()}
  92. <h1 className="text-[15px] font-medium ">{props.item.name}</h1>
  93. </header>
  94. <main className="flex my-2">
  95. <p className="flex-1 text-sm ">{`${props.item.lineName}`}</p>
  96. <p className="flex-1 text-sm ">{`${props.item.location}`}</p>
  97. <p className="flex-1 text-sm ">{`${props.item.direction}方向`}</p>
  98. </main>
  99. <footer>
  100. <span className="text-sm text-[#b7b7b7]">{props.item.createTime}</span>
  101. </footer>
  102. </main>
  103. <aside className="flex items-center" onClick={props.onDetail}>
  104. <span className="mr-2 text-sm text-primary font-medium"></span>
  105. <img src={icon_arr} alt="arr" className="h-[10px]" />
  106. </aside>
  107. <div className="absolute right-0 bottom-0">{stateText()}</div>
  108. </div>
  109. );
  110. }