mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-30 07:06:40 +08:00
feat(projects): Grayscale mode is added
This commit is contained in:
parent
5a5232bdf4
commit
302fef6a39
@ -46,6 +46,9 @@ const showSiderInverted = computed(() => !themeStore.darkMode && themeStore.layo
|
|||||||
<NSwitch v-model:value="themeStore.sider.inverted" />
|
<NSwitch v-model:value="themeStore.sider.inverted" />
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
<SettingItem label="灰度模式">
|
||||||
|
<NSwitch v-model:value="themeStore.grayscale" />
|
||||||
|
</SettingItem>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -5,7 +5,15 @@ import { useEventListener, usePreferredColorScheme } from '@vueuse/core';
|
|||||||
import { getColorPalette } from '@sa/color-palette';
|
import { getColorPalette } from '@sa/color-palette';
|
||||||
import { SetupStoreId } from '@/enum';
|
import { SetupStoreId } from '@/enum';
|
||||||
import { localStg } from '@/utils/storage';
|
import { localStg } from '@/utils/storage';
|
||||||
import { addThemeVarsToHtml, createThemeToken, getNaiveTheme, initThemeSettings, toggleCssDarkMode } from './shared';
|
import {
|
||||||
|
DARK_CLASS,
|
||||||
|
GRAYSCALE_CLASS,
|
||||||
|
addThemeVarsToHtml,
|
||||||
|
createThemeToken,
|
||||||
|
getNaiveTheme,
|
||||||
|
initThemeSettings,
|
||||||
|
toggleThemeMode
|
||||||
|
} from './shared';
|
||||||
|
|
||||||
/** Theme store */
|
/** Theme store */
|
||||||
export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
|
export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
|
||||||
@ -23,6 +31,9 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
|
|||||||
return settings.value.themeScheme === 'dark';
|
return settings.value.themeScheme === 'dark';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** grayscale mode */
|
||||||
|
const grayscaleMode = computed(() => settings.value.grayscale);
|
||||||
|
|
||||||
/** Theme colors */
|
/** Theme colors */
|
||||||
const themeColors = computed(() => {
|
const themeColors = computed(() => {
|
||||||
const { themeColor, otherColor, isInfoFollowPrimary } = settings.value;
|
const { themeColor, otherColor, isInfoFollowPrimary } = settings.value;
|
||||||
@ -125,7 +136,15 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
|
|||||||
watch(
|
watch(
|
||||||
darkMode,
|
darkMode,
|
||||||
val => {
|
val => {
|
||||||
toggleCssDarkMode(val);
|
toggleThemeMode(DARK_CLASS, val);
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
grayscaleMode,
|
||||||
|
val => {
|
||||||
|
toggleThemeMode(GRAYSCALE_CLASS, val);
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
@ -5,7 +5,10 @@ import { overrideThemeSettings, themeSettings } from '@/theme/settings';
|
|||||||
import { themeVars } from '@/theme/vars';
|
import { themeVars } from '@/theme/vars';
|
||||||
import { localStg } from '@/utils/storage';
|
import { localStg } from '@/utils/storage';
|
||||||
|
|
||||||
const DARK_CLASS = 'dark';
|
export const DARK_CLASS = 'dark';
|
||||||
|
export const GRAYSCALE_CLASS = 'grayscale';
|
||||||
|
|
||||||
|
type ThemeMode = typeof DARK_CLASS | typeof GRAYSCALE_CLASS;
|
||||||
|
|
||||||
/** Init theme settings */
|
/** Init theme settings */
|
||||||
export function initThemeSettings() {
|
export function initThemeSettings() {
|
||||||
@ -162,23 +165,24 @@ export function addThemeVarsToHtml(tokens: App.Theme.BaseToken, darkTokens: App.
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle css dark mode
|
* Toggle css dark mode or grayscale mode
|
||||||
*
|
*
|
||||||
* @param darkMode Is dark mode
|
* @param mode DARK_CLASS or GRAYSCALE_CLASS
|
||||||
|
* @param status
|
||||||
*/
|
*/
|
||||||
export function toggleCssDarkMode(darkMode = false) {
|
export function toggleThemeMode(mode: ThemeMode, status = false) {
|
||||||
function addDarkClass() {
|
function addClass() {
|
||||||
document.documentElement.classList.add(DARK_CLASS);
|
document.documentElement.classList.add(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeDarkClass() {
|
function removeClass() {
|
||||||
document.documentElement.classList.remove(DARK_CLASS);
|
document.documentElement.classList.remove(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (darkMode) {
|
if (status) {
|
||||||
addDarkClass();
|
addClass();
|
||||||
} else {
|
} else {
|
||||||
removeDarkClass();
|
removeClass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,3 +11,7 @@ body,
|
|||||||
html {
|
html {
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html.grayscale {
|
||||||
|
filter: grayscale(100%);
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/** Default theme settings */
|
/** Default theme settings */
|
||||||
export const themeSettings: App.Theme.ThemeSetting = {
|
export const themeSettings: App.Theme.ThemeSetting = {
|
||||||
themeScheme: 'light',
|
themeScheme: 'light',
|
||||||
|
grayscale: false,
|
||||||
themeColor: '#646cff',
|
themeColor: '#646cff',
|
||||||
otherColor: {
|
otherColor: {
|
||||||
info: '#2080f0',
|
info: '#2080f0',
|
||||||
|
2
src/typings/app.d.ts
vendored
2
src/typings/app.d.ts
vendored
@ -20,6 +20,8 @@ declare namespace App {
|
|||||||
themeScheme: UnionKey.ThemeScheme;
|
themeScheme: UnionKey.ThemeScheme;
|
||||||
/** Theme color */
|
/** Theme color */
|
||||||
themeColor: string;
|
themeColor: string;
|
||||||
|
/** grayscale mode */
|
||||||
|
grayscale: boolean;
|
||||||
/** Other color */
|
/** Other color */
|
||||||
otherColor: OtherColor;
|
otherColor: OtherColor;
|
||||||
/** Whether info color is followed by the primary color */
|
/** Whether info color is followed by the primary color */
|
||||||
|
Loading…
Reference in New Issue
Block a user