|
10 | 10 | <span class="color-mode" @click="switchColorMode"> |
11 | 11 | <el-icon v-if="isMatchColorMode('light')"><Sunny /></el-icon> |
12 | 12 | <el-icon v-else-if="isMatchColorMode('dark')"><Moon /></el-icon> |
13 | | - <el-icon v-else-if="isMatchColorMode('system')"><Setting /></el-icon> |
14 | 13 | </span> |
15 | 14 | </div> |
16 | 15 | <router-link |
@@ -80,49 +79,40 @@ export default { |
80 | 79 | }, |
81 | 80 | methods: { |
82 | 81 | initColorMode: function () { |
83 | | - if (window.matchMedia("(prefers-color-scheme: light)").matches) |
| 82 | + if (window.matchMedia("(prefers-color-scheme: light)").matches) { |
84 | 83 | document.querySelector("html").classList.remove("dark") |
85 | | - else document.querySelector("html").classList.add("dark") |
| 84 | + this.colorMode = "light" |
| 85 | + } else { |
| 86 | + document.querySelector("html").classList.add("dark") |
| 87 | + this.colorMode = "dark" |
| 88 | + } |
| 89 | +
|
| 90 | + console.log( |
| 91 | + this.colorMode, |
| 92 | + window.matchMedia("(prefers-color-scheme: light)").matches |
| 93 | + ) |
86 | 94 | }, |
87 | 95 | handleOpenUserArea: function () { |
88 | 96 | this.$router.push({ path: "/userArea" }) |
89 | 97 | }, |
90 | 98 | handleKeepDrag: () => false, |
91 | 99 | isMatchColorMode: function (mode) { |
| 100 | + if (this.$router.currentRoute.value.path === "/setting") return false |
92 | 101 | if (mode && this) return this.colorMode === mode |
93 | 102 | return false |
94 | 103 | }, |
95 | 104 | switchColorMode: function () { |
96 | 105 | 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 | | - } |
| 106 | + ipcRenderer.send( |
| 107 | + `color-schemeMode-${this.colorMode === "light" ? "dark" : "light"}` |
| 108 | + ) |
| 109 | +
|
| 110 | + data.data.userSetting.colorSchemeMode = this.colorMode |
123 | 111 | this.handleStorgeSetting(data.data, () => { |
124 | | - this.initColorMode() |
125 | | - console.log(data.data.userSetting.colorSchemeMode) |
| 112 | + setTimeout(() => { |
| 113 | + this.initColorMode() |
| 114 | + this.$public.emit("update-color-mode", this.colorMode) |
| 115 | + }, 0) |
126 | 116 | }) |
127 | 117 | }) |
128 | 118 | }, |
|
0 commit comments