Browse Source

反馈加撤回和编辑,搜索历史对话记录

dev-V1.2
parent
commit
6f695b839e
  1. 208
      zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/enforcement/enforcementChat.vue

208
zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/enforcement/enforcementChat.vue

@ -17,12 +17,18 @@
<div class="chat-target">{{ bureauDeptName }} · {{ contactPerson }}</div> <div class="chat-target">{{ bureauDeptName }} · {{ contactPerson }}</div>
</div> --> </div> -->
<!-- 搜索聊天记录 -->
<button class="search-entry" type="button" aria-label="搜索聊天记录" @click="openSearch">
<van-icon name="search" size="20" />
</button>
<!-- 消息列表 --> <!-- 消息列表 -->
<div class="message-list" ref="messageListRef"> <div class="message-list" ref="messageListRef">
<div <div
v-for="(msg, index) in messageList" v-for="(msg, index) in messageList"
:key="msg.id" :key="msg.id"
class="message-group" class="message-group"
:data-msg-id="msg.id"
> >
<!-- 时间分割线 --> <!-- 时间分割线 -->
<div <div
@ -73,8 +79,42 @@
</div> </div>
</div> </div>
<!-- 聊天记录搜索面板 -->
<div v-if="searchVisible" class="search-panel">
<div class="search-header">
<div class="search-input-wrapper">
<van-icon name="search" size="16" color="#999" />
<input
ref="searchInputRef"
v-model="searchKeyword"
type="text"
placeholder="搜索消息内容或发送人"
@keyup.esc="closeSearch"
/>
</div>
<span class="search-cancel" @click="closeSearch">取消</span>
</div>
<div class="search-results">
<div v-if="!searchKeyword.trim()" class="search-empty">输入关键字搜索当前对话记录</div>
<div v-else-if="searchResults.length === 0" class="search-empty">没有找到相关记录</div>
<div
v-for="msg in searchResults"
v-else
:key="msg.id"
class="search-result-item"
@click="locateMessage(msg.id)"
>
<div class="search-result-meta">
<span>{{ getMessageSenderName(msg) }}</span>
<span>{{ msg.time }}</span>
</div>
<div class="search-result-content">{{ getPlainText(msg.content) }}</div>
</div>
</div>
</div>
<!-- 长按/右击菜单 --> <!-- 长按/右击菜单 -->
<!-- <div <div
v-if="menuVisible" v-if="menuVisible"
class="menu-overlay" class="menu-overlay"
@click="closeMenu" @click="closeMenu"
@ -94,7 +134,7 @@
<span>撤回</span> <span>撤回</span>
</div> </div>
</div> </div>
</div> --> </div>
<!-- 底部输入区域 --> <!-- 底部输入区域 -->
<div class="chat-input-area"> <div class="chat-input-area">
@ -119,7 +159,7 @@
</template> </template>
<script setup name="enforcementChat"> <script setup name="enforcementChat">
import { ref, nextTick, onMounted } from 'vue'; import { ref, computed, nextTick, onMounted } from 'vue';
import { showToast } from 'vant'; import { showToast } from 'vant';
import 'vant/es/toast/style'; import 'vant/es/toast/style';
import { getLawNoticeMessageList, sendLawNoticeMessage, sendLawNoticeMessageViewed } from '@/api/enterprise/planNotice'; import { getLawNoticeMessageList, sendLawNoticeMessage, sendLawNoticeMessageViewed } from '@/api/enterprise/planNotice';
@ -197,6 +237,55 @@ onMounted(() => {
const inputMessage = ref(''); const inputMessage = ref('');
const messageListRef = ref(null); const messageListRef = ref(null);
// ========== 聊天记录搜索 ==========
const searchVisible = ref(false);
const searchKeyword = ref('');
const searchInputRef = ref(null);
const getPlainText = (content) => String(content || '').replace(/<[^>]*>/g, '');
const getMessageSenderName = (msg) => msg.msgFrom === 0
? (msg.bureauDeptName || useCommon.bureauUnitName || '执法单位')
: (msg.userName || '企业');
const searchResults = computed(() => {
const keyword = searchKeyword.value.trim().toLowerCase();
if (!keyword) return [];
return messageList.value.filter(msg => {
if (msg.isRecalled) return false;
return getPlainText(msg.content).toLowerCase().includes(keyword)
|| getMessageSenderName(msg).toLowerCase().includes(keyword);
});
});
const openSearch = () => {
searchVisible.value = true;
nextTick(() => {
searchInputRef.value?.focus();
});
};
const closeSearch = () => {
searchVisible.value = false;
searchKeyword.value = '';
};
const locateMessage = (id) => {
closeSearch();
nextTick(() => {
const container = messageListRef.value;
if (!container) return;
const target = Array.from(container.querySelectorAll('[data-msg-id]'))
.find(el => el.dataset.msgId === String(id));
if (target) {
container.scrollTop = Math.max(
target.offsetTop - (container.clientHeight - target.clientHeight) / 2,
0
);
}
});
};
// ========== 菜单相关 ========== // ========== 菜单相关 ==========
const menuVisible = ref(false); const menuVisible = ref(false);
const menuPosition = ref({ x: 0, y: 0 }); const menuPosition = ref({ x: 0, y: 0 });
@ -366,6 +455,7 @@ const sendMessage = () => {
time: timeStr, time: timeStr,
avatar: selfAvatar, avatar: selfAvatar,
msgFrom: 1, msgFrom: 1,
userName: useCommon.enterpriseName || '企业',
isRecalled: false, isRecalled: false,
}); });
inputMessage.value = ''; inputMessage.value = '';
@ -441,11 +531,31 @@ const onMoreClick = () => {
} }
} }
/* ===== 搜索入口 ===== */
.search-entry {
position: absolute;
top: 0.2rem;
right: 0.25rem;
z-index: 20;
width: 0.72rem;
height: 0.72rem;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
border: none;
border-radius: 50%;
background: #fff;
color: #4485f5;
box-shadow: 0 0.04rem 0.16rem rgba(0, 0, 0, 0.15);
cursor: pointer;
}
/* ===== 消息列表 ===== */ /* ===== 消息列表 ===== */
.message-list { .message-list {
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
padding: 0 0.3rem 0.3rem; padding: 1rem 0.3rem 0.3rem;
} }
.message-group { .message-group {
@ -513,6 +623,96 @@ const onMoreClick = () => {
.msg-sender { color: #ccc; } .msg-sender { color: #ccc; }
} }
/* ===== 聊天记录搜索 ===== */
.search-panel {
position: absolute;
inset: 0;
z-index: 1000;
display: flex;
flex-direction: column;
background: #f7f8fa;
}
.search-header {
display: flex;
align-items: center;
gap: 0.2rem;
padding: 0.2rem 0.3rem;
background: #fff;
border-bottom: 1px solid #e5e5e5;
}
.search-input-wrapper {
flex: 1;
display: flex;
align-items: center;
gap: 0.12rem;
height: 0.72rem;
padding: 0 0.24rem;
border-radius: 0.36rem;
background: #f2f3f5;
input {
flex: 1;
min-width: 0;
border: none;
outline: none;
background: transparent;
font-size: 0.3rem;
color: #333;
}
}
.search-cancel {
flex-shrink: 0;
font-size: 0.3rem;
color: #4485f5;
cursor: pointer;
}
.search-results {
flex: 1;
overflow-y: auto;
padding: 0.2rem 0.3rem;
}
.search-empty {
padding-top: 1rem;
text-align: center;
font-size: 0.28rem;
color: #999;
}
.search-result-item {
margin-bottom: 0.16rem;
padding: 0.22rem 0.26rem;
border-radius: 0.12rem;
background: #fff;
cursor: pointer;
&:active {
background: #f0f5ff;
}
}
.search-result-meta {
display: flex;
justify-content: space-between;
gap: 0.2rem;
margin-bottom: 0.1rem;
font-size: 0.24rem;
color: #999;
}
.search-result-content {
overflow: hidden;
font-size: 0.3rem;
line-height: 1.5;
color: #333;
text-overflow: ellipsis;
white-space: nowrap;
}
/* ===== 长按/右击菜单 ===== */ /* ===== 长按/右击菜单 ===== */
.menu-overlay { .menu-overlay {
position: fixed; position: fixed;

Loading…
Cancel
Save