feat: preference button supports automatic positioning (#4243)
parent
dc5cfab319
commit
d2f3a9d04f
|
@ -170,7 +170,7 @@ const defaultPreferences: Preferences = {
|
||||||
locale: 'zh-CN',
|
locale: 'zh-CN',
|
||||||
loginExpiredMode: 'modal',
|
loginExpiredMode: 'modal',
|
||||||
name: 'Vben Admin',
|
name: 'Vben Admin',
|
||||||
preferencesButtonPosition: 'fixed',
|
preferencesButtonPosition: 'auto',
|
||||||
watermark: false,
|
watermark: false,
|
||||||
},
|
},
|
||||||
breadcrumb: {
|
breadcrumb: {
|
||||||
|
|
|
@ -190,7 +190,7 @@ const defaultPreferences: Preferences = {
|
||||||
locale: 'zh-CN',
|
locale: 'zh-CN',
|
||||||
loginExpiredMode: 'modal',
|
loginExpiredMode: 'modal',
|
||||||
name: 'Vben Admin',
|
name: 'Vben Admin',
|
||||||
preferencesButtonPosition: 'fixed',
|
preferencesButtonPosition: 'auto',
|
||||||
watermark: false,
|
watermark: false,
|
||||||
},
|
},
|
||||||
breadcrumb: {
|
breadcrumb: {
|
||||||
|
|
|
@ -11,8 +11,9 @@ type ThemeModeType = 'auto' | 'dark' | 'light';
|
||||||
* 偏好设置按钮位置
|
* 偏好设置按钮位置
|
||||||
* fixed 固定在右侧
|
* fixed 固定在右侧
|
||||||
* header 顶栏
|
* header 顶栏
|
||||||
|
* auto 自动
|
||||||
*/
|
*/
|
||||||
type PreferencesButtonPositionType = 'fixed' | 'header';
|
type PreferencesButtonPositionType = 'auto' | 'fixed' | 'header';
|
||||||
|
|
||||||
type BuiltinThemeType =
|
type BuiltinThemeType =
|
||||||
| 'custom'
|
| 'custom'
|
||||||
|
|
|
@ -20,7 +20,7 @@ const defaultPreferences: Preferences = {
|
||||||
locale: 'zh-CN',
|
locale: 'zh-CN',
|
||||||
loginExpiredMode: 'page',
|
loginExpiredMode: 'page',
|
||||||
name: 'Vben Admin',
|
name: 'Vben Admin',
|
||||||
preferencesButtonPosition: 'fixed',
|
preferencesButtonPosition: 'auto',
|
||||||
watermark: false,
|
watermark: false,
|
||||||
},
|
},
|
||||||
breadcrumb: {
|
breadcrumb: {
|
||||||
|
|
|
@ -149,6 +149,45 @@ function usePreferences() {
|
||||||
return enable && globalLockScreen;
|
return enable && globalLockScreen;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh_CN 偏好设置按钮位置
|
||||||
|
*/
|
||||||
|
const preferencesButtonPosition = computed(() => {
|
||||||
|
const { enablePreferences, preferencesButtonPosition } = preferences.app;
|
||||||
|
|
||||||
|
// 如果没有启用偏好设置按钮
|
||||||
|
if (!enablePreferences) {
|
||||||
|
return {
|
||||||
|
fixed: false,
|
||||||
|
header: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const { header, sidebar } = preferences;
|
||||||
|
const headerHidden = header.hidden;
|
||||||
|
const sidebarHidden = sidebar.hidden;
|
||||||
|
|
||||||
|
const contentIsMaximize = headerHidden && sidebarHidden;
|
||||||
|
|
||||||
|
const isHeaderPosition = preferencesButtonPosition === 'header';
|
||||||
|
|
||||||
|
// 如果设置了固定位置
|
||||||
|
if (preferencesButtonPosition !== 'auto') {
|
||||||
|
return {
|
||||||
|
fixed: preferencesButtonPosition === 'fixed',
|
||||||
|
header: isHeaderPosition,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是全屏模式或者没有固定在顶部,
|
||||||
|
const fixed = contentIsMaximize || isFullContent.value || isMobile.value;
|
||||||
|
|
||||||
|
return {
|
||||||
|
fixed,
|
||||||
|
header: !fixed,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
authPanelCenter,
|
authPanelCenter,
|
||||||
authPanelLeft,
|
authPanelLeft,
|
||||||
|
@ -168,6 +207,7 @@ function usePreferences() {
|
||||||
isSideNav,
|
isSideNav,
|
||||||
keepAlive,
|
keepAlive,
|
||||||
layout,
|
layout,
|
||||||
|
preferencesButtonPosition,
|
||||||
sidebarCollapsed,
|
sidebarCollapsed,
|
||||||
theme,
|
theme,
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,7 +28,7 @@ withDefaults(defineProps<Props>(), {
|
||||||
});
|
});
|
||||||
|
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
const { globalSearchShortcutKey } = usePreferences();
|
const { globalSearchShortcutKey, preferencesButtonPosition } = usePreferences();
|
||||||
const slots = useSlots();
|
const slots = useSlots();
|
||||||
const rightSlots = computed(() => {
|
const rightSlots = computed(() => {
|
||||||
const list = [{ index: 100, name: 'user-dropdown' }];
|
const list = [{ index: 100, name: 'user-dropdown' }];
|
||||||
|
@ -39,10 +39,7 @@ const rightSlots = computed(() => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (preferencesButtonPosition.value.header) {
|
||||||
preferences.app.enablePreferences &&
|
|
||||||
preferences.app.preferencesButtonPosition === 'header'
|
|
||||||
) {
|
|
||||||
list.push({
|
list.push({
|
||||||
index: 10,
|
index: 10,
|
||||||
name: 'preferences',
|
name: 'preferences',
|
||||||
|
@ -121,7 +118,7 @@ const leftSlots = computed(() => {
|
||||||
<GlobalSearch
|
<GlobalSearch
|
||||||
:enable-shortcut-key="globalSearchShortcutKey"
|
:enable-shortcut-key="globalSearchShortcutKey"
|
||||||
:menus="accessStore.accessMenus"
|
:menus="accessStore.accessMenus"
|
||||||
class="mr-4"
|
class="mr-1 sm:mr-4"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ const {
|
||||||
isMobile,
|
isMobile,
|
||||||
isSideMixedNav,
|
isSideMixedNav,
|
||||||
layout,
|
layout,
|
||||||
|
preferencesButtonPosition,
|
||||||
sidebarCollapsed,
|
sidebarCollapsed,
|
||||||
theme,
|
theme,
|
||||||
} = usePreferences();
|
} = usePreferences();
|
||||||
|
@ -326,12 +327,7 @@ const headerSlots = computed(() => {
|
||||||
<slot v-if="lockStore.isLockScreen" name="lock-screen"></slot>
|
<slot v-if="lockStore.isLockScreen" name="lock-screen"></slot>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
||||||
<template
|
<template v-if="preferencesButtonPosition.fixed">
|
||||||
v-if="
|
|
||||||
preferences.app.enablePreferences &&
|
|
||||||
preferences.app.preferencesButtonPosition === 'fixed'
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<Preferences
|
<Preferences
|
||||||
class="z-100 fixed bottom-20 right-0"
|
class="z-100 fixed bottom-20 right-0"
|
||||||
@clear-preferences-and-logout="clearPreferencesAndLogout"
|
@clear-preferences-and-logout="clearPreferencesAndLogout"
|
||||||
|
|
|
@ -127,7 +127,7 @@ onMounted(() => {
|
||||||
@click="toggleOpen()"
|
@click="toggleOpen()"
|
||||||
>
|
>
|
||||||
<Search
|
<Search
|
||||||
class="text-muted-foreground group-hover:text-foreground size-3 group-hover:opacity-100"
|
class="text-muted-foreground group-hover:text-foreground size-4 group-hover:opacity-100"
|
||||||
/>
|
/>
|
||||||
<span
|
<span
|
||||||
class="text-muted-foreground group-hover:text-foreground hidden text-xs duration-300 md:block"
|
class="text-muted-foreground group-hover:text-foreground hidden text-xs duration-300 md:block"
|
||||||
|
|
|
@ -24,6 +24,10 @@ const appPreferencesButtonPosition = defineModel<string>(
|
||||||
);
|
);
|
||||||
|
|
||||||
const positionItems = computed((): SelectOption[] => [
|
const positionItems = computed((): SelectOption[] => [
|
||||||
|
{
|
||||||
|
label: $t('preferences.position.auto'),
|
||||||
|
value: 'auto',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: $t('preferences.position.header'),
|
label: $t('preferences.position.header'),
|
||||||
value: 'header',
|
value: 'header',
|
||||||
|
|
|
@ -175,6 +175,7 @@
|
||||||
"position": {
|
"position": {
|
||||||
"title": "Preferences Postion",
|
"title": "Preferences Postion",
|
||||||
"header": "Header",
|
"header": "Header",
|
||||||
|
"auto": "Auto",
|
||||||
"fixed": "Fixed"
|
"fixed": "Fixed"
|
||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
|
|
|
@ -175,6 +175,7 @@
|
||||||
"position": {
|
"position": {
|
||||||
"title": "偏好设置位置",
|
"title": "偏好设置位置",
|
||||||
"header": "顶栏",
|
"header": "顶栏",
|
||||||
|
"auto": "自动",
|
||||||
"fixed": "固定"
|
"fixed": "固定"
|
||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
|
|
Loading…
Reference in New Issue