Trim locale and notification payload
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ChatMessage } from '#/api/core/chat';
|
||||
import type {
|
||||
AnnouncementItem,
|
||||
NotificationItem,
|
||||
@@ -8,11 +7,10 @@ import type {
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben-core/popup-ui';
|
||||
import { Mail, MailCheck, Megaphone, MessageSquare, Trash2 } from '@vben/icons';
|
||||
import { Mail, MailCheck, Megaphone, Trash2 } from '@vben/icons';
|
||||
|
||||
import { ElButton, ElEmpty, ElScrollbar, ElTooltip } from 'element-plus';
|
||||
|
||||
import UserAvatar from '#/components/user-avatar/index.vue';
|
||||
import { ZqTabs } from '#/components/zq-tabs';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
@@ -25,12 +23,8 @@ interface Props {
|
||||
announcements?: AnnouncementItem[];
|
||||
// 公告未读数
|
||||
announcementUnreadCount?: number;
|
||||
// 未读聊天消息列表
|
||||
unreadChats?: ChatMessage[];
|
||||
// 聊天未读总数
|
||||
chatUnreadCount?: number;
|
||||
// 当前激活的 Tab
|
||||
activeTab?: 'announcement' | 'chat' | 'message';
|
||||
activeTab?: 'announcement' | 'message';
|
||||
}
|
||||
|
||||
defineOptions({ name: 'NotificationDrawer' });
|
||||
@@ -40,18 +34,15 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
messageUnreadCount: 0,
|
||||
announcements: () => [],
|
||||
announcementUnreadCount: 0,
|
||||
unreadChats: () => [],
|
||||
chatUnreadCount: 0,
|
||||
activeTab: 'message',
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
clear: [];
|
||||
clickChat: [ChatMessage];
|
||||
makeAll: [];
|
||||
readAnnouncement: [AnnouncementItem];
|
||||
readMessage: [NotificationItem];
|
||||
'update:activeTab': ['announcement' | 'chat' | 'message'];
|
||||
'update:activeTab': ['announcement' | 'message'];
|
||||
viewAll: [];
|
||||
}>();
|
||||
|
||||
@@ -65,11 +56,6 @@ const tabItems = computed(() => [
|
||||
label: `${$t('message.drawer.messageTab')}${props.messageUnreadCount > 0 ? ` (${props.messageUnreadCount})` : ''}`,
|
||||
icon: Mail,
|
||||
},
|
||||
{
|
||||
key: 'chat',
|
||||
label: `${$t('message.drawer.chatTab')}${props.chatUnreadCount > 0 ? ` (${props.chatUnreadCount})` : ''}`,
|
||||
icon: MessageSquare,
|
||||
},
|
||||
{
|
||||
key: 'announcement',
|
||||
label: `${$t('message.drawer.announcementTab')}${props.announcementUnreadCount > 0 ? ` (${props.announcementUnreadCount})` : ''}`,
|
||||
@@ -78,34 +64,10 @@ const tabItems = computed(() => [
|
||||
]);
|
||||
|
||||
function handleTabChange(value: string) {
|
||||
currentTab.value = value as 'announcement' | 'chat' | 'message';
|
||||
currentTab.value = value as 'announcement' | 'message';
|
||||
emit('update:activeTab', currentTab.value);
|
||||
}
|
||||
|
||||
function handleChatClick(msg: ChatMessage) {
|
||||
emit('clickChat', msg);
|
||||
}
|
||||
|
||||
function getMessagePreview(msg: ChatMessage): string {
|
||||
if (msg.msg_type === 'text') return msg.content || '';
|
||||
if (msg.msg_type === 'image') return `[${$t('chat.image')}]`;
|
||||
if (msg.msg_type === 'file')
|
||||
return `[${$t('chat.file')}] ${msg.file_name || ''}`;
|
||||
if (msg.msg_type === 'voice') return `[${$t('chat.voice')}]`;
|
||||
return `[${msg.msg_type}]`;
|
||||
}
|
||||
|
||||
function formatChatTime(datetime?: string): string {
|
||||
if (!datetime) return '';
|
||||
const date = new Date(datetime);
|
||||
const now = new Date();
|
||||
const isToday = date.toDateString() === now.toDateString();
|
||||
if (isToday) {
|
||||
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
return date.toLocaleDateString([], { month: '2-digit', day: '2-digit' });
|
||||
}
|
||||
|
||||
function handleViewAll() {
|
||||
emit('viewAll');
|
||||
}
|
||||
@@ -240,59 +202,6 @@ function getPriorityClass(priority: number): string {
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<!-- 聊天未读列表 -->
|
||||
<template v-else-if="currentTab === 'chat'">
|
||||
<ElScrollbar v-if="unreadChats.length > 0" class="flex-1">
|
||||
<ul class="flex w-full flex-col gap-2">
|
||||
<template v-for="msg in unreadChats" :key="msg.id">
|
||||
<li
|
||||
class="relative flex w-full cursor-pointer items-center gap-3 rounded-lg border border-[var(--el-border-color)] p-3 transition-colors hover:bg-[var(--el-fill-color-light)]"
|
||||
@click="handleChatClick(msg)"
|
||||
>
|
||||
<UserAvatar
|
||||
:user-id="msg.sender_id"
|
||||
:name="msg.sender_name || ''"
|
||||
:avatar="msg.sender_avatar"
|
||||
:size="40"
|
||||
:font-size="16"
|
||||
:show-popover="false"
|
||||
class="shrink-0"
|
||||
/>
|
||||
<div class="flex flex-1 flex-col gap-1 leading-none">
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-sm font-medium">
|
||||
{{ msg.sender_name || '' }}
|
||||
</p>
|
||||
<span
|
||||
class="text-xs text-[var(--el-text-color-placeholder)]"
|
||||
>
|
||||
{{ formatChatTime(msg.sys_create_datetime) }}
|
||||
</span>
|
||||
</div>
|
||||
<p
|
||||
class="truncate text-xs text-[var(--el-text-color-secondary)]"
|
||||
>
|
||||
{{ getMessagePreview(msg) }}
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
</template>
|
||||
</ul>
|
||||
</ElScrollbar>
|
||||
|
||||
<template v-else>
|
||||
<div class="flex flex-1 items-center justify-center">
|
||||
<ElEmpty :description="$t('message.drawer.noChats')">
|
||||
<template #image>
|
||||
<MessageSquare
|
||||
class="size-16 text-[var(--el-text-color-placeholder)]"
|
||||
/>
|
||||
</template>
|
||||
</ElEmpty>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<!-- 公告列表 -->
|
||||
<template v-else>
|
||||
<ElScrollbar v-if="announcements.length > 0" class="flex-1">
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ChatMessage } from '#/api/core/chat';
|
||||
import type {
|
||||
AnnouncementItem,
|
||||
NotificationItem,
|
||||
} from '#/composables/useNotification';
|
||||
import type { WatchStopHandle } from 'vue';
|
||||
|
||||
import {
|
||||
computed,
|
||||
defineAsyncComponent,
|
||||
onUnmounted,
|
||||
ref,
|
||||
watch,
|
||||
} from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { computed, defineAsyncComponent, onUnmounted, ref, watch } from 'vue';
|
||||
|
||||
import { useWatermark } from '@vben/hooks';
|
||||
import { BasicLayout } from '@vben/layouts';
|
||||
@@ -27,11 +19,13 @@ import { useAuthStore } from '#/store';
|
||||
const LoginForm = defineAsyncComponent(
|
||||
() => import('#/views/_core/authentication/login.vue'),
|
||||
);
|
||||
const AuthenticationLoginExpiredModal = defineAsyncComponent(() =>
|
||||
import('@vben/common-ui/es/login-expired-modal'),
|
||||
const AuthenticationLoginExpiredModal = defineAsyncComponent(
|
||||
() => import('@vben/common-ui/es/login-expired-modal'),
|
||||
);
|
||||
const UserDropdown = defineAsyncComponent(() =>
|
||||
import('@vben/layouts/es/user-dropdown').then((module) => module.UserDropdown),
|
||||
import('@vben/layouts/es/user-dropdown').then(
|
||||
(module) => module.UserDropdown,
|
||||
),
|
||||
);
|
||||
const NotificationPopup = defineAsyncComponent(
|
||||
() => import('#/components/notification/NotificationPopup.vue'),
|
||||
@@ -41,12 +35,10 @@ const notifications = ref<NotificationItem[]>([]);
|
||||
const messageUnreadCount = ref(0);
|
||||
const announcements = ref<AnnouncementItem[]>([]);
|
||||
const announcementUnreadCount = ref(0);
|
||||
const activeTab = ref<'announcement' | 'chat' | 'message'>('message');
|
||||
const activeTab = ref<'announcement' | 'message'>('message');
|
||||
const showDot = computed(
|
||||
() => messageUnreadCount.value + announcementUnreadCount.value > 0,
|
||||
);
|
||||
const unreadChatMessages = ref<ChatMessage[]>([]);
|
||||
const chatTotalUnread = ref(0);
|
||||
|
||||
const userStore = useUserStore();
|
||||
const authStore = useAuthStore();
|
||||
@@ -54,9 +46,7 @@ const accessStore = useAccessStore();
|
||||
const { destroyWatermark, updateWatermark } = useWatermark();
|
||||
|
||||
// 初始化消息通知
|
||||
const router = useRouter();
|
||||
let notificationApi: any = null;
|
||||
let chatApi: any = null;
|
||||
let layoutActive = true;
|
||||
let realtimeInitializing: Promise<void> | null = null;
|
||||
let realtimeInitialized = false;
|
||||
@@ -67,7 +57,6 @@ onUnmounted(() => {
|
||||
stopRealtimeWatches.forEach((stop) => stop());
|
||||
stopRealtimeWatches = [];
|
||||
notificationApi?.cleanup();
|
||||
chatApi?.disconnectChat();
|
||||
});
|
||||
|
||||
async function initRealtimeFeatures() {
|
||||
@@ -81,15 +70,11 @@ async function initRealtimeFeatures() {
|
||||
}
|
||||
|
||||
async function doInitRealtimeFeatures() {
|
||||
const [notificationModule, chatModule] = await Promise.all([
|
||||
import('#/composables/useNotification'),
|
||||
import('#/views/_core/chat/composables/useChat'),
|
||||
]);
|
||||
const notificationModule = await import('#/composables/useNotification');
|
||||
|
||||
if (!layoutActive) return;
|
||||
|
||||
notificationApi = notificationModule.useNotification();
|
||||
chatApi = chatModule.useChat();
|
||||
|
||||
stopRealtimeWatches = [
|
||||
watch(
|
||||
@@ -123,30 +108,13 @@ async function doInitRealtimeFeatures() {
|
||||
watch(
|
||||
notificationApi.activeTab,
|
||||
(value) => {
|
||||
activeTab.value = value;
|
||||
},
|
||||
{ immediate: true },
|
||||
),
|
||||
watch(
|
||||
chatApi.unreadChatMessages,
|
||||
(value) => {
|
||||
unreadChatMessages.value = value;
|
||||
},
|
||||
{ immediate: true },
|
||||
),
|
||||
watch(
|
||||
chatApi.totalUnread,
|
||||
(value) => {
|
||||
chatTotalUnread.value = value;
|
||||
activeTab.value = value === 'announcement' ? value : 'message';
|
||||
},
|
||||
{ immediate: true },
|
||||
),
|
||||
];
|
||||
|
||||
notificationApi.init();
|
||||
chatApi.connectChat();
|
||||
chatApi.loadConversations();
|
||||
chatApi.loadUnreadChatMessages();
|
||||
realtimeInitialized = true;
|
||||
}
|
||||
|
||||
@@ -225,7 +193,7 @@ function handleViewAll() {
|
||||
notificationApi?.viewAllMessages();
|
||||
}
|
||||
|
||||
function handleTabChange(tab: 'announcement' | 'chat' | 'message') {
|
||||
function handleTabChange(tab: 'announcement' | 'message') {
|
||||
activeTab.value = tab;
|
||||
if (notificationApi) {
|
||||
notificationApi.activeTab.value = tab;
|
||||
@@ -236,19 +204,6 @@ function handleNotificationOpen() {
|
||||
void initRealtimeFeatures();
|
||||
}
|
||||
|
||||
function handleChatClick(msg: ChatMessage) {
|
||||
// 新开tab跳转到聊天页面,带上会话ID
|
||||
const url = router.resolve(
|
||||
`/chat?conversationId=${msg.conversation_id}`,
|
||||
).href;
|
||||
window.open(url, '_blank');
|
||||
|
||||
// 从未读聊天列表中移除
|
||||
const index = unreadChatMessages.value.findIndex((m) => m.id === msg.id);
|
||||
if (index !== -1) {
|
||||
unreadChatMessages.value.splice(index, 1);
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => ({
|
||||
enable: preferences.app.watermark,
|
||||
@@ -287,16 +242,13 @@ watch(
|
||||
</template>
|
||||
<template #notification>
|
||||
<NotificationPopup
|
||||
:dot="showDot || chatTotalUnread > 0"
|
||||
:dot="showDot"
|
||||
:notifications="notifications"
|
||||
:message-unread-count="messageUnreadCount"
|
||||
:announcements="announcements"
|
||||
:announcement-unread-count="announcementUnreadCount"
|
||||
:unread-chats="unreadChatMessages"
|
||||
:chat-unread-count="chatTotalUnread"
|
||||
:active-tab="activeTab"
|
||||
@clear="handleNoticeClear"
|
||||
@click-chat="handleChatClick"
|
||||
@make-all="handleMakeAll"
|
||||
@open="handleNotificationOpen"
|
||||
@read-message="handleNoticeRead"
|
||||
@@ -322,7 +274,8 @@ watch(
|
||||
sidebarFooterProps?.compact
|
||||
? PRODUCT_BRAND_SHORT
|
||||
: $t('ui.layout.poweredBy')
|
||||
}}</span>
|
||||
}}</span
|
||||
>
|
||||
</button>
|
||||
</template>
|
||||
<template #extra>
|
||||
|
||||
@@ -30,23 +30,11 @@ const baseModules = import.meta.glob([
|
||||
]);
|
||||
|
||||
const businessModules = import.meta.glob([
|
||||
'./langs/zh-CN/account-settings.json',
|
||||
'./langs/zh-CN/api-token.json',
|
||||
'./langs/zh-CN/ai-platform.json',
|
||||
'./langs/zh-CN/announcement.json',
|
||||
'./langs/zh-CN/application.json',
|
||||
'./langs/zh-CN/chat.json',
|
||||
'./langs/zh-CN/dashboard-design.json',
|
||||
'./langs/zh-CN/dept.json',
|
||||
'./langs/zh-CN/dict.json',
|
||||
'./langs/zh-CN/file-manager.json',
|
||||
'./langs/zh-CN/loginLog.json',
|
||||
'./langs/zh-CN/menu.json',
|
||||
'./langs/zh-CN/message.json',
|
||||
'./langs/zh-CN/org-chart.json',
|
||||
'./langs/zh-CN/page-manager.json',
|
||||
'./langs/zh-CN/permission.json',
|
||||
'./langs/zh-CN/post.json',
|
||||
'./langs/zh-CN/role.json',
|
||||
'./langs/zh-CN/system-config.json',
|
||||
'./langs/zh-CN/system.json',
|
||||
|
||||
@@ -71,7 +71,7 @@ const coreRoutes: RouteRecordRaw[] = [
|
||||
hideInBreadcrumb: true,
|
||||
hideInMenu: true,
|
||||
hideInTab: true,
|
||||
title: $t('file-manager.filePreview'),
|
||||
title: '文件预览',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -10,6 +10,12 @@ import { ElButton, ElMessage } from 'element-plus';
|
||||
import { getFileTypeIcon } from '#/assets/file-icons';
|
||||
import { getFileUrl } from '#/composables/useFileUrl';
|
||||
|
||||
const FILE_PREVIEW_TITLE = '文件预览';
|
||||
const FILE_DOWNLOAD_TEXT = '下载';
|
||||
const FILE_DOWNLOAD_FAILED = '下载文件失败';
|
||||
const FILE_PREVIEW_FAILED = '预览失败';
|
||||
const FILE_PREVIEW_NOT_SUPPORTED = '该文件类型暂不支持预览';
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const fileId = computed(() => route.params.id as string);
|
||||
@@ -20,7 +26,9 @@ const textContent = ref('');
|
||||
const errorMsg = ref('');
|
||||
const loading = ref(false);
|
||||
|
||||
const normalizedExt = computed(() => fileExt.value.toLowerCase().replace('.', ''));
|
||||
const normalizedExt = computed(() =>
|
||||
fileExt.value.toLowerCase().replace('.', ''),
|
||||
);
|
||||
const textExts = new Set([
|
||||
'bash',
|
||||
'conf',
|
||||
@@ -87,7 +95,7 @@ async function handleDownload() {
|
||||
link.remove();
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
} catch {
|
||||
ElMessage.error($t('file-manager.downloadFailed'));
|
||||
ElMessage.error(FILE_DOWNLOAD_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +104,7 @@ function handleBack() {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.title = fileName.value || $t('file-manager.filePreview');
|
||||
document.title = fileName.value || FILE_PREVIEW_TITLE;
|
||||
loadFile();
|
||||
});
|
||||
</script>
|
||||
@@ -119,7 +127,7 @@ onMounted(() => {
|
||||
</div>
|
||||
<ElButton v-if="fileUrl" size="small" @click="handleDownload">
|
||||
<Download class="mr-1 size-4" />
|
||||
{{ $t('file-manager.download') }}
|
||||
{{ FILE_DOWNLOAD_TEXT }}
|
||||
</ElButton>
|
||||
</div>
|
||||
|
||||
@@ -130,7 +138,7 @@ onMounted(() => {
|
||||
|
||||
<div v-else-if="errorMsg" class="max-w-md text-center">
|
||||
<p class="mb-2 text-lg text-[var(--el-color-danger)]">
|
||||
{{ $t('file-manager.previewFailed') }}
|
||||
{{ FILE_PREVIEW_FAILED }}
|
||||
</p>
|
||||
<p class="text-sm text-[var(--el-text-color-secondary)]">
|
||||
{{ errorMsg }}
|
||||
@@ -152,16 +160,17 @@ onMounted(() => {
|
||||
<pre
|
||||
v-else-if="previewType === 'text'"
|
||||
class="h-full w-full overflow-auto bg-[var(--el-fill-color-light)] p-4 text-sm leading-6"
|
||||
>{{ textContent }}</pre>
|
||||
>{{ textContent }}</pre
|
||||
>
|
||||
|
||||
<div v-else class="text-center">
|
||||
<img :src="getFileTypeIcon(fileExt)" class="mx-auto mb-4 size-20" />
|
||||
<p class="mb-4 text-lg text-[var(--el-text-color-secondary)]">
|
||||
{{ $t('file-manager.previewNotSupported') }}
|
||||
{{ FILE_PREVIEW_NOT_SUPPORTED }}
|
||||
</p>
|
||||
<ElButton v-if="fileUrl" type="primary" @click="handleDownload">
|
||||
<Download class="mr-1 size-4" />
|
||||
{{ $t('file-manager.download') }}
|
||||
{{ FILE_DOWNLOAD_TEXT }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user