Browse Source

fix:保存时缓存上一次的记录

master
guoapeng 2 months ago
parent
commit
439ae77288
  1. 2
      src/App.tsx
  2. 1
      src/components/CustomNavBar.scss
  3. 12
      src/components/CustomNavBar.tsx
  4. 1
      src/components/MeasurementItem.tsx
  5. 4
      src/components/konva/MeasurementCanvas.tsx
  6. 5
      src/pages/Measure.tsx
  7. 2
      src/pages/MeasureRecord.tsx
  8. 33
      src/pages/MeasureSave.tsx
  9. 1
      src/services/apiTypes.ts
  10. 2
      src/store/features/contextSlice.ts

2
src/App.tsx

@ -34,7 +34,7 @@ function App() {
// 监听推送消息,更新store // 监听推送消息,更新store
useEffect(() => { useEffect(() => {
const subscription = bridgeOb.subscribe((datagram) => { const subscription = bridgeOb.subscribe((datagram) => {
console.log('datagram.type--', datagram.type)
// console.log('datagram.type--', datagram.type)
if (datagram.type === 'measure-event') { if (datagram.type === 'measure-event') {
dispatch(updateTaskState(datagram.data)); dispatch(updateTaskState(datagram.data));
} else if (datagram.type === 'measure-point') { } else if (datagram.type === 'measure-point') {

1
src/components/CustomNavBar.scss

@ -13,7 +13,6 @@
.bg-color { .bg-color {
position: absolute; position: absolute;
height: 100%; height: 100%;
width: 50%;
left: 0; left: 0;
border-radius: 4px; border-radius: 4px;
z-index: 1; z-index: 1;

12
src/components/CustomNavBar.tsx

@ -18,9 +18,9 @@ export default function CustomNavBar({ title }: { title: string }) {
className="absolute h-[30px] w-full bg-white border border-[#D8D8D8] flex items-center gap-2 px-2" className="absolute h-[30px] w-full bg-white border border-[#D8D8D8] flex items-center gap-2 px-2"
style={{ top: device.connected && showDetail ? '100%' : 0, transition: 'top 300ms' }} style={{ top: device.connected && showDetail ? '100%' : 0, transition: 'top 300ms' }}
> >
<span className="flex-1">: {device.temperature.toFixed(1)}°C</span>
<span className="flex-1">X轴倾斜: {device.inclinatorX.toFixed(2)}</span>
<span className="flex-1">Y轴倾斜: {device.inclinatorY.toFixed(2)}</span>
<span className="flex-1">: {device.temperature?.toFixed(1)}°C</span>
<span className="flex-1">X轴倾斜: {device.inclinatorX?.toFixed(2)}</span>
<span className="flex-1">Y轴倾斜: {device.inclinatorY?.toFixed(2)}</span>
</div> </div>
{/** 导航栏 */} {/** 导航栏 */}
<div className="absolute left-0 top-0 w-full h-full flex items-center px-3 bg-white"> <div className="absolute left-0 top-0 w-full h-full flex items-center px-3 bg-white">
@ -42,9 +42,9 @@ export default function CustomNavBar({ title }: { title: string }) {
}} }}
/> />
<div className="bluetooth-battery"> <div className="bluetooth-battery">
<div className="bg-color" style={{ width: `${device.power}%`, backgroundColor: device.flag ? '#1dbb1d' : device.power > 20 ? '#3e63cb' : 'red' }}></div>
<div className={'power-head'} style={{ backgroundColor: device.flag ? '#1dbb1d' : device.power > 20 ? '#3e63cb' : 'red' }}></div>
<span className="power-num">{device.power}</span>
<div className="bg-color" style={{ width: `${device.power || 0}%`, backgroundColor: device.flag ? '#1dbb1d' : device.power > 20 ? '#3e63cb' : 'red' }}></div>
<div className={'power-head'} style={{ backgroundColor: device.flag && device.power === 100? '#1dbb1d' : device.power === 100 ? '#3e63cb' : 'rgba(0,0,0,0.3)' }}></div>
<span className="power-num">{device.power || 0}</span>
{device.flag === 1 && <img src={power_icon} alt=""/>} {device.flag === 1 && <img src={power_icon} alt=""/>}
</div> </div>

1
src/components/MeasurementItem.tsx

@ -25,6 +25,7 @@ export default function MeasurementItem({
)} )}
<main className="flex-1"> <main className="flex-1">
<header className="flex items-center gap-2"> <header className="flex items-center gap-2">
<span className="text-sm text-[#606266]">{item.todayNumber}.</span>
<h1 className="text-[15px] font-medium ">{item.name}</h1> <h1 className="text-[15px] font-medium ">{item.name}</h1>
{item.syncStatus === 'finish' && <span className="text-[#04CA17] text-xs"></span>} {item.syncStatus === 'finish' && <span className="text-[#04CA17] text-xs"></span>}
</header> </header>

4
src/components/konva/MeasurementCanvas.tsx

@ -400,13 +400,13 @@ const MeasurementCanvas = forwardRef<MeasurementCanvasRef, MeasurementCanvasProp
for (let x = logicalExtent.minX; x <= logicalExtent.maxX; x += dynamicXInterval) { for (let x = logicalExtent.minX; x <= logicalExtent.maxX; x += dynamicXInterval) {
const pos = transform({ x, y: 0 }); const pos = transform({ x, y: 0 });
texts.push( texts.push(
<Text key={`coord-x-${x}`} x={pos.x - 10} y={height - 20} text={x.toFixed(0)} fontSize={12} fill="black" />
<Text key={`coord-x-${x}`} x={pos.x - 10} y={height - 20} text={x?.toFixed(0)} fontSize={12} fill="black" />
); );
} }
for (let y = logicalExtent.minY; y <= logicalExtent.maxY; y += dynamicYInterval) { for (let y = logicalExtent.minY; y <= logicalExtent.maxY; y += dynamicYInterval) {
const pos = transform({ x: 0, y }); const pos = transform({ x: 0, y });
texts.push( texts.push(
<Text key={`coord-y-${y}`} x={5} y={pos.y - 6} text={y.toFixed(0)} fontSize={12} fill="black" />
<Text key={`coord-y-${y}`} x={5} y={pos.y - 6} text={y?.toFixed(0)} fontSize={12} fill="black" />
); );
} }
return texts; return texts;

5
src/pages/Measure.tsx

@ -191,11 +191,12 @@ export default function Measure() {
}); });
const [status, setStatus] = useState(0) const [status, setStatus] = useState(0)
useEffect(() => { useEffect(() => {
console.log(measureState.taskState)
switch (measureState.taskState) { switch (measureState.taskState) {
case 'WAITING_FOR_RECORD_THE_1ST_SIDE': case 'WAITING_FOR_RECORD_THE_1ST_SIDE':
setStatus(1); setStatus(1);
setState({ setState({
left_ready: 'none',
left_ready: 'ongoing',
right_ready: 'none', right_ready: 'none',
left_begin: 'none', left_begin: 'none',
right_begin: 'none', right_begin: 'none',
@ -282,7 +283,7 @@ export default function Measure() {
right_end: 'none', right_end: 'none',
}); });
} }
}, [measureState.taskState, status]);
}, [measureState.taskState]);
function railName() { function railName() {
return baseState.railTypes.find((r) => r.id === railId[0])?.name || ''; return baseState.railTypes.find((r) => r.id === railId[0])?.name || '';

2
src/pages/MeasureRecord.tsx

@ -40,7 +40,7 @@ export default function MeasureRecord() {
} }
function drawMeasurePoints(leftPoints: string, rightPoints: string) { function drawMeasurePoints(leftPoints: string, rightPoints: string) {
if (canvasRef.current) {
if (canvasRef.current && leftPoints && rightPoints) {
canvasRef.current.setMeasurementDataLeft(JSON.parse(leftPoints)); canvasRef.current.setMeasurementDataLeft(JSON.parse(leftPoints));
canvasRef.current.setMeasurementDataRight(JSON.parse(rightPoints)); canvasRef.current.setMeasurementDataRight(JSON.parse(rightPoints));
} }

33
src/pages/MeasureSave.tsx

@ -1,7 +1,7 @@
import { NavBar, Picker, Toast } from 'antd-mobile'; import { NavBar, Picker, Toast } from 'antd-mobile';
import { useNavigate } from 'react-router'; import { useNavigate } from 'react-router';
import icon_arr_r from '../assets/icon_arr_s_r.svg'; import icon_arr_r from '../assets/icon_arr_s_r.svg';
import { ChangeEvent, useEffect, useState } from 'react';
import {ChangeEvent, useCallback, useEffect, useState} from 'react';
import { useAppDispatch, useAppSelector } from '../utils/hooks'; import { useAppDispatch, useAppSelector } from '../utils/hooks';
import { DATA_SOURCE, LINE_CLASSIFY, UNIT_TYPES, XB_CODES } from '../utils/constant'; import { DATA_SOURCE, LINE_CLASSIFY, UNIT_TYPES, XB_CODES } from '../utils/constant';
import { ExtraDesc, MeasurementDTO } from '../services/apiTypes'; import { ExtraDesc, MeasurementDTO } from '../services/apiTypes';
@ -19,6 +19,32 @@ export default function MeasureSave() {
const measureState = useAppSelector((state) => state.measure); const measureState = useAppSelector((state) => state.measure);
const orgTextArr = useAppSelector(selectOrgTextArr); const orgTextArr = useAppSelector(selectOrgTextArr);
const loadData = useCallback(() => {
Bridge.getRecordList({ pageNum: 1, size: 1 }).then((res) => {
if (res.success && res.data.list.length) {
const data = res.data.list[0]?.records?.[0]
console.log(data)
setName(data?.name)
setBatch(data?.batch)
setMile(data?.mileage?.split('+')?.[0])
setMeter(data?.mileage?.split('+')?.[1])
setLineClassCode([data?.lineClassify])
setDataSourceCode([data?.dataSource])
setDirectionCode([data?.xbCode])
setUnitType([data?.unitType])
setTurnoutNum(Number(data?.turnoutNum || 1))
setSleeperNum(Number(data?.sleeperNum || 1))
setStationCode([data?.stationCode])
document.getElementById('name-id')?.focus()
}
});
}, []);
useEffect(() => {
loadData();
}, [loadData]);
const [name, setName] = useState(''); const [name, setName] = useState('');
const [batch, setBatch] = useState(''); const [batch, setBatch] = useState('');
const [mile, setMile] = useState('10'); const [mile, setMile] = useState('10');
@ -110,8 +136,8 @@ export default function MeasureSave() {
stationCode: stationCode.length > 0 ? stationCode[0] : '', stationCode: stationCode.length > 0 ? stationCode[0] : '',
lineClassify: lineClassCode[0], lineClassify: lineClassCode[0],
dataSource: dataSourceCode[0], dataSource: dataSourceCode[0],
turnoutNum: turnoutNum.toFixed(),
sleeperNum: sleeperNum.toFixed(),
turnoutNum: turnoutNum?.toFixed(),
sleeperNum: sleeperNum?.toFixed(),
unitType: unitType[0], unitType: unitType[0],
mileage: `${mile}+${meter.padStart(3, '0')}`, mileage: `${mile}+${meter.padStart(3, '0')}`,
radius: '', radius: '',
@ -149,6 +175,7 @@ export default function MeasureSave() {
<div className="h-12 flex items-center border-b border-[#eee]"> <div className="h-12 flex items-center border-b border-[#eee]">
<span></span> <span></span>
<input <input
id='name-id'
type="text" type="text"
name="name" name="name"
value={name} value={name}

1
src/services/apiTypes.ts

@ -2,6 +2,7 @@ export type ReqStatus = 'idle' | 'loading' | 'succeeded' | 'failed';
export type Measurement = MeasurementDTO & { export type Measurement = MeasurementDTO & {
id: number; id: number;
todayNumber: string;
createTime: string; // Date; createTime: string; // Date;
leftPoints: string; // json: 坐标数组 leftPoints: string; // json: 坐标数组
rightPoints: string; // json: 坐标数组 rightPoints: string; // json: 坐标数组

2
src/store/features/contextSlice.ts

@ -35,7 +35,7 @@ const initialState: ContextState = {
device: { device: {
flag: 0, flag: 0,
connected: true, //是否已连接蓝牙 connected: true, //是否已连接蓝牙
power: 60, //电量
power: 0, //电量
inclinatorX: 0.276, //x轴倾斜 inclinatorX: 0.276, //x轴倾斜
inclinatorY: 3.019, //y轴倾斜 inclinatorY: 3.019, //y轴倾斜
temperature: 32.026, //温度 temperature: 32.026, //温度

Loading…
Cancel
Save