feat(projects): support set global redius

This commit is contained in:
CyberShen123
2025-10-02 23:52:41 +08:00
committed by Soybean
parent dac5075be9
commit 24c6df528b
10 changed files with 49 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
<script setup lang="ts">
import ThemeSchema from './modules/theme-schema.vue';
import ThemeColor from './modules/theme-color.vue';
import ThemeRadius from './modules/theme-radius.vue';
defineOptions({
name: 'AppearanceSettings'
@@ -11,6 +12,7 @@ defineOptions({
<div class="flex-col-stretch gap-16px">
<ThemeSchema />
<ThemeColor />
<ThemeRadius />
</div>
</template>

View File

@@ -0,0 +1,22 @@
<script setup lang="ts">
import { useThemeStore } from '@/store/modules/theme';
import { $t } from '@/locales';
import SettingItem from '../../../components/setting-item.vue';
defineOptions({
name: 'ThemeRadius'
});
const themeStore = useThemeStore();
</script>
<template>
<NDivider>{{ $t('theme.appearance.themeRadius.title') }}</NDivider>
<TransitionGroup tag="div" name="setting-list" class="flex-col-stretch gap-12px">
<SettingItem key="1" :label="$t('theme.appearance.themeRadius.title')">
<NInputNumber v-model:value="themeStore.themeRadius" size="small" :step="1" :min="0" :max="16" class="w-120px" />
</SettingItem>
</TransitionGroup>
</template>
<style scoped></style>

View File

@@ -83,6 +83,9 @@ const local: App.I18n.Schema = {
error: 'Error',
followPrimary: 'Follow Primary'
},
themeRadius: {
title: 'Theme Radius'
},
recommendColor: 'Apply Recommended Color Algorithm',
recommendColorDesc: 'The recommended color algorithm refers to',
preset: {

View File

@@ -83,6 +83,9 @@ const local: App.I18n.Schema = {
error: '错误色',
followPrimary: '跟随主色'
},
themeRadius: {
title: '主题圆角'
},
recommendColor: '应用推荐算法的颜色',
recommendColorDesc: '推荐颜色的算法参照',
preset: {

View File

@@ -53,7 +53,7 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
});
/** Naive theme */
const naiveTheme = computed(() => getNaiveTheme(themeColors.value, settings.value.recommendColor));
const naiveTheme = computed(() => getNaiveTheme(themeColors.value, settings.value));
/**
* Settings json

View File

@@ -239,19 +239,19 @@ function getNaiveThemeColors(colors: App.Theme.ThemeColor, recommended = false)
* @param colors Theme colors
* @param [recommended=false] Use recommended color. Default is `false`
*/
export function getNaiveTheme(colors: App.Theme.ThemeColor, recommended = false) {
export function getNaiveTheme(colors: App.Theme.ThemeColor, settings: App.Theme.ThemeSetting) {
const { primary: colorLoading } = colors;
const theme: GlobalThemeOverrides = {
common: {
...getNaiveThemeColors(colors, recommended),
borderRadius: '6px'
...getNaiveThemeColors(colors, settings.recommendColor),
borderRadius: `${settings.themeRadius}px`
},
LoadingBar: {
colorLoading
},
Tag: {
borderRadius: '6px'
borderRadius: `${settings.themeRadius}px`
}
};

View File

@@ -5,6 +5,7 @@ export const themeSettings: App.Theme.ThemeSetting = {
colourWeakness: false,
recommendColor: false,
themeColor: '#646cff',
themeRadius: 8,
otherColor: {
info: '#2080f0',
success: '#52c41a',

View File

@@ -16,6 +16,8 @@ declare namespace App {
recommendColor: boolean;
/** Theme color */
themeColor: string;
/** Theme radius */
themeRadius: number;
/** Other color */
otherColor: OtherColor;
/** Whether info color is followed by the primary color */
@@ -379,6 +381,9 @@ declare namespace App {
} & Record<Theme.ThemeColorKey, string>;
recommendColor: string;
recommendColorDesc: string;
themeRadius: {
title: string;
};
preset: {
title: string;
apply: string;

View File

@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue';
import { createReusableTemplate } from '@vueuse/core';
import { useThemeStore } from '@/store/modules/theme';
import { $t } from '@/locales';
defineOptions({
@@ -72,6 +73,8 @@ interface GradientBgProps {
const [DefineGradientBg, GradientBg] = createReusableTemplate<GradientBgProps>();
const themeStore = useThemeStore();
function getGradientColor(color: CardData['color']) {
return `linear-gradient(to bottom right, ${color.start}, ${color.end})`;
}
@@ -81,7 +84,10 @@ function getGradientColor(color: CardData['color']) {
<NCard :bordered="false" size="small" class="card-wrapper">
<!-- define component start: GradientBg -->
<DefineGradientBg v-slot="{ $slots, gradientColor }">
<div class="rd-8px px-16px pb-4px pt-8px text-white" :style="{ backgroundImage: gradientColor }">
<div
class="rd-8px px-16px pb-4px pt-8px text-white"
:style="{ backgroundImage: gradientColor, borderRadius: themeStore.themeRadius + 'px' }"
>
<component :is="$slots.default" />
</div>
</DefineGradientBg>

View File

@@ -23,7 +23,7 @@ export default defineConfig<Theme>({
}
},
shortcuts: {
'card-wrapper': 'rd-8px shadow-sm'
'card-wrapper': 'shadow-sm'
},
transformers: [transformerDirectives(), transformerVariantGroup()],
presets: [presetWind3({ dark: 'class' }), presetSoybeanAdmin()]