添加日志过滤框

master
lld 2025-12-28 23:59:04 +08:00
parent 2380a85a40
commit 9b2cfc9509
1 changed files with 105 additions and 4 deletions

View File

@ -126,17 +126,51 @@
</view> </view>
</view> </view>
<!-- 消息日志区域 --> <!-- 消息日志区域 -->
<view class="log-section"> <view class="log-section">
<view class="section-title">消息日志</view> <view class="section-title">消息日志</view>
<!-- 日志过滤和清空区域 -->
<view class="log-filter-wrapper">
<!-- 主题过滤输入框 -->
<view class="input-wrapper filter-input">
<input
v-model="logFilterKeyword"
type="text"
placeholder="输入主题关键词过滤日志(模糊匹配)"
class="form-input"
/>
<text class="clear-icon" @click="logFilterKeyword = ''" v-if="logFilterKeyword">×</text>
</view>
<!-- 清空日志按钮 -->
<button
size="mini"
type="warn"
@click="clearAllLogs"
:disabled="messageLogs.length === 0"
class="clear-log-btn"
>
清空日志
</button>
</view>
<!-- 日志内容区域 -->
<scroll-view <scroll-view
class="log-content" class="log-content"
scroll-y="true" scroll-y="true"
:style="{height: logHeight + 'px'}" :style="{height: logHeight + 'px'}"
> >
<!-- 空日志提示 -->
<view class="empty-log-tip" v-if="filteredLogs.length === 0">
{{messageLogs.length === 0 ? '暂无消息日志' : '未找到匹配的日志内容'}}
</view>
<!-- 过滤后的日志列表 -->
<view <view
class="log-item" class="log-item"
v-for="(log, index) in messageLogs" v-for="(log, index) in filteredLogs"
:key="index" :key="index"
:class="{'received': log.type === 'received', 'sent': log.type === 'sent', 'system': log.type === 'system'}" :class="{'received': log.type === 'received', 'sent': log.type === 'sent', 'system': log.type === 'system'}"
> >
@ -211,14 +245,29 @@ export default {
publishMessage: '', publishMessage: '',
// //
messageLogs: [], messageLogs: [],
logHeight: 300 // logHeight: 300, //
//
logFilterKeyword: '' //
}
},
computed: {
//
filteredLogs() {
if (!this.logFilterKeyword) {
return this.messageLogs
}
//
const keyword = this.logFilterKeyword.toLowerCase()
return this.messageLogs.filter(log => {
return log.topic.toLowerCase().includes(keyword)
})
} }
}, },
onReady() { onReady() {
// //
uni.getSystemInfo({ uni.getSystemInfo({
success: (res) => { success: (res) => {
this.logHeight = res.windowHeight - 600 this.logHeight = res.windowHeight - 650 //
} }
}) })
}, },
@ -238,6 +287,25 @@ export default {
} }
}, },
//
clearAllLogs() {
uni.showModal({
title: '确认清空',
content: '是否确定清空所有消息日志?',
success: (res) => {
if (res.confirm) {
this.messageLogs = []
this.logFilterKeyword = '' //
uni.showToast({
title: '日志已清空',
icon: 'success',
duration: 1500
})
}
}
})
},
// //
addLog(type, topic, message) { addLog(type, topic, message) {
const time = new Date().toLocaleTimeString() const time = new Date().toLocaleTimeString()
@ -446,10 +514,31 @@ export default {
.section-title { .section-title {
font-size: 16px; font-size: 16px;
font-weight: bold; font-weight: bold;
margin-bottom: 15px;
color: #333; color: #333;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
padding-bottom: 8px; padding-bottom: 8px;
margin-bottom: 15px;
}
/* 日志过滤和清空区域 */
.log-filter-wrapper {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 15px;
}
/* 过滤输入框 */
.filter-input {
flex: 1;
}
/* 清空日志按钮 */
.clear-log-btn {
height: 40px;
line-height: 40px;
padding: 0 15px;
white-space: nowrap;
} }
.form-item { .form-item {
@ -478,6 +567,10 @@ export default {
border-radius: 4px; border-radius: 4px;
padding: 0 30px 0 10px; /* 右侧留出清除按钮空间 */ padding: 0 30px 0 10px; /* 右侧留出清除按钮空间 */
font-size: 14px; font-size: 14px;
/* 开启横向滚动 */
white-space: nowrap;
overflow-x: auto;
-webkit-overflow-scrolling: touch; /* 顺滑滚动 */
} }
/* 文本域容器 */ /* 文本域容器 */
@ -561,6 +654,14 @@ export default {
padding: 10px; padding: 10px;
} }
/* 空日志提示 */
.empty-log-tip {
text-align: center;
color: #999;
padding: 20px 0;
font-size: 14px;
}
.log-item { .log-item {
padding: 8px; padding: 8px;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;