162 lines
3.3 KiB
JavaScript
162 lines
3.3 KiB
JavaScript
|
|
// pages/index/index.js
|
||
|
|
Page({
|
||
|
|
data: {
|
||
|
|
totalDevices: 0,
|
||
|
|
warningDevices: 0,
|
||
|
|
expiredDevices: 0,
|
||
|
|
warningList: [],
|
||
|
|
recentList: []
|
||
|
|
},
|
||
|
|
|
||
|
|
onLoad() {
|
||
|
|
this.loadData();
|
||
|
|
},
|
||
|
|
|
||
|
|
onShow() {
|
||
|
|
// 每次显示页面时刷新数据
|
||
|
|
this.loadData();
|
||
|
|
},
|
||
|
|
|
||
|
|
// 加载数据
|
||
|
|
loadData() {
|
||
|
|
// TODO: 从后端或本地存储加载数据
|
||
|
|
// 这里先使用模拟数据
|
||
|
|
const mockData = this.getMockData();
|
||
|
|
|
||
|
|
this.setData({
|
||
|
|
totalDevices: mockData.totalDevices,
|
||
|
|
warningDevices: mockData.warningDevices,
|
||
|
|
expiredDevices: mockData.expiredDevices,
|
||
|
|
warningList: mockData.warningList.slice(0, 3), // 只显示前3条
|
||
|
|
recentList: mockData.recentList.slice(0, 5) // 只显示前5条
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
// 模拟数据
|
||
|
|
getMockData() {
|
||
|
|
return {
|
||
|
|
totalDevices: 156,
|
||
|
|
warningDevices: 12,
|
||
|
|
expiredDevices: 3,
|
||
|
|
warningList: [
|
||
|
|
{
|
||
|
|
id: '1',
|
||
|
|
deviceName: '绝缘手套',
|
||
|
|
deviceCode: 'SB-2023-001',
|
||
|
|
useUnit: '施工一队',
|
||
|
|
daysLeft: 7,
|
||
|
|
warningLevel: '紧急'
|
||
|
|
},
|
||
|
|
{
|
||
|
|
id: '2',
|
||
|
|
deviceName: '安全帽',
|
||
|
|
deviceCode: 'SB-2023-015',
|
||
|
|
useUnit: '施工二队',
|
||
|
|
daysLeft: 15,
|
||
|
|
warningLevel: '预警'
|
||
|
|
},
|
||
|
|
{
|
||
|
|
id: '3',
|
||
|
|
deviceName: '安全带',
|
||
|
|
deviceCode: 'SB-2023-028',
|
||
|
|
useUnit: '施工三队',
|
||
|
|
daysLeft: 20,
|
||
|
|
warningLevel: '提醒'
|
||
|
|
}
|
||
|
|
],
|
||
|
|
recentList: [
|
||
|
|
{
|
||
|
|
id: '1',
|
||
|
|
deviceId: '1',
|
||
|
|
deviceName: '绝缘手套',
|
||
|
|
operation: '查看详情',
|
||
|
|
time: '2分钟前',
|
||
|
|
icon: 'view-list'
|
||
|
|
},
|
||
|
|
{
|
||
|
|
id: '2',
|
||
|
|
deviceId: '2',
|
||
|
|
deviceName: '安全帽',
|
||
|
|
operation: '更新检验日期',
|
||
|
|
time: '1小时前',
|
||
|
|
icon: 'edit'
|
||
|
|
},
|
||
|
|
{
|
||
|
|
id: '3',
|
||
|
|
deviceId: '3',
|
||
|
|
deviceName: '安全带',
|
||
|
|
operation: '添加设备',
|
||
|
|
time: '3小时前',
|
||
|
|
icon: 'add'
|
||
|
|
}
|
||
|
|
]
|
||
|
|
};
|
||
|
|
},
|
||
|
|
|
||
|
|
// 跳转到预警列表
|
||
|
|
goToWarning() {
|
||
|
|
wx.switchTab({
|
||
|
|
url: '/pages/warning/list/list'
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
// 跳转到设备详情
|
||
|
|
goToDeviceDetail(e) {
|
||
|
|
const id = e.currentTarget.dataset.id;
|
||
|
|
wx.navigateTo({
|
||
|
|
url: `/pages/device/detail/detail?id=${id}`
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
// 跳转到设备列表
|
||
|
|
goToDeviceList() {
|
||
|
|
wx.switchTab({
|
||
|
|
url: '/pages/device/list/list'
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
// 跳转到添加设备
|
||
|
|
goToAddDevice() {
|
||
|
|
wx.navigateTo({
|
||
|
|
url: '/pages/device/add/add'
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
// 跳转到统计分析
|
||
|
|
goToStatistics() {
|
||
|
|
wx.switchTab({
|
||
|
|
url: '/pages/statistics/index/index'
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
// 扫码查询
|
||
|
|
scanCode() {
|
||
|
|
wx.scanCode({
|
||
|
|
success: (res) => {
|
||
|
|
console.log('扫码结果:', res);
|
||
|
|
// TODO: 根据扫码结果查询设备
|
||
|
|
wx.showToast({
|
||
|
|
title: '扫码成功',
|
||
|
|
icon: 'success'
|
||
|
|
});
|
||
|
|
},
|
||
|
|
fail: (err) => {
|
||
|
|
console.error('扫码失败:', err);
|
||
|
|
wx.showToast({
|
||
|
|
title: '扫码失败',
|
||
|
|
icon: 'none'
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
// 下拉刷新
|
||
|
|
onPullDownRefresh() {
|
||
|
|
this.loadData();
|
||
|
|
setTimeout(() => {
|
||
|
|
wx.stopPullDownRefresh();
|
||
|
|
}, 1000);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|