@hlw-uni/mp-vue 2.1.56 → 2.1.58
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/dist/app.d.ts +12 -1
- package/dist/composables/ad/index.d.ts +26 -0
- package/dist/composables/device/index.d.ts +14 -0
- package/dist/composables/index.d.ts +1 -1
- package/dist/composables/msg/index.d.ts +44 -3
- package/dist/composables/navigator/index.d.ts +37 -1
- package/dist/composables/refs/index.d.ts +15 -1
- package/dist/composables/request/client.d.ts +87 -0
- package/dist/composables/request/service.d.ts +64 -0
- package/dist/composables/request/types.d.ts +50 -13
- package/dist/composables/share/index.d.ts +38 -0
- package/dist/composables/theme/appearance.d.ts +30 -4
- package/dist/composables/theme/font.d.ts +23 -0
- package/dist/composables/theme/index.d.ts +19 -6
- package/dist/composables/theme/palette.d.ts +23 -0
- package/dist/composables/theme/typography.d.ts +9 -1
- package/dist/composables/utils/index.d.ts +120 -13
- package/dist/directives/copy.d.ts +5 -0
- package/dist/hlw.d.ts +10 -0
- package/dist/index.js +305 -199
- package/dist/index.mjs +306 -200
- package/dist/stores/theme.d.ts +3 -0
- package/package.json +1 -1
- package/src/app.ts +20 -3
- package/src/components/hlw-ad/index.vue +58 -12
- package/src/components/hlw-add-mini/README.md +10 -11
- package/src/components/hlw-add-mini/index.vue +93 -66
- package/src/components/hlw-button/index.vue +33 -18
- package/src/composables/ad/index.ts +136 -62
- package/src/composables/device/index.ts +32 -2
- package/src/composables/index.ts +18 -1
- package/src/composables/msg/index.ts +70 -16
- package/src/composables/navigator/index.ts +45 -1
- package/src/composables/refs/index.ts +27 -4
- package/src/composables/request/client.ts +149 -0
- package/src/composables/request/service.ts +64 -0
- package/src/composables/request/types.ts +53 -13
- package/src/composables/share/index.ts +48 -0
- package/src/composables/theme/appearance.ts +31 -4
- package/src/composables/theme/font.ts +23 -0
- package/src/composables/theme/index.ts +23 -7
- package/src/composables/theme/palette.ts +32 -0
- package/src/composables/theme/typography.ts +9 -1
- package/src/composables/utils/index.ts +227 -127
- package/src/directives/copy.ts +31 -19
- package/src/hlw.ts +11 -0
- package/src/stores/theme.ts +28 -5
|
@@ -11,16 +11,26 @@
|
|
|
11
11
|
* - 用 `var(--border-color-light)` 代替硬编码 `#f1f5f9`
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
/** 外观模式选项类型:浅色模式、深色模式、跟随系统 */
|
|
14
15
|
export type Appearance = "light" | "dark" | "auto";
|
|
16
|
+
|
|
17
|
+
/** 实际生效的外观模式:仅浅色或深色 */
|
|
15
18
|
export type AppearanceMode = "light" | "dark";
|
|
16
19
|
|
|
20
|
+
/**
|
|
21
|
+
* 外观预设配置接口。
|
|
22
|
+
*/
|
|
17
23
|
export interface AppearancePreset {
|
|
24
|
+
/** 选项值 */
|
|
18
25
|
value: Appearance;
|
|
26
|
+
/** 选项展示名称 */
|
|
19
27
|
label: string;
|
|
20
28
|
}
|
|
21
29
|
|
|
30
|
+
/** 存储外观设置的 LocalStorage 键名 */
|
|
22
31
|
export const APPEARANCE_KEY = "hlw_appearance";
|
|
23
32
|
|
|
33
|
+
/** 预设外观模式列表,常供设置页渲染选择器使用 */
|
|
24
34
|
export const APPEARANCE_PRESETS: AppearancePreset[] = [
|
|
25
35
|
{ value: "light", label: "浅色模式" },
|
|
26
36
|
{ value: "dark", label: "深色模式" },
|
|
@@ -67,12 +77,17 @@ const DARK_VARS: Record<string, string> = {
|
|
|
67
77
|
"--shadow-card": "0 4rpx 16rpx rgba(0, 0, 0, 0.35)",
|
|
68
78
|
};
|
|
69
79
|
|
|
80
|
+
/** 不同外观模式的 CSS 变量映射 */
|
|
70
81
|
export const APPEARANCE_VAR_MAP: Record<AppearanceMode, Record<string, string>> = {
|
|
71
82
|
light: LIGHT_VARS,
|
|
72
83
|
dark: DARK_VARS,
|
|
73
84
|
};
|
|
74
85
|
|
|
75
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* 读取用户设置的外观配置(light / dark / auto)。
|
|
88
|
+
* 默认返回 'auto'。
|
|
89
|
+
* @returns 设定的外观模式类型
|
|
90
|
+
*/
|
|
76
91
|
export function getCurrentAppearance(): Appearance {
|
|
77
92
|
try {
|
|
78
93
|
const v = uni.getStorageSync(APPEARANCE_KEY);
|
|
@@ -81,7 +96,12 @@ export function getCurrentAppearance(): Appearance {
|
|
|
81
96
|
return "auto";
|
|
82
97
|
}
|
|
83
98
|
|
|
84
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* 将 auto 设置或用户选择解析为具体的 light/dark 实际模式。
|
|
101
|
+
* 当为 auto 时,将读取系统当前的配色偏好。
|
|
102
|
+
* @param appearance 输入的外观配置
|
|
103
|
+
* @returns 解析后最终生效的外观模式 (light 或 dark)
|
|
104
|
+
*/
|
|
85
105
|
export function resolveAppearance(appearance: Appearance): AppearanceMode {
|
|
86
106
|
if (appearance === "light" || appearance === "dark") return appearance;
|
|
87
107
|
try {
|
|
@@ -91,12 +111,19 @@ export function resolveAppearance(appearance: Appearance): AppearanceMode {
|
|
|
91
111
|
return "light";
|
|
92
112
|
}
|
|
93
113
|
|
|
94
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* 获取当前实际生效的外观模式 (light 或 dark)。
|
|
116
|
+
* 自动根据用户偏好及系统主题进行判定。
|
|
117
|
+
* @returns 实际生效的外观模式
|
|
118
|
+
*/
|
|
95
119
|
export function getCurrentAppearanceMode(): AppearanceMode {
|
|
96
120
|
return resolveAppearance(getCurrentAppearance());
|
|
97
121
|
}
|
|
98
122
|
|
|
99
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* 获取当前外观对应的 CSS 变量映射表。
|
|
125
|
+
* @returns 包含各 CSS 变量名与对应颜色值键值对
|
|
126
|
+
*/
|
|
100
127
|
export function getCurrentAppearanceVars(): Record<string, string> {
|
|
101
128
|
return APPEARANCE_VAR_MAP[getCurrentAppearanceMode()];
|
|
102
129
|
}
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 字体大小缩放档位类型。
|
|
3
|
+
* 从较小到特大,共 7 个档位。
|
|
4
|
+
*/
|
|
1
5
|
export type FontScale = "small" | "compact" | "normal" | "medium" | "large" | "xlarge" | "xxlarge";
|
|
2
6
|
|
|
7
|
+
/**
|
|
8
|
+
* 字体大小配置预设接口。
|
|
9
|
+
*/
|
|
3
10
|
export interface FontPreset {
|
|
11
|
+
/** 档位名称 */
|
|
4
12
|
label: string;
|
|
13
|
+
/** 该档位对应的全部 CSS 字号变量及对应尺寸 */
|
|
5
14
|
vars: Record<string, string>;
|
|
6
15
|
}
|
|
7
16
|
|
|
17
|
+
/** 存储字体字号档位设置的 LocalStorage 键名 */
|
|
8
18
|
export const FONT_SCALE_KEY = "hlw_font_scale";
|
|
9
19
|
|
|
20
|
+
/**
|
|
21
|
+
* 字体档位对应的尺寸变量预设表。
|
|
22
|
+
* 每个档位定义了从超小 (--font-xs) 到超大 (--font-xl) 的响应式字号。
|
|
23
|
+
*/
|
|
10
24
|
export const FONT_PRESETS: Record<FontScale, FontPreset> = {
|
|
11
25
|
small: {
|
|
12
26
|
label: "较小",
|
|
@@ -59,6 +73,11 @@ export const FONT_PRESETS: Record<FontScale, FontPreset> = {
|
|
|
59
73
|
},
|
|
60
74
|
};
|
|
61
75
|
|
|
76
|
+
/**
|
|
77
|
+
* 获取当前用户配置的字体字号缩放档位。
|
|
78
|
+
* 默认返回 'normal'。
|
|
79
|
+
* @returns 字体档位
|
|
80
|
+
*/
|
|
62
81
|
export function getCurrentFontScale(): FontScale {
|
|
63
82
|
try {
|
|
64
83
|
const v = uni.getStorageSync(FONT_SCALE_KEY);
|
|
@@ -67,6 +86,10 @@ export function getCurrentFontScale(): FontScale {
|
|
|
67
86
|
return "normal";
|
|
68
87
|
}
|
|
69
88
|
|
|
89
|
+
/**
|
|
90
|
+
* 获取当前字体字号档位所映射的 CSS 变量表。
|
|
91
|
+
* @returns CSS 变量名与具体字号的键值对
|
|
92
|
+
*/
|
|
70
93
|
export function getCurrentFontVars(): Record<string, string> {
|
|
71
94
|
return FONT_PRESETS[getCurrentFontScale()].vars;
|
|
72
95
|
}
|
|
@@ -11,10 +11,12 @@ import { getCurrentThemeVars } from "./palette";
|
|
|
11
11
|
export const THEME_CHANGE_EVENT = "hlw:theme-change";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* 构建仅注入运行时配置变量(字号档位、主题色)的行内样式字符串。
|
|
15
|
+
*
|
|
16
16
|
* 页面背景、卡片色、文字色、边框色等业务视觉变量统一由项目全局 CSS
|
|
17
17
|
* (static/css/style.scss)控制,避免 page-meta 运行时样式覆盖业务侧配置。
|
|
18
|
+
*
|
|
19
|
+
* @returns 扁平化后的 CSS 变量样式属性字符串
|
|
18
20
|
*/
|
|
19
21
|
export function buildThemeStyle(): string {
|
|
20
22
|
return varsToStyle({
|
|
@@ -23,18 +25,32 @@ export function buildThemeStyle(): string {
|
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
/**
|
|
29
|
+
* 将 CSS 键值对对象平铺拼接为 CSS inline style 格式字符串。
|
|
30
|
+
*/
|
|
26
31
|
function varsToStyle(vars: Record<string, string>): string {
|
|
27
32
|
return Object.entries(vars).map(([key, value]) => `${key}:${value}`).join(";") + ";";
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
|
-
*
|
|
36
|
+
* 获取及监听主题与字号变化,返回可注入到 `<page-meta :page-style="themePageStyle">` 的计算属性。
|
|
32
37
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
38
|
+
* 实现基于 pinia store 响应式:当 store 中的字号档位或主题色发生改变时,
|
|
39
|
+
* 触发计算属性重算并由 Vue 自动更新至 `<page-meta>` 的 setData 接口。
|
|
35
40
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
41
|
+
* @returns 包含 `themePageStyle` 计算属性的对象
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```vue
|
|
45
|
+
* <template>
|
|
46
|
+
* <page-meta :page-style="themePageStyle" />
|
|
47
|
+
* <view class="container">...</view>
|
|
48
|
+
* </template>
|
|
49
|
+
*
|
|
50
|
+
* <script setup>
|
|
51
|
+
* const { themePageStyle } = useThemePageStyle();
|
|
52
|
+
* </script>
|
|
53
|
+
* ```
|
|
38
54
|
*/
|
|
39
55
|
export function useThemePageStyle() {
|
|
40
56
|
const store = useThemeStore();
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 主题颜色配置项接口。
|
|
3
|
+
*/
|
|
1
4
|
export interface ThemeColor {
|
|
5
|
+
/** 颜色名称描述 */
|
|
2
6
|
label: string;
|
|
7
|
+
/** 主题色十六进制值 (Hex Color) */
|
|
3
8
|
value: string;
|
|
4
9
|
}
|
|
5
10
|
|
|
11
|
+
/** 存储当前主题色设置的 LocalStorage 键名 */
|
|
6
12
|
export const THEME_COLOR_KEY = "hlw_theme_color";
|
|
7
13
|
|
|
14
|
+
/**
|
|
15
|
+
* 预设的语义化颜色。
|
|
16
|
+
* 包含成功、警告、错误和提示的默认色彩配置。
|
|
17
|
+
*/
|
|
8
18
|
export const THEME_SEMANTIC_COLORS = {
|
|
9
19
|
success: "#10b981",
|
|
10
20
|
warning: "#f59e0b",
|
|
@@ -12,6 +22,9 @@ export const THEME_SEMANTIC_COLORS = {
|
|
|
12
22
|
info: "#64748b",
|
|
13
23
|
} as const;
|
|
14
24
|
|
|
25
|
+
/**
|
|
26
|
+
* 系统预设的默认主题色列表。
|
|
27
|
+
*/
|
|
15
28
|
export const DEFAULT_THEMES: ThemeColor[] = [
|
|
16
29
|
{ label: "翡翠绿", value: "#10b981" },
|
|
17
30
|
{ label: "活力橙", value: "#f97316" },
|
|
@@ -21,6 +34,11 @@ export const DEFAULT_THEMES: ThemeColor[] = [
|
|
|
21
34
|
{ label: "青石灰", value: "#64748b" },
|
|
22
35
|
];
|
|
23
36
|
|
|
37
|
+
/**
|
|
38
|
+
* 读取当前配置的主题色 Hex 字符串。
|
|
39
|
+
* 默认使用 `DEFAULT_THEMES` 数组中首位颜色的值。
|
|
40
|
+
* @returns 十六进制颜色字符串
|
|
41
|
+
*/
|
|
24
42
|
export function getCurrentThemeColor(): string {
|
|
25
43
|
try {
|
|
26
44
|
const v = uni.getStorageSync(THEME_COLOR_KEY);
|
|
@@ -29,6 +47,11 @@ export function getCurrentThemeColor(): string {
|
|
|
29
47
|
return DEFAULT_THEMES[0].value;
|
|
30
48
|
}
|
|
31
49
|
|
|
50
|
+
/**
|
|
51
|
+
* 获取当前主题色所对应的完整 CSS 颜色语义变量映射表。
|
|
52
|
+
* 会基于当前主题色,自动计算衍生出对应的亮色调、暗色调以及各状态色语义变量。
|
|
53
|
+
* @returns 包含各 CSS 变量名与对应颜色值键值对
|
|
54
|
+
*/
|
|
32
55
|
export function getCurrentThemeVars(): Record<string, string> {
|
|
33
56
|
const color = getCurrentThemeColor();
|
|
34
57
|
return {
|
|
@@ -64,6 +87,9 @@ export function getCurrentThemeVars(): Record<string, string> {
|
|
|
64
87
|
|
|
65
88
|
const HEX_RE = /^#[0-9a-fA-F]{6}$/;
|
|
66
89
|
|
|
90
|
+
/**
|
|
91
|
+
* 将 6 位 hex 颜色字符串转换为 RGB 三原色元组。
|
|
92
|
+
*/
|
|
67
93
|
function parseHex(hex: string): [number, number, number] {
|
|
68
94
|
if (!HEX_RE.test(hex)) throw new Error(`Invalid hex color: ${hex}`);
|
|
69
95
|
return [
|
|
@@ -73,11 +99,17 @@ function parseHex(hex: string): [number, number, number] {
|
|
|
73
99
|
];
|
|
74
100
|
}
|
|
75
101
|
|
|
102
|
+
/**
|
|
103
|
+
* 转换 Hex 颜色为 rgba 格式字符串。
|
|
104
|
+
*/
|
|
76
105
|
function hexToRgba(hex: string, alpha: number): string {
|
|
77
106
|
const [r, g, b] = parseHex(hex);
|
|
78
107
|
return `rgba(${r},${g},${b},${alpha})`;
|
|
79
108
|
}
|
|
80
109
|
|
|
110
|
+
/**
|
|
111
|
+
* 将 Hex 颜色调暗。
|
|
112
|
+
*/
|
|
81
113
|
function darkenHex(hex: string, amount = 0.15): string {
|
|
82
114
|
const [r, g, b] = parseHex(hex);
|
|
83
115
|
const darken = (value: number) => Math.max(0, Math.round(value * (1 - amount)));
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* - caption: 角标 / 底部小字 / 时间戳
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* 语义排版角色配置项接口。
|
|
19
|
+
*/
|
|
17
20
|
export interface TypographyRole {
|
|
18
21
|
/** 对应 `--text-{role}-size` 的值(通常引用字号档位 token) */
|
|
19
22
|
size: string;
|
|
@@ -25,6 +28,9 @@ export interface TypographyRole {
|
|
|
25
28
|
color: string;
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
/**
|
|
32
|
+
* 全局预设排版角色的参数配置表。
|
|
33
|
+
*/
|
|
28
34
|
export const TYPOGRAPHY_ROLES: Record<string, TypographyRole> = {
|
|
29
35
|
"title-lg": {
|
|
30
36
|
size: "var(--font-xl)",
|
|
@@ -68,7 +74,9 @@ export const TYPOGRAPHY_ROLES: Record<string, TypographyRole> = {
|
|
|
68
74
|
* 展开成 CSS 变量平铺 map,用于 buildThemeStyle 注入 page 元素。
|
|
69
75
|
*
|
|
70
76
|
* 每个角色产出 4 个变量:
|
|
71
|
-
* --text
|
|
77
|
+
* --text-${role}-size / -weight / -line-height / -color
|
|
78
|
+
*
|
|
79
|
+
* @returns 包含全部排版 CSS 变量键值对的对象
|
|
72
80
|
*/
|
|
73
81
|
export function getCurrentTypographyVars(): Record<string, string> {
|
|
74
82
|
const vars: Record<string, string> = {};
|