mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-17 17:26:38 +08:00
feat(projects): add recommend color switch. closed #388
This commit is contained in:
parent
34999971fd
commit
a1920fcad9
@ -36,6 +36,27 @@ const swatches: string[] = [
|
|||||||
<template>
|
<template>
|
||||||
<NDivider>{{ $t('theme.themeColor.title') }}</NDivider>
|
<NDivider>{{ $t('theme.themeColor.title') }}</NDivider>
|
||||||
<div class="flex-col-stretch gap-12px">
|
<div class="flex-col-stretch gap-12px">
|
||||||
|
<NTooltip placement="top-start">
|
||||||
|
<template #trigger>
|
||||||
|
<SettingItem key="recommend-color" :label="$t('theme.recommendColor')">
|
||||||
|
<NSwitch v-model:value="themeStore.recommendColor" />
|
||||||
|
</SettingItem>
|
||||||
|
</template>
|
||||||
|
<p>
|
||||||
|
<span class="pr-12px">{{ $t('theme.recommendColorDesc') }}</span>
|
||||||
|
<br />
|
||||||
|
<NButton
|
||||||
|
text
|
||||||
|
tag="a"
|
||||||
|
href="https://uicolors.app/create"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="text-gray"
|
||||||
|
>
|
||||||
|
https://uicolors.app/create
|
||||||
|
</NButton>
|
||||||
|
</p>
|
||||||
|
</NTooltip>
|
||||||
<SettingItem v-for="(_, key) in themeStore.themeColors" :key="key" :label="$t(`theme.themeColor.${key}`)">
|
<SettingItem v-for="(_, key) in themeStore.themeColors" :key="key" :label="$t(`theme.themeColor.${key}`)">
|
||||||
<template v-if="key === 'info'" #suffix>
|
<template v-if="key === 'info'" #suffix>
|
||||||
<NCheckbox v-model:checked="themeStore.isInfoFollowPrimary">
|
<NCheckbox v-model:checked="themeStore.isInfoFollowPrimary">
|
||||||
|
@ -65,7 +65,8 @@ const local: App.I18n.Schema = {
|
|||||||
'vertical-mix': 'Vertical Mix Menu Mode',
|
'vertical-mix': 'Vertical Mix Menu Mode',
|
||||||
'horizontal-mix': 'Horizontal Mix menu Mode'
|
'horizontal-mix': 'Horizontal Mix menu Mode'
|
||||||
},
|
},
|
||||||
recommendColor: 'Apply Recommended Algorithm Color',
|
recommendColor: 'Apply Recommended Color Algorithm',
|
||||||
|
recommendColorDesc: 'The recommended color algorithm refers to',
|
||||||
themeColor: {
|
themeColor: {
|
||||||
title: 'Theme Color',
|
title: 'Theme Color',
|
||||||
primary: 'Primary',
|
primary: 'Primary',
|
||||||
|
@ -66,6 +66,7 @@ const local: App.I18n.Schema = {
|
|||||||
'horizontal-mix': '顶部菜单混合模式'
|
'horizontal-mix': '顶部菜单混合模式'
|
||||||
},
|
},
|
||||||
recommendColor: '应用推荐算法的颜色',
|
recommendColor: '应用推荐算法的颜色',
|
||||||
|
recommendColorDesc: '推荐颜色的算法参照',
|
||||||
themeColor: {
|
themeColor: {
|
||||||
title: '主题颜色',
|
title: '主题颜色',
|
||||||
primary: '主色',
|
primary: '主色',
|
||||||
|
@ -45,7 +45,7 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/** Naive theme */
|
/** Naive theme */
|
||||||
const naiveTheme = computed(() => getNaiveTheme(themeColors.value));
|
const naiveTheme = computed(() => getNaiveTheme(themeColors.value, settings.value.recommendColor));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings json
|
* Settings json
|
||||||
@ -125,7 +125,7 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
|
|||||||
|
|
||||||
/** Setup theme vars to html */
|
/** Setup theme vars to html */
|
||||||
function setupThemeVarsToHtml() {
|
function setupThemeVarsToHtml() {
|
||||||
const { themeTokens, darkThemeTokens } = createThemeToken(themeColors.value);
|
const { themeTokens, darkThemeTokens } = createThemeToken(themeColors.value, settings.value.recommendColor);
|
||||||
addThemeVarsToHtml(themeTokens, darkThemeTokens);
|
addThemeVarsToHtml(themeTokens, darkThemeTokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,10 @@ export function initThemeSettings() {
|
|||||||
* Create theme token
|
* Create theme token
|
||||||
*
|
*
|
||||||
* @param colors Theme colors
|
* @param colors Theme colors
|
||||||
|
* @param [recommended=false] Use recommended color. Default is `false`
|
||||||
*/
|
*/
|
||||||
export function createThemeToken(colors: App.Theme.ThemeColor) {
|
export function createThemeToken(colors: App.Theme.ThemeColor, recommended = false) {
|
||||||
const paletteColors = createThemePaletteColors(colors);
|
const paletteColors = createThemePaletteColors(colors, recommended);
|
||||||
|
|
||||||
const themeTokens: App.Theme.ThemeToken = {
|
const themeTokens: App.Theme.ThemeToken = {
|
||||||
colors: {
|
colors: {
|
||||||
@ -75,6 +76,7 @@ export function createThemeToken(colors: App.Theme.ThemeColor) {
|
|||||||
* Create theme palette colors
|
* Create theme palette colors
|
||||||
*
|
*
|
||||||
* @param colors Theme colors
|
* @param colors Theme colors
|
||||||
|
* @param [recommended=false] Use recommended color. Default is `false`
|
||||||
*/
|
*/
|
||||||
function createThemePaletteColors(colors: App.Theme.ThemeColor, recommended = false) {
|
function createThemePaletteColors(colors: App.Theme.ThemeColor, recommended = false) {
|
||||||
const colorKeys = Object.keys(colors) as App.Theme.ThemeColorKey[];
|
const colorKeys = Object.keys(colors) as App.Theme.ThemeColorKey[];
|
||||||
@ -205,6 +207,7 @@ interface NaiveColorAction {
|
|||||||
* Get naive theme colors
|
* Get naive theme colors
|
||||||
*
|
*
|
||||||
* @param colors Theme colors
|
* @param colors Theme colors
|
||||||
|
* @param [recommended=false] Use recommended color. Default is `false`
|
||||||
*/
|
*/
|
||||||
function getNaiveThemeColors(colors: App.Theme.ThemeColor, recommended = false) {
|
function getNaiveThemeColors(colors: App.Theme.ThemeColor, recommended = false) {
|
||||||
const colorActions: NaiveColorAction[] = [
|
const colorActions: NaiveColorAction[] = [
|
||||||
@ -234,13 +237,14 @@ function getNaiveThemeColors(colors: App.Theme.ThemeColor, recommended = false)
|
|||||||
* Get naive theme
|
* Get naive theme
|
||||||
*
|
*
|
||||||
* @param colors Theme colors
|
* @param colors Theme colors
|
||||||
|
* @param [recommended=false] Use recommended color. Default is `false`
|
||||||
*/
|
*/
|
||||||
export function getNaiveTheme(colors: App.Theme.ThemeColor) {
|
export function getNaiveTheme(colors: App.Theme.ThemeColor, recommended = false) {
|
||||||
const { primary: colorLoading } = colors;
|
const { primary: colorLoading } = colors;
|
||||||
|
|
||||||
const theme: GlobalThemeOverrides = {
|
const theme: GlobalThemeOverrides = {
|
||||||
common: {
|
common: {
|
||||||
...getNaiveThemeColors(colors),
|
...getNaiveThemeColors(colors, recommended),
|
||||||
borderRadius: '6px'
|
borderRadius: '6px'
|
||||||
},
|
},
|
||||||
LoadingBar: {
|
LoadingBar: {
|
||||||
|
1
src/typings/app.d.ts
vendored
1
src/typings/app.d.ts
vendored
@ -305,6 +305,7 @@ declare namespace App {
|
|||||||
grayscale: string;
|
grayscale: string;
|
||||||
layoutMode: { title: string } & Record<UnionKey.ThemeLayoutMode, string>;
|
layoutMode: { title: string } & Record<UnionKey.ThemeLayoutMode, string>;
|
||||||
recommendColor: string;
|
recommendColor: string;
|
||||||
|
recommendColorDesc: string;
|
||||||
themeColor: {
|
themeColor: {
|
||||||
title: string;
|
title: string;
|
||||||
followPrimary: string;
|
followPrimary: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user