wui-components-v2 1.2.18 → 1.2.20

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.
@@ -22,6 +22,25 @@ export interface LocaleOption {
22
22
  */
23
23
  export type ThemeMode = 'light' | 'dark'
24
24
 
25
+ /**
26
+ * 应用自定义主题变量
27
+ * 在 wot-design-uni 的 ConfigProviderThemeVars 基础上扩展业务自定义字段
28
+ */
29
+ export interface CustomThemeVars extends ConfigProviderThemeVars {
30
+ darkBackground: string
31
+ darkBackground2: string
32
+ darkBackground3: string
33
+ darkBackground4: string
34
+ darkBackground5: string
35
+ darkBackground6: string
36
+ darkBackground7: string
37
+ darkColor: string
38
+ darkColor2: string
39
+ darkColor3: string
40
+ colorTheme: string
41
+ colorPrimary?: string
42
+ }
43
+
25
44
  /**
26
45
  * 主题状态接口
27
46
  */
@@ -31,7 +50,7 @@ export interface ThemeState {
31
50
  followSystem: boolean
32
51
  hasUserSet: boolean
33
52
  currentThemeColor: ThemeColorOption
34
- themeVars: ConfigProviderThemeVars
53
+ themeVars: CustomThemeVars
35
54
  }
36
55
 
37
56
  /**
@@ -39,7 +58,7 @@ export interface ThemeState {
39
58
  */
40
59
  export interface SystemThemeState {
41
60
  theme: ThemeMode
42
- themeVars: ConfigProviderThemeVars
61
+ themeVars: CustomThemeVars
43
62
  }
44
63
 
45
64
  /**
@@ -1,4 +1,4 @@
1
- import { computed, onBeforeMount, onUnmounted, ref } from 'vue'
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.2.18",
3
+ "version": "1.2.20",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",
@@ -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: true, // 是否跟随系统主题
11
+ followSystem: false, // 是否跟随系统主题(已关闭:不再读取设备系统主题色)
12
12
  hasUserSet: false, // 用户是否手动设置过主题
13
13
  currentThemeColor: themeColorOptions[0],
14
14
  Locale: LocaleOptions[0],
@@ -112,30 +112,15 @@ 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
118
+ // 用户未手动设置过主题时,强制默认白色
119
+ // 避免沿用旧版本跟随系统时期写入缓存的深色,也不跟随系统
120
+ if (!this.hasUserSet) {
121
+ this.theme = 'light'
122
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
-
123
+ console.log('初始化主题:', this.theme)
139
124
  this.setNavigationBarColor()
140
125
  },
141
126