feat(projects): add switch for customize darkmode transition
This commit is contained in:
parent
d3ebe95076
commit
6e0cce4d49
@ -13,6 +13,8 @@ defineOptions({ name: 'DarkModeSwitch' });
|
|||||||
interface Props {
|
interface Props {
|
||||||
/** 暗黑模式 */
|
/** 暗黑模式 */
|
||||||
dark?: boolean;
|
dark?: boolean;
|
||||||
|
/** 自定义暗黑模式动画过渡 */
|
||||||
|
customizeTransition?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
@ -38,7 +40,7 @@ async function handleSwitch(event: MouseEvent) {
|
|||||||
const x = event.clientX;
|
const x = event.clientX;
|
||||||
const y = event.clientY;
|
const y = event.clientY;
|
||||||
|
|
||||||
if (!document.startViewTransition) {
|
if (!props.customizeTransition || !document.startViewTransition) {
|
||||||
darkMode.value = !darkMode.value;
|
darkMode.value = !darkMode.value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<hover-container class="w-40px" :inverted="theme.header.inverted" tooltip-content="主题模式">
|
<hover-container class="w-40px" :inverted="theme.header.inverted" tooltip-content="主题模式">
|
||||||
<dark-mode-switch :dark="theme.darkMode" class="wh-full" @update:dark="theme.setDarkMode" />
|
<dark-mode-switch
|
||||||
|
:dark="theme.darkMode"
|
||||||
|
:customize-transition="theme.isCustomizeDarkModeTransition"
|
||||||
|
class="wh-full"
|
||||||
|
@update:dark="theme.setDarkMode"
|
||||||
|
/>
|
||||||
</hover-container>
|
</hover-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -21,6 +21,16 @@
|
|||||||
</template>
|
</template>
|
||||||
</n-switch>
|
</n-switch>
|
||||||
</setting-menu>
|
</setting-menu>
|
||||||
|
<setting-menu label="自定义暗黑主题动画过渡">
|
||||||
|
<n-switch :value="theme.isCustomizeDarkModeTransition" @update:value="theme.setIsCustomizeDarkModeTransition">
|
||||||
|
<template #checked>
|
||||||
|
<icon-ic-baseline-do-not-disturb class="text-14px text-white" />
|
||||||
|
</template>
|
||||||
|
<template #unchecked>
|
||||||
|
<icon-ic-round-hdr-auto class="text-14px text-white" />
|
||||||
|
</template>
|
||||||
|
</n-switch>
|
||||||
|
</setting-menu>
|
||||||
<setting-menu label="侧边栏深色">
|
<setting-menu label="侧边栏深色">
|
||||||
<n-switch :value="theme.sider.inverted" @update:value="theme.setSiderInverted" />
|
<n-switch :value="theme.sider.inverted" @update:value="theme.setSiderInverted" />
|
||||||
</setting-menu>
|
</setting-menu>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"darkMode": false,
|
"darkMode": false,
|
||||||
"followSystemTheme": true,
|
"followSystemTheme": true,
|
||||||
|
"isCustomizeDarkModeTransition": false,
|
||||||
"layout": {
|
"layout": {
|
||||||
"minWidth": 900,
|
"minWidth": 900,
|
||||||
"mode": "vertical",
|
"mode": "vertical",
|
||||||
|
@ -37,6 +37,7 @@ const themeColorList = [
|
|||||||
const defaultThemeSetting: Theme.Setting = {
|
const defaultThemeSetting: Theme.Setting = {
|
||||||
darkMode: false,
|
darkMode: false,
|
||||||
followSystemTheme: true,
|
followSystemTheme: true,
|
||||||
|
isCustomizeDarkModeTransition: false,
|
||||||
layout: {
|
layout: {
|
||||||
minWidth: 900,
|
minWidth: 900,
|
||||||
mode: 'vertical',
|
mode: 'vertical',
|
||||||
|
@ -43,6 +43,10 @@ export const useThemeStore = defineStore('theme-store', {
|
|||||||
setFollowSystemTheme(visible: boolean) {
|
setFollowSystemTheme(visible: boolean) {
|
||||||
this.followSystemTheme = visible;
|
this.followSystemTheme = visible;
|
||||||
},
|
},
|
||||||
|
/** 设置自动跟随系统主题 */
|
||||||
|
setIsCustomizeDarkModeTransition(isCustomize: boolean) {
|
||||||
|
this.isCustomizeDarkModeTransition = isCustomize;
|
||||||
|
},
|
||||||
/** 自动跟随系统主题 */
|
/** 自动跟随系统主题 */
|
||||||
setAutoFollowSystemMode(darkMode: boolean) {
|
setAutoFollowSystemMode(darkMode: boolean) {
|
||||||
if (this.followSystemTheme) {
|
if (this.followSystemTheme) {
|
||||||
|
2
src/typings/system.d.ts
vendored
2
src/typings/system.d.ts
vendored
@ -90,6 +90,8 @@ declare namespace Theme {
|
|||||||
darkMode: boolean;
|
darkMode: boolean;
|
||||||
/** 是否自动跟随系统主题 */
|
/** 是否自动跟随系统主题 */
|
||||||
followSystemTheme: boolean;
|
followSystemTheme: boolean;
|
||||||
|
/** 自定义暗黑动画过渡 */
|
||||||
|
isCustomizeDarkModeTransition: boolean;
|
||||||
/** 布局样式 */
|
/** 布局样式 */
|
||||||
layout: Layout;
|
layout: Layout;
|
||||||
/** 滚动模式 */
|
/** 滚动模式 */
|
||||||
|
Loading…
Reference in New Issue
Block a user