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
+97
View File
@@ -0,0 +1,97 @@
// pages/device_management/index.js
const { deviceApi } = require("../../utils/api");
const Toast = require("../../miniprogram_npm/tdesign-miniprogram/toast/index");
Page({
/**
* 页面的初始数据
*/
data: {
devices: [], // 设备列表数据
loading: true, // 加载状态
loadError: false, // 加载错误状态
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
this.fetchDevices();
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 页面显示时也刷新数据
this.fetchDevices();
},
/**
* 获取设备列表数据
*/
async fetchDevices() {
this.setData({
loading: true,
loadError: false,
});
try {
const response = await deviceApi.getDevices();
// 处理设备数据,计算子设备数量
const deviceList = response.data.list || response.data || [];
const formattedDevices = deviceList.map((device) => {
// 计算子设备数量
const subDeviceCount = device.subdevices ? device.subdevices.length : 0;
return {
...device,
subDeviceCount: subDeviceCount,
};
});
this.setData({
devices: formattedDevices,
loading: false,
});
} catch (error) {
this.setData({
loadError: true,
loading: false,
});
}
},
/**
* 查看子设备
*/
viewSubDevices(e) {
const device = e.currentTarget.dataset.device;
wx.navigateTo({
url: `/pages/device_subdevices/index?device_id=${device.id}`
});
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
this.fetchDevices();
setTimeout(() => {
wx.stopPullDownRefresh();
}, 1000);
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
return {
title: "设备管理",
path: "/pages/device_management/index",
};
}
});
+16
View File
@@ -0,0 +1,16 @@
{
"navigationBarTitleText": "设备管理",
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"backgroundColor": "#f7f8fa",
"enablePullDownRefresh": true,
"usingComponents": {
"t-toast": "tdesign-miniprogram/toast/toast",
"t-dialog": "tdesign-miniprogram/dialog/dialog",
"t-skeleton": "tdesign-miniprogram/skeleton/skeleton",
"t-empty": "tdesign-miniprogram/empty/empty",
"t-swipe-cell": "tdesign-miniprogram/swipe-cell/swipe-cell",
"t-fab": "tdesign-miniprogram/fab/fab",
"t-input": "tdesign-miniprogram/input/input"
}
}
+44
View File
@@ -0,0 +1,44 @@
<view class="device-container">
<block wx:if="{{loading}}">
<!-- 加载中骨架屏 -->
<view wx:for="{{5}}" wx:key="index" class="skeleton-item">
<t-skeleton theme="paragraph" loading></t-skeleton>
</view>
</block>
<block wx:elif="{{loadError}}">
<!-- 加载错误提示 -->
<view class="error-container">
<t-empty icon="error-circle" description="加载失败,请下拉刷新重试" />
</view>
</block>
<block wx:elif="{{devices && devices.length > 0}}">
<!-- 设备列表 -->
<view class="device-list">
<block wx:for="{{devices}}" wx:key="id">
<view class="device-card" bindtap="viewSubDevices" data-device="{{item}}">
<view class="device-title">{{item.name}}</view>
<view class="device-info">
<view class="info-item usage">
<text>使用次数: {{item.usage_count || 0}}次</text>
</view>
<!-- 子设备数量显示 -->
<view class="info-item subdevice-count">
<text class="count">子设备: {{item.subDeviceCount}}个</text>
</view>
</view>
<view class="device-id-tag">ID: {{item.id}}</view>
</view>
</block>
</view>
</block>
<block wx:else>
<!-- 空数据提示 -->
<view class="empty-container">
<t-empty icon="device" description="暂无设备数据" />
</view>
</block>
</view>
<!-- Toast 消息提示 -->
<t-toast id="t-toast" />
+154
View File
@@ -0,0 +1,154 @@
/* pages/device_management/index.wxss */
page {
background-color: #f7f8fa;
}
.device-container {
padding: 24rpx 0;
}
/* 骨架屏样式 */
.skeleton-item {
background-color: #fff;
border-radius: 8rpx;
padding: 24rpx;
margin: 16rpx 24rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
}
/* 设备列表样式 */
.device-list {
padding: 0 24rpx;
}
/* 滑动单元格容器 */
.swipe-cell-container {
margin-bottom: 16rpx;
border-radius: 8rpx;
overflow: hidden;
display: block;
}
.device-card {
background-color: #ffffff;
border-radius: 8rpx;
padding: 24rpx;
position: relative;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
width: 100%;
box-sizing: border-box;
}
.device-title {
font-size: 32rpx;
font-weight: 500;
color: #333;
margin-bottom: 16rpx;
padding-right: 100rpx;
}
.device-info {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.info-item {
font-size: 28rpx;
color: #666;
line-height: 1.5;
}
/* 使用次数样式 */
.usage {
margin-top: 8rpx;
}
.usage text {
font-size: 28rpx;
color: #0052d9;
background-color: #eef4ff;
padding: 4rpx 12rpx;
border-radius: 4rpx;
display: inline-block;
}
/* 子设备数量样式 */
.subdevice-count {
margin-top: 8rpx;
}
.subdevice-count .count {
font-size: 28rpx;
color: #06a56c;
background-color: #e8f6f1;
padding: 4rpx 12rpx;
border-radius: 4rpx;
display: inline-block;
}
.device-id-tag {
position: absolute;
top: 24rpx;
right: 24rpx;
font-size: 24rpx;
color: #999;
}
/* 空状态和错误容器 */
.empty-container,
.error-container {
padding: 100rpx 24rpx;
}
/* 侧滑按钮样式 */
.swipe-cell-btn {
height: 100% !important;
width: 120rpx !important;
display: flex !important;
align-items: center !important;
justify-content: center !important;
font-size: 28rpx !important;
}
.edit-btn {
background-color: #0052d9 !important;
color: white !important;
}
.delete-btn {
background-color: #e34d59 !important;
color: white !important;
}
/* 修改TDesign原生样式,确保按钮高度与卡片一致 */
.device-list .t-swipe-cell__right {
height: 100% !important;
display: flex !important;
align-items: stretch !important;
}
/* 对话框内容样式 */
.dialog-content {
padding: 20rpx 0;
}
.t-input {
margin-bottom: 20rpx;
}
/* 悬浮按钮样式 */
.t-fab {
position: fixed !important;
bottom: 120rpx !important;
right: 32rpx !important;
}
/* 对话框内容样式 */
.dialog-content {
padding: 20rpx 0;
}
.t-input {
margin-bottom: 20rpx;
}