-
+ function onBleStart() {
+ start().then(() => {
+ message.success('蓝牙开始扫描')
+ })
+ }
+
+ function onBleStop() {
+ stop().then(() => {
+ })
+ }
+
+ function bleConnect(address: string) {
+ connect(address).then((res) => {
+ if (res.status !== 0) {
+ message.error(res.data.info);
+ return
+ }
+ message.success('蓝牙连接成功')
+ })
+ }
+
+ function bleDisconnect() {
+ disconnect().then(() => {
+ message.success('蓝牙断开连接')
+ })
+ }
+
+ const connectionStatus = () => {
+ if (!deviceInfo.isConnected) {
+ return (
+
+ 附近设备
+ {bleList.map(item => {
+ return
+
+
+
{item.name}
+
{item.address}
+
+ {
+ item.connect ?
已连接
:
+ }
+
+
+
+ })}
+
+ );
+ } else {
+ if(deviceInfo.connectedType === 'UART_CHANNEL') {
+ return (
+
+ 已通过usb连接
+
sn码:{deviceInfo.sn}
+
+ )
+
+ }else if(deviceInfo.connectedType === 'BLE_CHANNEL') {
+ return (
+
+ 已通过蓝牙连接
+
+
sn码:{deviceInfo.sn}
+
+ )
+ }
+ }
+ };
+
+
+ // @ts-ignore
+ return <>
+
+
系统配置
+
+
设备配置
+ {connectionStatus()}
+
+
+ >
}
\ No newline at end of file
diff --git a/src/pages/system/types.ts b/src/pages/system/types.ts
index bf9aa64..ce9c7e8 100644
--- a/src/pages/system/types.ts
+++ b/src/pages/system/types.ts
@@ -22,3 +22,9 @@ export type systemItem = {
value?: string;
}
+export type bleItem = {
+ "name": string;
+ "address": string;
+ "connect": boolean
+}
+
diff --git a/src/services/ble/ble.ts b/src/services/ble/ble.ts
new file mode 100644
index 0000000..8811c8f
--- /dev/null
+++ b/src/services/ble/ble.ts
@@ -0,0 +1,29 @@
+import httpRequest, {type BaseResponse} from "../httpRequest";
+export function start() {
+ return httpRequest
({
+ url: "/api/ble/list/start",
+ method: "POST",
+ });
+}
+
+export function stop() {
+ return httpRequest({
+ url: "/api/ble/list/stop",
+ method: "POST",
+ });
+}
+
+export function connect(address: string) {
+ return httpRequest({
+ url: `/api/ble/connect/${address}`,
+ method: "POST"
+ });
+}
+export function disconnect() {
+ return httpRequest({
+ url: `/api/ble/disconnect`,
+ method: "POST"
+ });
+}
+
+
diff --git a/src/services/wsTypes.ts b/src/services/wsTypes.ts
index d4875e2..6e94d92 100644
--- a/src/services/wsTypes.ts
+++ b/src/services/wsTypes.ts
@@ -129,10 +129,14 @@ export type DeviceStatus = {
messageType: "STATE";
data: {
isConnected: boolean; //是否链接
+ connectedType: "UART_CHANNEL" | "BLE_CHANNEL";
+ sn: string;
power: number; //电量
inclinatorX: number; //x轴倾斜
inclinatorY: number; //y轴倾斜
temperature: number; //温度
+ state: number;
+ flag: number
};
path: "/api/profiler-state/get-state";
};
@@ -148,4 +152,14 @@ export type ProgressStatus = {
path: "/get-task-progress";
};
+export type bleStatus = {
+ messageType: "STATE";
+ data: {
+ name: string;
+ address: string;
+ connect: boolean;
+ };
+ path: "/api/ble/ble-list";
+};
+
export type Datagram = TrackRecordSig | TaskState | ContextMessage | MeasureState | ChannelMessage | DeviceStatus | ProgressStatus;
diff --git a/src/store/ble/bleState.ts b/src/store/ble/bleState.ts
new file mode 100644
index 0000000..ca327d6
--- /dev/null
+++ b/src/store/ble/bleState.ts
@@ -0,0 +1,31 @@
+// 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 bleStateSlice = createSlice({
+ name: "bleState",
+ initialState,
+ // 定义 reducers 并生成关联的操作
+ reducers: {
+ // 定义一个加的方法
+ updateBleState: (state, { payload }) => {
+ state.isConnect = payload.isConnect;
+ state.connectPort = payload.connectPort;
+ state.sn = payload.sn;
+ state.descriptivePortName = payload.descriptivePortName;
+ },
+ },
+});
+export const { updateBleState } = bleStateSlice.actions;
+
+// 默认导出
+export default bleStateSlice.reducer;
diff --git a/src/store/features/contextSlice.ts b/src/store/features/contextSlice.ts
index 2778c46..0d32142 100644
--- a/src/store/features/contextSlice.ts
+++ b/src/store/features/contextSlice.ts
@@ -12,11 +12,15 @@ const initialState: ContextSlice = {
user: { loginFlag: false, loginUser: { nickname: "", userRole: "User", account: "" } },
newMeasureAfterSave: false,
device: {
- isConnected: true, //是否链接
+ isConnected: false, //是否链接
+ connectedType: "BLE_CHANNEL",
power: 60, //电量
inclinatorX: 0.276, //x轴倾斜
inclinatorY: 3.019, //y轴倾斜
temperature: 32.026, //温度
+ sn: '00000',
+ state: 1,
+ flag: 0
},
};
diff --git a/src/store/index.ts b/src/store/index.ts
index c39f325..8f7878b 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -4,6 +4,7 @@ import { configureStore } from "@reduxjs/toolkit";
import counterSlice from "./features/counterSlice";
import contextSlice from "./features/contextSlice";
import deviceStateSlice from "./device/deviceState";
+import bleState from "./ble/bleState";
import orgStateSlice from "./ktj/orgState";
import measureStateSlice from "./measure/measureState";
import systemStateSlice from "./system/systemSlice";
@@ -15,6 +16,7 @@ const store = configureStore({
counter: counterSlice,
context: contextSlice,
deviceState: deviceStateSlice,
+ bleState: bleState,
orgState: orgStateSlice,
measureState:measureStateSlice,
systemState:systemStateSlice