From 30fe13dac2c264d83822ae6a99223291fcf53bd3 Mon Sep 17 00:00:00 2001
From: 18796357645 <674126018@qq.com>
Date: Sat, 19 Jul 2025 18:39:37 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=8B=E5=A5=BD=E6=8F=90?=
=?UTF-8?q?=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/deviceBind/index.vue | 18 ++-
pages/deviceManage/index.vue | 283 +++++++++++++++++++----------------
2 files changed, 169 insertions(+), 132 deletions(-)
diff --git a/pages/deviceBind/index.vue b/pages/deviceBind/index.vue
index 64961fc..4a0a648 100644
--- a/pages/deviceBind/index.vue
+++ b/pages/deviceBind/index.vue
@@ -136,10 +136,20 @@ export default {
showCancel: false // 不显示取消按钮(可选)
});
// console.log('res', res);
-
- if (res.statusCode === 200) {
- uni.showToast({ title: "绑定成功" });
- }
+ if (res.statusCode === 200) {
+ uni.showToast({
+ title: "绑定成功",
+ icon: "success", // 可选,增加成功图标
+ duration: 1500 // 1.5秒后自动关闭
+ });
+
+ // 1.5秒后跳转到设备页面
+ setTimeout(() => {
+ uni.navigateTo({
+ url: "/pages/device/index"
+ });
+ }, 1500);
+ }
} catch (error) {
console.error("设备绑定失败:", error);
uni.showToast({ title: "设备绑定失败", icon: "none" });
diff --git a/pages/deviceManage/index.vue b/pages/deviceManage/index.vue
index e198533..32d53cf 100644
--- a/pages/deviceManage/index.vue
+++ b/pages/deviceManage/index.vue
@@ -16,7 +16,7 @@
+ @click="getVideoImg('video')">
获取视频
@@ -24,11 +24,6 @@
-
-
-
-
@@ -38,23 +33,23 @@
+ @loadedmetadata="isMediaLoading = false" @error="isMediaLoading = false">
+ @error="isMediaLoading = false">
设备状态
+ @click="deviceType = 1">设备状态
设备日志
+ @click="deviceType = 2">设备日志
设备控制
+ @click="deviceType = 3">设备控制
@@ -66,21 +61,21 @@
{{ field.label }}
-
-
+
空闲
-
-
- 准备中
-
打印中
+
+
+ 准备中
+
+
铲件中
@@ -94,10 +89,9 @@
-
-
-
- {{ getStatusText2(deviceDetail.printStatus) }}
+
+
+ {{ getStatusText2(printInfo.status) }}
@@ -111,10 +105,10 @@
{{ getCurrentTime() }}
-
-
- {{ deviceDetail[field.key] }}
-
+
+
+ {{ deviceDetail[field.key] }}
+
@@ -124,7 +118,7 @@
-
+
@@ -141,68 +135,77 @@
-
-
-
-
- 暂无日志数据
-
-
-
-
-
+
+
+
+
+ 暂无日志数据
+
+
+
+
+
打印文件名称:
-
+
+ src="https://online.totustec.com/upload/deviceManage/clear_deviceN_icon.png">
文件位置:桌面File文件夹内
-
-
-
- 开始打印
+
+
+
+ 开始打印
-
+
+
- 继续打印
+ 继续打印
-
+
-
- 暂停打印
+ 暂停打印
- 退出打印
+ 退出打印
+
@@ -238,7 +248,7 @@ import {
} from "@/config.js";
export default {
- data () {
+ data() {
return {
isMediaLoading: false,
deviceName: "",
@@ -357,7 +367,7 @@ export default {
label: '错误码',
key: 'errorStatus',
isErrorCode: true,
- },
+ },
{
label: '当前时间',
@@ -403,7 +413,7 @@ export default {
socketData: {},
};
},
- onLoad (options) {
+ onLoad(options) {
const systemInfo = wx.getSystemInfoSync();
const {
statusBarHeight, // 状态栏高度(单位:px)
@@ -421,12 +431,15 @@ export default {
this.connectWebSocket(); // 初始化 WebSocket 连接
},
- onUnload () {
+ onUnload() {
this.closeWebSocket(); // 页面卸载时关闭连接
},
methods: {
+
+
+
// ---------------------- WebSocket 核心方法 ----------------------
- connectWebSocket () {
+ connectWebSocket() {
const wsUrl = BASE_STOKECT_URL;
// 初始化 WebSocket 连接(使用 uni-app 接口)
@@ -444,7 +457,7 @@ export default {
});
},
- listenSocketMessage () {
+ listenSocketMessage() {
// 监听 WebSocket 消息
uni.onSocketMessage((event) => {
console.log("event", event);
@@ -455,7 +468,7 @@ export default {
});
},
- closeWebSocket () {
+ closeWebSocket() {
// 关闭连接并清理资源
if (this.socketTask) {
uni.closeSocket();
@@ -465,7 +478,7 @@ export default {
clearTimeout(this.reconnectTimer);
},
- tryReconnect () {
+ tryReconnect() {
// 自动重连机制
clearTimeout(this.reconnectTimer);
this.reconnectTimer = setTimeout(() => {
@@ -474,7 +487,7 @@ export default {
}, this.reconnectInterval);
},
- updateDeviceStatus (message) {
+ updateDeviceStatus(message) {
console.log("实时消息", message);
// CLOSE、STATUS 你那就刷新接口就行
if (message.msgType == "CLOSE" || message.msgType == "STATUS") {
@@ -493,7 +506,7 @@ export default {
this.socketData = message.data;
if (this.socketData.imageUrl) {
this.socketData.imageUrl =
- BASE_IMG_URL + message.data.imageUrl;
+ BASE_IMG_URL + message.data.imageUrl;
}
}
// WRITEIMG 接收图片数据中
@@ -510,7 +523,7 @@ export default {
* 发送 WebSocket 指令
* @param {string} command - 指令值(如 PAUSE、CONTINUE 等)
*/
- sendWsCommand (command) {
+ sendWsCommand(command) {
if (!this.isSocketConnected) {
console.warn("WebSocket 未连接,无法发送指令");
return;
@@ -532,18 +545,18 @@ export default {
// 发送消息(使用 uni-app 的 sendSocketMessage)
uni
- .sendSocketMessage({
- data: JSON.stringify(message),
- })
- .then(() => {
- console.log("指令发送成功:", message);
- })
- .catch((err) => {
- console.error("指令发送失败:", err);
- });
+ .sendSocketMessage({
+ data: JSON.stringify(message),
+ })
+ .then(() => {
+ console.log("指令发送成功:", message);
+ })
+ .catch((err) => {
+ console.error("指令发送失败:", err);
+ });
},
- operationData (type) {
+ operationData(type) {
if (type == "PRINT") {
// 检查设备名称是否为空
if (!this.deviceName || this.deviceName.trim() === '') {
@@ -554,7 +567,6 @@ export default {
});
return;
}
-
// 检查设备状态
if (this.deviceDetail.status == 0 && this.deviceDetail.status != -1) {
// 显示确认提示框
@@ -572,19 +584,30 @@ export default {
});
}
}
- if (type == "CONTINUE") {
- if (
- this.deviceDetail.status != 0 &&
- this.deviceDetail.status != 1 &&
- this.deviceDetail.printStatus != 6 &&
- this.deviceDetail.status != -1
- ) {
- this.sendWsCommand(type);
+ if (type === "CONTINUE") {
+ // 检查设备状态
+ if (this.deviceDetail.status === 0) {
+ uni.showToast({
+ title: "当前设备空闲,禁止继续打印",
+ icon: "none",
+ duration: 1500
+ });
+ console.log("设备未就绪,禁止继续打印");
+ return;
}
+ if (this.printInfo.status !== 6) {
+ uni.showToast({
+ title: "当前设备未暂定,禁止继续打印",
+ icon: "none",
+ duration: 1500
+ });
+ return;
+ }
+
+ this.sendWsCommand(type);
}
if (type == 'PAUSE') {
- if ((this.deviceDetail.status == 1 || this.deviceDetail.status == 2) && this.deviceDetail.status != -
- 1) {
+ if ((this.deviceDetail.status == 1 || this.deviceDetail.status == 2 || this.printInfo.status == 3) && this.deviceDetail.status != -1) {
uni.showModal({
title: '提示',
content: '确定要暂停打印吗?',
@@ -614,7 +637,7 @@ export default {
}
}
},
- getVideoImg (type) {
+ getVideoImg(type) {
this.isMediaLoading = true;
if (type == "img") {
this.getType = "img";
@@ -625,39 +648,41 @@ export default {
}
},
// 获取状态文字
- getStatusText (status) {
+ getStatusText(status) {
if (status == -1) {
return "断开";
}
return this.statusMap[status]?.text || "";
},
- getStatusText2 (status) {
- if (status == -1) {
+ getStatusText2(status) {
+ //如果状态为-1就算断开
+ if (status === -1) {
return "断开";
}
return this.childStatusMap[status]?.text || "";
},
// 获取状态颜色
- getStatusColor (status) {
+ getStatusColor(status) {
if (status == -1) {
return "#999999";
}
return this.childStatusMap[status]?.color; // 默认灰色
},
- getCurrentTime () {
+ getCurrentTime() {
const date = new Date();
const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, "0");
- const day = String(date.getDate()).padStart(2, "0");
- const hours = String(date.getHours()).padStart(2, "0");
- const minutes = String(date.getMinutes()).padStart(2, "0");
-
- return `${year}年${month}月${day}日${hours}时${minutes}分`;
+ const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份补零
+ const day = String(date.getDate()).padStart(2, "0"); // 日期补零
+ const hours = String(date.getHours()).padStart(2, "0"); // 小时补零
+ const minutes = String(date.getMinutes()).padStart(2, "0"); // 分钟补零
+ const seconds = String(date.getSeconds()).padStart(2, "0"); // 新增:秒补零
+ // 格式:YYYY.MM.DD HH:MM:SS
+ return `${year}.${month}.${day} ${hours}:${minutes}:${seconds}`;
},
- goBack () {
+ goBack() {
uni.navigateBack();
},
- async getDeviceDetail () {
+ async getDeviceDetail() {
try {
const res = await uni.request({
url: BASE_API_URL + '/api/front/device/get',
@@ -675,24 +700,24 @@ export default {
this.deviceDetail = res.data;
this.printInfo = res.data.printInfo;
console.log("设备详情:", this.deviceDetail);
- //判断状态是否为断开
- // 判断状态是否为断开
- if (res.data.status == -1) {
- uni.showToast({
- title: '设备处于断开状态,暂不支持查看',
- icon: 'none',
- duration: 2000, // 提示显示时长
- complete: () => {
- // 提示显示完成后跳转
- setTimeout(() => {
- uni.reLaunch({
- url: '/pages/index/index'
- });
- }, 1500); // 稍微延迟一点确保用户看到提示
- }
- });
- return;
- }
+ //判断状态是否为断开
+ // 判断状态是否为断开
+ if (res.data.status == -1) {
+ uni.showToast({
+ title: '设备处于断开状态,暂不支持查看',
+ icon: 'none',
+ duration: 2000, // 提示显示时长
+ complete: () => {
+ // 提示显示完成后跳转
+ setTimeout(() => {
+ uni.reLaunch({
+ url: '/pages/index/index'
+ });
+ }, 1500); // 稍微延迟一点确保用户看到提示
+ }
+ });
+ return;
+ }
}
} catch (error) {
console.error("获取设备详情失败:", error);
@@ -702,7 +727,7 @@ export default {
});
}
},
- onDeviceNameInput (e) {
+ onDeviceNameInput(e) {
this.deviceName = e.detail.value;
// console.log('输入内容:', e.detail.value);
},
@@ -810,6 +835,8 @@ export default {
display: flex;
justify-content: center;
align-items: center;
+ border: 2rpx solid #cccccc;
+ color: #cccccc;
}
.device_operation_warp {