Skip to content

Commit 9a805c9

Browse files
committed
fix: 切换主题不成功
1 parent 2fe90a1 commit 9a805c9

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"pinia": "^2.2.6",
2828
"pinia-plugin-persist": "^1.0.0",
2929
"sparticles": "^1.3.1",
30-
"theme-change": "^2.5.0",
3130
"three": "^0.166.0",
3231
"three-css3d": "^1.0.6",
3332
"vue": "^3.5.13",

src/App.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
22
import PlayMusic from '@/components/PlayMusic/index.vue'
33
import useStore from '@/store'
4+
import { themeChange } from '@/utils'
45
import { storeToRefs } from 'pinia'
5-
import { themeChange } from 'theme-change'
66
import { onMounted, ref } from 'vue'
77
import { useI18n } from 'vue-i18n'
88
@@ -14,10 +14,6 @@ const { getTheme: localTheme } = storeToRefs(globalConfig)
1414
const { getPrizeConfig: prizeList } = storeToRefs(prizeConfig)
1515
1616
const tipDialog = ref()
17-
// const isMobileValue = ref(structuredClone(isMobile.value))
18-
function setLocalTheme(theme: any) {
19-
themeChange(theme.name)
20-
}
2117
2218
// 设置当前奖列表
2319
function setCurrentPrize() {
@@ -53,7 +49,7 @@ function judgeChromeOrEdge() {
5349
return isChrome || isEdge
5450
}
5551
onMounted(() => {
56-
setLocalTheme(localTheme.value)
52+
themeChange(localTheme.value.name)
5753
setCurrentPrize()
5854
if (judgeMobile() || !judgeChromeOrEdge()) {
5955
tipDialog.value.showModal()

src/utils/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ export function selectCard(cardIndexArr: number[], tableLength: number, personId
3939

4040
return cardIndex
4141
}
42+
43+
export function themeChange(theme: string) {
44+
// 获取根html
45+
const html = document.querySelectorAll('html')
46+
if (html) {
47+
html[0].setAttribute('data-theme', theme)
48+
localStorage.setItem('theme', theme)
49+
}
50+
}

src/views/Config/Global/FaceConfig.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import i18n, { languageList } from '@/locales/i18n'
33
44
import useStore from '@/store'
5+
import { themeChange } from '@/utils'
56
import { isHex, isRgbOrRgba } from '@/utils/color'
67
import daisyuiThemes from 'daisyui/src/theming/themes'
78
import { storeToRefs } from 'pinia'
8-
import { themeChange } from 'theme-change'
99
import { onMounted, ref, watch } from 'vue'
1010
import { ColorPicker } from 'vue3-colorpicker'
1111
import { useI18n } from 'vue-i18n'

0 commit comments

Comments
 (0)