优化搜索定位反馈:修复Flash动画时序、添加脉冲动画、增加滚动留白、内联无结果提示

This commit is contained in:
2026-05-19 14:55:40 +08:00
parent a954f9cc49
commit b1491ad69e
2 changed files with 133 additions and 20 deletions

View File

@@ -9,7 +9,7 @@
<!-- 搜索浮条 -->
<view class="search-bar" v-if="showSearchBar">
<view class="search-bar-inner">
<view class="search-bar-input-wrap">
<view class="search-bar-input-wrap" :class="{ 'has-results': searchResults.length > 0, 'no-results': searched && searchResults.length === 0 }">
<text class="iconfont icon-sousuo search-bar-icon"></text>
<input
class="search-bar-input"
@@ -29,6 +29,10 @@
</view>
<text class="search-bar-close" @click="closeSearch">{{ $lang('searchClose') }}</text>
</view>
<view class="search-bar-status" v-if="searched && searchKeyword && searchResults.length === 0">
<text class="search-bar-status-icon">!</text>
<text class="search-bar-status-text">{{ $lang('noMatchResult') }}</text>
</view>
</view>
</view>
</template>
@@ -68,6 +72,7 @@ export default {
searchKeyword: '',
searchResults: [], // 匹配结果在过滤后数组中的索引列表
searchResultIndex: -1, // 当前在 searchResults 中的位置
searched: false, // 是否已执行过搜索(用于显示无结果提示)
}
},
@@ -92,7 +97,9 @@ export default {
methods: {
// 生成消息唯一 key(与父组件 getMessageKey 保持一致)
getMessageKey(message, index) {
return `msg-${message.id || message.tempId || index}-${message.role}`
const rawId = message.id || message.timestamp || index;
const id = String(rawId).replace(/[^a-zA-Z0-9_-]/g, '-');
return 'msg-' + id + '-' + index;
},
toggleSearch() {
@@ -113,6 +120,7 @@ export default {
this.searchKeyword = ''
this.searchResults = []
this.searchResultIndex = -1
this.searched = false
this.$emit('result-change', -1)
this.$emit('keyword-change', '')
},
@@ -132,6 +140,7 @@ export default {
if (!keyword) {
this.searchResults = []
this.searchResultIndex = -1
this.searched = false
this.$emit('result-change', -1)
this.$emit('keyword-change', '')
return
@@ -147,6 +156,7 @@ export default {
this.searchResults = results
this.searchResultIndex = results.length > 0 ? 0 : -1
this.searched = true
const filteredIdx = results.length > 0 ? results[0] : -1
this.$emit('result-change', filteredIdx)
@@ -156,8 +166,6 @@ export default {
this.$nextTick(() => {
this._emitScrollTo(filteredIdx)
})
} else {
uni.showToast({ title: this.$lang('noMatchResult'), icon: 'none' })
}
},
@@ -413,4 +421,46 @@ export default {
}
}
}
// 搜索状态提示
.search-bar-status {
display: flex;
align-items: center;
justify-content: center;
gap: 8rpx;
padding: 14rpx 16rpx;
background: #fffae6;
border-top: 1rpx solid #f0e6c0;
.search-bar-status-icon {
width: 32rpx;
height: 32rpx;
border-radius: 50%;
background: #f5a623;
color: #fff;
font-size: 20rpx;
font-weight: 700;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
line-height: 1;
}
.search-bar-status-text {
font-size: 24rpx;
color: #8a7a4a;
line-height: 1.4;
}
}
// 搜索输入框 - 有结果时绿色边框
.search-bar-input-wrap.has-results {
border-color: #07c160;
}
// 搜索输入框 - 无结果时橙色边框
.search-bar-input-wrap.no-results {
border-color: #f5a623;
}
</style>