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

169 lines
4.0 KiB
Vue
Raw Normal View History

2024-05-19 21:20:42 +08:00
<script lang="ts" setup>
import { computed, onMounted, watch } from 'vue';
2024-09-02 15:13:17 +08:00
import { useRouter } from 'vue-router';
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 { useWatermark } from '@vben/hooks';
import {
BookOpenText,
CircleHelp,
2024-12-09 09:57:27 +08:00
GiteeIcon,
GitHubOutlined,
UserOutlined,
} from '@vben/icons';
import {
BasicLayout,
LockScreen,
Notification,
UserDropdown,
} from '@vben/layouts';
import { preferences } from '@vben/preferences';
import { 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';
2024-09-05 08:07:34 +08:00
import { TenantToggle } from '#/components/tenant-toggle';
import { $t } from '#/locales';
import { resetRoutes } from '#/router';
2024-08-07 08:57:56 +08:00
import { useAuthStore, useNotifyStore } from '#/store';
import { useTenantStore } from '#/store/tenant';
import LoginForm from '#/views/_core/authentication/login.vue';
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-09-02 15:13:17 +08:00
const router = useRouter();
const { destroyWatermark, updateWatermark } = useWatermark();
const tenantStore = useTenantStore();
const menus = computed(() => {
const defaultMenus = [
{
handler: () => {
openWindow(VBEN_DOC_URL, {
target: '_blank',
});
},
icon: BookOpenText,
2024-10-20 09:47:07 +08:00
text: $t('ui.widgets.document'),
2024-05-19 21:20:42 +08:00
},
{
handler: () => {
router.push('/profile');
},
icon: UserOutlined,
2024-10-20 09:47:07 +08:00
text: $t('ui.widgets.profile'),
2024-09-02 15:13:17 +08:00
},
2024-12-09 09:57:27 +08:00
{
handler: () => {
openWindow('https://gitee.com/dapppp/ruoyi-plus-vben5', {
target: '_blank',
});
},
icon: GiteeIcon,
2024-12-09 09:57:27 +08:00
text: 'Gitee项目地址',
},
{
handler: () => {
openWindow(VBEN_GITHUB_URL, {
target: '_blank',
});
},
icon: GitHubOutlined,
2024-12-09 09:57:27 +08:00
text: 'Vben官方地址',
2024-05-19 21:20:42 +08:00
},
{
handler: () => {
openWindow(`${VBEN_GITHUB_URL}/issues`, {
target: '_blank',
});
},
icon: CircleHelp,
2024-10-20 09:47:07 +08:00
text: $t('ui.widgets.qa'),
2024-05-19 21:20:42 +08:00
},
];
/**
* 租户选中状态 不显示个人中心
*/
if (tenantStore.checked) {
defaultMenus.splice(1, 1);
}
return defaultMenus;
});
2024-05-19 21:20:42 +08:00
const avatar = computed(() => {
2024-07-30 21:10:28 +08:00
return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
});
async function handleLogout() {
/**
* 主动登出不需要带跳转地址
*/
await authStore.logout(false);
resetRoutes();
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('暂未开放');
}
watch(
() => preferences.app.watermark,
async (enable) => {
if (enable) {
await updateWatermark({
content: `${userStore.userInfo?.username}`,
});
} else {
destroyWatermark();
}
},
{
immediate: true,
},
);
2024-05-19 21:20:42 +08:00
</script>
<template>
<BasicLayout @clear-preferences-and-logout="handleLogout">
2024-08-07 11:55:13 +08:00
<template #header-right-1>
<TenantToggle />
</template>
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.notifications"
2024-08-07 08:57:56 +08:00
@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
>
<LoginForm />
</AuthenticationLoginExpiredModal>
</template>
<template #lock-screen>
<LockScreen :avatar @to-login="handleLogout" />
</template>
2024-05-19 21:20:42 +08:00
</BasicLayout>
</template>