Compare commits
2 Commits
e74cbab2bc
...
7561634e99
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7561634e99 | ||
![]() |
5900a8157c |
15
config.js
15
config.js
@ -1,9 +1,18 @@
|
|||||||
|
|
||||||
// 后端接口
|
// 后端接口
|
||||||
export const BASE_API_URL = "https://online.totustec.com/api";
|
export const BASE_API_URL = "https://online.totustec.com/api";
|
||||||
|
|
||||||
|
|
||||||
// 静态数据
|
// 静态数据
|
||||||
export const BASE_IMG_URL = "https://online.totustec.com/upload";
|
export const BASE_IMG_URL = "https://online.totustec.com/upload";
|
||||||
|
export const BASE_STOKECT_URL = "wss://online.totustec.com/webSocket/vue"
|
||||||
|
|
||||||
export const BASE_STOKECT_URL = "wss://online.totustec.com/webSocket/vue"
|
// 打印状态颜色以及对应编号
|
||||||
|
export const DEVICE_STATUS_MAP={
|
||||||
|
0: { color: '#999999', text: '空闲' },
|
||||||
|
1: { color: '#00d195', text: '打印中' },
|
||||||
|
2: { color: '#00abff', text: '准备中' },
|
||||||
|
3: { color: '#FDCB3B', text: '铲件中' },
|
||||||
|
4: { color: '#FDCB3B', text: '暂停' },
|
||||||
|
5: { color: '#4CAF50', text: '打印完成' },
|
||||||
|
6: { color: '#18a2af', text: '报警' },
|
||||||
|
'-1': { color: '#999999', text: '断开' }
|
||||||
|
}
|
||||||
|
@ -24,36 +24,33 @@
|
|||||||
<view class="device_table_area">
|
<view class="device_table_area">
|
||||||
<view class="device_table_top">
|
<view class="device_table_top">
|
||||||
<view class="table_top_item" style="padding-left: 27rpx">机器序号</view>
|
<view class="table_top_item" style="padding-left: 27rpx">机器序号</view>
|
||||||
<view class="table_top_item" style="width: 301rpx">机器描述</view>
|
<view class="table_top_item" style="width: 240rpx">机器描述</view>
|
||||||
<view class="table_top_item" style="width: 200rpx">设备运行状态</view>
|
<view class="table_top_item" style="width: 230rpx">运行状态</view>
|
||||||
|
<view class="table_top_item" style="width: 160rpx">设备控制</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="table_data_warp" v-if="deviceList.length > 0">
|
<view class="table_data_warp" v-if="deviceList.length > 0">
|
||||||
<view class="table_data_item" v-for="(item, index) in deviceList">
|
<view class="table_data_item" v-for="(item, index) in deviceList" :key="item.deviceCode">
|
||||||
<view class="data_display_warp">
|
<view class="data_display_warp">
|
||||||
<view class="data_item_line" style="padding-left: 27rpx">{{ item.deviceCode }}</view>
|
<view class="data_item_line" style="padding-left: 27rpx">{{ item.deviceCode }}</view>
|
||||||
<view class="data_item_line" style="width: 301rpx">{{ item.brand }}</view>
|
<view class="data_item_line" style="width: 240rpx">{{ item.brand }}</view>
|
||||||
<view class="data_item_line" style="width: 200rpx">
|
<view class="data_item_line">
|
||||||
<view class="label_warp" v-if="item.status == 0">
|
<view class="label_warp">
|
||||||
<view class="label_icon"></view>
|
<view
|
||||||
<view class="label_text">空闲</view>
|
class="label_icon"
|
||||||
</view>
|
:style="{ background: getStatusConfig(item.status).color }"
|
||||||
<view class="label_warp" v-if="item.status == 2">
|
></view>
|
||||||
<view class="label_icon" style="background: #00abff"></view>
|
<view
|
||||||
<view class="label_text" style="color: #00abff">准备中</view>
|
class="label_text"
|
||||||
</view>
|
:style="{ color: getStatusConfig(item.status).color }"
|
||||||
<view class="label_warp" v-if="item.status == 1">
|
>
|
||||||
<view class="label_icon" style="background: #00d195"></view>
|
{{ getStatusConfig(item.status).text }}
|
||||||
<view class="label_text" style="color: #00d195">打印中</view>
|
</view>
|
||||||
</view>
|
|
||||||
<view class="label_warp" v-if="item.status == 3">
|
|
||||||
<view class="label_icon" style="background: #FDCB3B"></view>
|
|
||||||
<view class="label_text" style="color: #FDCB3B">铲件中</view>
|
|
||||||
</view>
|
|
||||||
<view class="label_warp" v-if="item.status == -1">
|
|
||||||
<view class="label_icon" style="background: #999999"></view>
|
|
||||||
<view class="label_text" style="color: #999999">断开</view>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="data_item_line" style="width: 160rpx">
|
||||||
|
<button class="device_control_btn" @click="toDeviceControl(item.deviceCode, item.status)">查看
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="data_dline_warp">
|
<view class="data_dline_warp">
|
||||||
@ -74,20 +71,19 @@
|
|||||||
<view style="height: 100rpx"></view>
|
<view style="height: 100rpx"></view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<image class="equipment_control_warp" src="https://online.totustec.com/upload/devicePage/equipment_control_warp.png"
|
<!-- <image class="equipment_control_warp" src="https://online.totustec.com/upload/devicePage/equipment_control_warp.png"-->
|
||||||
@click="toPage('设备控制')">
|
<!-- @click="toPage('设备控制')">-->
|
||||||
</image>
|
<!-- </image>-->
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {
|
import {
|
||||||
BASE_API_URL,
|
BASE_API_URL,
|
||||||
BASE_STOKECT_URL,
|
BASE_STOKECT_URL,DEVICE_STATUS_MAP
|
||||||
BASE_IMG_URL
|
|
||||||
} from "@/config.js";
|
} from "@/config.js";
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data() {
|
||||||
return {
|
return {
|
||||||
title: "Hello",
|
title: "Hello",
|
||||||
statusBarHeight: 0,
|
statusBarHeight: 0,
|
||||||
@ -96,33 +92,30 @@ export default {
|
|||||||
size: 10000,
|
size: 10000,
|
||||||
},
|
},
|
||||||
deviceList: [],
|
deviceList: [],
|
||||||
|
|
||||||
// WebSocket 相关状态
|
// WebSocket 相关状态
|
||||||
socketTask: null, // uni-app 的 WebSocket 任务实例
|
socketTask: null, // uni-app 的 WebSocket 任务实例
|
||||||
isSocketConnected: false, // 连接状态
|
isSocketConnected: false, // 连接状态
|
||||||
reconnectTimer: null, // 重连定时器
|
reconnectTimer: null, // 重连定时器
|
||||||
reconnectInterval: 5000 // 重连间隔(5秒)
|
reconnectInterval: 5000, // 重连间隔(5秒)
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onLoad () {
|
onLoad() {
|
||||||
const systemInfo = wx.getSystemInfoSync();
|
const systemInfo = wx.getSystemInfoSync();
|
||||||
const {
|
const {
|
||||||
statusBarHeight, // 状态栏高度(单位:px)
|
statusBarHeight, // 状态栏高度(单位:px)
|
||||||
} = systemInfo;
|
} = systemInfo;
|
||||||
|
|
||||||
this.statusBarHeight = statusBarHeight;
|
this.statusBarHeight = statusBarHeight;
|
||||||
|
|
||||||
this.connectWebSocket(); // 初始化 WebSocket 连接
|
this.connectWebSocket(); // 初始化 WebSocket 连接
|
||||||
},
|
},
|
||||||
onUnload () {
|
onUnload() {
|
||||||
this.closeWebSocket(); // 页面卸载时关闭连接
|
this.closeWebSocket(); // 页面卸载时关闭连接
|
||||||
},
|
},
|
||||||
onShow () {
|
onShow() {
|
||||||
this.getDeviceList(); // 每次显示页面时调用
|
this.getDeviceList(); // 每次显示页面时调用
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// ---------------------- WebSocket 核心方法 ----------------------
|
// ---------------------- WebSocket 核心方法 ----------------------
|
||||||
connectWebSocket () {
|
connectWebSocket() {
|
||||||
const wsUrl = BASE_STOKECT_URL;
|
const wsUrl = BASE_STOKECT_URL;
|
||||||
// 初始化 WebSocket 连接(使用 uni-app 接口)
|
// 初始化 WebSocket 连接(使用 uni-app 接口)
|
||||||
this.socketTask = uni.connectSocket({
|
this.socketTask = uni.connectSocket({
|
||||||
@ -138,20 +131,17 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
listenSocketMessage() {
|
||||||
listenSocketMessage () {
|
|
||||||
// 监听 WebSocket 消息
|
// 监听 WebSocket 消息
|
||||||
uni.onSocketMessage((event) => {
|
uni.onSocketMessage((event) => {
|
||||||
console.log('event', event);
|
console.log('event', event);
|
||||||
|
|
||||||
const message = JSON.parse(event.data);
|
const message = JSON.parse(event.data);
|
||||||
console.log('收到实时消息:', message);
|
console.log('收到实时消息:', message);
|
||||||
this.getDeviceList();
|
this.getDeviceList();
|
||||||
// this.updateDeviceStatus(message); // 更新设备状态
|
// this.updateDeviceStatus(message); // 更新设备状态
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
closeWebSocket() {
|
||||||
closeWebSocket () {
|
|
||||||
// 关闭连接并清理资源
|
// 关闭连接并清理资源
|
||||||
if (this.socketTask) {
|
if (this.socketTask) {
|
||||||
uni.closeSocket();
|
uni.closeSocket();
|
||||||
@ -160,8 +150,7 @@ export default {
|
|||||||
}
|
}
|
||||||
clearTimeout(this.reconnectTimer);
|
clearTimeout(this.reconnectTimer);
|
||||||
},
|
},
|
||||||
|
tryReconnect() {
|
||||||
tryReconnect () {
|
|
||||||
// 自动重连机制
|
// 自动重连机制
|
||||||
clearTimeout(this.reconnectTimer);
|
clearTimeout(this.reconnectTimer);
|
||||||
this.reconnectTimer = setTimeout(() => {
|
this.reconnectTimer = setTimeout(() => {
|
||||||
@ -169,14 +158,10 @@ export default {
|
|||||||
this.connectWebSocket();
|
this.connectWebSocket();
|
||||||
}, this.reconnectInterval);
|
}, this.reconnectInterval);
|
||||||
},
|
},
|
||||||
|
updateDeviceStatus(message) {
|
||||||
updateDeviceStatus (message) {
|
|
||||||
console.log('实时消息');
|
console.log('实时消息');
|
||||||
|
|
||||||
},
|
},
|
||||||
|
toPage(type) {
|
||||||
|
|
||||||
toPage (type) {
|
|
||||||
if (type == "设备控制") {
|
if (type == "设备控制") {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/selectDevice/index",
|
url: "/pages/selectDevice/index",
|
||||||
@ -188,8 +173,20 @@ export default {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
toDeviceControl(deviceCode, status) {
|
||||||
async getDeviceList () {
|
if (status === -1) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '设备处于断开状态,暂不支持查看',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log("data", deviceCode);
|
||||||
|
uni.navigateTo({
|
||||||
|
url: `/pages/deviceManage/index?deviceCode=${deviceCode}`
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async getDeviceList() {
|
||||||
try {
|
try {
|
||||||
// 从本地缓存获取用户信息
|
// 从本地缓存获取用户信息
|
||||||
const userInfo = uni.getStorageSync("userInfo") || {};
|
const userInfo = uni.getStorageSync("userInfo") || {};
|
||||||
@ -210,13 +207,15 @@ export default {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('请求接口失败', error);
|
console.log('请求接口失败', error);
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getStatusConfig(status) {
|
||||||
|
return DEVICE_STATUS_MAP[status] || { color: '#cccccc', text: '未知' };
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<!-- 临时样式 -->
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.label_icon {
|
.label_icon {
|
||||||
width: 18rpx;
|
width: 18rpx;
|
||||||
@ -224,7 +223,6 @@ export default {
|
|||||||
background: #cccccc;
|
background: #cccccc;
|
||||||
border-radius: 100%;
|
border-radius: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.label_text {
|
.label_text {
|
||||||
font-family: PingFang SC, PingFang SC;
|
font-family: PingFang SC, PingFang SC;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
@ -233,19 +231,9 @@ export default {
|
|||||||
margin-left: 8rpx;
|
margin-left: 8rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.label_text2 {
|
|
||||||
color: #ff0000;
|
|
||||||
}
|
|
||||||
|
|
||||||
.label_warp {
|
.label_warp {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-left: 48rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.label_warp2 {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.data_item_line {
|
.data_item_line {
|
||||||
@ -451,4 +439,18 @@ export default {
|
|||||||
margin-top: -28rpx;
|
margin-top: -28rpx;
|
||||||
padding-top: 28rpx;
|
padding-top: 28rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.device_control_btn {
|
||||||
|
width: 114rpx;
|
||||||
|
height: 48rpx;
|
||||||
|
background: #f2c141;
|
||||||
|
border-radius: 24rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
font-family: PingFang SC, PingFang SC;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -129,7 +129,6 @@ export default {
|
|||||||
"Authorization": uni.getStorageSync("userInfo")?.token || ""
|
"Authorization": uni.getStorageSync("userInfo")?.token || ""
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
content: res.data.message, // 直接显示完整文本
|
content: res.data.message, // 直接显示完整文本
|
||||||
@ -139,16 +138,16 @@ export default {
|
|||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "绑定成功",
|
title: "绑定成功",
|
||||||
icon: "success", // 可选,增加成功图标
|
icon: "success",
|
||||||
duration: 1500 // 1.5秒后自动关闭
|
duration: 1500,
|
||||||
|
success: () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.switchTab({
|
||||||
|
url: "/pages/device/index"
|
||||||
|
});
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 1.5秒后跳转到设备页面
|
|
||||||
setTimeout(() => {
|
|
||||||
uni.navigateTo({
|
|
||||||
url: "/pages/device/index"
|
|
||||||
});
|
|
||||||
}, 1500);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("设备绑定失败:", error);
|
console.error("设备绑定失败:", error);
|
||||||
|
@ -32,11 +32,26 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 媒体内容 -->
|
<!-- 媒体内容 -->
|
||||||
<video class="img_video_warp" :src="socketData.videoUrl" v-if="socketData.videoUrl"
|
<video
|
||||||
@loadedmetadata="handleMediaLoaded" @error="handleMediaError"></video>
|
class="img_video_warp"
|
||||||
<image class="img_video_warp" :src="socketData.imageUrl" v-else-if="socketData.imageUrl"
|
:src="socketData.videoUrl"
|
||||||
@load="handleMediaLoaded" @error="handleMediaError"></image>
|
v-if="socketData.videoUrl"
|
||||||
<image class="img_video_warp" :src="TOPBG" v-else mode="aspectFill" />
|
@loadedmetadata="handleMediaLoaded"
|
||||||
|
@error="handleMediaError"
|
||||||
|
></video>
|
||||||
|
<image
|
||||||
|
class="img_video_warp"
|
||||||
|
:src="socketData.imageUrl"
|
||||||
|
v-else-if="socketData.imageUrl"
|
||||||
|
@load="handleMediaLoaded"
|
||||||
|
@error="handleMediaError"
|
||||||
|
></image>
|
||||||
|
<image
|
||||||
|
class="img_video_warp"
|
||||||
|
:src="TOPBG"
|
||||||
|
v-else
|
||||||
|
mode="aspectFill"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 设备状态选择 -->
|
<!-- 设备状态选择 -->
|
||||||
@ -234,7 +249,7 @@ import {
|
|||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
TOPBG: BASE_IMG_URL + "/minePage/top.jpg",
|
TOPBG:BASE_IMG_URL + "/minePage/top.jpg",
|
||||||
isMediaLoading: false,
|
isMediaLoading: false,
|
||||||
deviceName: "",
|
deviceName: "",
|
||||||
title: "Hello",
|
title: "Hello",
|
||||||
|
@ -323,10 +323,7 @@ export default {
|
|||||||
const {
|
const {
|
||||||
statusBarHeight, // 状态栏高度(单位:px)
|
statusBarHeight, // 状态栏高度(单位:px)
|
||||||
} = systemInfo;
|
} = systemInfo;
|
||||||
|
|
||||||
this.statusBarHeight = statusBarHeight;
|
this.statusBarHeight = statusBarHeight;
|
||||||
|
|
||||||
|
|
||||||
this.connectWebSocket(); // 初始化 WebSocket 连接
|
this.connectWebSocket(); // 初始化 WebSocket 连接
|
||||||
},
|
},
|
||||||
onShow () {
|
onShow () {
|
||||||
@ -388,11 +385,7 @@ export default {
|
|||||||
|
|
||||||
updateDeviceStatus (message) {
|
updateDeviceStatus (message) {
|
||||||
console.log('实时消息');
|
console.log('实时消息');
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 获取状态文字
|
// 获取状态文字
|
||||||
getStatusText (status) {
|
getStatusText (status) {
|
||||||
if (status == -1) {
|
if (status == -1) {
|
||||||
|
@ -120,8 +120,8 @@ export default {
|
|||||||
},
|
},
|
||||||
toPage (pageName) {
|
toPage (pageName) {
|
||||||
if (pageName == "设备管理") {
|
if (pageName == "设备管理") {
|
||||||
uni.navigateTo({
|
uni.switchTab({
|
||||||
url: "/pages/selectDevice/index",
|
url: "/pages/device/index"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user