7 changed files with 92 additions and 22 deletions
-
3src/App.tsx
-
50src/components/Header.tsx
-
9src/services/device/deviceState.ts
-
4src/services/measure/type.ts
-
13src/services/wsTypes.ts
-
32src/store/device/deviceState.ts
-
3src/store/index.ts
@ -0,0 +1,9 @@ |
|||
import httpRequest, { type BaseResponse } from "../httpRequest"; |
|||
import type { Device } from "../../services/measure/type"; |
|||
|
|||
export function getDeviceInfo() { |
|||
return httpRequest<BaseResponse<{list:Device[]}>>({ |
|||
url: "/measurement-data/getDevice", |
|||
method: "POST", |
|||
}); |
|||
} |
@ -0,0 +1,32 @@ |
|||
// counterSlice.ts 文件
|
|||
|
|||
import { createSlice } from "@reduxjs/toolkit"; |
|||
import { ChannelMessage } from "../../services/wsTypes"; |
|||
|
|||
const initialState: ChannelMessage["data"] = { |
|||
"isConnect": false, //是否连接
|
|||
"connectPort": "COM4",//串口名
|
|||
"sn": "",//连接的设备ID
|
|||
"descriptivePortName": "COM4 serial ch340" //用于详细系
|
|||
}; |
|||
|
|||
// 创建一个 Slice
|
|||
export const deviceStateSlice = createSlice({ |
|||
name: "deviceState", |
|||
initialState, |
|||
// 定义 reducers 并生成关联的操作
|
|||
reducers: { |
|||
// 定义一个加的方法
|
|||
updateDeviceState: (state, { payload }) => { |
|||
state.isConnect = payload.isConnect; |
|||
state.connectPort = payload.connectPort; |
|||
state.sn = payload.sn; |
|||
state.descriptivePortName = payload.descriptivePortName; |
|||
}, |
|||
}, |
|||
}); |
|||
// 导出加减的方法
|
|||
export const { updateDeviceState } = deviceStateSlice.actions; |
|||
|
|||
// 默认导出
|
|||
export default deviceStateSlice.reducer; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue