ruoyi-plus-vben5/apps/web-antd/src/layouts/basic.vue

115 lines
2.8 KiB
Vue
Raw Normal View History

2024-05-19 21:20:42 +08:00
<script lang="ts" setup>
2024-08-07 08:57:56 +08:00
import { computed, onMounted } from 'vue';
2024-06-01 23:15:29 +08:00
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
2024-08-07 08:57:56 +08:00
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
import {
BasicLayout,
LockScreen,
Notification,
UserDropdown,
} from '@vben/layouts';
import { preferences } from '@vben/preferences';
2024-08-07 08:57:56 +08:00
import { storeToRefs, useAccessStore, useUserStore } from '@vben/stores';
import { openWindow } from '@vben/utils';
2024-05-19 21:20:42 +08:00
2024-08-07 08:57:56 +08:00
import { message } from 'ant-design-vue';
import { $t } from '#/locales';
import { resetRoutes } from '#/router';
2024-08-07 08:57:56 +08:00
import { useAuthStore, useNotifyStore } from '#/store';
2024-05-19 21:20:42 +08:00
2024-07-30 21:10:28 +08:00
const userStore = useUserStore();
const authStore = useAuthStore();
const accessStore = useAccessStore();
2024-05-19 21:20:42 +08:00
const menus = computed(() => [
{
handler: () => {
openWindow(VBEN_DOC_URL, {
2024-05-19 21:20:42 +08:00
target: '_blank',
});
},
icon: BookOpenText,
2024-05-19 21:20:42 +08:00
text: $t('widgets.document'),
},
{
handler: () => {
openWindow(VBEN_GITHUB_URL, {
2024-05-19 21:20:42 +08:00
target: '_blank',
});
},
icon: MdiGithub,
text: 'GitHub',
},
{
handler: () => {
openWindow(`${VBEN_GITHUB_URL}/issues`, {
2024-05-19 21:20:42 +08:00
target: '_blank',
});
},
icon: CircleHelp,
2024-05-19 21:20:42 +08:00
text: $t('widgets.qa'),
},
]);
2024-07-30 21:10:28 +08:00
const { loginLoading } = storeToRefs(authStore);
const avatar = computed(() => {
2024-07-30 21:10:28 +08:00
return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
});
async function handleLogout() {
2024-08-07 08:57:56 +08:00
// resetAllStores();
resetRoutes();
2024-08-07 08:57:56 +08:00
// await router.replace(LOGIN_PATH);
authStore.logout();
2024-05-19 21:20:42 +08:00
}
2024-08-07 08:57:56 +08:00
const notifyStore = useNotifyStore();
onMounted(() => notifyStore.startListeningMessage());
2024-08-07 08:57:56 +08:00
function handleViewAll() {
message.warning('暂未开放');
}
2024-05-19 21:20:42 +08:00
</script>
<template>
<BasicLayout @clear-preferences-and-logout="handleLogout">
2024-05-19 21:20:42 +08:00
<template #user-dropdown>
<UserDropdown
:avatar
:menus
2024-07-30 21:10:28 +08:00
:text="userStore.userInfo?.realName"
2024-05-19 21:20:42 +08:00
description="ann.vben@gmail.com"
tag-text="Pro"
@logout="handleLogout"
/>
</template>
<template #notification>
<Notification
2024-08-07 08:57:56 +08:00
:dot="notifyStore.showDot"
:notifications="notifyStore.notificationList"
@clear="notifyStore.clearAllMessage"
@make-all="notifyStore.setAllRead"
@read="notifyStore.setRead"
@view-all="handleViewAll"
2024-05-19 21:20:42 +08:00
/>
</template>
<template #extra>
<AuthenticationLoginExpiredModal
2024-07-30 21:10:28 +08:00
v-model:open="accessStore.loginExpired"
2024-07-18 21:31:34 +08:00
:avatar
2024-07-11 21:48:56 +08:00
:loading="loginLoading"
password-placeholder="123456"
username-placeholder="vben"
2024-07-30 21:10:28 +08:00
@submit="authStore.authLogin"
/>
</template>
<template #lock-screen>
<LockScreen :avatar @to-login="handleLogout" />
</template>
2024-05-19 21:20:42 +08:00
</BasicLayout>
</template>