66 v-show =" isLogined"
77 :isDot =" false"
88 />
9+ <div class =" shiftOperations" >
10+ <span class =" color-mode" @click =" switchColorMode" >
11+ <el-icon v-if =" isMatchColorMode('light')" ><Sunny /></el-icon >
12+ <el-icon v-else-if =" isMatchColorMode('dark')" ><Moon /></el-icon >
13+ <el-icon v-else-if =" isMatchColorMode('system')" ><Setting /></el-icon >
14+ </span >
15+ </div >
916 <router-link
1017 class =" areaLink"
1118 tabindex =" -1"
4148<script >
4249// @ is an alias to /src
4350import UserAvatar from " @/components/UserAssets/Avatar/index.vue"
51+ const { ipcRenderer } = window .require (" electron" )
4452
4553export default {
4654 name: " Navigation" ,
@@ -51,6 +59,7 @@ export default {
5159 data () {
5260 return {
5361 isLogined: false ,
62+ colorMode: " light" ,
5463 signText: " 登录" ,
5564 }
5665 },
@@ -67,12 +76,64 @@ export default {
6776 },
6877 mounted () {
6978 this .isLogined = ! (localStorage .getItem (" checkKey" ) == (undefined || null ))
79+ this .initColorMode ()
7080 },
7181 methods: {
82+ initColorMode : function () {
83+ if (window .matchMedia (" (prefers-color-scheme: light)" ).matches )
84+ document .querySelector (" html" ).classList .remove (" dark" )
85+ else document .querySelector (" html" ).classList .add (" dark" )
86+ },
7287 handleOpenUserArea : function () {
7388 this .$router .push ({ path: " /userArea" })
7489 },
7590 handleKeepDrag : () => false ,
91+ isMatchColorMode : function (mode ) {
92+ if (mode && this ) return this .colorMode === mode
93+ return false
94+ },
95+ switchColorMode : function () {
96+ this .$conf .getConfPromise ().then ((data ) => {
97+ switch (this .colorMode ) {
98+ case " light" : {
99+ data .data .userSetting .colorSchemeMode = " light"
100+ ipcRenderer .send (" color-schemeMode-light" )
101+ break
102+ }
103+ case " dark" : {
104+ data .data .userSetting .colorSchemeMode = " dark"
105+ ipcRenderer .send (" color-schemeMode-dark" )
106+ break
107+ }
108+ case " system" : {
109+ data .data .userSetting .colorSchemeMode = " system"
110+ ipcRenderer .send (" color-schemeMode-system" )
111+ break
112+ }
113+ default :
114+ break
115+ }
116+ if (this .colorMode === " light" ) {
117+ this .colorMode = " dark"
118+ } else if (this .colorMode === " dark" ) {
119+ this .colorMode = " system"
120+ } else if (this .colorMode === " system" ) {
121+ this .colorMode = " light"
122+ }
123+ this .handleStorgeSetting (data .data , () => {
124+ this .initColorMode ()
125+ console .log (data .data .userSetting .colorSchemeMode )
126+ })
127+ })
128+ },
129+ handleStorgeSetting : function (setting , cb ) {
130+ this .$conf .updateLocalConfig (setting, (err ) => {
131+ if (err) {
132+ console .log (err)
133+ }
134+ })
135+ cb && cb ()
136+ },
76137 },
77138}
78139 </script >
@@ -98,6 +159,23 @@ export default {
98159.avatar {
99160 @apply w-11 h-11 absolute left-2;
100161}
162+
163+ .shiftOperations {
164+ @apply absolute right-4 inline-flex items-center;
165+ }
166+
167+ .shiftOperations .color-mode {
168+ @apply inline-flex items-center justify-center w-8 h-8 p-1.5
169+ hover :bg-gray-200 dark:hover:bg-gray-600 rounded-full cursor-pointer transition-all;
170+ }
171+
172+ .el-icon {
173+ @apply inline-flex items-center justify-center w-full h-full;
174+ }
175+
176+ .el-icon svg {
177+ @apply inline-block w-full h-full;
178+ }
101179 </style >
102180
103181<style lang="postcss">
0 commit comments