wui-components-v2 1.0.9 → 1.0.10
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.
package/composables/useLocale.ts
CHANGED
package/composables/useTheme.ts
CHANGED
|
@@ -1,73 +1,74 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* -
|
|
15
|
-
* -
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* -
|
|
20
|
-
* -
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
1
|
+
import { computed, onBeforeMount, onUnmounted } from 'vue'
|
|
2
|
+
import type { ThemeMode } from '../composables/types/theme'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 简化版系统主题管理组合式API
|
|
6
|
+
*
|
|
7
|
+
* 功能特性:
|
|
8
|
+
* - 仅跟随系统主题变化
|
|
9
|
+
* - 自动响应系统主题切换
|
|
10
|
+
* - 导航栏颜色通过 theme.json 自动处理
|
|
11
|
+
* - 轻量级,无额外功能
|
|
12
|
+
*
|
|
13
|
+
* 适用场景:
|
|
14
|
+
* - 只需要系统主题适应的简单应用
|
|
15
|
+
* - 不需要用户手动控制主题的应用
|
|
16
|
+
* - 追求轻量级主题管理的应用
|
|
17
|
+
*
|
|
18
|
+
* 注意事项:
|
|
19
|
+
* - 不支持手动切换主题
|
|
20
|
+
* - 不支持主题色自定义
|
|
21
|
+
* - 导航栏颜色依赖 theme.json 配置
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```vue
|
|
25
|
+
* <script setup>
|
|
26
|
+
* import { useTheme } from '@/composables/useTheme'
|
|
27
|
+
*
|
|
28
|
+
* const { theme, isDark, themeVars } = useTheme()
|
|
29
|
+
* </script>
|
|
30
|
+
*
|
|
31
|
+
* <template>
|
|
32
|
+
* <wd-config-provider :theme-vars="themeVars">
|
|
33
|
+
* <view :class="{ 'dark-mode': isDark }">
|
|
34
|
+
* <text>当前主题: {{ theme }}</text>
|
|
35
|
+
* </view>
|
|
36
|
+
* </wd-config-provider>
|
|
37
|
+
* </template>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function useTheme() {
|
|
41
|
+
const store = useThemeStore()
|
|
42
|
+
|
|
43
|
+
// 组件挂载前初始化系统主题
|
|
44
|
+
onBeforeMount(() => {
|
|
45
|
+
store.initSystemTheme()
|
|
46
|
+
// 监听系统主题变化
|
|
47
|
+
if (typeof uni !== 'undefined' && uni.onThemeChange) {
|
|
48
|
+
uni.onThemeChange((res) => {
|
|
49
|
+
// 系统主题变化时自动更新,导航栏颜色由 theme.json 自动处理
|
|
50
|
+
store.setTheme(res.theme as ThemeMode)
|
|
51
|
+
console.log('系统主题已切换至:', res.theme)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// 组件卸载时清理监听
|
|
57
|
+
onUnmounted(() => {
|
|
58
|
+
if (typeof uni !== 'undefined' && uni.offThemeChange) {
|
|
59
|
+
uni.offThemeChange((res) => {
|
|
60
|
+
store.setTheme(res.theme as ThemeMode)
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
// 状态(只读)
|
|
67
|
+
theme: computed(() => store.theme),
|
|
68
|
+
isDark: computed(() => store.isDark),
|
|
69
|
+
themeVars: computed(() => store.themeVars),
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 导出类型供外部使用
|
|
74
|
+
export type { ThemeMode }
|