mirror of
https://gitee.com/yudaocode/yudao-ui-admin-vben.git
synced 2025-12-30 10:32:25 +00:00
202 lines
4.9 KiB
Vue
202 lines
4.9 KiB
Vue
<script lang="ts" setup>
|
|
import type { ExtendedModalApi } from '@vben/common-ui';
|
|
import type { NotificationItem } from '@vben/layouts';
|
|
|
|
import { computed, onMounted, ref, unref, watch } from 'vue';
|
|
|
|
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
|
|
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
|
|
import { useWatermark } from '@vben/hooks';
|
|
import { BookOpenText, CircleHelp, SvgGithubIcon } from '@vben/icons';
|
|
import {
|
|
BasicLayout,
|
|
LockScreen,
|
|
Notification,
|
|
TimezoneButton,
|
|
UserDropdown,
|
|
} from '@vben/layouts';
|
|
import { preferences } from '@vben/preferences';
|
|
import { useAccessStore, useUserStore } from '@vben/stores';
|
|
import { openWindow } from '@vben/utils';
|
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
|
import { getTimezoneOptionsApi } from '#/api';
|
|
import { $t } from '#/locales';
|
|
import { useAuthStore, useUserProfileStore } from '#/store';
|
|
import LoginForm from '#/views/_core/authentication/login.vue';
|
|
|
|
const notifications = ref<NotificationItem[]>([
|
|
{
|
|
avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB',
|
|
date: '3小时前',
|
|
isRead: true,
|
|
message: '描述信息描述信息描述信息',
|
|
title: '收到了 14 份新周报',
|
|
},
|
|
{
|
|
avatar: 'https://avatar.vercel.sh/1',
|
|
date: '刚刚',
|
|
isRead: false,
|
|
message: '描述信息描述信息描述信息',
|
|
title: '朱偏右 回复了你',
|
|
},
|
|
{
|
|
avatar: 'https://avatar.vercel.sh/1',
|
|
date: '2024-01-01',
|
|
isRead: false,
|
|
message: '描述信息描述信息描述信息',
|
|
title: '曲丽丽 评论了你',
|
|
},
|
|
{
|
|
avatar: 'https://avatar.vercel.sh/satori',
|
|
date: '1天前',
|
|
isRead: false,
|
|
message: '描述信息描述信息描述信息',
|
|
title: '代办提醒',
|
|
},
|
|
]);
|
|
|
|
const userStore = useUserStore();
|
|
const authStore = useAuthStore();
|
|
const accessStore = useAccessStore();
|
|
const { destroyWatermark, updateWatermark } = useWatermark();
|
|
const showDot = computed(() =>
|
|
notifications.value.some((item) => !item.isRead),
|
|
);
|
|
|
|
const userProfileStore = useUserProfileStore();
|
|
const computedTimezone = computed(() => unref(userProfileStore.timezone));
|
|
|
|
const timezoneOptions = ref<string[]>([]);
|
|
onMounted(async () => {
|
|
timezoneOptions.value = ((await getTimezoneOptionsApi()) || []).map(
|
|
(item) => item.timezone,
|
|
);
|
|
});
|
|
const handleSetTimezone = async (
|
|
modalApi: ExtendedModalApi,
|
|
timezone?: string,
|
|
) => {
|
|
if (!timezone) {
|
|
return;
|
|
}
|
|
try {
|
|
modalApi.setState({ confirmLoading: true });
|
|
await userProfileStore.setTimezone(timezone);
|
|
ElMessage.success($t('ui.widgets.timezone.setSuccess'));
|
|
modalApi.close();
|
|
} finally {
|
|
modalApi.setState({ confirmLoading: false });
|
|
}
|
|
};
|
|
|
|
const menus = computed(() => [
|
|
{
|
|
handler: () => {
|
|
openWindow(VBEN_DOC_URL, {
|
|
target: '_blank',
|
|
});
|
|
},
|
|
icon: BookOpenText,
|
|
text: $t('ui.widgets.document'),
|
|
},
|
|
{
|
|
handler: () => {
|
|
openWindow(VBEN_GITHUB_URL, {
|
|
target: '_blank',
|
|
});
|
|
},
|
|
icon: SvgGithubIcon,
|
|
text: 'GitHub',
|
|
},
|
|
{
|
|
handler: () => {
|
|
openWindow(`${VBEN_GITHUB_URL}/issues`, {
|
|
target: '_blank',
|
|
});
|
|
},
|
|
icon: CircleHelp,
|
|
text: $t('ui.widgets.qa'),
|
|
},
|
|
]);
|
|
|
|
const avatar = computed(() => {
|
|
return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
|
|
});
|
|
|
|
async function handleLogout() {
|
|
await authStore.logout(false);
|
|
}
|
|
|
|
function handleNoticeClear() {
|
|
notifications.value = [];
|
|
}
|
|
|
|
function handleMakeAll() {
|
|
notifications.value.forEach((item) => (item.isRead = true));
|
|
}
|
|
watch(
|
|
() => ({
|
|
enable: preferences.app.watermark,
|
|
content: preferences.app.watermarkContent,
|
|
}),
|
|
async ({ enable, content }) => {
|
|
if (enable) {
|
|
await updateWatermark({
|
|
content:
|
|
content ||
|
|
`${userStore.userInfo?.username} - ${userStore.userInfo?.realName}`,
|
|
});
|
|
} else {
|
|
destroyWatermark();
|
|
}
|
|
},
|
|
{
|
|
immediate: true,
|
|
},
|
|
);
|
|
</script>
|
|
|
|
<template>
|
|
<BasicLayout @clear-preferences-and-logout="handleLogout">
|
|
<template #user-dropdown>
|
|
<UserDropdown
|
|
:avatar
|
|
:menus
|
|
:text="userStore.userInfo?.realName"
|
|
description="ann.vben@gmail.com"
|
|
tag-text="Pro"
|
|
@logout="handleLogout"
|
|
/>
|
|
</template>
|
|
<template #notification>
|
|
<Notification
|
|
:dot="showDot"
|
|
:notifications="notifications"
|
|
@clear="handleNoticeClear"
|
|
@make-all="handleMakeAll"
|
|
/>
|
|
</template>
|
|
<template #timezone>
|
|
<TimezoneButton
|
|
:ok-handler="handleSetTimezone"
|
|
:timezone="computedTimezone"
|
|
:timezone-options="timezoneOptions"
|
|
name="out"
|
|
/>
|
|
</template>
|
|
<template #extra>
|
|
<AuthenticationLoginExpiredModal
|
|
v-model:open="accessStore.loginExpired"
|
|
:avatar
|
|
>
|
|
<LoginForm />
|
|
</AuthenticationLoginExpiredModal>
|
|
</template>
|
|
<template #lock-screen>
|
|
<LockScreen :avatar @to-login="handleLogout" />
|
|
</template>
|
|
</BasicLayout>
|
|
</template>
|