HomeLease/pages/index/index.vue

280 lines
8.0 KiB
Vue
Raw Normal View History

2025-08-12 15:38:25 +08:00
<template>
<view class="home-container">
<!-- 头部信息 -->
2025-08-14 09:24:37 +08:00
<custom-nav-bar title="福鼎创特物联科技有限公司"></custom-nav-bar>
2025-08-12 15:38:25 +08:00
<!-- 公告栏 -->
2025-08-13 11:05:40 +08:00
<announcement-bar
:announcement-icon="commonEnum.ANNOUNCEMENT_ICON"
:announcement-text="announcementText"
@announcement-click="onAnnouncementClick"
/>
2025-08-12 15:38:25 +08:00
<!-- 轮播图 -->
2025-08-13 11:05:40 +08:00
<banner-swiper
:autoplay="autoplay"
:banner-list="bannerList"
:duration="duration"
:indicator-dots="indicatorDots"
:interval="interval"
@change="onBannerChange"
@banner-click="onBannerClick"
/>
2025-08-12 15:38:25 +08:00
<!-- 设备列表 -->
2025-08-13 11:05:40 +08:00
<equipment-list
:equipment-list="equipmentList"
:title="equipmentTitle"
@renew="onRenew"
@equipment-click="onEquipmentClick"
/>
2025-08-12 15:38:25 +08:00
2025-08-13 11:43:35 +08:00
<!-- 底部导航已由系统tabBar处理 -->
2025-08-20 13:57:52 +08:00
</view>
2025-08-12 15:38:25 +08:00
</template>
<script>
2025-08-13 11:10:19 +08:00
import commonEnum from '../../enum/commonEnum'
import AnnouncementBar from '../../components/announcement-bar/announcement-bar.vue'
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'
2025-08-18 17:58:18 +08:00
import { getBannerList } from '../../api/banner/banner.js'
2025-08-19 08:55:34 +08:00
import { getDeviceList } from '../../api/device/device.js'
2025-08-13 11:10:19 +08:00
2025-08-20 13:57:52 +08:00
export default {
2025-08-13 11:10:19 +08:00
components: {
AnnouncementBar,
BannerSwiper,
EquipmentList,
},
2025-08-20 13:57:52 +08:00
data() {
return {
2025-08-13 11:10:19 +08:00
// 基础配置
indicatorDots: true,
autoplay: true,
interval: 2000,
duration: 500,
commonEnum: commonEnum,
// 页面数据
companyName: '福鼎创特物联科技有限公司',
announcementText: '暂无更多公告! 暂无更多公告! 暂无更多公告!',
currentAnnouncement: null, // 当前公告数据
2025-08-13 11:10:19 +08:00
equipmentTitle: '我的租赁设备',
navItems: ['首页', '申请租赁', '个人中心'],
activeNavIndex: 0,
// 轮播图数据
currentBannerIndex: 0,
2025-08-18 17:58:18 +08:00
bannerList: [],
2025-08-13 11:10:19 +08:00
// 设备列表数据
2025-08-19 08:55:34 +08:00
equipmentList: [],
2025-08-20 13:57:52 +08:00
}
},
2025-08-13 11:10:19 +08:00
// 生命周期钩子
2025-08-20 13:57:52 +08:00
onLoad() {
this.fetchAnnouncement()
2025-08-18 17:58:18 +08:00
this.fetchBannerList()
2025-08-19 08:55:34 +08:00
this.fetchDeviceList()
},
2025-08-13 11:10:19 +08:00
methods: {
// 获取最新公告
async fetchAnnouncement() {
try {
const response = await getNewAnnouncement()
if (response.code === 200 && response.data) {
this.currentAnnouncement = response.data
// 更新公告文本去除HTML标签
const content = response.data.content || ''
const plainText = content.replace(/<[^>]*>/g, '')
this.announcementText = response.data.title || plainText || '暂无更多公告!'
}
} catch (error) {
console.error('获取公告失败:', error)
this.announcementText = '暂无更多公告!'
}
},
2025-08-18 17:58:18 +08:00
// 获取轮播图列表
async fetchBannerList() {
try {
const response = await getBannerList()
if (response.code === 200 && response.data && Array.isArray(response.data)) {
// 按orderNum排序确保轮播图顺序正确
const sortedBanners = response.data
.filter(banner => banner.state === '1') // 只显示启用的轮播图
.sort((a, b) => parseInt(a.orderNum) - parseInt(b.orderNum))
.map(banner => ({
id: banner.id,
image: banner.imgUrl,
link: banner.link,
2025-08-20 13:57:52 +08:00
name: `轮播图${banner.id}`,
2025-08-18 17:58:18 +08:00
}))
2025-08-20 13:57:52 +08:00
2025-08-18 17:58:18 +08:00
this.bannerList = sortedBanners
}
} catch (error) {
console.error('获取轮播图失败:', error)
// 如果获取失败,使用默认轮播图
this.bannerList = [
{
id: 'default1',
image: commonEnum.TEMP1,
2025-08-20 13:57:52 +08:00
name: '默认轮播图1',
2025-08-18 17:58:18 +08:00
},
{
2025-08-20 13:57:52 +08:00
id: 'default2',
2025-08-18 17:58:18 +08:00
image: commonEnum.TEMP2,
2025-08-20 13:57:52 +08:00
name: '默认轮播图2',
},
2025-08-18 17:58:18 +08:00
]
}
},
2025-08-19 08:55:34 +08:00
// 获取设备列表
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') {
2025-08-19 08:58:59 +08:00
status = 'available' // 可租用
2025-08-19 08:55:34 +08:00
} else if (device.operationState === '2') {
2025-08-19 08:58:59 +08:00
status = 'rented' // 已出租
2025-08-19 08:55:34 +08:00
} else if (device.operationState === '3') {
status = 'maintenance' // 维护中
2025-08-19 08:58:59 +08:00
} else if (device.operationState === '4') {
status = 'scrapped' // 报废
2025-08-19 08:55:34 +08:00
}
// 根据onlineState判断在线状态
const isOnline = device.onlineState === '1'
2025-08-20 13:57:52 +08:00
2025-08-19 08:55:34 +08:00
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,
2025-08-20 13:57:52 +08:00
iotExpireTime: device.iotExpireTime,
2025-08-19 08:55:34 +08:00
}
})
2025-08-20 13:57:52 +08:00
2025-08-19 08:55:34 +08:00
this.equipmentList = devices
}
} catch (error) {
console.error('获取设备列表失败:', error)
// 如果获取失败,使用默认设备数据
this.equipmentList = [
{
id: 'default1',
name: '商用节能灶',
2025-08-19 08:58:59 +08:00
status: 'rented',
2025-08-19 08:55:34 +08:00
startTime: '2025-07-25 13:23:59',
endTime: '2026-07-25 13:23:59',
image: commonEnum.TEMP2,
2025-08-20 13:57:52 +08:00
isOnline: true,
2025-08-19 08:55:34 +08:00
},
{
id: 'default2',
name: '节能燃烧器',
2025-08-19 08:58:59 +08:00
status: 'rented',
2025-08-19 08:55:34 +08:00
startTime: '2025-07-25 13:23:59',
endTime: '2026-07-25 13:23:59',
image: commonEnum.TEMP3,
2025-08-20 13:57:52 +08:00
isOnline: true,
},
2025-08-19 08:55:34 +08:00
]
}
},
2025-08-13 11:10:19 +08:00
// 头部点击事件
onLocationClick() {
uni.showToast({
title: '选择位置',
icon: 'none',
})
2025-08-12 15:38:25 +08:00
},
2025-08-13 11:10:19 +08:00
// 公告栏点击事件
onAnnouncementClick() {
if (this.currentAnnouncement) {
// 显示公告详情
uni.navigateTo({
url:'/pages/announcementList/announcementList'
})
} else {
uni.showToast({
title: '暂无公告',
icon: 'none',
})
}
2025-08-13 11:10:19 +08:00
},
// 轮播图变化事件
onBannerChange(index) {
this.currentBannerIndex = index
},
// 轮播图点击事件
onBannerClick({ item, index }) {
2025-08-18 17:58:18 +08:00
if (item.link) {
// 如果有链接,跳转到对应页面
uni.navigateTo({
2025-08-20 13:57:52 +08:00
url: item.link,
2025-08-18 17:58:18 +08:00
})
2025-08-20 13:57:52 +08:00
}
2025-08-13 11:10:19 +08:00
},
// 设备点击事件
onEquipmentClick(equipment) {
2025-08-19 08:55:34 +08:00
// 跳转到设备详情页面,传递设备信息
uni.navigateTo({
2025-08-20 13:57:52 +08:00
url: `/pages/device-detail/device-detail?id=${equipment.id}&name=${encodeURIComponent(equipment.name)}`,
2025-08-13 11:10:19 +08:00
})
},
// 续费事件
onRenew(equipment) {
2025-08-19 08:55:34 +08:00
// 跳转到续费页面,传递设备信息
uni.navigateTo({
2025-08-20 13:57:52 +08:00
url: `/pages/renew/renew?id=${equipment.id}&name=${encodeURIComponent(equipment.name)}&endTime=${encodeURIComponent(equipment.endTime)}`,
2025-08-13 11:10:19 +08:00
})
2025-08-12 15:38:25 +08:00
},
2025-08-13 11:05:40 +08:00
2025-08-13 11:10:19 +08:00
// 底部导航点击事件
onNavClick(index) {
this.activeNavIndex = index
const navItems = ['首页', '申请租赁', '个人中心']
uni.showToast({
title: `切换到${navItems[index]}`,
icon: 'none',
})
2025-08-13 09:58:47 +08:00
},
2025-08-13 11:10:19 +08:00
},
2025-08-20 13:57:52 +08:00
}
2025-08-12 15:38:25 +08:00
</script>
2025-08-13 11:05:40 +08:00
<style lang="scss" scoped>
2025-08-13 11:10:19 +08:00
.home-container {
background: linear-gradient(to bottom, #ffddca 0px, #ffddca 450rpx, #f5f5f5 450rpx, #f5f5f5 100%);
padding-bottom: 120rpx; /* 为底部导航留出空间 */
max-width: 750rpx;
margin: 0 auto;
z-index: -2;
2025-08-20 13:57:52 +08:00
}
2025-08-12 15:38:25 +08:00
</style>