Commit 3faf04c4 by User

登录角色名称修改

parent 2190a231
<!doctype html> <!doctype html>
<html lang="zh-cmn-Hans"> <html lang="zh-cmn-Hans">
<head> <head>
<meta name="buildTime" content="2025-04-25 15:49:09"> <meta name="buildTime" content="2025-04-25 17:56:27">
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" href="/favicon.svg" /> <link rel="icon" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" /> <meta name="color-scheme" content="light dark" />
<title>VueDashboard</title> <title>VueDashboard</title>
<script type="module" crossorigin src="/Content/VueDashboardUi/VueDashboard1/assets/index-CrvCiZyA.js"></script> <script type="module" crossorigin src="/Content/VueDashboardUi/VueDashboard1/assets/index-CsI39EZy.js"></script>
<link rel="stylesheet" crossorigin href="/Content/VueDashboardUi/VueDashboard1/assets/index-DhhgO4aJ.css"> <link rel="stylesheet" crossorigin href="/Content/VueDashboardUi/VueDashboard1/assets/index-DhhgO4aJ.css">
</head> </head>
<body> <body>
......
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'; import { computed } from 'vue';
import type { VNode } from 'vue'; import type { DropdownOption } from 'naive-ui';
import type { RouteKey } from '@elegant-router/types';
import { useAuthStore } from '@/store/modules/auth'; import { useAuthStore } from '@/store/modules/auth';
import { $t } from '@/locales';
import { useRouterPush } from '@/hooks/common/router'; import { useRouterPush } from '@/hooks/common/router';
import { useSvgIcon } from '@/hooks/common/icon'; import { useSvgIcon } from '@/hooks/common/icon';
import { $t } from '@/locales';
defineOptions({ defineOptions({
name: 'UserAvatar' name: 'UserAvatar'
...@@ -14,59 +15,40 @@ const authStore = useAuthStore(); ...@@ -14,59 +15,40 @@ const authStore = useAuthStore();
const { routerPushByKey, toLogin } = useRouterPush(); const { routerPushByKey, toLogin } = useRouterPush();
const { SvgIconVNode } = useSvgIcon(); const { SvgIconVNode } = useSvgIcon();
// 计算属性获取认证状态
const isAuthenticated = computed(() => {
const globalConfig = (window as any).uiGlobalConfig;
return globalConfig?.IsAuthenticated ?? false;
});
function loginOrRegister() { function loginOrRegister() {
toLogin(); toLogin();
} }
type DropdownKey = 'logout'; const options = computed<DropdownOption[]>(() => [
// {
type DropdownOption = // label: $t('common.userCenter'),
| { // key: 'user_center',
key: DropdownKey; // icon: SvgIconVNode({ icon: 'carbon:user-avatar', fontSize: 18 })
label: string; // },
icon?: () => VNode;
}
| {
type: 'divider';
key: string;
};
const options = computed(() => {
const opts: DropdownOption[] = [
{ {
label: $t('common.logout'), label: $t('common.logout'),
key: 'logout', key: 'logout',
icon: SvgIconVNode({ icon: 'ph:sign-out', fontSize: 18 }) icon: SvgIconVNode({ icon: 'carbon:logout', fontSize: 18 })
} }
]; ]);
return opts; function handleDropdown(key: string) {
});
function logout() {
window.$dialog?.info({
title: $t('common.tip'),
content: $t('common.logoutConfirm'),
positiveText: $t('common.confirm'),
negativeText: $t('common.cancel'),
onPositiveClick: () => {
authStore.resetStore();
}
});
}
function handleDropdown(key: DropdownKey) {
if (key === 'logout') { if (key === 'logout') {
logout(); authStore.resetStore();
} else { } else if (key === 'user_center') {
// If your other options are jumps from other routes, they will be directly supported here routerPushByKey(key as RouteKey);
routerPushByKey(key);
} }
} }
</script> </script>
<template> <template>
<NButton v-if="!authStore.isLogin" quaternary @click="loginOrRegister"> <NButton v-if="!isAuthenticated" quaternary @click="loginOrRegister">
{{ $t('page.login.common.loginOrRegister') }} {{ $t('page.login.common.loginOrRegister') }}
</NButton> </NButton>
<NDropdown v-else placement="bottom" trigger="click" :options="options" @select="handleDropdown"> <NDropdown v-else placement="bottom" trigger="click" :options="options" @select="handleDropdown">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment