wui-components-v2 1.2.18 → 1.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, onBeforeMount,
|
|
1
|
+
import { computed, onBeforeMount, ref } from 'vue'
|
|
2
2
|
import { onShow } from '@dcloudio/uni-app'
|
|
3
3
|
import { useManualThemeStore } from '../store/manualThemeStore'
|
|
4
4
|
import { useLocale } from './useLocale'
|
|
@@ -117,15 +117,6 @@ export function useManualTheme() {
|
|
|
117
117
|
// 组件挂载前初始化主题
|
|
118
118
|
onBeforeMount(() => {
|
|
119
119
|
initTheme()
|
|
120
|
-
|
|
121
|
-
// 监听系统主题变化
|
|
122
|
-
if (typeof uni !== 'undefined' && uni.onThemeChange) {
|
|
123
|
-
uni.onThemeChange((res) => {
|
|
124
|
-
if (store.followSystem) {
|
|
125
|
-
toggleTheme(res.theme as ThemeMode)
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
120
|
})
|
|
130
121
|
|
|
131
122
|
// 页面显示时更新导航栏颜色,确保每次切换页面时导航栏颜色都是正确的
|
|
@@ -133,17 +124,6 @@ export function useManualTheme() {
|
|
|
133
124
|
store.setNavigationBarColor()
|
|
134
125
|
})
|
|
135
126
|
|
|
136
|
-
// 组件卸载时清理监听
|
|
137
|
-
onUnmounted(() => {
|
|
138
|
-
if (typeof uni !== 'undefined' && uni.offThemeChange) {
|
|
139
|
-
uni.offThemeChange((res) => {
|
|
140
|
-
if (store.followSystem) {
|
|
141
|
-
toggleTheme(res.theme as ThemeMode)
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
|
|
147
127
|
return {
|
|
148
128
|
// 状态
|
|
149
129
|
theme: computed(() => store.theme),
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ import { LocaleOptions, themeColorOptions } from '../composables/types/theme'
|
|
|
8
8
|
export const useManualThemeStore = defineStore('manualTheme', {
|
|
9
9
|
state: (): ThemeState => ({
|
|
10
10
|
theme: 'light',
|
|
11
|
-
followSystem:
|
|
11
|
+
followSystem: false, // 是否跟随系统主题(已关闭:不再读取设备系统主题色)
|
|
12
12
|
hasUserSet: false, // 用户是否手动设置过主题
|
|
13
13
|
currentThemeColor: themeColorOptions[0],
|
|
14
14
|
Locale: LocaleOptions[0],
|
|
@@ -112,30 +112,10 @@ export const useManualThemeStore = defineStore('manualTheme', {
|
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
114
|
* 初始化主题
|
|
115
|
+
* 注:不再读取设备的系统主题色,直接使用已存储/默认主题
|
|
115
116
|
*/
|
|
116
117
|
initTheme() {
|
|
117
|
-
|
|
118
|
-
if (this.hasUserSet && !this.followSystem) {
|
|
119
|
-
console.log('使用用户设置的主题:', this.theme)
|
|
120
|
-
this.setNavigationBarColor()
|
|
121
|
-
return
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 获取系统主题
|
|
125
|
-
const systemTheme = this.getSystemTheme()
|
|
126
|
-
|
|
127
|
-
// 如果是首次启动或跟随系统,使用系统主题
|
|
128
|
-
if (!this.hasUserSet || this.followSystem) {
|
|
129
|
-
this.theme = systemTheme
|
|
130
|
-
if (!this.hasUserSet) {
|
|
131
|
-
this.followSystem = true
|
|
132
|
-
// console.log('首次启动,使用系统主题:', this.theme)
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
console.log('跟随系统主题:', this.theme)
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
118
|
+
console.log('初始化主题:', this.theme)
|
|
139
119
|
this.setNavigationBarColor()
|
|
140
120
|
},
|
|
141
121
|
|