10 changed files with 511 additions and 26 deletions
-
39package-lock.json
-
2package.json
-
6public/main.js
-
53src/index.ts
-
68src/routes/ble.ts
-
33src/routes/record.ts
-
42src/routes/sync.ts
-
20src/routes/system.ts
-
15src/types/apiTypes.ts
-
259src/utils/constant.ts
@ -0,0 +1,68 @@ |
|||||
|
import express from "express"; |
||||
|
import { delay, prismaClient } from "../utils/helper"; |
||||
|
const router = express.Router(); |
||||
|
import { WsProxy } from "../utils/wss"; |
||||
|
|
||||
|
let intervalId1: ReturnType<typeof setInterval>; |
||||
|
let connectId = ""; |
||||
|
|
||||
|
router.post("/list/start", (req, res) => { |
||||
|
intervalId1 = setInterval(() => { |
||||
|
WsProxy.sendMobile({ |
||||
|
type: "ble-list", |
||||
|
data: [ |
||||
|
{ |
||||
|
mac: "xyz", // 蓝牙设备的 MAC 地址(唯一标识)
|
||||
|
name: "TEST-XYZ", // 蓝牙设备的可读名称(如型号/别名)
|
||||
|
linked: connectId === "xyz", //该设备是否已链接
|
||||
|
}, |
||||
|
{ |
||||
|
mac: "abc", // 蓝牙设备的 MAC 地址(唯一标识)
|
||||
|
name: "TEST-ABC", // 蓝牙设备的可读名称(如型号/别名)
|
||||
|
linked: connectId === "abc", //该设备是否已链接
|
||||
|
}, |
||||
|
], |
||||
|
}); |
||||
|
}, 1000); |
||||
|
res.json({ success: true }); |
||||
|
}); |
||||
|
router.post("/list/stop", (req, res) => { |
||||
|
clearInterval(intervalId1); |
||||
|
res.json({ success: true }); |
||||
|
}); |
||||
|
router.post("/connect", (req, res) => { |
||||
|
const id = req.body.id; |
||||
|
connectId = id; |
||||
|
|
||||
|
setTimeout(() => { |
||||
|
WsProxy.sendMobile({ |
||||
|
type: "peripheral-status", |
||||
|
data: { |
||||
|
connected: true, //是否已连接蓝牙
|
||||
|
power: 60, //电量
|
||||
|
inclinatorX: 0.276, //x轴倾斜
|
||||
|
inclinatorY: 3.019, //y轴倾斜
|
||||
|
temperature: 32.026, //温度
|
||||
|
}, |
||||
|
}); |
||||
|
}); |
||||
|
res.json({ success: true }); |
||||
|
}); |
||||
|
router.post("/disconnect", (req, res) => { |
||||
|
connectId = ""; |
||||
|
setTimeout(() => { |
||||
|
WsProxy.sendMobile({ |
||||
|
type: "peripheral-status", |
||||
|
data: { |
||||
|
connected: false, //是否已连接蓝牙
|
||||
|
power: 60, //电量
|
||||
|
inclinatorX: 0.276, //x轴倾斜
|
||||
|
inclinatorY: 3.019, //y轴倾斜
|
||||
|
temperature: 32.026, //温度
|
||||
|
}, |
||||
|
}); |
||||
|
}); |
||||
|
res.json({ success: true }); |
||||
|
}); |
||||
|
|
||||
|
export default router; |
@ -0,0 +1,33 @@ |
|||||
|
import express from "express"; |
||||
|
import * as R from "ramda"; |
||||
|
import { delay, prismaClient } from "../utils/helper"; |
||||
|
const router = express.Router(); |
||||
|
import { WsProxy } from "../utils/wss"; |
||||
|
import { dataList, dataListFlat, dataListFlatMore } from "../utils/constant"; |
||||
|
|
||||
|
const settingObj = { |
||||
|
server: "", |
||||
|
}; |
||||
|
|
||||
|
router.post("/list", (req, res) => { |
||||
|
if (req.body.pageNum === 1) { |
||||
|
res.json({ success: true, data: { list: dataList } }); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
router.post("/detail", (req, res) => { |
||||
|
const id = +req.body.id; |
||||
|
const item = R.flatten(dataList.map(item => item.records)).find(t => t.id === id); |
||||
|
res.json({ |
||||
|
success: true, |
||||
|
data: item || {}, |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
router.post("/delete", (req, res) => { |
||||
|
const ids = req.body.ids; |
||||
|
|
||||
|
res.json({ success: true }); |
||||
|
}); |
||||
|
|
||||
|
export default router; |
@ -0,0 +1,42 @@ |
|||||
|
import express from "express"; |
||||
|
import { delay, prismaClient } from "../utils/helper"; |
||||
|
const router = express.Router(); |
||||
|
import { WsProxy } from "../utils/wss"; |
||||
|
import { dataListFlat, dataListFlatMore } from "../utils/constant"; |
||||
|
|
||||
|
const settingObj = { |
||||
|
server: "", |
||||
|
}; |
||||
|
|
||||
|
router.post("/list", (req, res) => { |
||||
|
if (req.body.pageNum === 1) { |
||||
|
res.json({ success: true, data: { list: dataListFlat } }); |
||||
|
} else { |
||||
|
res.json({ success: true, data: { list: dataListFlatMore } }); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
router.post("/add", (req, res) => { |
||||
|
const ids = req.body.ids; |
||||
|
res.json({ success: true }); |
||||
|
}); |
||||
|
|
||||
|
router.post("/progress", (req, res) => { |
||||
|
res.json({ |
||||
|
success: true, |
||||
|
data: { |
||||
|
remaining: 123, // 剩余未同步数量
|
||||
|
fail: 1, // 同步失败数量
|
||||
|
total: 123, // 总数量
|
||||
|
finish: false, // 是否同步完成(true 表示全部完成)
|
||||
|
}, |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
router.post("/config/save", (req, res) => { |
||||
|
const server = req.body.server; |
||||
|
settingObj.server = server; |
||||
|
res.json({ success: true }); |
||||
|
}); |
||||
|
|
||||
|
export default router; |
@ -0,0 +1,20 @@ |
|||||
|
import express from "express"; |
||||
|
import { delay, prismaClient } from "../utils/helper"; |
||||
|
const router = express.Router(); |
||||
|
import { WsProxy } from "../utils/wss"; |
||||
|
|
||||
|
const settingObj = { |
||||
|
server: "", |
||||
|
}; |
||||
|
|
||||
|
router.post("/config", (req, res) => { |
||||
|
res.json({ success: true, data: settingObj }); |
||||
|
}); |
||||
|
|
||||
|
router.post("/config/save", (req, res) => { |
||||
|
const server = req.body.server; |
||||
|
settingObj.server = server; |
||||
|
res.json({ success: true }); |
||||
|
}); |
||||
|
|
||||
|
export default router; |
@ -0,0 +1,15 @@ |
|||||
|
export type Measurement = { |
||||
|
id: number; |
||||
|
name: string; |
||||
|
railId: number; |
||||
|
bureau: string; |
||||
|
line: string; |
||||
|
section: string; |
||||
|
direction: string; |
||||
|
createAt: string; // Date;
|
||||
|
leftPoints: string; // json: 坐标数组
|
||||
|
rightPoints: string; // json: 坐标数组
|
||||
|
upload: boolean; |
||||
|
syncStatus: 'wait' | 'finish' | 'fail'; |
||||
|
}; |
||||
|
|
@ -0,0 +1,259 @@ |
|||||
|
import { Measurement } from "../types/apiTypes"; |
||||
|
|
||||
|
export const dataListFlat: Measurement[] = [ |
||||
|
{ |
||||
|
id: 1, |
||||
|
name: "测量名称1", |
||||
|
createAt: "2025-03-02 10:20", |
||||
|
line: "京沪线", |
||||
|
section: "A段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 2, |
||||
|
name: "测量名称2", |
||||
|
createAt: "2025-03-02 12:22", |
||||
|
line: "京沪线", |
||||
|
section: "B段", |
||||
|
direction: "下行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 3, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 4, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 5, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 6, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 7, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 8, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 9, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 10, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
]; |
||||
|
|
||||
|
export const dataListFlatMore: Measurement[] = [ |
||||
|
{ |
||||
|
id: 11, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 12, |
||||
|
name: "测量名称3", |
||||
|
createAt: "2025-03-02 12:20", |
||||
|
line: "京沪线", |
||||
|
section: "C段", |
||||
|
direction: "上行", |
||||
|
railId: 2, |
||||
|
leftPoints: "[]", |
||||
|
rightPoints: "[]", |
||||
|
bureau: "北京铁路局", |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
]; |
||||
|
|
||||
|
|
||||
|
export const dataList: Array<{ date: string; records: Measurement[] }> = [ |
||||
|
{ |
||||
|
date: '2025-03-02', |
||||
|
records: [ |
||||
|
{ |
||||
|
id: 1, |
||||
|
name: '测量名称1', |
||||
|
createAt: '2025-03-02 10:20', |
||||
|
line: '京沪线', |
||||
|
section: 'A段', |
||||
|
direction: '上行', |
||||
|
railId: 2, |
||||
|
leftPoints: '[]', |
||||
|
rightPoints: '[]', |
||||
|
bureau: '北京铁路局', |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 2, |
||||
|
name: '测量名称2', |
||||
|
createAt: '2025-03-02 12:22', |
||||
|
line: '京沪线', |
||||
|
section: 'B段', |
||||
|
direction: '下行', |
||||
|
railId: 2, |
||||
|
leftPoints: '[]', |
||||
|
rightPoints: '[]', |
||||
|
bureau: '北京铁路局', |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 3, |
||||
|
name: '测量名称3', |
||||
|
createAt: '2025-03-02 12:20', |
||||
|
line: '京沪线', |
||||
|
section: 'C段', |
||||
|
direction: '上行', |
||||
|
railId: 2, |
||||
|
leftPoints: '[]', |
||||
|
rightPoints: '[]', |
||||
|
bureau: '北京铁路局', |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
], |
||||
|
}, |
||||
|
{ |
||||
|
date: '2025-02-01', |
||||
|
records: [ |
||||
|
{ |
||||
|
id: 4, |
||||
|
name: '测量名称2', |
||||
|
createAt: '2025-03-02 10:20', |
||||
|
line: '京沪线', |
||||
|
section: 'D段', |
||||
|
direction: '下行', |
||||
|
railId: 2, |
||||
|
leftPoints: '[]', |
||||
|
rightPoints: '[]', |
||||
|
bureau: '北京铁路局', |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
{ |
||||
|
id: 5, |
||||
|
name: '测量名称2', |
||||
|
createAt: '2025-03-02 10:20', |
||||
|
line: '京沪线', |
||||
|
section: 'E段', |
||||
|
direction: '下行', |
||||
|
railId: 2, |
||||
|
leftPoints: '[]', |
||||
|
rightPoints: '[]', |
||||
|
bureau: '北京铁路局', |
||||
|
upload: false, |
||||
|
syncStatus: 'finish' |
||||
|
}, |
||||
|
], |
||||
|
}, |
||||
|
]; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue