# Conflicts: # .gitignore # .husky/pre-commit # .vscode/extensions.json # .vscode/settings.json # README.ja-JP.md # README.md # README.zh-CN.md # apps/backend-mock/api/auth/codes.ts # apps/backend-mock/api/auth/login.post.ts # apps/backend-mock/api/auth/logout.post.ts # apps/backend-mock/api/auth/refresh.post.ts # apps/backend-mock/api/menu/all.ts # apps/backend-mock/api/status.ts # apps/backend-mock/api/table/list.ts # apps/backend-mock/api/test.get.ts # apps/backend-mock/api/test.post.ts # apps/backend-mock/api/user/info.ts # apps/backend-mock/middleware/1.api.ts # apps/backend-mock/nitro.config.ts # apps/backend-mock/package.json # apps/backend-mock/routes/[...].ts # apps/backend-mock/tsconfig.json # apps/backend-mock/utils/cookie-utils.ts # apps/backend-mock/utils/jwt-utils.ts # apps/backend-mock/utils/mock-data.ts # apps/backend-mock/utils/response.ts # apps/web-antd/.env # apps/web-antd/src/adapter/component/index.ts # apps/web-antd/src/adapter/form.ts # apps/web-antd/src/api/request.ts # apps/web-antd/src/layouts/auth.vue # apps/web-antd/src/layouts/basic.vue # apps/web-antd/src/preferences.ts # apps/web-antd/src/router/guard.ts # apps/web-antd/src/router/routes/modules/demos.ts # apps/web-antd/src/store/auth.ts # apps/web-antd/src/views/demos/antd/index.vue # apps/web-antdv-next/vite.config.ts # apps/web-ele/.env # apps/web-ele/index.html # apps/web-ele/package.json # apps/web-ele/src/adapter/component/index.ts # apps/web-ele/src/adapter/form.ts # apps/web-ele/src/adapter/vxe-table.ts # apps/web-ele/src/api/request.ts # apps/web-ele/src/bootstrap.ts # apps/web-ele/src/layouts/auth.vue # apps/web-ele/src/layouts/basic.vue # apps/web-ele/src/locales/index.ts # apps/web-ele/src/locales/langs/en-US/demos.json # apps/web-ele/src/locales/langs/en-US/page.json # apps/web-ele/src/locales/langs/zh-CN/demos.json # apps/web-ele/src/locales/langs/zh-CN/page.json # apps/web-ele/src/preferences.ts # apps/web-ele/src/router/guard.ts # apps/web-ele/src/router/routes/core.ts # apps/web-ele/src/router/routes/modules/dashboard.ts # apps/web-ele/src/router/routes/modules/demos.ts # apps/web-ele/src/router/routes/modules/vben.ts # apps/web-ele/src/store/auth.ts # apps/web-ele/src/views/_core/authentication/code-login.vue # apps/web-ele/src/views/_core/authentication/forget-password.vue # apps/web-ele/src/views/_core/authentication/register.vue # apps/web-ele/src/views/dashboard/analytics/analytics-trends.vue # apps/web-ele/src/views/dashboard/analytics/analytics-visits-data.vue # apps/web-ele/src/views/dashboard/analytics/analytics-visits-sales.vue # apps/web-ele/src/views/dashboard/analytics/analytics-visits-source.vue # apps/web-ele/src/views/dashboard/analytics/analytics-visits.vue # apps/web-ele/src/views/dashboard/analytics/index.vue # apps/web-ele/src/views/demos/element/index.vue # apps/web-ele/src/views/demos/form/basic.vue # apps/web-ele/tsconfig.json # apps/web-ele/tsconfig.node.json # apps/web-naive/.env # apps/web-naive/index.html # apps/web-naive/package.json # apps/web-naive/src/adapter/component/index.ts # apps/web-naive/src/adapter/form.ts # apps/web-naive/src/adapter/vxe-table.ts # apps/web-naive/src/api/request.ts # apps/web-naive/src/bootstrap.ts # apps/web-naive/src/layouts/auth.vue # apps/web-naive/src/layouts/basic.vue # apps/web-naive/src/locales/index.ts # apps/web-naive/src/locales/langs/en-US/demos.json # apps/web-naive/src/locales/langs/en-US/page.json # apps/web-naive/src/locales/langs/zh-CN/demos.json # apps/web-naive/src/locales/langs/zh-CN/page.json # apps/web-naive/src/preferences.ts # apps/web-naive/src/router/guard.ts # apps/web-naive/src/router/routes/core.ts # apps/web-naive/src/router/routes/modules/dashboard.ts # apps/web-naive/src/router/routes/modules/demos.ts # apps/web-naive/src/router/routes/modules/vben.ts # apps/web-naive/src/store/auth.ts # apps/web-naive/src/views/_core/authentication/code-login.vue # apps/web-naive/src/views/_core/authentication/forget-password.vue # apps/web-naive/src/views/_core/authentication/register.vue # apps/web-naive/src/views/dashboard/analytics/analytics-trends.vue # apps/web-naive/src/views/dashboard/analytics/analytics-visits-data.vue # apps/web-naive/src/views/dashboard/analytics/analytics-visits-sales.vue # apps/web-naive/src/views/dashboard/analytics/analytics-visits-source.vue # apps/web-naive/src/views/dashboard/analytics/analytics-visits.vue # apps/web-naive/src/views/dashboard/analytics/index.vue # apps/web-naive/src/views/demos/form/basic.vue # apps/web-naive/src/views/demos/naive/index.vue # apps/web-naive/tsconfig.json # apps/web-naive/tsconfig.node.json # apps/web-naive/vite.config.ts # docs/.vitepress/components/demo-preview.vue # docs/.vitepress/components/preview-group.vue # docs/.vitepress/config/en.mts # docs/.vitepress/config/index.mts # docs/.vitepress/config/plugins/demo-preview.ts # docs/.vitepress/config/shared.mts # docs/.vitepress/config/zh.mts # docs/.vitepress/theme/components/site-layout.vue # docs/.vitepress/theme/components/vben-contributors.vue # docs/.vitepress/theme/styles/variables.css # docs/package.json # docs/src/_env/adapter/component.ts # docs/src/_env/adapter/form.ts # docs/src/_env/adapter/vxe-table.ts # docs/src/commercial/community.md # docs/src/components/common-ui/vben-count-to-animator.md # docs/src/components/common-ui/vben-drawer.md # docs/src/components/common-ui/vben-form.md # docs/src/components/common-ui/vben-modal.md # docs/src/components/common-ui/vben-vxe-table.md # docs/src/components/layout-ui/page.md # docs/src/demos/vben-drawer/auto-height/drawer.vue # docs/src/demos/vben-drawer/basic/index.vue # docs/src/demos/vben-drawer/dynamic/index.vue # docs/src/demos/vben-drawer/shared-data/drawer.vue # docs/src/demos/vben-drawer/shared-data/index.vue # docs/src/demos/vben-form/api/index.vue # docs/src/demos/vben-form/basic/index.vue # docs/src/demos/vben-form/custom/index.vue # docs/src/demos/vben-form/dynamic/index.vue # docs/src/demos/vben-form/query/index.vue # docs/src/demos/vben-form/rules/index.vue # docs/src/demos/vben-modal/auto-height/modal.vue # docs/src/demos/vben-modal/basic/index.vue # docs/src/demos/vben-modal/dynamic/index.vue # docs/src/demos/vben-modal/shared-data/index.vue # docs/src/demos/vben-modal/shared-data/modal.vue # docs/src/demos/vben-vxe-table/basic/index.vue # docs/src/demos/vben-vxe-table/custom-cell/index.vue # docs/src/demos/vben-vxe-table/edit-row/index.vue # docs/src/demos/vben-vxe-table/fixed/index.vue # docs/src/demos/vben-vxe-table/form/index.vue # docs/src/demos/vben-vxe-table/remote/index.vue # docs/src/demos/vben-vxe-table/tree/index.vue # docs/src/demos/vben-vxe-table/virtual/index.vue # docs/src/en/guide/essentials/development.md # docs/src/en/guide/essentials/external-module.md # docs/src/en/guide/essentials/route.md # docs/src/en/guide/essentials/server.md # docs/src/en/guide/essentials/settings.md # docs/src/en/guide/in-depth/access.md # docs/src/en/guide/in-depth/loading.md # docs/src/en/guide/in-depth/locale.md # docs/src/en/guide/in-depth/theme.md # docs/src/en/guide/introduction/quick-start.md # docs/src/en/guide/introduction/thin.md # docs/src/en/guide/introduction/vben.md # docs/src/en/guide/other/faq.md # docs/src/en/guide/project/dir.md # docs/src/en/guide/project/standard.md # docs/src/en/guide/project/tailwindcss.md # docs/src/en/index.md # docs/src/friend-links/index.md # docs/src/guide/essentials/build.md # docs/src/guide/essentials/development.md # docs/src/guide/essentials/external-module.md # docs/src/guide/essentials/route.md # docs/src/guide/essentials/server.md # docs/src/guide/essentials/settings.md # docs/src/guide/in-depth/access.md # docs/src/guide/in-depth/check-updates.md # docs/src/guide/in-depth/loading.md # docs/src/guide/in-depth/locale.md # docs/src/guide/in-depth/theme.md # docs/src/guide/introduction/quick-start.md # docs/src/guide/introduction/thin.md # docs/src/guide/introduction/vben.md # docs/src/guide/introduction/why.md # docs/src/guide/other/faq.md # docs/src/guide/project/dir.md # docs/src/guide/project/standard.md # docs/src/guide/project/tailwindcss.md # docs/src/index.md # docs/tsconfig.json # package.json # packages/@core/ui-kit/shadcn-ui/src/components/logo/logo.vue # packages/constants/src/core.ts # packages/effects/common-ui/src/components/index.ts # packages/effects/common-ui/src/ui/dashboard/analysis/analysis-overview.vue # packages/effects/common-ui/src/ui/dashboard/workbench/workbench-header.vue # packages/effects/common-ui/src/ui/dashboard/workbench/workbench-project.vue # packages/effects/layouts/src/authentication/authentication.vue # packages/effects/layouts/src/basic/layout.vue # packages/effects/layouts/src/widgets/notification/notification.vue # packages/effects/layouts/src/widgets/notification/types.ts # packages/icons/src/iconify/index.ts # packages/icons/src/svg/index.ts # packages/stores/src/modules/user.ts # playground/src/adapter/component/index.ts # playground/src/store/auth.ts # pnpm-lock.yaml # vben-admin.code-workspace
346 lines
9.0 KiB
Vue
346 lines
9.0 KiB
Vue
<script lang="ts" setup>
|
|
import type { NotificationItem } from '@vben/layouts';
|
|
|
|
import {computed, onUnmounted, ref, watch} from 'vue';
|
|
import { useRouter } from 'vue-router';
|
|
|
|
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
|
|
|
|
// import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
|
|
import { useWatermark } from '@vben/hooks';
|
|
// import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
|
|
// import { CircleHelp } from '@vben/icons';
|
|
// import { BookOpenText, CircleHelp, SvgGithubIcon } from '@vben/icons';
|
|
import {
|
|
BasicLayout,
|
|
LockScreen,
|
|
Notification,
|
|
UserDropdown,
|
|
} from '@vben/layouts';
|
|
import { preferences, usePreferences } from '@vben/preferences';
|
|
import { useAccessStore, useUserStore } from '@vben/stores';
|
|
// import { openWindow } from '@vben/utils';
|
|
|
|
import {
|
|
Bell,
|
|
CalendarClock,
|
|
Megaphone,
|
|
Users,
|
|
} from 'lucide-vue-next';
|
|
|
|
// import { $t } from '#/locales';
|
|
import DoctorTransferFloat from '#/components/doctor-transfer-float/DoctorTransferFloat.vue';
|
|
import HeaderVipBadge from '#/components/vip/HeaderVipBadge.vue';
|
|
import { useAuthStore } from '#/store';
|
|
import LoginForm from '#/views/_core/authentication/login.vue';
|
|
import SwitchAccountModal from '#/layouts/components/SwitchAccountModal.vue';
|
|
import { useRouter } from 'vue-router';
|
|
import {getNoticeListApi, readAllApi} from "#/views/notice/api";
|
|
import {formatTimeToRelative} from "#/util/tool";
|
|
import {notification} from "ant-design-vue";
|
|
|
|
const router = useRouter();
|
|
const switchAccountModalRef = ref<InstanceType<typeof SwitchAccountModal>>();
|
|
|
|
// 样式相关
|
|
const typeIcons = {
|
|
0: Megaphone,
|
|
1: Bell,
|
|
2: CalendarClock,
|
|
};
|
|
|
|
const typeColors = {
|
|
0: 'text-sky-500',
|
|
1: 'text-amber-500',
|
|
2: 'text-emerald-500',
|
|
};
|
|
|
|
const typeBgColors = {
|
|
0: 'bg-sky-50',
|
|
1: 'bg-amber-50',
|
|
2: 'bg-emerald-50',
|
|
};
|
|
|
|
const typeBorderColors = {
|
|
0: 'border-sky-200',
|
|
1: 'border-amber-200',
|
|
2: 'border-emerald-200',
|
|
};
|
|
|
|
const notifications = ref<NotificationItem[]>([]);
|
|
|
|
// 获取消息列表数据
|
|
const getNoticeList = async () => {
|
|
try {
|
|
const res = await getNoticeListApi({
|
|
status: 0,
|
|
});
|
|
let message = '未读消息';
|
|
if (res.items.length > 0) {
|
|
if (res.items.length > notifications.value.length) {
|
|
if (notifications.value.length === 0) {
|
|
message = '新消息';
|
|
}
|
|
notification.info({
|
|
message: `您有${message}`,
|
|
description: `您有 ${res.items.length} 条${message}请注意查收`,
|
|
duration: 5,
|
|
});
|
|
}
|
|
|
|
notifications.value = res.items.map(item => ({
|
|
id: item.id,
|
|
icon: typeIcons[item.type],
|
|
// 将API返回的数据映射到组件需要的格式
|
|
message: item.title,
|
|
title: getMessageTypeName(item.type),
|
|
date: formatTimeToRelative(item.created_at),
|
|
color: typeColors[item.type],
|
|
isRead: item.status
|
|
}));
|
|
} else {
|
|
notifications.value = [];
|
|
}
|
|
} catch (error) {
|
|
console.error('获取消息列表失败:', error);
|
|
}
|
|
};
|
|
getNoticeList();
|
|
// 每隔二十秒刷新一次
|
|
let intervalId = setInterval(getNoticeList, 20_000);
|
|
|
|
// 封装定时器重启逻辑
|
|
const restartInterval = () => {
|
|
clearInterval(intervalId);
|
|
getNoticeList(); // 立即获取最新数据
|
|
intervalId = setInterval(getNoticeList, 20_000);
|
|
};
|
|
|
|
// 处理跨标签页修改
|
|
const handleStorageChange = (event) => {
|
|
if (event.key === 'readStatus') {
|
|
restartInterval();
|
|
}
|
|
};
|
|
|
|
// 处理当前标签页修改(核心新增部分)
|
|
const handleLocalChange = () => {
|
|
restartInterval();
|
|
};
|
|
|
|
// 添加双重监听
|
|
window.addEventListener('storage', handleStorageChange); // 跨标签页监听
|
|
const originalSetItem = localStorage.setItem.bind(localStorage);
|
|
|
|
// 拦截当前页的 localStorage.setItem 操作
|
|
localStorage.setItem = (key, value) => {
|
|
originalSetItem(key, value);
|
|
if (key === 'readStatus') {
|
|
handleLocalChange(); // 手动触发当前页回调
|
|
}
|
|
};
|
|
|
|
// 组件卸载时清理
|
|
onUnmounted(() => {
|
|
clearInterval(intervalId);
|
|
window.removeEventListener('storage', handleStorageChange);
|
|
localStorage.setItem = originalSetItem; // 恢复原始方法
|
|
});
|
|
|
|
// 消息类型定义
|
|
const messageTypes = [
|
|
{ id: -1, name: '全部消息' },
|
|
{ id: 0, name: '系统公告', icon: Megaphone },
|
|
{ id: 1, name: '系统通知', icon: Bell },
|
|
{ id: 2, name: '周报提醒', icon: CalendarClock },
|
|
];
|
|
// 根据类型ID获取类型名称
|
|
const getMessageTypeName = (typeId) => {
|
|
const type = messageTypes.find(t => t.id === typeId);
|
|
return type ? type.name : '未知类型';
|
|
};
|
|
const goNoticeList = () => {
|
|
// TODO 跳转通知列表
|
|
router.push('/notice/list');
|
|
};
|
|
|
|
// 处理消息点击
|
|
const handleItemClick = (item) => {
|
|
notifications.value.forEach((value) => {
|
|
if (value.id === item.id) {
|
|
value.status = 1;
|
|
value.isRead = 1;
|
|
}
|
|
});
|
|
router.push(`/notice/detail/${item.id}`);
|
|
};
|
|
|
|
const userStore = useUserStore();
|
|
const authStore = useAuthStore();
|
|
const accessStore = useAccessStore();
|
|
const { destroyWatermark, updateWatermark } = useWatermark();
|
|
const { isDark } = usePreferences();
|
|
const showDot = computed(() =>
|
|
notifications.value.some((item) => !item.isRead),
|
|
);
|
|
|
|
/** 与原先悬浮窗一致:有 doctor_id 且绑定门店才显示传方入口 */
|
|
const showDoctorTransfer = computed(() => {
|
|
const info = userStore.userInfo as Record<string, any> | null | undefined;
|
|
if (!info) return false;
|
|
return !!(info.doctor_id && info.store_id);
|
|
});
|
|
|
|
const menus = computed(() => [
|
|
{
|
|
handler: () => {
|
|
router.push({ name: 'Profile' });
|
|
},
|
|
icon: 'lucide:user',
|
|
text: $t('page.auth.profile'),
|
|
},
|
|
{
|
|
handler: () => {
|
|
switchAccountModalRef.value?.openModal();
|
|
},
|
|
icon: Users,
|
|
text: '切换账号',
|
|
},
|
|
]);
|
|
|
|
const avatar = computed(() => {
|
|
return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
|
|
});
|
|
|
|
async function handleLogout() {
|
|
await authStore.logout(false);
|
|
destroyWatermark();
|
|
}
|
|
|
|
function handleNoticeClear() {
|
|
readAllApi().then(() => {
|
|
notifications.value = [];
|
|
// 成功后可以重新获取数据或者直接更新本地状态
|
|
notification.success({
|
|
message: '标记成功',
|
|
duration: 2,
|
|
});
|
|
});
|
|
}
|
|
|
|
function markRead(id: number | string) {
|
|
const item = notifications.value.find((item) => item.id === id);
|
|
if (item) {
|
|
item.isRead = true;
|
|
}
|
|
}
|
|
|
|
function remove(id: number | string) {
|
|
notifications.value = notifications.value.filter((item) => item.id !== id);
|
|
}
|
|
|
|
function handleMakeAll() {
|
|
notifications.value.forEach((item) => (item.isRead = true));
|
|
}
|
|
|
|
const viewAll = () => {};
|
|
|
|
const handleClick = (item: NotificationItem) => {
|
|
// 如果通知项有链接,点击时跳转
|
|
if (item.link) {
|
|
navigateTo(item.link, item.query, item.state);
|
|
}
|
|
};
|
|
|
|
function navigateTo(
|
|
link: string,
|
|
query?: Record<string, any>,
|
|
state?: Record<string, any>,
|
|
) {
|
|
if (link.startsWith('http://') || link.startsWith('https://')) {
|
|
// 外部链接,在新标签页打开
|
|
window.open(link, '_blank');
|
|
} else {
|
|
// 内部路由链接,支持 query 参数和 state
|
|
router.push({
|
|
path: link,
|
|
query: query || {},
|
|
state,
|
|
});
|
|
}
|
|
}
|
|
|
|
watch(
|
|
() => ({
|
|
enable: preferences.app.watermark,
|
|
content: preferences.app.watermarkContent,
|
|
isDark: isDark.value,
|
|
}),
|
|
async ({ enable, content, isDark: isDarkValue }) => {
|
|
if (enable) {
|
|
const watermarkColor = isDarkValue
|
|
? 'rgba(255, 255, 255, 0.12)'
|
|
: 'rgba(0, 0, 0, 0.12)';
|
|
|
|
await updateWatermark({
|
|
// 这里更改水印内容
|
|
// content: `${userStore.userInfo?.nick_name || import.meta.env.VITE_APP_TITLE}`,
|
|
content: `${userStore.userInfo?.nick_name}\r\n${userStore.userInfo?.phone || import.meta.env.VITE_APP_TITLE}`,
|
|
});
|
|
} else {
|
|
destroyWatermark();
|
|
}
|
|
},
|
|
{
|
|
immediate: true,
|
|
},
|
|
);
|
|
</script>
|
|
|
|
<template>
|
|
<BasicLayout
|
|
:avatar
|
|
:text="userStore.userInfo?.realName"
|
|
@clear-preferences-and-logout="handleLogout"
|
|
@logout="handleLogout"
|
|
>
|
|
<template #header-right-55>
|
|
<DoctorTransferFloat v-if="showDoctorTransfer" />
|
|
</template>
|
|
<template #user-dropdown>
|
|
<UserDropdown
|
|
:avatar
|
|
:menus
|
|
:text="userStore.userInfo?.nick_name"
|
|
:description="userStore.userInfo?.email"
|
|
:tag-text="userStore.userInfo?.roles?.name"
|
|
@clear-preferences-and-logout="handleLogout"
|
|
@logout="handleLogout"
|
|
/>
|
|
</template>
|
|
<template #notification>
|
|
<Notification
|
|
:dot="showDot"
|
|
:notifications="notifications"
|
|
@clear="handleNoticeClear"
|
|
@make-all="handleMakeAll"
|
|
@read="handleItemClick"
|
|
@view-all="goNoticeList"
|
|
@on-click="handleClick"
|
|
/>
|
|
</template>
|
|
<template #extra>
|
|
<AuthenticationLoginExpiredModal
|
|
v-model:open="accessStore.loginExpired"
|
|
:avatar
|
|
>
|
|
<LoginForm />
|
|
</AuthenticationLoginExpiredModal>
|
|
<SwitchAccountModal ref="switchAccountModalRef" />
|
|
</template>
|
|
<template #lock-screen>
|
|
<LockScreen :avatar @to-login="handleLogout" />
|
|
</template>
|
|
</BasicLayout>
|
|
</template>
|