You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
4.6 KiB

import { computed } from 'vue';
import { diff } from '@vben-core/shared';
import { preferencesManager } from './preferences';
import { isDarkTheme } from './update-css-variables';
function usePreferences() {
const preferences = preferencesManager.getPreferences();
const initialPreferences = preferencesManager.getInitialPreferences();
/**
* @zh_CN
*/
const diffPreference = computed(() => {
return diff(initialPreferences, preferences);
});
const appPreferences = computed(() => preferences.app);
const shortcutKeysPreferences = computed(() => preferences.shortcutKeys);
/**
* @zh_CN
* @param preferences -
* @returns true false
*/
const isDark = computed(() => {
return isDarkTheme(preferences.theme.mode);
});
const isMobile = computed(() => {
return appPreferences.value.isMobile;
});
const theme = computed(() => {
return isDark.value ? 'dark' : 'light';
});
/**
* @zh_CN
*/
const layout = computed(() =>
isMobile.value ? 'sidebar-nav' : appPreferences.value.layout,
);
/**
* @zh_CN contenttab
*/
const isFullContent = computed(
() => appPreferences.value.layout === 'full-content',
);
/**
* @zh_CN
*/
const isSideNav = computed(
() => appPreferences.value.layout === 'sidebar-nav',
);
/**
* @zh_CN
*/
const isSideMixedNav = computed(
() => appPreferences.value.layout === 'sidebar-mixed-nav',
);
/**
* @zh_CN
*/
const isHeaderNav = computed(
() => appPreferences.value.layout === 'header-nav',
);
/**
* @zh_CN
*/
const isMixedNav = computed(
() => appPreferences.value.layout === 'mixed-nav',
);
/**
* @zh_CN
*/
const isSideMode = computed(() => {
return isMixedNav.value || isSideMixedNav.value || isSideNav.value;
});
const sidebarCollapsed = computed(() => {
return preferences.sidebar.collapsed;
});
/**
* @zh_CN keep-alive
* tabskeep-alive
*/
const keepAlive = computed(
() => preferences.tabbar.enable && preferences.tabbar.keepAlive,
);
/**
* @zh_CN
*/
const authPanelLeft = computed(() => {
return appPreferences.value.authPageLayout === 'panel-left';
});
/**
* @zh_CN
*/
const authPanelRight = computed(() => {
return appPreferences.value.authPageLayout === 'panel-right';
});
/**
* @zh_CN
*/
const authPanelCenter = computed(() => {
return appPreferences.value.authPageLayout === 'panel-center';
});
/**
* @zh_CN
* full-content
*/
const contentIsMaximize = computed(() => {
const headerIsHidden = preferences.header.hidden;
const sidebarIsHidden = preferences.sidebar.hidden;
return headerIsHidden && sidebarIsHidden && !isFullContent.value;
});
/**
* @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;
});
const globalLockScreenShortcutKey = computed(() => {
const { enable, globalLockScreen } = shortcutKeysPreferences.value;
return enable && globalLockScreen;
});
/**
* @zh_CN
*/
const globalPreferencesShortcutKey = computed(() => {
const { enable, globalPreferences } = shortcutKeysPreferences.value;
return enable && globalPreferences;
});
return {
authPanelCenter,
authPanelLeft,
authPanelRight,
contentIsMaximize,
diffPreference,
globalLockScreenShortcutKey,
globalLogoutShortcutKey,
globalPreferencesShortcutKey,
globalSearchShortcutKey,
isDark,
isFullContent,
isHeaderNav,
isMixedNav,
isMobile,
isSideMixedNav,
isSideMode,
isSideNav,
keepAlive,
layout,
sidebarCollapsed,
theme,
};
}
export { usePreferences };