fix:温湿度操作记录日志、温湿度同步后台、删除查询日志、停止视频播放

This commit is contained in:
吉浩茹
2025-10-10 10:58:43 +08:00
parent 7a88643b5d
commit 4e66592cf8
8 changed files with 716 additions and 163 deletions

View File

@ -24,7 +24,7 @@
<view class="table-cell header-cell content-column">内容</view>
<view class="table-cell header-cell type-column">种类</view>
<view class="table-cell header-cell time-column">时间</view>
<view class="table-cell header-cell level-column">级别</view>
<!-- <view class="table-cell header-cell level-column">级别</view> -->
<!-- <view class="table-cell header-cell action-column">处置</view> -->
<!-- <view class="table-cell header-cell action-time-column">时间</view> -->
</view>
@ -56,9 +56,9 @@
<view class="table-cell type-column">{{ alarm.type }}</view>
<view class="table-cell time-column">{{ alarm.time }}</view>
<!-- <view class="table-cell level-column" :class="getLevelClass(alarm.level)"> -->
<view class="table-cell level-column">
<!-- <view class="table-cell level-column">
{{ alarm.level }}
</view>
</view> -->
<!-- <view class="table-cell action-column">{{ alarm.action }}</view> -->
<!-- <view class="table-cell action-time-column">{{ alarm.actionTime }}</view> -->
</view>
@ -143,7 +143,6 @@ const mqttAlarmService = {
// 获取历史报警记录(分页)
getHistoryAlarms: async (page = 0, size = 20, isLoadMore = false) => {
console.log(`获取历史报警记录,页码:${page}, 每页:${size}`);
try {
if (!isLoadMore) {
isLoading.value = true;
@ -158,8 +157,6 @@ const mqttAlarmService = {
size: size
});
console.log('📊 获取告警数据响应:', response);
// 处理响应数据
if (response && response.data) {
const newAlarms = response.data.map(item => ({
@ -188,7 +185,6 @@ const mqttAlarmService = {
await createQueryEvent('success', newAlarms.length);
}
} else {
console.warn('⚠️ 响应数据格式异常:', response);
if (!isLoadMore) {
alarmList.value = [];
}
@ -447,23 +443,23 @@ const stopRealtimeAlarm = () => {
// 创建查询事件
const createQueryEvent = async (status, dataCount) => {
try {
const currentTime = formatDateTime(new Date().toISOString())
const queryEvent = {
eventType: "报警记录查询",
eventTime: currentTime,
status: getEventStatus(status),
description: getEventDescription(status, dataCount),
deviceId: "ALARM_QUERY_001"
}
// try {
// const currentTime = formatDateTime(new Date().toISOString())
// const queryEvent = {
// eventType: "报警记录查询",
// eventTime: currentTime,
// status: getEventStatus(status),
// description: getEventDescription(status, dataCount),
// deviceId: "ALARM_QUERY_001"
// }
console.log('📤 提交报警查询事件:', queryEvent)
const response = await eventApi.create(queryEvent)
console.log('✅ 报警查询事件创建成功:', response)
// console.log('📤 提交报警查询事件:', queryEvent)
// const response = await eventApi.create(queryEvent)
// console.log('✅ 报警查询事件创建成功:', response)
} catch (error) {
console.error('❌ 报警查询事件创建失败:', error)
}
// } catch (error) {
// console.error('❌ 报警查询事件创建失败:', error)
// }
};
// 获取事件状态
@ -488,7 +484,6 @@ const getEventDescription = (status, dataCount) => {
// 刷新数据方法
const refreshData = async () => {
console.log('🔄 刷新报警记录数据')
try {
// 重置分页状态
currentPage.value = 0;

View File

@ -29,27 +29,20 @@
</view>
<!-- #endif -->
<!-- APP平台使用 cover-view -->
<!-- APP平台控制按钮已集成到HTML页面中 -->
<!-- #ifdef APP-PLUS -->
<cover-view class="control-buttons-cover" v-if="!loading && webviewUrl">
<cover-view class="control-btn-cover play-btn-cover" @click="togglePlay">
<cover-view class="btn-text">{{ isPlaying ? '⏸ 暂停' : '▶ 播放' }}</cover-view>
</cover-view>
<cover-view class="control-btn-cover refresh-btn-cover" @click="refresh">
<cover-view class="btn-text">🔄 刷新</cover-view>
</cover-view>
</cover-view>
<!-- 控制按钮现在直接在 ezviz-iframe.html 页面中 -->
<!-- #endif -->
<!-- H5平台使用普通按钮 -->
<!-- H5平台使用悬浮按钮与APP平台保持一致 -->
<!-- #ifdef H5 -->
<view class="control-buttons" v-if="!loading && iframeUrl">
<button class="control-btn play-btn" @click="togglePlay">
{{ isPlaying ? ' 暂停' : ' 播放' }}
</button>
<button class="control-btn refresh-btn" @click="refresh">
🔄 刷新
</button>
<view class="control-buttons-unified" v-if="!loading && iframeUrl && !error">
<view class="control-btn-unified play-btn-unified" @click="togglePlay">
<text class="btn-text-unified">{{ isPlaying ? '⏸ 暂停' : '▶ 播放' }}</text>
</view>
<view class="control-btn-unified refresh-btn-unified" @click="refresh">
<text class="btn-text-unified">🔄 刷新</text>
</view>
</view>
<!-- #endif -->
@ -134,6 +127,7 @@ export default {
const url = encodeURIComponent(config.play_url)
this.webviewUrl = `/static/html/ezviz-iframe.html?accessToken=${token}&playUrl=${url}`
console.log('[简单播放器] APP平台 - 使用本地HTML文件')
console.log('[简单播放器] APP平台 - webviewUrl:', this.webviewUrl)
// #endif
// #ifdef H5
@ -145,14 +139,21 @@ export default {
'&height=100%' +
'&autoplay=1' +
'&audio=1' +
'&controls=1'
console.log('[简单播放器] H5平台 - 直接使用萤石云iframe')
'&controls=1';
console.log('[简单播放器] H5平台 - 直接使用萤石云iframe', this.iframeUrl)
// #endif
setTimeout(() => {
if (this.loading) {
this.loading = false
this.status = '播放器已加载'
console.log('[简单播放器] 加载完成,显示控制按钮')
console.log('[简单播放器] 当前状态:', {
loading: this.loading,
webviewUrl: !!this.webviewUrl,
iframeUrl: !!this.iframeUrl,
platform: this.platform
})
}
}, 3000)
@ -193,55 +194,102 @@ export default {
},
// 切换播放/暂停
// 统一的播放状态切换逻辑
togglePlay() {
console.log('[简单播放器] 切换播放状态:', this.isPlaying ? '暂停' : '播放')
// 通过重新加载URL来实现播放/暂停
// 因为iframe播放器不支持直接控制所以采用重新加载的方式
if (this.isPlaying) {
// 暂停清空URL
// 防止重复点击和加载中操作
if (this.loading) {
console.log('[简单播放器] 播放器加载中,忽略操作')
return
}
const newPlayState = !this.isPlaying
// 统一的状态更新逻辑
if (newPlayState) {
this.startPlayback()
} else {
this.pausePlayback()
}
// 返回新的播放状态
return this.isPlaying
},
// 统一的开始播放逻辑
startPlayback() {
console.log('[简单播放器] 开始播放')
if (!this.config) {
console.error('[简单播放器] 配置信息不存在,无法播放')
return
}
try {
// 设置播放URL - 两个平台使用相同的逻辑
// #ifdef APP-PLUS
this.webviewUrl = ''
// #endif
// #ifdef H5
this.iframeUrl = ''
const token = encodeURIComponent(this.config.accessToken)
const url = encodeURIComponent(this.config.play_url)
this.webviewUrl = `/static/html/ezviz-iframe.html?accessToken=${token}&playUrl=${url}`
console.log('[简单播放器] APP平台 - 设置webviewUrl')
// #endif
// #ifdef H5
this.iframeUrl = 'https://open.ys7.com/ezopen/h5/iframe?' +
'url=' + encodeURIComponent(this.config.play_url) +
'&accessToken=' + encodeURIComponent(this.config.accessToken) +
'&width=100%' +
'&height=100%' +
'&autoplay=1' +
'&audio=1' +
'&controls=1'
console.log('[简单播放器] H5平台 - 设置iframeUrl', this.iframeUrl)
// #endif
// 统一更新状态
this.isPlaying = true
this.status = '播放中'
this.error = false
// 触发状态变化事件
this.$emit('playStateChange', true)
console.log('[简单播放器] 播放状态已更新为:播放中')
} catch (error) {
console.error('[简单播放器] 开始播放失败:', error)
this.error = true
this.errorText = '播放失败: ' + error.message
}
},
// 统一的暂停播放逻辑
pausePlayback() {
console.log('[简单播放器] 暂停播放')
try {
// 清空播放URL - 两个平台使用相同的逻辑
// #ifdef APP-PLUS
this.webviewUrl = ''
console.log('[简单播放器] APP平台 - 清空webviewUrl')
// #endif
// #ifdef H5
this.iframeUrl = ''
console.log('[简单播放器] H5平台 - 清空iframeUrl')
// #endif
// 统一更新状态
this.isPlaying = false
this.status = '已暂停'
// 触发状态变化事件
this.$emit('playStateChange', false)
} else {
// 播放重新设置URL
if (this.config) {
// #ifdef APP-PLUS
const token = encodeURIComponent(this.config.accessToken)
const url = encodeURIComponent(this.config.play_url)
this.webviewUrl = `/static/html/ezviz-iframe.html?accessToken=${token}&playUrl=${url}`
// #endif
// #ifdef H5
this.iframeUrl = 'https://open.ys7.com/ezopen/h5/iframe?' +
'url=' + encodeURIComponent(this.config.play_url) +
'&accessToken=' + encodeURIComponent(this.config.accessToken) +
'&width=100%' +
'&height=100%' +
'&autoplay=1' +
'&audio=1' +
'&controls=1'
// #endif
this.isPlaying = true
this.status = '播放中'
// 触发状态变化事件
this.$emit('playStateChange', true)
}
console.log('[简单播放器] 播放状态已更新为:已暂停')
} catch (error) {
console.error('[简单播放器] 暂停播放失败:', error)
}
// 返回新的播放状态
return this.isPlaying
},
// 获取当前播放状态
@ -249,18 +297,89 @@ export default {
return this.isPlaying
},
// 刷新播放器
// 统一的刷新播放器逻辑
refresh() {
console.log('[简单播放器] 刷新播放器')
if (this.config) {
if (!this.config) {
console.error('[简单播放器] 配置信息不存在,无法刷新')
uni.showToast({
title: '配置信息不存在',
icon: 'error',
duration: 2000
})
return
}
try {
// 显示刷新提示
uni.showToast({
title: '正在刷新...',
icon: 'loading',
duration: 1000
})
// 先清空再重新加载
// 重置播放器状态
this.error = false
this.loading = true
this.loadingText = '重新加载中...'
// 先暂停播放
this.pausePlayback()
// 延迟重新开始播放,确保清空操作完成
setTimeout(() => {
try {
// 重新开始播放
this.startPlayback()
// 显示成功提示
uni.showToast({
title: '刷新成功',
icon: 'success',
duration: 1500
})
// 重置加载状态
setTimeout(() => {
this.loading = false
this.loadingText = '加载中...'
}, 1000)
} catch (error) {
console.error('[简单播放器] 重新播放失败:', error)
this.loading = false
this.error = true
this.errorText = '刷新失败: ' + error.message
uni.showToast({
title: '刷新失败',
icon: 'error',
duration: 2000
})
}
}, 500)
} catch (error) {
console.error('[简单播放器] 刷新播放器失败:', error)
this.loading = false
this.error = true
this.errorText = '刷新失败: ' + error.message
uni.showToast({
title: '刷新失败',
icon: 'error',
duration: 2000
})
}
},
// 停止播放器(页面关闭时调用)
stopPlayer() {
console.log('[简单播放器] 停止播放器')
try {
// 清空播放URL停止播放
// #ifdef APP-PLUS
this.webviewUrl = ''
// #endif
@ -268,33 +387,18 @@ export default {
this.iframeUrl = ''
// #endif
setTimeout(() => {
// #ifdef APP-PLUS
const token = encodeURIComponent(this.config.accessToken)
const url = encodeURIComponent(this.config.play_url)
this.webviewUrl = `/static/html/ezviz-iframe.html?accessToken=${token}&playUrl=${url}`
// #endif
// #ifdef H5
this.iframeUrl = 'https://open.ys7.com/ezopen/h5/iframe?' +
'url=' + encodeURIComponent(this.config.play_url) +
'&accessToken=' + encodeURIComponent(this.config.accessToken) +
'&width=100%' +
'&height=100%' +
'&autoplay=1' +
'&audio=1' +
'&controls=1'
// #endif
this.isPlaying = true
this.status = '播放中'
uni.showToast({
title: '刷新成功',
icon: 'success',
duration: 1500
})
}, 500)
// 重置状态
this.isPlaying = false
this.status = '已停止'
this.loading = false
this.error = false
// 触发状态变化事件
this.$emit('playStateChange', false)
console.log('[简单播放器] 播放器已停止')
} catch (error) {
console.error('[简单播放器] 停止播放器失败:', error)
}
}
}
@ -473,5 +577,107 @@ export default {
.refresh-btn:active {
background: rgba(25, 118, 210, 1);
}
/* 统一的控制按钮样式 - APP平台使用 cover-view */
.control-buttons-cover {
position: fixed;
top: 50%;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 20rpx;
z-index: 999;
}
.control-btn-cover {
background: rgba(0, 0, 0, 0.75);
border: 2rpx solid rgba(255, 255, 255, 0.6);
border-radius: 40rpx;
padding: 16rpx 32rpx;
min-width: 140rpx;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
}
.play-btn-cover {
background: rgba(46, 125, 50, 0.85);
border-color: rgba(76, 175, 80, 0.9);
}
.refresh-btn-cover {
background: rgba(25, 118, 210, 0.85);
border-color: rgba(33, 150, 243, 0.9);
}
.btn-text {
color: white;
font-size: 24rpx;
font-weight: 600;
text-align: center;
}
/* 统一的控制按钮样式 - H5平台使用 view */
.control-buttons-unified {
position: fixed;
top: 50%;;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 20rpx;
z-index: 999;
}
.control-btn-unified {
background: rgba(0, 0, 0, 0.75);
border: 2rpx solid rgba(255, 255, 255, 0.6);
border-radius: 40rpx;
padding: 16rpx 32rpx;
min-width: 140rpx;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s ease;
user-select: none;
}
.control-btn-unified:hover {
transform: scale(1.05);
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.3);
}
.control-btn-unified:active {
transform: scale(0.95);
}
.play-btn-unified {
background: rgba(46, 125, 50, 0.85);
border-color: rgba(76, 175, 80, 0.9);
}
.play-btn-unified:hover {
background: rgba(46, 125, 50, 0.95);
border-color: rgba(76, 175, 80, 1);
}
.refresh-btn-unified {
background: rgba(25, 118, 210, 0.85);
border-color: rgba(33, 150, 243, 0.9);
}
.refresh-btn-unified:hover {
background: rgba(25, 118, 210, 0.95);
border-color: rgba(33, 150, 243, 1);
}
.btn-text-unified {
color: white;
font-size: 24rpx;
font-weight: 600;
text-align: center;
pointer-events: none;
}
</style>