2024-05-19 13:20:42 +00:00
|
|
|
|
import { computed } from 'vue';
|
|
|
|
|
|
2024-07-30 13:05:03 +00:00
|
|
|
|
import { diff } from '@vben-core/shared';
|
2024-06-08 11:49:06 +00:00
|
|
|
|
|
2024-06-01 15:15:29 +00:00
|
|
|
|
import { isDarkTheme, preferencesManager } from './preferences';
|
2024-05-19 13:20:42 +00:00
|
|
|
|
|
2024-06-01 15:15:29 +00:00
|
|
|
|
function usePreferences() {
|
|
|
|
|
const preferences = preferencesManager.getPreferences();
|
|
|
|
|
const initialPreferences = preferencesManager.getInitialPreferences();
|
2024-05-19 13:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 计算偏好设置的变化
|
|
|
|
|
*/
|
|
|
|
|
const diffPreference = computed(() => {
|
2024-06-01 15:15:29 +00:00
|
|
|
|
return diff(initialPreferences, preferences);
|
2024-05-19 13:20:42 +00:00
|
|
|
|
});
|
|
|
|
|
|
2024-06-09 04:53:38 +00:00
|
|
|
|
const appPreferences = computed(() => preferences.app);
|
|
|
|
|
|
2024-06-16 05:43:33 +00:00
|
|
|
|
const shortcutKeysPreferences = computed(() => preferences.shortcutKeys);
|
|
|
|
|
|
2024-05-19 13:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 判断是否为暗黑模式
|
2024-06-01 15:15:29 +00:00
|
|
|
|
* @param preferences - 当前偏好设置对象,它的主题值将被用来判断是否为暗黑模式。
|
2024-05-19 13:20:42 +00:00
|
|
|
|
* @returns 如果主题为暗黑模式,返回 true,否则返回 false。
|
|
|
|
|
*/
|
|
|
|
|
const isDark = computed(() => {
|
2024-06-23 11:17:31 +00:00
|
|
|
|
return isDarkTheme(preferences.theme.mode);
|
2024-05-19 13:20:42 +00:00
|
|
|
|
});
|
|
|
|
|
|
2024-07-17 14:25:27 +00:00
|
|
|
|
const isMobile = computed(() => {
|
|
|
|
|
return appPreferences.value.isMobile;
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-19 13:20:42 +00:00
|
|
|
|
const theme = computed(() => {
|
|
|
|
|
return isDark.value ? 'dark' : 'light';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 布局方式
|
|
|
|
|
*/
|
|
|
|
|
const layout = computed(() =>
|
2024-07-17 14:25:27 +00:00
|
|
|
|
isMobile.value ? 'sidebar-nav' : appPreferences.value.layout,
|
2024-05-19 13:20:42 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否全屏显示content,不需要侧边、底部、顶部、tab区域
|
|
|
|
|
*/
|
2024-06-01 15:15:29 +00:00
|
|
|
|
const isFullContent = computed(
|
2024-06-09 04:53:38 +00:00
|
|
|
|
() => appPreferences.value.layout === 'full-content',
|
2024-06-01 15:15:29 +00:00
|
|
|
|
);
|
2024-05-19 13:20:42 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否侧边导航模式
|
|
|
|
|
*/
|
2024-06-09 07:39:11 +00:00
|
|
|
|
const isSideNav = computed(
|
|
|
|
|
() => appPreferences.value.layout === 'sidebar-nav',
|
|
|
|
|
);
|
2024-05-19 13:20:42 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否侧边混合模式
|
|
|
|
|
*/
|
2024-06-01 15:15:29 +00:00
|
|
|
|
const isSideMixedNav = computed(
|
2024-06-09 07:39:11 +00:00
|
|
|
|
() => appPreferences.value.layout === 'sidebar-mixed-nav',
|
2024-06-01 15:15:29 +00:00
|
|
|
|
);
|
2024-05-19 13:20:42 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否为头部导航模式
|
|
|
|
|
*/
|
2024-06-01 15:15:29 +00:00
|
|
|
|
const isHeaderNav = computed(
|
2024-06-09 04:53:38 +00:00
|
|
|
|
() => appPreferences.value.layout === 'header-nav',
|
2024-06-01 15:15:29 +00:00
|
|
|
|
);
|
2024-05-19 13:20:42 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否为混合导航模式
|
|
|
|
|
*/
|
2024-06-09 04:53:38 +00:00
|
|
|
|
const isMixedNav = computed(
|
|
|
|
|
() => appPreferences.value.layout === 'mixed-nav',
|
|
|
|
|
);
|
2024-05-19 13:20:42 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否包含侧边导航模式
|
|
|
|
|
*/
|
|
|
|
|
const isSideMode = computed(() => {
|
|
|
|
|
return isMixedNav.value || isSideMixedNav.value || isSideNav.value;
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-18 13:59:18 +00:00
|
|
|
|
const sidebarCollapsed = computed(() => {
|
|
|
|
|
return preferences.sidebar.collapsed;
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-19 13:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否开启keep-alive
|
|
|
|
|
* 在tabs可见以及开启keep-alive的情况下才开启
|
|
|
|
|
*/
|
|
|
|
|
const keepAlive = computed(
|
2024-06-09 04:53:38 +00:00
|
|
|
|
() => preferences.tabbar.enable && preferences.tabbar.keepAlive,
|
2024-05-19 13:20:42 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 登录注册页面布局是否为左侧
|
|
|
|
|
*/
|
|
|
|
|
const authPanelLeft = computed(() => {
|
2024-06-09 04:53:38 +00:00
|
|
|
|
return appPreferences.value.authPageLayout === 'panel-left';
|
2024-05-19 13:20:42 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 登录注册页面布局是否为左侧
|
|
|
|
|
*/
|
|
|
|
|
const authPanelRight = computed(() => {
|
2024-06-09 04:53:38 +00:00
|
|
|
|
return appPreferences.value.authPageLayout === 'panel-right';
|
2024-05-19 13:20:42 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 登录注册页面布局是否为中间
|
|
|
|
|
*/
|
|
|
|
|
const authPanelCenter = computed(() => {
|
2024-06-09 04:53:38 +00:00
|
|
|
|
return appPreferences.value.authPageLayout === 'panel-center';
|
2024-05-19 13:20:42 +00:00
|
|
|
|
});
|
|
|
|
|
|
2024-07-17 14:25:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 内容是否已经最大化
|
|
|
|
|
* 排除 full-content模式
|
|
|
|
|
*/
|
|
|
|
|
const contentIsMaximize = computed(() => {
|
|
|
|
|
const headerIsHidden = preferences.header.hidden;
|
|
|
|
|
const sidebarIsHidden = preferences.sidebar.hidden;
|
|
|
|
|
return headerIsHidden && sidebarIsHidden && !isFullContent.value;
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-16 05:43:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否启用全局搜索快捷键
|
|
|
|
|
*/
|
|
|
|
|
const globalSearchShortcutKey = computed(() => {
|
|
|
|
|
const { enable, globalSearch } = shortcutKeysPreferences.value;
|
|
|
|
|
return enable && globalSearch;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否启用全局注销快捷键
|
|
|
|
|
*/
|
|
|
|
|
const globalLogoutShortcutKey = computed(() => {
|
|
|
|
|
const { enable, globalLogout } = shortcutKeysPreferences.value;
|
|
|
|
|
return enable && globalLogout;
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-12 04:14:09 +00:00
|
|
|
|
const globalLockScreenShortcutKey = computed(() => {
|
|
|
|
|
const { enable, globalLockScreen } = shortcutKeysPreferences.value;
|
|
|
|
|
return enable && globalLockScreen;
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-16 05:43:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* @zh_CN 是否启用全局偏好设置快捷键
|
|
|
|
|
*/
|
|
|
|
|
const globalPreferencesShortcutKey = computed(() => {
|
|
|
|
|
const { enable, globalPreferences } = shortcutKeysPreferences.value;
|
|
|
|
|
return enable && globalPreferences;
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-19 13:20:42 +00:00
|
|
|
|
return {
|
|
|
|
|
authPanelCenter,
|
|
|
|
|
authPanelLeft,
|
|
|
|
|
authPanelRight,
|
2024-07-12 15:43:47 +00:00
|
|
|
|
contentIsMaximize,
|
2024-05-19 13:20:42 +00:00
|
|
|
|
diffPreference,
|
2024-07-12 04:14:09 +00:00
|
|
|
|
globalLockScreenShortcutKey,
|
2024-06-16 05:43:33 +00:00
|
|
|
|
globalLogoutShortcutKey,
|
|
|
|
|
globalPreferencesShortcutKey,
|
|
|
|
|
globalSearchShortcutKey,
|
2024-05-19 13:20:42 +00:00
|
|
|
|
isDark,
|
|
|
|
|
isFullContent,
|
|
|
|
|
isHeaderNav,
|
|
|
|
|
isMixedNav,
|
2024-07-17 14:25:27 +00:00
|
|
|
|
isMobile,
|
2024-05-19 13:20:42 +00:00
|
|
|
|
isSideMixedNav,
|
|
|
|
|
isSideMode,
|
|
|
|
|
isSideNav,
|
|
|
|
|
keepAlive,
|
|
|
|
|
layout,
|
2024-07-18 13:59:18 +00:00
|
|
|
|
sidebarCollapsed,
|
2024-05-19 13:20:42 +00:00
|
|
|
|
theme,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-01 15:15:29 +00:00
|
|
|
|
export { usePreferences };
|