Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"node": ">=20.10.0",
"pnpm": ">=9.12.0"
},
"packageManager": "pnpm@10.14.0",
"packageManager": "pnpm@10.21.0",
"pnpm": {
"peerDependencyRules": {
"allowedVersions": {
Expand Down
3 changes: 2 additions & 1 deletion packages/@core/base/design/src/css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
}

html {
@apply text-foreground bg-background font-sans text-[100%];
@apply text-foreground bg-background font-sans;

font-size: var(--font-size-base, 16px);
font-variation-settings: normal;
line-height: 1.15;
text-size-adjust: 100%;
Expand Down
1 change: 1 addition & 0 deletions packages/@core/preferences/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const defaultPreferences: Preferences = {
colorWarning: 'hsl(42 84% 61%)',
mode: 'dark',
radius: '0.5',
fontSize: 16,
semiDarkHeader: false,
semiDarkSidebar: false,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/@core/preferences/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ interface ThemePreferences {
colorSuccess: string;
/** 警告色 */
colorWarning: string;
/** 字体大小(单位:px) */
fontSize: number;
/** 当前主题 */
mode: ThemeModeType;
/** 圆角 */
Expand Down
8 changes: 8 additions & 0 deletions packages/@core/preferences/src/update-css-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ function updateCSSVariables(preferences: Preferences) {
if (Reflect.has(theme, 'radius')) {
document.documentElement.style.setProperty('--radius', `${radius}rem`);
}

// 更新字体大小
if (Reflect.has(theme, 'fontSize')) {
document.documentElement.style.setProperty(
'--font-size-base',
`${theme.fontSize}px`,
);
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/@core/ui-kit/menu-ui/src/components/menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ $namespace: vben;
.#{$namespace}-menu__popup-container,
.#{$namespace}-menu {
--menu-title-width: 140px;
--menu-item-icon-size: 16px;
--menu-item-icon-size: var(--font-size-base, 16px);
--menu-item-height: 38px;
--menu-item-padding-y: 21px;
--menu-item-padding-x: 12px;
Expand All @@ -458,7 +458,7 @@ $namespace: vben;
--menu-item-collapse-margin-x: 0px;
--menu-item-radius: 0px;
--menu-item-indent: 16px;
--menu-font-size: 14px;
--menu-font-size: calc(var(--font-size-base, 16px) * 0.875);

&.is-dark {
--menu-background-color: hsl(var(--menu));
Expand Down Expand Up @@ -752,15 +752,15 @@ $namespace: vben;
}
.#{$namespace}-menu__icon {
display: block;
font-size: 20px !important;
font-size: calc(var(--font-size-base, 16px) * 1.25) !important;
transition: all 0.25s ease;
}

.#{$namespace}-menu__name {
display: inline-flex;
margin-top: 8px;
margin-bottom: 0;
font-size: 12px;
font-size: calc(var(--font-size-base, 16px) * 0.75);
font-weight: 400;
line-height: normal;
transition: all 0.25s ease;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ $namespace: vben;
}

.#{$namespace}-normal-menu__icon {
font-size: 20px;
font-size: calc(var(--font-size-base, 16px) * 1.25);
}
}

Expand Down Expand Up @@ -146,14 +146,14 @@ $namespace: vben;

&__icon {
max-height: 20px;
font-size: 20px;
font-size: calc(var(--font-size-base, 16px) * 1.25);
transition: all 0.25s ease;
}

&__name {
margin-top: 8px;
margin-bottom: 0;
font-size: 12px;
font-size: calc(var(--font-size-base, 16px) * 0.75);
font-weight: 400;
transition: all 0.25s ease;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export { default as GlobalShortcutKeys } from './shortcut-keys/global.vue';
export { default as SwitchItem } from './switch-item.vue';
export { default as BuiltinTheme } from './theme/builtin.vue';
export { default as ColorMode } from './theme/color-mode.vue';
export { default as FontSize } from './theme/font-size.vue';
export { default as Radius } from './theme/radius.vue';
export { default as Theme } from './theme/theme.vue';
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<script setup lang="ts">
import { watch } from 'vue';

import { $t } from '@vben/locales';

import {
NumberField,
NumberFieldContent,
NumberFieldDecrement,
NumberFieldIncrement,
NumberFieldInput,
} from '@vben-core/shadcn-ui';

defineOptions({
name: 'PreferenceFontSize',
});

const modelValue = defineModel<number>({
default: 16,
});

const min = 15;
const max = 22;
const step = 1;

// 限制输入值在 min 和 max 之间
watch(
modelValue,
(newValue) => {
if (newValue < min) {
modelValue.value = min;
} else if (newValue > max) {
modelValue.value = max;
}
},
{ immediate: true },
);
</script>

<template>
<div class="flex w-full flex-col gap-4">
<div class="flex items-center gap-2">
<NumberField
v-model="modelValue"
:max="max"
:min="min"
:step="step"
class="w-full"
>
<NumberFieldContent>
<NumberFieldDecrement />
<NumberFieldInput />
<NumberFieldIncrement />
</NumberFieldContent>
</NumberField>
<span class="text-muted-foreground whitespace-nowrap text-xs">px</span>
</div>
<div class="text-muted-foreground text-xs">
{{ $t('preferences.theme.fontSizeTip') }}
</div>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
ColorMode,
Content,
Copyright,
FontSize,
Footer,
General,
GlobalShortcutKeys,
Expand Down Expand Up @@ -85,6 +86,7 @@ const themeColorPrimary = defineModel<string>('themeColorPrimary');
const themeBuiltinType = defineModel<BuiltinThemeType>('themeBuiltinType');
const themeMode = defineModel<ThemeModeType>('themeMode');
const themeRadius = defineModel<string>('themeRadius');
const themeFontSize = defineModel<number>('themeFontSize');
const themeSemiDarkSidebar = defineModel<boolean>('themeSemiDarkSidebar');
const themeSemiDarkHeader = defineModel<boolean>('themeSemiDarkHeader');

Expand Down Expand Up @@ -328,6 +330,9 @@ async function handleReset() {
<Block :title="$t('preferences.theme.radius')">
<Radius v-model="themeRadius" />
</Block>
<Block :title="$t('preferences.theme.fontSize')">
<FontSize v-model="themeFontSize" />
</Block>
<Block :title="$t('preferences.other')">
<ColorMode
v-model:app-color-gray-mode="appColorGrayMode"
Expand Down
2 changes: 2 additions & 0 deletions packages/locales/src/langs/en-US/preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
"theme": {
"title": "Theme",
"radius": "Radius",
"fontSize": "Font Size",
"fontSizeTip": "Adjust global font size with real-time preview",
"light": "Light",
"dark": "Dark",
"darkSidebar": "Semi Dark Sidebar",
Expand Down
2 changes: 2 additions & 0 deletions packages/locales/src/langs/zh-CN/preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
"theme": {
"title": "主题",
"radius": "圆角",
"fontSize": "字体大小",
"fontSizeTip": "调整全局字体大小,实时预览效果",
"light": "浅色",
"dark": "深色",
"darkSidebar": "深色侧边栏",
Expand Down
Loading