前端:
1、更新界面图标 2、修改消息缓存逻辑 3、新增清空未读消息数 后端: 1、修复不同时区导致的时间显示问题 2、新增清空未读消息数接口
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
<template>
|
||||
<div class="add-menu-container" v-click-outside="closeMenu">
|
||||
<button class="add-btn" :class="{ active: isShow }" @click="toggleMenu">
|
||||
<span class="plus-icon">+</span>
|
||||
</button>
|
||||
|
||||
<Transition name="pop">
|
||||
<div v-if="isShow" class="menu-card">
|
||||
<div class="arrow"></div>
|
||||
|
||||
<div class="menu-list">
|
||||
<div class="menu-item" v-for="(item, index) in props.menuList" :key="index" @click="handleAction(item.action)">
|
||||
<i class="icon" v-html="item.icon"></i>
|
||||
<span>{{item.text}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, defineProps, onMounted, defineEmits } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
menuList: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['actionActive'])
|
||||
|
||||
const isShow = ref(false);
|
||||
|
||||
const toggleMenu = () => {
|
||||
isShow.value = !isShow.value;
|
||||
};
|
||||
|
||||
const closeMenu = () => {
|
||||
isShow.value = false;
|
||||
};
|
||||
|
||||
const handleAction = (type) => {
|
||||
emit('actionActive', type);
|
||||
isShow.value = false; // 点击后关闭
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 自定义指令:点击外部区域关闭菜单
|
||||
* 也可以使用第三方库如 @vueuse/core 的 onClickOutside
|
||||
*/
|
||||
const vClickOutside = {
|
||||
mounted(el, binding) {
|
||||
el.clickOutsideEvent = (event) => {
|
||||
if (!(el === event.target || el.contains(event.target))) {
|
||||
binding.value();
|
||||
}
|
||||
};
|
||||
document.addEventListener('click', el.clickOutsideEvent);
|
||||
},
|
||||
unmounted(el) {
|
||||
document.removeEventListener('click', el.clickOutsideEvent);
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.add-menu-container {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* 加号按钮样式 */
|
||||
.add-btn {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: #dbdbdb;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.add-btn:hover {
|
||||
background: #cccbcb;
|
||||
}
|
||||
/*
|
||||
.add-btn.active {
|
||||
background: #007aff;
|
||||
color: white;
|
||||
}
|
||||
*/
|
||||
|
||||
.plus-icon {
|
||||
font-size: 22px;
|
||||
line-height: 1;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
/* 弹出卡片容器 */
|
||||
.menu-card {
|
||||
position: absolute;
|
||||
top: 45px;
|
||||
right: 0;
|
||||
width: 100px;
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
||||
z-index: 100;
|
||||
transform-origin: top right;
|
||||
}
|
||||
|
||||
/* 小三角 */
|
||||
.arrow {
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
right: 12px;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 6px solid transparent;
|
||||
border-right: 6px solid transparent;
|
||||
border-bottom: 6px solid white;
|
||||
}
|
||||
|
||||
/* 列表样式 */
|
||||
.menu-list {
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 5px 5px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.menu-item:hover {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.menu-item:first-child:hover {
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
|
||||
.menu-item:last-child:hover {
|
||||
border-bottom-left-radius: 10px;
|
||||
border-bottom-right-radius: 10px;
|
||||
}
|
||||
|
||||
.icon {
|
||||
margin-right: 5px;
|
||||
font-size: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
/*width: 20px;*/
|
||||
}
|
||||
|
||||
.menu-item span {
|
||||
font-size: 12px;
|
||||
/*font-weight: 400;*/
|
||||
}
|
||||
|
||||
/* 弹出动画 */
|
||||
.pop-enter-active, .pop-leave-active {
|
||||
transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
||||
}
|
||||
|
||||
.pop-enter-from, .pop-leave-to {
|
||||
opacity: 0;
|
||||
transform: scale(0.9) translateY(-10px);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,256 @@
|
||||
<template>
|
||||
<div class="modal-overlay" @click.self="$emit('close')">
|
||||
<div class="chat-modal">
|
||||
<div class="modal-header">
|
||||
<div class="header-top">
|
||||
<h3>群聊</h3>
|
||||
<button class="close-btn" @click="$emit('close')">×</button>
|
||||
</div>
|
||||
<div class="search-bar">
|
||||
<input
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
placeholder="搜索群组..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-list">
|
||||
<TransitionGroup name="list">
|
||||
<div
|
||||
v-for="group in filteredGroups"
|
||||
:key="group.id"
|
||||
class="chat-item"
|
||||
@click="handleSelect(group)"
|
||||
>
|
||||
<div
|
||||
class="avatar"
|
||||
:style="{ background: group.avatar ? `url(${group.avatar}) center/cover` : group.color }"
|
||||
>
|
||||
{{ group.avatar ? '' : group.name.charAt(0) }}
|
||||
</div>
|
||||
|
||||
<div class="chat-info">
|
||||
<div class="chat-name">{{ group.name }}</div>
|
||||
<!--<div class="chat-preview">{{ group.lastMsg }}</div>-->
|
||||
</div>
|
||||
<!--
|
||||
<div class="chat-meta">
|
||||
<span class="time">{{ group.time }}</span>
|
||||
<span v-if="group.unread" class="unread">{{ group.unread }}</span>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
|
||||
</TransitionGroup>
|
||||
|
||||
<div v-if="filteredGroups.length === 0" class="empty-state">
|
||||
未找到相关群聊
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, defineProps } from 'vue';
|
||||
|
||||
// 检查你的代码,确保 default 是一个返回数组的函数,且逗号、括号一一对应
|
||||
const props = defineProps({
|
||||
initialGroups: {
|
||||
type: Array,
|
||||
default: () => [
|
||||
{ id: 1, name: '产品设计交流群', lastMsg: '张三: 确认一下原型图', time: '14:30', unread: 3, color: 'linear-gradient(45deg, #007AFF, #5AC8FA)' },
|
||||
{ id: 2, name: '技术研发部', lastMsg: '王五: Bug已修复并上线', time: '12:05', unread: 0, color: 'linear-gradient(45deg, #4CD964, #5AC8FA)' },
|
||||
{ id: 3, name: '周末户外徒步', lastMsg: '李四: 记得带雨伞', time: '昨天', unread: 12, color: 'linear-gradient(45deg, #FF9500, #FFCC00)' },
|
||||
{ id: 4, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' }, // 确保这里没有多余或缺失的逗号
|
||||
{ id: 5, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' },
|
||||
{ id: 6, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' },
|
||||
{ id: 7, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' },
|
||||
{ id: 8, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' },
|
||||
{ id: 9, name: 'Family 家族群', lastMsg: '[图片]', time: '周一', unread: 0, color: 'linear-gradient(45deg, #5856D6, #AF52DE)' }
|
||||
]
|
||||
}
|
||||
}); // 检查这里是否漏掉了右括号 )
|
||||
|
||||
|
||||
const emit = defineEmits(['close', 'select']);
|
||||
const searchQuery = ref('');
|
||||
|
||||
// 搜索过滤逻辑
|
||||
const filteredGroups = computed(() => {
|
||||
return props.initialGroups.filter(g =>
|
||||
g.name.toLowerCase().includes(searchQuery.value.toLowerCase())
|
||||
);
|
||||
});
|
||||
|
||||
const handleSelect = (group) => {
|
||||
emit('select', group);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 遮罩层 */
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
backdrop-filter: blur(4px);
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
/* 弹出层主容器 */
|
||||
.chat-modal {
|
||||
width: 360px;
|
||||
max-height: 80vh;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
backdrop-filter: blur(20px);
|
||||
border-radius: 28px;
|
||||
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
border: 1px solid rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
/* 头部样式 */
|
||||
.modal-header {
|
||||
padding: 20px 20px 10px;
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.header-top h3 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
color: #1d1d1f;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
background: #eee;
|
||||
border: none;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
font-size: 18px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* 搜索框 */
|
||||
.search-bar input {
|
||||
width: 100%;
|
||||
padding: 10px 15px;
|
||||
border-radius: 12px;
|
||||
border: none;
|
||||
background: rgba(0, 0, 0, 0.05);
|
||||
outline: none;
|
||||
box-sizing: border-box;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* 列表滚动区 */
|
||||
.chat-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.chat-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
border-radius: 18px;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
cursor: pointer;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.chat-item:hover {
|
||||
background: rgba(0, 122, 255, 0.08);
|
||||
}
|
||||
|
||||
/* 头像 */
|
||||
.avatar {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 15px;
|
||||
margin-right: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.chat-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.chat-name {
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
color: #1d1d1f;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.chat-preview {
|
||||
font-size: 13px;
|
||||
color: #86868b;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.chat-meta {
|
||||
text-align: right;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 12px;
|
||||
color: #86868b;
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.unread {
|
||||
background: #007AFF;
|
||||
color: white;
|
||||
font-size: 11px;
|
||||
padding: 2px 7px;
|
||||
border-radius: 10px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 列表过渡动画 */
|
||||
.list-enter-active, .list-leave-active {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
.list-enter-from, .list-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateX(-10px);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px 0;
|
||||
color: #86868b;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user