我的设备加载
This commit is contained in:
parent
f9d9063398
commit
ba20cd182a
19
api/device/device.js
Normal file
19
api/device/device.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @param {Object} params - 查询参数
|
||||
* @param {string} params.appId - 应用ID,默认为1
|
||||
* @param {string} params.userId - 用户ID
|
||||
* @returns {Promise} 返回设备列表数据
|
||||
*/
|
||||
export function getDeviceList(params = {}) {
|
||||
return request({
|
||||
url: '/app/device/list',
|
||||
method: 'GET',
|
||||
params: {
|
||||
appId: '1',
|
||||
...params,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
export const DEV_CONFIG = {
|
||||
// 临时token,用于开发测试
|
||||
TEMP_TOKEN:
|
||||
' eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImVmZmVjZjk4LWUzZWMtNDY4YS04Y2VlLTcyMjUyOTllOGI2OSJ9.4u5ypyRjZCiQr-E02MJ2UQ0dV-PGK-s402Ex7CtAIO_8YDaUoQ0MTmwfFqS2IZenlrB7H5RB80P__U9zXB68Pg',
|
||||
'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImQ4ZWNjNGU3LWE0ZTktNGZlNy04YmI3LWJmOTZhNzI1NWEwOSJ9.uI6rJaSte4Bnk304giU_3KS_AK9EVdscM6WnCRMoz_if1RFeRCcH_egiyfIsJ7C32C4RJ7U-0ySu9Ar0Mr4HRQ',
|
||||
|
||||
// 是否使用临时token
|
||||
USE_TEMP_TOKEN: true,
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import BannerSwiper from '../../components/banner-swiper/banner-swiper.vue'
|
|||
import EquipmentList from '../../components/equipment-list/equipment-list.vue'
|
||||
import { getNewAnnouncement } from '../../api/article/article.js'
|
||||
import { getBannerList } from '../../api/banner/banner.js'
|
||||
import { getDeviceList } from '../../api/device/device.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
|
|
@ -70,24 +71,7 @@ export default {
|
|||
bannerList: [],
|
||||
|
||||
// 设备列表数据
|
||||
equipmentList: [
|
||||
{
|
||||
id: 1,
|
||||
name: '商用节能灶',
|
||||
status: 'normal',
|
||||
startTime: '2025-07-25 13:23:59',
|
||||
endTime: '2026-07-25 13:23:59',
|
||||
image: commonEnum.TEMP2,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: '节能燃烧器',
|
||||
status: 'normal',
|
||||
startTime: '2025-07-25 13:23:59',
|
||||
endTime: '2026-07-25 13:23:59',
|
||||
image: commonEnum.TEMP3,
|
||||
},
|
||||
],
|
||||
equipmentList: [],
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -95,6 +79,7 @@ export default {
|
|||
onLoad() {
|
||||
this.fetchAnnouncement()
|
||||
this.fetchBannerList()
|
||||
this.fetchDeviceList()
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
|
@ -151,6 +136,69 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
// 获取设备列表
|
||||
async fetchDeviceList() {
|
||||
try {
|
||||
const response = await getDeviceList()
|
||||
if (response.code === 200 && response.data && Array.isArray(response.data)) {
|
||||
// 转换设备数据格式
|
||||
const devices = response.data.map(device => {
|
||||
// 根据operationState判断设备状态
|
||||
let status = 'normal'
|
||||
if (device.operationState === '1') {
|
||||
status = 'normal' // 正常
|
||||
} else if (device.operationState === '2') {
|
||||
status = 'expired' // 过期
|
||||
} else if (device.operationState === '3') {
|
||||
status = 'maintenance' // 维护中
|
||||
}
|
||||
|
||||
// 根据onlineState判断在线状态
|
||||
const isOnline = device.onlineState === '1'
|
||||
|
||||
return {
|
||||
id: device.id,
|
||||
name: device.newTypeName || device.typeName || '未知设备',
|
||||
status: status,
|
||||
startTime: device.leaseTime || '',
|
||||
endTime: device.expirationTime || '',
|
||||
image: device.img || commonEnum.TEMP2,
|
||||
mac: device.mac,
|
||||
sn: device.sn,
|
||||
isOnline: isOnline,
|
||||
powerStatus: device.powerStatus,
|
||||
iotExpireTime: device.iotExpireTime
|
||||
}
|
||||
})
|
||||
|
||||
this.equipmentList = devices
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败:', error)
|
||||
// 如果获取失败,使用默认设备数据
|
||||
this.equipmentList = [
|
||||
{
|
||||
id: 'default1',
|
||||
name: '商用节能灶',
|
||||
status: 'normal',
|
||||
startTime: '2025-07-25 13:23:59',
|
||||
endTime: '2026-07-25 13:23:59',
|
||||
image: commonEnum.TEMP2,
|
||||
isOnline: true
|
||||
},
|
||||
{
|
||||
id: 'default2',
|
||||
name: '节能燃烧器',
|
||||
status: 'normal',
|
||||
startTime: '2025-07-25 13:23:59',
|
||||
endTime: '2026-07-25 13:23:59',
|
||||
image: commonEnum.TEMP3,
|
||||
isOnline: true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
// 头部点击事件
|
||||
onLocationClick() {
|
||||
uni.showToast({
|
||||
|
|
@ -196,17 +244,17 @@ export default {
|
|||
|
||||
// 设备点击事件
|
||||
onEquipmentClick(equipment) {
|
||||
uni.showToast({
|
||||
title: `查看${equipment.name}详情`,
|
||||
icon: 'none',
|
||||
// 跳转到设备详情页面,传递设备信息
|
||||
uni.navigateTo({
|
||||
url: `/pages/device-detail/device-detail?id=${equipment.id}&name=${encodeURIComponent(equipment.name)}`
|
||||
})
|
||||
},
|
||||
|
||||
// 续费事件
|
||||
onRenew(equipment) {
|
||||
uni.showToast({
|
||||
title: `正在处理${equipment.name}的续费`,
|
||||
icon: 'none',
|
||||
// 跳转到续费页面,传递设备信息
|
||||
uni.navigateTo({
|
||||
url: `/pages/renew/renew?id=${equipment.id}&name=${encodeURIComponent(equipment.name)}&endTime=${encodeURIComponent(equipment.endTime)}`
|
||||
})
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
// 环境配置
|
||||
const ENV_CONFIG = {
|
||||
develop: {
|
||||
loadingText: '开发环境加载中~',
|
||||
loadingText: '加载中~',
|
||||
loadingTime: 100,
|
||||
},
|
||||
trial: {
|
||||
loadingText: '体验版加载中~',
|
||||
loadingText: '加载中~',
|
||||
loadingTime: 100,
|
||||
},
|
||||
release: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user