10 changed files with 179 additions and 85 deletions
-
3.vscode/settings.json
-
31src/App.tsx
-
6src/components/CustomNavBar.tsx
-
25src/pages/Measure.tsx
-
31src/pages/Setting.tsx
-
66src/services/mobileWsType.ts
-
5src/services/socket.ts
-
57src/store/features/contextSlice.ts
-
27src/utils/bridge.ts
-
13src/utils/helper.ts
@ -0,0 +1,3 @@ |
|||
{ |
|||
"cSpell.words": ["Cascader"] |
|||
} |
@ -0,0 +1,66 @@ |
|||
export type PeripheralStatus = { |
|||
type: 'peripheral-status'; |
|||
data: { |
|||
connected: boolean; |
|||
power: number; |
|||
inclinatorX: number; |
|||
inclinatorY: number; |
|||
temperature: number; |
|||
}; |
|||
}; |
|||
|
|||
export type MeasureEvent = { |
|||
type: 'measure-event'; |
|||
data: { |
|||
event: |
|||
| 'START_RECORD_LEFT' |
|||
| 'FINISH_RECORD_LEFT' |
|||
| 'START_RECORD_RIGHT' |
|||
| 'FINISH_RECORD_RIGHT' |
|||
| 'WRONG_SIDE'; |
|||
}; |
|||
}; |
|||
|
|||
export type MeasurePoint = { |
|||
type: 'measure-point'; |
|||
data: { |
|||
x: number; |
|||
y: number; |
|||
}; |
|||
}; |
|||
|
|||
export type BleList = { |
|||
type: 'ble-list'; |
|||
data: Array<{ |
|||
mac: string; // 蓝牙设备的 MAC 地址(唯一标识)
|
|||
name: string; // 蓝牙设备的可读名称(如型号/别名)
|
|||
linked: boolean; //该设备是否已链接
|
|||
// ... 后续补充
|
|||
}>; |
|||
}; |
|||
|
|||
export type SyncProgress = { |
|||
type: 'sync-progress'; // 数据类型:同步进度状态上报
|
|||
data: { |
|||
remaining: number; // 剩余未同步数量
|
|||
fail: number; // 同步失败数量
|
|||
total: number; // 总数量
|
|||
finish: boolean; // 是否同步完成(true 表示全部完成)
|
|||
}; |
|||
}; |
|||
|
|||
export type SyncItemFinish = { |
|||
type: 'sync-item-finish'; // 数据类型:单项数据同步完成上报
|
|||
data: { |
|||
id: number; // 数据同步任务的 ID
|
|||
success: boolean; // 是否同步成功(true 表示成功,false 表示失败)
|
|||
}; |
|||
}; |
|||
|
|||
export type MobileDatagram = |
|||
| PeripheralStatus |
|||
| MeasureEvent |
|||
| MeasurePoint |
|||
| BleList |
|||
| SyncProgress |
|||
| SyncItemFinish; |
@ -1,35 +1,78 @@ |
|||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; |
|||
import { DeviceStatus } from '../../services/wsTypes'; |
|||
import { BleList, PeripheralStatus, SyncItemFinish, SyncProgress } from '../../services/mobileWsType'; |
|||
|
|||
interface ContextState { |
|||
device: DeviceStatus['data']; |
|||
currRailTypeId: number; |
|||
device: PeripheralStatus['data']; |
|||
currRailTypeId: number; // 当前选择的轨型
|
|||
currOrgCode: string; // 铁路局
|
|||
currGWDCode: string; // 工务段
|
|||
currXMCode: string; // 线名
|
|||
|
|||
bleList: BleList["data"]; |
|||
syncProgress: SyncProgress["data"]; |
|||
syncItems: Array<SyncItemFinish["data"]> |
|||
} |
|||
|
|||
const orgGwdXmStr = localStorage.getItem('org_gwd_xm'); |
|||
let orgGwdXm: string[] | undefined; |
|||
if (orgGwdXmStr) { |
|||
orgGwdXm = orgGwdXmStr.split(','); |
|||
} |
|||
|
|||
const initialState: ContextState = { |
|||
device: { |
|||
isConnected: true, //是否链接
|
|||
connected: true, //是否已连接蓝牙
|
|||
power: 60, //电量
|
|||
inclinatorX: 0.276, //x轴倾斜
|
|||
inclinatorY: 3.019, //y轴倾斜
|
|||
temperature: 32.026, //温度
|
|||
}, |
|||
// 当前选择的轨型
|
|||
|
|||
currRailTypeId: 1, |
|||
|
|||
currOrgCode: orgGwdXm ? orgGwdXm[0] : '', |
|||
currGWDCode: orgGwdXm ? orgGwdXm[1] : '', |
|||
currXMCode: orgGwdXm ? orgGwdXm[2] : '', |
|||
|
|||
bleList: [], |
|||
syncProgress: { |
|||
remaining: 0, |
|||
fail: 0, |
|||
total: 0, |
|||
finish: true, |
|||
}, |
|||
syncItems:[] |
|||
}; |
|||
|
|||
export const contextSlice = createSlice({ |
|||
name: 'context', |
|||
initialState, |
|||
reducers: { |
|||
updateDevice: (state, action: PayloadAction<DeviceStatus['data']>) => { |
|||
updateOrg: (state, action: PayloadAction<string[]>) => { |
|||
state.currOrgCode = action.payload[0]; |
|||
state.currGWDCode = action.payload[1]; |
|||
state.currXMCode = action.payload[2]; |
|||
localStorage.setItem('org_gwd_xm', action.payload.join(',')) |
|||
}, |
|||
|
|||
updateDevice: (state, action: PayloadAction<PeripheralStatus['data']>) => { |
|||
state.device = action.payload; |
|||
}, |
|||
|
|||
updateRailTypeId: (state, action: PayloadAction<number>) => { |
|||
state.currRailTypeId = action.payload; |
|||
}, |
|||
|
|||
updateBleList:(state, action: PayloadAction<BleList["data"]>) => { |
|||
state.bleList = action.payload |
|||
}, |
|||
|
|||
updateSyncProgress: (state, action: PayloadAction<SyncProgress["data"]>) => { |
|||
state.syncProgress = action.payload; |
|||
}, |
|||
|
|||
}, |
|||
}); |
|||
|
|||
export const { updateDevice, updateRailTypeId } = contextSlice.actions; |
|||
export const { updateOrg, updateDevice, updateRailTypeId, updateBleList, updateSyncProgress } = contextSlice.actions; |
|||
export default contextSlice.reducer; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue