wui-components-v2 1.0.8 → 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/index.d.ts CHANGED
@@ -1,17 +1,30 @@
1
1
  import type { App } from 'vue'
2
2
  import type { ConfigProviderThemeVars } from 'wot-design-uni'
3
3
 
4
+ // 类型声明
5
+ export interface ThemeColorOption {
6
+ name: string
7
+ value: string
8
+ primary: string
9
+ }
10
+
11
+ export interface LocaleOption {
12
+ name: string
13
+ value: string
14
+ }
15
+
16
+ export type ThemeMode = 'light' | 'dark'
17
+
4
18
  // SystemSettings 组件类型
5
- interface ComponentWithInstall extends Record<string, any> {
19
+ interface Component {
6
20
  name: string
7
- install?: (app: App) => void
8
21
  }
9
22
 
10
23
  // 声明 SystemSettings 组件
11
- declare const SystemSettings: ComponentWithInstall
24
+ declare const SystemSettings: import('vue').DefineComponent<Record<string, any>, Record<string, any>, any> & { name: string }
12
25
 
13
26
  // 组件列表类型
14
- declare const coms: ComponentWithInstall[]
27
+ declare const coms: Component[]
15
28
 
16
29
  /**
17
30
  * 批量注册组件
@@ -19,26 +32,14 @@ declare const coms: ComponentWithInstall[]
19
32
  */
20
33
  declare function install(app: App): void
21
34
 
22
- // 主题相关类型
23
- interface ThemeColorOption {
24
- name: string
25
- value: string
26
- primary: string
27
- }
28
-
29
- interface LocaleOption {
30
- name: string
31
- value: string
32
- }
33
-
34
- type ThemeMode = 'light' | 'dark'
35
-
36
- interface UseLocaleReturn {
35
+ // useLocale 组合式函数返回类型
36
+ export interface UseLocaleReturn {
37
37
  locale: Readonly<LocaleOption>
38
38
  changeSystemLocale: () => void
39
39
  }
40
40
 
41
- interface UseManualThemeReturn {
41
+ // useManualTheme 组合式函数返回类型
42
+ export interface UseManualThemeReturn {
42
43
  theme: Readonly<ThemeMode>
43
44
  primary: import('vue').ComputedRef<string>
44
45
  isDark: import('vue').ComputedRef<boolean>
@@ -62,18 +63,24 @@ interface UseManualThemeReturn {
62
63
  selectLanguage: (option: LocaleOption) => void
63
64
  }
64
65
 
65
- // 组合式API函数
66
+ // useTheme 组合式函数返回类型
67
+ export interface UseThemeReturn {
68
+ theme: Readonly<ThemeMode>
69
+ isDark: import('vue').ComputedRef<boolean>
70
+ themeVars: import('vue').ComputedRef<ConfigProviderThemeVars>
71
+ }
72
+
73
+ // 组合式API函数类型声明
66
74
  declare function useLocale(): UseLocaleReturn
67
75
  declare function useManualTheme(): UseManualThemeReturn
76
+ declare function useTheme(): UseThemeReturn
68
77
 
69
- // 核心功能函数集合类型
70
- interface CoreFunctions {
71
- useLocale: typeof useLocale
72
- useManualTheme: typeof useManualTheme
73
- }
78
+ // 导出声明
79
+ export { SystemSettings, useLocale, useManualTheme, useTheme }
74
80
 
75
- // 导出核心功能函数集合
76
- export declare const coreFunctions: CoreFunctions
81
+ // 导出常量
82
+ export const themeColorOptions: ThemeColorOption[]
83
+ export const LocaleOptions: LocaleOption[]
77
84
 
78
85
  // 默认导出 install 函数
79
86
  export default install
package/index.ts CHANGED
@@ -21,7 +21,7 @@ function install(app: App): void {
21
21
  /**
22
22
  * 核心功能函数集合
23
23
  */
24
- export const coreFunctions = {
24
+ export {
25
25
  useLocale,
26
26
  useManualTheme,
27
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",