我的设备加载

This commit is contained in:
WindowBird 2025-08-19 08:55:34 +08:00
parent f9d9063398
commit ba20cd182a
4 changed files with 94 additions and 27 deletions

19
api/device/device.js Normal file
View 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,
},
})
}

View File

@ -2,7 +2,7 @@
export const DEV_CONFIG = { export const DEV_CONFIG = {
// 临时token用于开发测试 // 临时token用于开发测试
TEMP_TOKEN: TEMP_TOKEN:
' eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImVmZmVjZjk4LWUzZWMtNDY4YS04Y2VlLTcyMjUyOTllOGI2OSJ9.4u5ypyRjZCiQr-E02MJ2UQ0dV-PGK-s402Ex7CtAIO_8YDaUoQ0MTmwfFqS2IZenlrB7H5RB80P__U9zXB68Pg', 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImQ4ZWNjNGU3LWE0ZTktNGZlNy04YmI3LWJmOTZhNzI1NWEwOSJ9.uI6rJaSte4Bnk304giU_3KS_AK9EVdscM6WnCRMoz_if1RFeRCcH_egiyfIsJ7C32C4RJ7U-0ySu9Ar0Mr4HRQ',
// 是否使用临时token // 是否使用临时token
USE_TEMP_TOKEN: true, USE_TEMP_TOKEN: true,

View File

@ -41,6 +41,7 @@ import BannerSwiper from '../../components/banner-swiper/banner-swiper.vue'
import EquipmentList from '../../components/equipment-list/equipment-list.vue' import EquipmentList from '../../components/equipment-list/equipment-list.vue'
import { getNewAnnouncement } from '../../api/article/article.js' import { getNewAnnouncement } from '../../api/article/article.js'
import { getBannerList } from '../../api/banner/banner.js' import { getBannerList } from '../../api/banner/banner.js'
import { getDeviceList } from '../../api/device/device.js'
export default { export default {
components: { components: {
@ -70,24 +71,7 @@ export default {
bannerList: [], bannerList: [],
// //
equipmentList: [ 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,
},
],
} }
}, },
@ -95,6 +79,7 @@ export default {
onLoad() { onLoad() {
this.fetchAnnouncement() this.fetchAnnouncement()
this.fetchBannerList() this.fetchBannerList()
this.fetchDeviceList()
}, },
methods: { 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() { onLocationClick() {
uni.showToast({ uni.showToast({
@ -196,17 +244,17 @@ export default {
// //
onEquipmentClick(equipment) { onEquipmentClick(equipment) {
uni.showToast({ //
title: `查看${equipment.name}详情`, uni.navigateTo({
icon: 'none', url: `/pages/device-detail/device-detail?id=${equipment.id}&name=${encodeURIComponent(equipment.name)}`
}) })
}, },
// //
onRenew(equipment) { onRenew(equipment) {
uni.showToast({ //
title: `正在处理${equipment.name}的续费`, uni.navigateTo({
icon: 'none', url: `/pages/renew/renew?id=${equipment.id}&name=${encodeURIComponent(equipment.name)}&endTime=${encodeURIComponent(equipment.endTime)}`
}) })
}, },

View File

@ -6,11 +6,11 @@
// 环境配置 // 环境配置
const ENV_CONFIG = { const ENV_CONFIG = {
develop: { develop: {
loadingText: '开发环境加载中~', loadingText: '加载中~',
loadingTime: 100, loadingTime: 100,
}, },
trial: { trial: {
loadingText: '体验版加载中~', loadingText: '加载中~',
loadingTime: 100, loadingTime: 100,
}, },
release: { release: {