2
0

fix: 菜单固定顶部,路由隐藏排序

This commit is contained in:
TsMask
2024-12-04 17:19:22 +08:00
parent 79354a845c
commit d438b525b2
6 changed files with 15 additions and 82 deletions

View File

@@ -9,10 +9,10 @@ export function useAuth() {
} }
if (typeof codes === 'string') { if (typeof codes === 'string') {
return authStore.userInfo.buttons.includes(codes); return authStore.userInfo.permissions.includes(codes);
} }
return codes.some(code => authStore.userInfo.buttons.includes(code)); return codes.some(code => authStore.userInfo.permissions.includes(code));
} }
function hasRole(role: string | string[]) { function hasRole(role: string | string[]) {

View File

@@ -57,14 +57,15 @@ const headerMenus = computed(() => {
<GlobalBreadcrumb v-if="!appStore.isMobile" class="ml-12px" /> <GlobalBreadcrumb v-if="!appStore.isMobile" class="ml-12px" />
</div> </div>
<div class="h-full flex-y-center justify-end"> <div class="h-full flex-y-center justify-end">
<LangSwitch :lang="appStore.locale" :lang-options="appStore.localeOptions" @change-lang="appStore.changeLocale" /> <LangSwitch :lang="appStore.locale" :lang-options="appStore.localeOptions" @change-lang="appStore.changeLocale" v-if="hasRole('super')" />
<FullScreen v-if="!appStore.isMobile" :full="isFullscreen" @click="toggle" /> <FullScreen v-if="!appStore.isMobile" :full="isFullscreen" @click="toggle" />
<ThemeSchemaSwitch <ThemeSchemaSwitch
:theme-schema="themeStore.themeScheme" :theme-schema="themeStore.themeScheme"
:is-dark="themeStore.darkMode" :is-dark="themeStore.darkMode"
@switch="themeStore.toggleThemeScheme" @switch="themeStore.toggleThemeScheme"
v-if="hasRole('super')"
/> />
<ThemeButton v-if="hasRole('admin')" /> <ThemeButton v-if="hasRole('super')" />
<UserAvatar /> <UserAvatar />
</div> </div>
</DarkModeContainer> </DarkModeContainer>

View File

@@ -7,7 +7,6 @@ export function getToken() {
export const emptyInfo: Api.Auth.UserInfo = { export const emptyInfo: Api.Auth.UserInfo = {
roles: [], roles: [],
buttons: [],
permissions: [], permissions: [],
user: null user: null
}; };

View File

@@ -1,23 +1,16 @@
/** Default theme settings */ /** Default theme settings */
export const themeSettings: App.Theme.ThemeSetting = { export const themeSettings: App.Theme.ThemeSetting = {
themeScheme: 'light', themeScheme: "light",
themeColor: '#646cff', themeColor: "#06B6D4",
otherColor: { info: '#2080f0', success: '#52c41a', warning: '#faad14', error: '#f5222d' }, otherColor: {info: "#06B6D4", success: "#52c41a", warning: "#faad14", error: "#f5222d"},
isInfoFollowPrimary: true, isInfoFollowPrimary: true,
layout: { mode: 'horizontal-mix', scrollMode: 'content' }, layout: {mode: "horizontal", scrollMode: "content"},
page: { animate: true, animateMode: 'fade-slide' }, page: {animate: true, animateMode: "fade-slide"},
header: { height: 56, breadcrumb: { visible: true, showIcon: true } }, header: {height: 56, breadcrumb: {visible: true, showIcon: true}},
tab: { visible: false, cache: true, height: 44, mode: 'chrome' }, tab: {visible: false, cache: true, height: 44, mode: "chrome"},
fixedHeaderAndTab: true, fixedHeaderAndTab: true,
sider: { sider: {inverted: false, width: 220, collapsedWidth: 64, mixWidth: 90, mixCollapsedWidth: 64, mixChildMenuWidth: 200},
inverted: false, footer: {visible: true, fixed: false, height: 36, right: true}
width: 220,
collapsedWidth: 64,
mixWidth: 90,
mixCollapsedWidth: 64,
mixChildMenuWidth: 200
},
footer: { visible: true, fixed: false, height: 36, right: true }
}; };
/** /**

View File

@@ -81,7 +81,6 @@ declare namespace Api {
interface UserInfo { interface UserInfo {
user: User | null; user: User | null;
roles: string[]; roles: string[];
buttons: string[];
/** permissions */ /** permissions */
permissions: string[]; permissions: string[];
} }

View File

@@ -1,56 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from 'vue';
import { useLoading } from '@sa/hooks';
import { $t } from '@/locales'; import { $t } from '@/locales';
import { useAppStore } from '@/store/modules/app';
import { useAuthStore } from '@/store/modules/auth'; import { useAuthStore } from '@/store/modules/auth';
import { useAuth } from '@/hooks/business/auth'; import { useAuth } from '@/hooks/business/auth';
const appStore = useAppStore();
const authStore = useAuthStore(); const authStore = useAuthStore();
const { hasAuth } = useAuth(); const { hasAuth } = useAuth();
const { loading, startLoading, endLoading } = useLoading();
type AccountKey = 'super' | 'admin' | 'user';
interface Account {
key: AccountKey;
label: string;
username: string;
password: string;
}
const accounts = computed<Account[]>(() => [
{
key: 'super',
label: $t('page.login.pwdLogin.superAdmin'),
username: 'Super',
password: '123456'
},
{
key: 'admin',
label: $t('page.login.pwdLogin.admin'),
username: 'Admin',
password: '123456'
},
{
key: 'user',
label: $t('page.login.pwdLogin.user'),
username: 'User',
password: '123456'
}
]);
const loginAccount = ref<AccountKey>('super');
async function handleToggleAccount(account: Account) {
loginAccount.value = account.key;
startLoading();
await authStore.login(account.username, account.password, false);
endLoading();
appStore.reloadPage();
}
</script> </script>
<template> <template>
@@ -62,24 +16,11 @@ async function handleToggleAccount(account: Account) {
<ATag v-for="role in authStore.userInfo.roles" :key="role">{{ role }}</ATag> <ATag v-for="role in authStore.userInfo.roles" :key="role">{{ role }}</ATag>
</ASpace> </ASpace>
</ADescriptionsItem> </ADescriptionsItem>
<ADescriptionsItem ions-item :label="$t('page.function.toggleAuth.toggleAccount')">
<ASpace>
<AButton
v-for="account in accounts"
:key="account.key"
:loading="loading && loginAccount === account.key"
:disabled="loading && loginAccount !== account.key"
@click="handleToggleAccount(account)"
>
{{ account.label }}
</AButton>
</ASpace>
</ADescriptionsItem>
</ADescriptions> </ADescriptions>
</ACard> </ACard>
<ACard :title="$t('page.function.toggleAuth.authHook')" :bordered="false" size="small" class="card-wrapper"> <ACard :title="$t('page.function.toggleAuth.authHook')" :bordered="false" size="small" class="card-wrapper">
<ASpace> <ASpace>
<AButton v-if="hasAuth('B_CODE1')">{{ $t('page.function.toggleAuth.superAdminVisible') }}</AButton> <AButton v-if="hasAuth('*:*:*')">{{ $t('page.function.toggleAuth.superAdminVisible') }}</AButton>
<AButton v-if="hasAuth('B_CODE2')">{{ $t('page.function.toggleAuth.adminVisible') }}</AButton> <AButton v-if="hasAuth('B_CODE2')">{{ $t('page.function.toggleAuth.adminVisible') }}</AButton>
<AButton v-if="hasAuth('B_CODE3')"> <AButton v-if="hasAuth('B_CODE3')">
{{ $t('page.function.toggleAuth.adminOrUserVisible') }} {{ $t('page.function.toggleAuth.adminOrUserVisible') }}