first commit

This commit is contained in:
chz
2026-01-15 15:05:29 +08:00
commit 0ec405e137
66 changed files with 8572 additions and 0 deletions
+123
View File
@@ -0,0 +1,123 @@
// pages/device_status/index.js
const { deviceApi } = require("../../utils/api");
Page({
/**
* 页面的初始数据
*/
data: {
devices: [],
statusMap: {
0: "空闲",
1: "使用中",
2: "维修中",
},
loading: true, // 添加加载状态
activeDevices: [], // 当前展开的设备面板,空数组表示全部收起
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 检查用户是否已登录
const app = getApp();
if (app.globalData.token) {
// 已登录用户,跳转到设备管理页面
wx.redirectTo({
url: '/pages/device_management/index',
});
return;
}
this.fetchDeviceStatus();
},
/**
* 获取设备状态数据
*/
fetchDeviceStatus() {
const that = this;
// 保存当前展开状态
const currentActiveDevices = this.data.activeDevices || [];
// 显示加载中
that.setData({ loading: true });
deviceApi
.getDeviceStatus()
.then((response) => {
// 处理API响应格式,获取设备数组
const devices = response.data || [];
// 处理设备状态的显示文本
devices.forEach((device) => {
if (device.sub_devices && device.sub_devices.length) {
device.sub_devices.forEach((subDevice) => {
subDevice.statusText = that.data.statusMap[subDevice.status] || subDevice.status;
});
}
});
// 保持之前的展开状态
that.setData({
devices,
activeDevices: currentActiveDevices, // 保持之前的展开状态
loading: false,
});
})
.catch((err) => {
wx.showToast({
title: "获取设备状态失败",
icon: "error",
});
})
.finally(() => {
// 停止下拉刷新动画
wx.stopPullDownRefresh();
that.setData({ loading: false });
});
},
/**
* 处理折叠面板展开/收起事件
*/
handleCollapseChange(e) {
this.setData({
activeDevices: e.detail.value,
});
},
/**
* 跳转到保养记录页面
*/
goToMaintenancePage(e) {
const subDeviceId = e.currentTarget.dataset.subDeviceId;
wx.navigateTo({
url: `/pages/device_maintenance/index?sub_device_id=${subDeviceId}`,
});
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
this.fetchDeviceStatus();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
return {
title: "设备状态监控",
path: "/pages/device_status/index",
};
},
});
+15
View File
@@ -0,0 +1,15 @@
{
"navigationBarTitleText": "设备状态监控",
"enablePullDownRefresh": true,
"backgroundColor": "#f6f6f6",
"usingComponents": {
"t-cell": "tdesign-miniprogram/cell/cell",
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group",
"t-navbar": "tdesign-miniprogram/navbar/navbar",
"t-tag": "tdesign-miniprogram/tag/tag",
"t-icon": "tdesign-miniprogram/icon/icon",
"t-empty": "tdesign-miniprogram/empty/empty",
"t-collapse": "tdesign-miniprogram/collapse/collapse",
"t-collapse-panel": "tdesign-miniprogram/collapse-panel/collapse-panel"
}
}
+52
View File
@@ -0,0 +1,52 @@
<view class="device-page">
<view class="device-container">
<!-- 设备列表 -->
<block wx:if="{{devices.length > 0}}">
<t-collapse value="{{activeDevices}}" expandMutex="{{false}}" bind:change="handleCollapseChange">
<t-collapse-panel
wx:for="{{devices}}"
wx:key="device_id"
wx:for-item="device"
value="{{index}}"
header="{{device.device_name}}"
header-right-content="{{device.sub_devices.length || 0}}个子设备"
t-class="device-panel">
<!-- 设备图标 -->
<view slot="header-icon" class="device-icon">
<t-icon name="device" size="48rpx" />
</view>
<!-- 子设备列表 -->
<block wx:if="{{device.sub_devices && device.sub_devices.length > 0}}">
<t-cell
wx:for="{{device.sub_devices}}"
wx:key="id"
wx:for-item="subDevice"
title="{{device.device_name}}-{{subDevice.name}}"
description="子设备"
hover
t-class="sub-device-cell"
bordered>
<!-- 状态标签和保养记录按钮 -->
<view slot="note" class="note-container">
<t-tag
theme="{{subDevice.status === 0 ? 'success' : (subDevice.status === 1 ? 'primary' : 'warning')}}"
variant="light"
size="small">
{{subDevice.statusText}}
</t-tag>
</view>
</t-cell>
</block>
<!-- 无子设备时的提示 -->
<t-empty wx:else description="暂无子设备" />
</t-collapse-panel>
</t-collapse>
</block>
<!-- 无设备时的提示 -->
<t-empty wx:else icon="device" description="暂无设备数据" />
</view>
</view>
+48
View File
@@ -0,0 +1,48 @@
/* pages/device_status/index.wxss */
.device-page {
min-height: 100vh;
background-color: #f6f6f6;
}
.device-container {
padding: 24rpx;
}
.device-panel {
margin-bottom: 24rpx;
border-radius: 12rpx;
overflow: hidden;
background-color: #fff;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
}
.device-icon {
display: flex;
align-items: center;
margin-right: 16rpx;
color: #0052d9;
}
.sub-device-cell {
padding: 20rpx 32rpx;
}
.status-tag-container {
display: flex;
align-items: center;
justify-content: flex-end;
}
/* 适配不同状态的标签样式 */
.t-tag--success {
color: #07c160 !important;
}
.t-tag--primary {
color: #0052d9 !important;
}
.t-tag--warning {
color: #ff9702 !important;
}