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.

159 lines
5.9 KiB

  1. import { NavBar, Toast } from 'antd-mobile';
  2. import { useEffect, useRef, useState } from 'react';
  3. import { useNavigate, useParams } from 'react-router-dom';
  4. import MeasurementCanvas, {
  5. BenchmarkShape,
  6. MeasurementCanvasRef,
  7. } from '../components/konva/MeasurementCanvas';
  8. import Bridge from '../utils/bridge';
  9. import { Measurement } from '../services/apiTypes';
  10. import { useAppDispatch, useAppSelector } from '../utils/hooks';
  11. // import { XB_CODES } from '../utils/constant';
  12. import { updateRailPoints } from '../store/features/baseData';
  13. export default function MeasureRecord() {
  14. const navigate = useNavigate();
  15. const dispatch = useAppDispatch();
  16. const baseState = useAppSelector((state) => state.baseData);
  17. const params = useParams(); // params.recordId
  18. const [measure, setMeasure] = useState<Measurement | undefined>(undefined);
  19. const canvasRef = useRef<MeasurementCanvasRef>(null);
  20. const back = () => navigate(-1);
  21. useEffect(() => {
  22. Bridge.getMeasurementDetail({ id: +(params.recordId || '') }).then((res) => {
  23. if (res.success) {
  24. setMeasure({ ...res.data, extraDescObj: JSON.parse(res.data.extraDesc) });
  25. } else {
  26. Toast.show(res.message);
  27. }
  28. });
  29. }, [params.recordId]);
  30. function drawRailBaseLine(points: string) {
  31. const benchmarkShapes = JSON.parse(points) as BenchmarkShape[];
  32. if (canvasRef.current) {
  33. canvasRef.current.setBenchmarkData(benchmarkShapes);
  34. }
  35. }
  36. function drawMeasurePoints(leftPoints: string, rightPoints: string) {
  37. if (canvasRef.current) {
  38. canvasRef.current.setMeasurementDataLeft(JSON.parse(leftPoints));
  39. canvasRef.current.setMeasurementDataRight(JSON.parse(rightPoints));
  40. }
  41. }
  42. useEffect(() => {
  43. if (measure) {
  44. const r = baseState.railTypes.find((rail) => rail.code === measure.railSize);
  45. if (!r) return;
  46. if (!!r.points) {
  47. drawRailBaseLine(r.points);
  48. drawMeasurePoints(measure.leftPoints, measure.rightPoints);
  49. return;
  50. }
  51. Bridge.getTrackPoint({ code: r.code }).then((res) => {
  52. if (res.success) {
  53. dispatch(updateRailPoints(res.data));
  54. drawRailBaseLine(res.data.points!);
  55. drawMeasurePoints(measure.leftPoints, measure.rightPoints);
  56. } else {
  57. Toast.show(res.message);
  58. }
  59. });
  60. }
  61. }, [baseState.railTypes, dispatch, measure]);
  62. // function railType(code: string) {
  63. // const rail = baseState.railTypes.find((rail) => rail.code === code);
  64. // return rail;
  65. // }
  66. // function direction(directCode: string) {
  67. // return XB_CODES.find((dire) => dire.value === directCode);
  68. // }
  69. return (
  70. <div>
  71. <NavBar className="bg-white" onBack={back}>
  72. </NavBar>
  73. <div className="main-page-content ">
  74. <div className="relative h-0 p-0 pb-[70%] border-y border-[#dedede]">
  75. <div className="absolute left-0 right-0 top-0 bottom-0 bg-title">
  76. <MeasurementCanvas
  77. width={window.innerWidth}
  78. height={window.innerWidth * 0.7}
  79. logicalExtent={{ minX: -45, maxX: 45, minY: -18, maxY: 52 }}
  80. gridStep={3}
  81. origin={{ x: 0, y: 20 }}
  82. pixelPerMm={window.innerWidth / 90}
  83. maxZoom={5}
  84. showGrid={true}
  85. showBenchmark={true}
  86. showAnalysis={false}
  87. showScale={false}
  88. scaleInterval={1}
  89. showCoordinates={false}
  90. ref={canvasRef}
  91. />
  92. </div>
  93. </div>
  94. <section>
  95. <h1 className="h-10 px-4 text-base font-medium leading-10"></h1>
  96. {measure && (
  97. <div
  98. className="overflow-x-hidden overflow-y-auto"
  99. style={{
  100. height: 'calc(100vh - var(--navBarHeight) - (100vw * 0.7) - 50px)',
  101. }}
  102. >
  103. <div className="grid grid-cols-[auto_1fr] bg-white px-5 py-3 gap-x-5 gap-y-4 text-sm ">
  104. <p className="text-[#818181]"></p>
  105. <span className="text-text">{measure.createTime}</span>
  106. <p className="text-[#818181]"></p>
  107. <span className="text-text">{measure.name}</span>
  108. <p className="text-[#818181]"></p>
  109. <span className="text-text">{measure.batch}</span>
  110. <p className="text-[#818181]"></p>
  111. <span className="text-text">{measure.extraDescObj?.dataSource}</span>
  112. <p className="text-[#818181]">线</p>
  113. <span className="text-text">{measure.extraDescObj?.lineClassify}</span>
  114. <p className="text-[#818181]"></p>
  115. <span className="text-text">{measure.extraDescObj?.railSize}</span>
  116. <p className="text-[#818181]"></p>
  117. <span className="text-text">{measure.extraDescObj?.tljCode}</span>
  118. <p className="text-[#818181]"></p>
  119. <span className="text-text">{measure.extraDescObj?.gwdCode}</span>
  120. <p className="text-[#818181]">线</p>
  121. <span className="text-text">{measure.extraDescObj?.xmCode}</span>
  122. <p className="text-[#818181]"></p>
  123. <span className="text-text">{measure.extraDescObj?.stationCode}</span>
  124. <p className="text-[#818181]"></p>
  125. <span className="text-text">{measure.extraDescObj?.xbCode}</span>
  126. <p className="text-[#818181]"></p>
  127. <span className="text-text">{measure.extraDescObj?.unitType}</span>
  128. <p className="text-[#818181]"></p>
  129. <span className="text-text">{`${measure.extraDescObj?.mile}公里+${measure.extraDescObj?.meter}`}</span>
  130. </div>
  131. </div>
  132. )}
  133. </section>
  134. </div>
  135. </div>
  136. );
  137. }