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.
- package/composables/useLocale.ts +1 -0
- package/composables/useManualTheme.ts +1 -0
- package/composables/useTheme.ts +74 -73
- package/index.d.ts +35 -28
- package/index.ts +1 -1
- package/package.json +1 -1
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 }
|
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
|
|
19
|
+
interface Component {
|
|
6
20
|
name: string
|
|
7
|
-
install?: (app: App) => void
|
|
8
21
|
}
|
|
9
22
|
|
|
10
23
|
// 声明 SystemSettings 组件
|
|
11
|
-
declare const SystemSettings:
|
|
24
|
+
declare const SystemSettings: import('vue').DefineComponent<Record<string, any>, Record<string, any>, any> & { name: string }
|
|
12
25
|
|
|
13
26
|
// 组件列表类型
|
|
14
|
-
declare const coms:
|
|
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
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
71
|
-
useLocale: typeof useLocale
|
|
72
|
-
useManualTheme: typeof useManualTheme
|
|
73
|
-
}
|
|
78
|
+
// 导出声明
|
|
79
|
+
export { SystemSettings, useLocale, useManualTheme, useTheme }
|
|
74
80
|
|
|
75
|
-
//
|
|
76
|
-
export
|
|
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