|
|
@ -1,11 +1,17 @@ |
|
|
<template> |
|
|
<template> |
|
|
<div class="chat-page"> |
|
|
<div class="chat-page"> |
|
|
|
|
|
<!-- 右上角搜索入口 --> |
|
|
|
|
|
<div class="search-entry" @click="openSearch"> |
|
|
|
|
|
<van-icon name="search" size="18" color="#333" /> |
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
<!-- 消息列表 --> |
|
|
<!-- 消息列表 --> |
|
|
<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 || index" |
|
|
:key="msg.id || index" |
|
|
class="message-group" |
|
|
class="message-group" |
|
|
|
|
|
:data-msg-id="msg.id" |
|
|
> |
|
|
> |
|
|
<!-- 时间分割线 --> |
|
|
<!-- 时间分割线 --> |
|
|
<div |
|
|
<div |
|
|
@ -53,6 +59,20 @@ |
|
|
@click="closeMenu" |
|
|
@click="closeMenu" |
|
|
@contextmenu.prevent |
|
|
@contextmenu.prevent |
|
|
> |
|
|
> |
|
|
|
|
|
<div |
|
|
|
|
|
class="context-menu" |
|
|
|
|
|
:style="{ top: menuPosition.y + 'px', left: menuPosition.x + 'px' }" |
|
|
|
|
|
> |
|
|
|
|
|
<div class="menu-item" @click.stop="onEdit"> |
|
|
|
|
|
<van-icon name="edit" size="16" /> |
|
|
|
|
|
<span>编辑</span> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div class="menu-divider"></div> |
|
|
|
|
|
<div class="menu-item" @click.stop="onRecall"> |
|
|
|
|
|
<van-icon name="revoke" size="16" /> |
|
|
|
|
|
<span>撤回</span> |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
<!-- 底部输入区域(非只读时显示) --> |
|
|
<!-- 底部输入区域(非只读时显示) --> |
|
|
@ -74,6 +94,50 @@ |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<!-- 搜索页面 --> |
|
|
|
|
|
<div v-if="searchVisible" class="search-panel"> |
|
|
|
|
|
<div class="search-header"> |
|
|
|
|
|
<div class="search-input-wrap"> |
|
|
|
|
|
<van-icon name="search" size="14" color="#999" /> |
|
|
|
|
|
<input |
|
|
|
|
|
ref="searchInputRef" |
|
|
|
|
|
v-model="searchKeyword" |
|
|
|
|
|
type="text" |
|
|
|
|
|
class="search-input" |
|
|
|
|
|
placeholder="搜索聊天记录" |
|
|
|
|
|
/> |
|
|
|
|
|
<van-icon |
|
|
|
|
|
v-if="searchKeyword" |
|
|
|
|
|
name="clear" |
|
|
|
|
|
size="14" |
|
|
|
|
|
color="#c8c9cc" |
|
|
|
|
|
@click="searchKeyword = ''" |
|
|
|
|
|
/> |
|
|
|
|
|
</div> |
|
|
|
|
|
<span class="search-cancel" @click="closeSearch">取消</span> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div class="search-results"> |
|
|
|
|
|
<div v-if="!searchKeyword.trim()" class="search-tip">输入关键字搜索当前对话记录</div> |
|
|
|
|
|
<template v-else> |
|
|
|
|
|
<div v-if="searchResults.length === 0" class="search-tip">没有找到相关记录</div> |
|
|
|
|
|
<div |
|
|
|
|
|
v-for="(item, idx) in searchResults" |
|
|
|
|
|
:key="item.id || idx" |
|
|
|
|
|
class="search-result-item" |
|
|
|
|
|
@click="onSelectResult(item)" |
|
|
|
|
|
> |
|
|
|
|
|
<div class="result-top"> |
|
|
|
|
|
<span class="result-sender"> |
|
|
|
|
|
{{ item.msgFrom === 0 ? (item.bureauDeptName || useCommon.bureauUnitName || '执法单位') : item.userName }} |
|
|
|
|
|
</span> |
|
|
|
|
|
<span class="result-time">{{ item.time }}</span> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div class="result-content">{{ plainText(item.message) }}</div> |
|
|
|
|
|
</div> |
|
|
|
|
|
</template> |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
@ -96,6 +160,75 @@ const inputMessage = ref(''); |
|
|
const messageListRef = ref(null); |
|
|
const messageListRef = ref(null); |
|
|
let pollTimer = null; |
|
|
let pollTimer = null; |
|
|
|
|
|
|
|
|
|
|
|
// 本地编辑/撤回结果,轮询或重新加载时保留,避免被服务端数据覆盖 |
|
|
|
|
|
const localOverrides = {}; |
|
|
|
|
|
|
|
|
|
|
|
const mapMessage = (item) => { |
|
|
|
|
|
const msg = { |
|
|
|
|
|
id: item.id, |
|
|
|
|
|
msgFrom: item.msgFrom ?? 0, |
|
|
|
|
|
content: item.content || item.message || '', |
|
|
|
|
|
message: item.content || item.message || '', |
|
|
|
|
|
time: item.createTime || item.time || '', |
|
|
|
|
|
isRecalled: item.isRecalled || false, |
|
|
|
|
|
userName: item.userName || '', |
|
|
|
|
|
bureauDeptName: item.bureauDeptName || '', |
|
|
|
|
|
}; |
|
|
|
|
|
const override = msg.id != null ? localOverrides[msg.id] : null; |
|
|
|
|
|
if (override) { |
|
|
|
|
|
if (override.content !== undefined) { |
|
|
|
|
|
msg.content = override.content; |
|
|
|
|
|
msg.message = override.content; |
|
|
|
|
|
} |
|
|
|
|
|
if (override.isRecalled) { |
|
|
|
|
|
msg.isRecalled = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return msg; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// ========== 聊天记录搜索 ========== |
|
|
|
|
|
const searchVisible = ref(false); |
|
|
|
|
|
const searchKeyword = ref(''); |
|
|
|
|
|
const searchInputRef = ref(null); |
|
|
|
|
|
|
|
|
|
|
|
// 去掉消息里的 HTML 标签,用于搜索匹配和结果展示 |
|
|
|
|
|
const plainText = (html) => String(html || '').replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim(); |
|
|
|
|
|
|
|
|
|
|
|
const searchResults = computed(() => { |
|
|
|
|
|
const keyword = searchKeyword.value.trim().toLowerCase(); |
|
|
|
|
|
if (!keyword) return []; |
|
|
|
|
|
return messageList.value.filter(msg => { |
|
|
|
|
|
if (msg.isRecalled) return false; |
|
|
|
|
|
return plainText(msg.message).toLowerCase().includes(keyword) |
|
|
|
|
|
|| String(msg.userName || '').toLowerCase().includes(keyword); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const openSearch = () => { |
|
|
|
|
|
searchKeyword.value = ''; |
|
|
|
|
|
searchVisible.value = true; |
|
|
|
|
|
nextTick(() => { |
|
|
|
|
|
if (searchInputRef.value) searchInputRef.value.focus(); |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const closeSearch = () => { |
|
|
|
|
|
searchVisible.value = false; |
|
|
|
|
|
searchKeyword.value = ''; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 点击搜索结果定位到对应消息 |
|
|
|
|
|
const onSelectResult = (item) => { |
|
|
|
|
|
closeSearch(); |
|
|
|
|
|
nextTick(() => { |
|
|
|
|
|
const el = messageListRef.value && messageListRef.value.querySelector(`[data-msg-id="${item.id}"]`); |
|
|
|
|
|
if (el) { |
|
|
|
|
|
el.scrollIntoView({ block: 'center' }); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
onMounted(() => { |
|
|
onMounted(() => { |
|
|
loadMessages(); |
|
|
loadMessages(); |
|
|
startPolling(); |
|
|
startPolling(); |
|
|
@ -111,16 +244,7 @@ const loadMessages = () => { |
|
|
getNoticeMessages(noticeId.value, (res) => { |
|
|
getNoticeMessages(noticeId.value, (res) => { |
|
|
if (res && res.code === 200 && Array.isArray(res.data)) { |
|
|
if (res && res.code === 200 && Array.isArray(res.data)) { |
|
|
const lastItem = res.data[res.data.length - 1]; |
|
|
const lastItem = res.data[res.data.length - 1]; |
|
|
messageList.value = res.data.map(item => ({ |
|
|
messageList.value = res.data.map(mapMessage); |
|
|
id: item.id, |
|
|
|
|
|
msgFrom: item.msgFrom ?? 0, |
|
|
|
|
|
content: item.content || item.message || '', |
|
|
|
|
|
message: item.content || item.message || '', |
|
|
|
|
|
time: item.createTime || item.time || '', |
|
|
|
|
|
isRecalled: item.isRecalled || false, |
|
|
|
|
|
userName: item.userName || '', |
|
|
|
|
|
bureauDeptName: item.bureauDeptName || '', |
|
|
|
|
|
})); |
|
|
|
|
|
nextTick(() => scrollToBottom()); |
|
|
nextTick(() => scrollToBottom()); |
|
|
if (lastItem && lastItem.id) { |
|
|
if (lastItem && lastItem.id) { |
|
|
messageRead(lastItem.id, () => {}, () => {}); |
|
|
messageRead(lastItem.id, () => {}, () => {}); |
|
|
@ -151,16 +275,7 @@ const pollMessages = () => { |
|
|
getNoticeMessages(noticeId.value, (res) => { |
|
|
getNoticeMessages(noticeId.value, (res) => { |
|
|
if (res.code === 200 && Array.isArray(res.data)) { |
|
|
if (res.code === 200 && Array.isArray(res.data)) { |
|
|
const oldCount = messageList.value.length; |
|
|
const oldCount = messageList.value.length; |
|
|
messageList.value = res.data.map(item => ({ |
|
|
messageList.value = res.data.map(mapMessage); |
|
|
id: item.id, |
|
|
|
|
|
msgFrom: item.msgFrom ?? 0, |
|
|
|
|
|
content: item.content || item.message || '', |
|
|
|
|
|
message: item.content || item.message || '', |
|
|
|
|
|
time: item.createTime || item.time || '', |
|
|
|
|
|
isRecalled: item.isRecalled || false, |
|
|
|
|
|
userName: item.userName || '', |
|
|
|
|
|
bureauDeptName: item.bureauDeptName || '', |
|
|
|
|
|
})); |
|
|
|
|
|
if (res.data.length > oldCount) { |
|
|
if (res.data.length > oldCount) { |
|
|
scrollToBottom(); |
|
|
scrollToBottom(); |
|
|
} |
|
|
} |
|
|
@ -192,6 +307,7 @@ const shouldShowTime = (index) => { |
|
|
|
|
|
|
|
|
// ========== 判断消息是否可编辑/撤回 ========== |
|
|
// ========== 判断消息是否可编辑/撤回 ========== |
|
|
const canEditOrRecall = (msg, index) => { |
|
|
const canEditOrRecall = (msg, index) => { |
|
|
|
|
|
if (isReadonly.value) return false; |
|
|
if (msg.msgFrom !== 0) return false; |
|
|
if (msg.msgFrom !== 0) return false; |
|
|
if (msg.isRecalled) return false; |
|
|
if (msg.isRecalled) return false; |
|
|
const msgTime = new Date(msg.time.replace(/-/g, '/')); |
|
|
const msgTime = new Date(msg.time.replace(/-/g, '/')); |
|
|
@ -279,7 +395,11 @@ const onEdit = () => { |
|
|
// ========== 撤回消息 ========== |
|
|
// ========== 撤回消息 ========== |
|
|
const onRecall = () => { |
|
|
const onRecall = () => { |
|
|
if (selectedIndex.value === -1) return; |
|
|
if (selectedIndex.value === -1) return; |
|
|
messageList.value[selectedIndex.value].isRecalled = true; |
|
|
const target = messageList.value[selectedIndex.value]; |
|
|
|
|
|
target.isRecalled = true; |
|
|
|
|
|
if (target.id != null) { |
|
|
|
|
|
localOverrides[target.id] = { ...(localOverrides[target.id] || {}), isRecalled: true }; |
|
|
|
|
|
} |
|
|
showToast('消息已撤回'); |
|
|
showToast('消息已撤回'); |
|
|
closeMenu(); |
|
|
closeMenu(); |
|
|
}; |
|
|
}; |
|
|
@ -304,6 +424,7 @@ const sendMessage = () => { |
|
|
if (msg) { |
|
|
if (msg) { |
|
|
msg.message = text; |
|
|
msg.message = text; |
|
|
msg.content = text; |
|
|
msg.content = text; |
|
|
|
|
|
localOverrides[msg.id] = { ...(localOverrides[msg.id] || {}), content: text }; |
|
|
showToast('消息已修改'); |
|
|
showToast('消息已修改'); |
|
|
} |
|
|
} |
|
|
cancelEdit(); |
|
|
cancelEdit(); |
|
|
@ -355,7 +476,121 @@ const formatTime = (dateStr) => { |
|
|
.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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.search-entry { |
|
|
|
|
|
position: absolute; |
|
|
|
|
|
top: 0.2rem; |
|
|
|
|
|
right: 0.24rem; |
|
|
|
|
|
width: 0.72rem; |
|
|
|
|
|
height: 0.72rem; |
|
|
|
|
|
border-radius: 50%; |
|
|
|
|
|
background: rgba(255, 255, 255, 0.92); |
|
|
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); |
|
|
|
|
|
display: flex; |
|
|
|
|
|
align-items: center; |
|
|
|
|
|
justify-content: center; |
|
|
|
|
|
z-index: 10; |
|
|
|
|
|
cursor: pointer; |
|
|
|
|
|
|
|
|
|
|
|
&:active { |
|
|
|
|
|
opacity: 0.8; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* ===== 聊天记录搜索页 ===== */ |
|
|
|
|
|
.search-panel { |
|
|
|
|
|
position: fixed; |
|
|
|
|
|
top: 0; |
|
|
|
|
|
left: 0; |
|
|
|
|
|
width: 100%; |
|
|
|
|
|
height: 100%; |
|
|
|
|
|
background: #f7f8fa; |
|
|
|
|
|
z-index: 1000; |
|
|
|
|
|
display: flex; |
|
|
|
|
|
flex-direction: column; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.search-header { |
|
|
|
|
|
display: flex; |
|
|
|
|
|
align-items: center; |
|
|
|
|
|
gap: 0.2rem; |
|
|
|
|
|
padding: 0.2rem 0.3rem; |
|
|
|
|
|
background: #fff; |
|
|
|
|
|
border-bottom: 1px solid #e5e5e5; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.search-input-wrap { |
|
|
|
|
|
flex: 1; |
|
|
|
|
|
display: flex; |
|
|
|
|
|
align-items: center; |
|
|
|
|
|
gap: 0.1rem; |
|
|
|
|
|
height: 0.72rem; |
|
|
|
|
|
padding: 0 0.24rem; |
|
|
|
|
|
border-radius: 0.36rem; |
|
|
|
|
|
background: #f2f3f5; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.search-input { |
|
|
|
|
|
flex: 1; |
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.search-tip { |
|
|
|
|
|
padding: 0.8rem 0.3rem; |
|
|
|
|
|
text-align: center; |
|
|
|
|
|
font-size: 0.28rem; |
|
|
|
|
|
color: #999; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.search-result-item { |
|
|
|
|
|
padding: 0.24rem 0.3rem; |
|
|
|
|
|
background: #fff; |
|
|
|
|
|
border-bottom: 1px solid #f0f0f0; |
|
|
|
|
|
cursor: pointer; |
|
|
|
|
|
|
|
|
|
|
|
&:active { |
|
|
|
|
|
background: #f7f8fa; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.result-top { |
|
|
|
|
|
display: flex; |
|
|
|
|
|
justify-content: space-between; |
|
|
|
|
|
align-items: center; |
|
|
|
|
|
margin-bottom: 0.1rem; |
|
|
|
|
|
font-size: 0.26rem; |
|
|
|
|
|
color: #999; |
|
|
|
|
|
|
|
|
|
|
|
.result-sender { |
|
|
|
|
|
color: #4485f5; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.result-content { |
|
|
|
|
|
font-size: 0.3rem; |
|
|
|
|
|
color: #333; |
|
|
|
|
|
line-height: 1.5; |
|
|
|
|
|
white-space: nowrap; |
|
|
|
|
|
overflow: hidden; |
|
|
|
|
|
text-overflow: ellipsis; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.message-group { |
|
|
.message-group { |
|
|
@ -445,6 +680,55 @@ const formatTime = (dateStr) => { |
|
|
z-index: 999; |
|
|
z-index: 999; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.context-menu { |
|
|
|
|
|
position: absolute; |
|
|
|
|
|
background: rgba(50, 50, 50, 0.9); |
|
|
|
|
|
border-radius: 0.12rem; |
|
|
|
|
|
padding: 0.1rem 0; |
|
|
|
|
|
min-width: 2rem; |
|
|
|
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); |
|
|
|
|
|
transform: translate(-50%, -100%); |
|
|
|
|
|
|
|
|
|
|
|
/* 底部三角形箭头 */ |
|
|
|
|
|
&::after { |
|
|
|
|
|
content: ''; |
|
|
|
|
|
position: absolute; |
|
|
|
|
|
bottom: -0.12rem; |
|
|
|
|
|
left: 50%; |
|
|
|
|
|
transform: translateX(-50%); |
|
|
|
|
|
width: 0; |
|
|
|
|
|
height: 0; |
|
|
|
|
|
border-left: 0.12rem solid transparent; |
|
|
|
|
|
border-right: 0.12rem solid transparent; |
|
|
|
|
|
border-top: 0.12rem solid rgba(50, 50, 50, 0.9); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.menu-item { |
|
|
|
|
|
display: flex; |
|
|
|
|
|
align-items: center; |
|
|
|
|
|
justify-content: center; |
|
|
|
|
|
gap: 0.1rem; |
|
|
|
|
|
padding: 0.2rem 0.3rem; |
|
|
|
|
|
color: #fff; |
|
|
|
|
|
font-size: 0.3rem; |
|
|
|
|
|
cursor: pointer; |
|
|
|
|
|
|
|
|
|
|
|
&:active { |
|
|
|
|
|
background: rgba(255, 255, 255, 0.1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
:deep(.van-icon) { |
|
|
|
|
|
color: #fff; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.menu-divider { |
|
|
|
|
|
height: 1px; |
|
|
|
|
|
background: rgba(255, 255, 255, 0.2); |
|
|
|
|
|
margin: 0 0.2rem; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
.chat-input-area { |
|
|
.chat-input-area { |
|
|
background-color: #fff; |
|
|
background-color: #fff; |
|
|
padding: 0.2rem 0.3rem; |
|
|
padding: 0.2rem 0.3rem; |
|
|
|