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