@hlw-uni/mp-vue 2.1.59 → 2.1.60
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/README.md +388 -213
- package/dist/composables/index.d.ts +0 -8
- package/dist/composables/request/service.d.ts +2 -6
- package/dist/core/index.d.ts +1 -0
- package/dist/core/theme.d.ts +8 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +9 -384
- package/dist/index.mjs +8 -384
- package/package.json +1 -1
- package/src/components/hlw-nav-bar/index.vue +121 -0
- package/src/components/hlw-page/index.vue +24 -120
- package/src/composables/index.ts +1 -31
- package/src/composables/request/service.ts +10 -3
- package/src/core/index.ts +1 -0
- package/src/core/theme.ts +12 -0
- package/src/env.d.ts +8 -0
- package/src/index.ts +1 -2
- package/dist/composables/theme/appearance.d.ts +0 -55
- package/dist/composables/theme/font.d.ts +0 -32
- package/dist/composables/theme/index.d.ts +0 -46
- package/dist/composables/theme/palette.d.ts +0 -37
- package/dist/composables/theme/typography.d.ts +0 -41
- package/dist/stores/theme.d.ts +0 -56
- package/src/composables/theme/README.md +0 -131
- package/src/composables/theme/appearance.ts +0 -129
- package/src/composables/theme/font.ts +0 -95
- package/src/composables/theme/index.ts +0 -89
- package/src/composables/theme/palette.ts +0 -117
- package/src/composables/theme/typography.ts +0 -90
- package/src/stores/theme.ts +0 -114
|
@@ -1,128 +1,32 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view :class="
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
<hlw-header
|
|
6
|
-
v-if="props.title || props.isBack"
|
|
7
|
-
:title="props.title"
|
|
8
|
-
:is-back="props.isBack"
|
|
9
|
-
:bg-class="props.bgClass"
|
|
10
|
-
/>
|
|
11
|
-
</slot>
|
|
12
|
-
</view>
|
|
13
|
-
|
|
14
|
-
<scroll-view
|
|
15
|
-
class="hlw-page-content"
|
|
16
|
-
:scroll-y="true"
|
|
17
|
-
:enable-flex="true"
|
|
18
|
-
:enhanced="true"
|
|
19
|
-
:show-scrollbar="false"
|
|
20
|
-
:scroll-top="scrollTo"
|
|
21
|
-
:scroll-with-animation="true"
|
|
22
|
-
@scroll="onScroll"
|
|
23
|
-
>
|
|
24
|
-
<view class="hlw-page-body" :class="bodyClass" :style="bodyStyle">
|
|
25
|
-
<slot />
|
|
26
|
-
</view>
|
|
27
|
-
</scroll-view>
|
|
28
|
-
|
|
29
|
-
<view class="hlw-page-footer">
|
|
30
|
-
<slot name="footer" />
|
|
31
|
-
</view>
|
|
2
|
+
<view :class="theme" style="padding-bottom: 100rpx">
|
|
3
|
+
<hlw-nav-bar :is-back="props.isBack" :title="title" :is-bar="props.isBar"></hlw-nav-bar>
|
|
4
|
+
<slot></slot>
|
|
32
5
|
</view>
|
|
33
6
|
</template>
|
|
34
7
|
|
|
35
|
-
<script
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
type StyleValue = string | Record<string, string | number>;
|
|
55
|
-
|
|
56
|
-
interface Props {
|
|
57
|
-
title?: string;
|
|
58
|
-
isBack?: boolean;
|
|
59
|
-
bgClass?: string;
|
|
60
|
-
/**
|
|
61
|
-
* 透传到 scroll-view 内层 view 包裹(不是 scroll-view 本身)的 class,常用于直接挂 .container。
|
|
62
|
-
* 用 view 包裹是因为 mp-weixin 的 scroll-view 是原生组件,flex/gap 行为跟普通 view 不一致。
|
|
63
|
-
*/
|
|
64
|
-
bodyClass?: ClassValue;
|
|
65
|
-
/** 透传到内层 view 包裹的 style,规则同 bodyClass */
|
|
66
|
-
bodyStyle?: StyleValue;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
70
|
-
title: "",
|
|
71
|
-
isBack: false,
|
|
72
|
-
bgClass: "",
|
|
73
|
-
bodyClass: "",
|
|
74
|
-
bodyStyle: "",
|
|
8
|
+
<script lang="ts" setup>
|
|
9
|
+
import { useTheme } from "@/core";
|
|
10
|
+
import { onLoad, onShow } from "@dcloudio/uni-app";
|
|
11
|
+
import { ref } from "vue";
|
|
12
|
+
const { theme } = useTheme();
|
|
13
|
+
|
|
14
|
+
const props = defineProps({
|
|
15
|
+
isBar: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
default: false,
|
|
18
|
+
},
|
|
19
|
+
title: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: "",
|
|
22
|
+
},
|
|
23
|
+
isBack: {
|
|
24
|
+
type: Boolean,
|
|
25
|
+
default: false,
|
|
26
|
+
},
|
|
75
27
|
});
|
|
76
|
-
const attrs = useAttrs();
|
|
77
28
|
|
|
78
|
-
const
|
|
79
|
-
const scrollTo = ref(0);
|
|
80
|
-
|
|
81
|
-
function onScroll(e: any) {
|
|
82
|
-
scrollTop.value = e?.detail?.scrollTop ?? 0;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function scrollToTop() {
|
|
86
|
-
// 先同步到当前位置,再动画到 0;否则同值不会触发 scroll-view 重滚
|
|
87
|
-
scrollTo.value = scrollTop.value;
|
|
88
|
-
nextTick(() => {
|
|
89
|
-
scrollTo.value = 0;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
provide("hlwPageScroll", {
|
|
94
|
-
scrollTop,
|
|
95
|
-
scrollToTop,
|
|
96
|
-
});
|
|
29
|
+
const title = ref(props.title);
|
|
97
30
|
</script>
|
|
98
31
|
|
|
99
|
-
<style
|
|
100
|
-
.hlw-page {
|
|
101
|
-
width: 100%;
|
|
102
|
-
height: 100vh;
|
|
103
|
-
display: flex;
|
|
104
|
-
flex-direction: column;
|
|
105
|
-
overflow: hidden;
|
|
106
|
-
color: var(--text-primary, #0f172a);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.hlw-page-header {
|
|
110
|
-
flex-shrink: 0;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
.hlw-page-content {
|
|
114
|
-
flex: 1;
|
|
115
|
-
height: 0;
|
|
116
|
-
width: 100%;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
.hlw-page-body {
|
|
120
|
-
width: 100%;
|
|
121
|
-
display: flex;
|
|
122
|
-
flex-direction: column;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
.hlw-page-footer {
|
|
126
|
-
flex-shrink: 0;
|
|
127
|
-
}
|
|
128
|
-
</style>
|
|
32
|
+
<style></style>
|
package/src/composables/index.ts
CHANGED
|
@@ -35,34 +35,4 @@ export {
|
|
|
35
35
|
} from "./utils";
|
|
36
36
|
export { useNavigate, type NavigateType, type NavigateOptions } from "./navigator";
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
export type { FontScale, FontPreset } from "./theme";
|
|
40
|
-
export {
|
|
41
|
-
FONT_SCALE_KEY,
|
|
42
|
-
FONT_PRESETS,
|
|
43
|
-
getCurrentFontScale,
|
|
44
|
-
getCurrentFontVars,
|
|
45
|
-
THEME_CHANGE_EVENT,
|
|
46
|
-
buildThemeStyle,
|
|
47
|
-
useThemePageStyle,
|
|
48
|
-
} from "./theme";
|
|
49
|
-
export type { ThemeColor } from "./theme";
|
|
50
|
-
export {
|
|
51
|
-
THEME_COLOR_KEY,
|
|
52
|
-
THEME_SEMANTIC_COLORS,
|
|
53
|
-
DEFAULT_THEMES,
|
|
54
|
-
getCurrentThemeColor,
|
|
55
|
-
getCurrentThemeVars,
|
|
56
|
-
} from "./theme";
|
|
57
|
-
export type { Appearance, AppearanceMode, AppearancePreset } from "./theme";
|
|
58
|
-
export {
|
|
59
|
-
APPEARANCE_KEY,
|
|
60
|
-
APPEARANCE_PRESETS,
|
|
61
|
-
APPEARANCE_VAR_MAP,
|
|
62
|
-
getCurrentAppearance,
|
|
63
|
-
getCurrentAppearanceMode,
|
|
64
|
-
getCurrentAppearanceVars,
|
|
65
|
-
resolveAppearance,
|
|
66
|
-
} from "./theme";
|
|
67
|
-
export type { TypographyRole } from "./theme";
|
|
68
|
-
export { TYPOGRAPHY_ROLES, getCurrentTypographyVars } from "./theme";
|
|
38
|
+
|
|
@@ -119,8 +119,15 @@ export function ServicePrefix(value: string | ServicePrefixOptions) {
|
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
121
|
* 插件服务类装饰器。
|
|
122
|
-
* 自动使用 `import.meta.env.VITE_PLUGIN_NAME`
|
|
122
|
+
* 自动使用 `import.meta.env.VITE_PLUGIN_NAME` 作为服务前缀(通过 globalThis 动态读取)。
|
|
123
123
|
*/
|
|
124
|
-
export function PluginService(target:
|
|
125
|
-
target.prototype
|
|
124
|
+
export function PluginService(target: any) {
|
|
125
|
+
Object.defineProperty(target.prototype, "servicePrefix", {
|
|
126
|
+
get() {
|
|
127
|
+
return globalThis.VITE_PLUGIN_NAME || "";
|
|
128
|
+
},
|
|
129
|
+
enumerable: true,
|
|
130
|
+
configurable: true
|
|
131
|
+
});
|
|
126
132
|
}
|
|
133
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./theme";
|
package/src/env.d.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -15,8 +15,7 @@ export * from "./composables";
|
|
|
15
15
|
export type { HlwMenuItem } from "./components/hlw-menu/types";
|
|
16
16
|
export type { HlwPagingRef, HlwPagingInstance } from "./components/hlw-paging/types";
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
export { useThemeStore } from "./stores/theme";
|
|
18
|
+
|
|
20
19
|
|
|
21
20
|
// App 根上下文
|
|
22
21
|
export { useApp } from "./app";
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 外观模式 — 浅色 / 深色 / 跟随系统
|
|
3
|
-
*
|
|
4
|
-
* 提供一套语义化 CSS 变量(--bg-page, --surface-card, --text-primary ...)。
|
|
5
|
-
* 默认不通过 useThemePageStyle 注入,业务项目应在全局 CSS 中声明这些变量,
|
|
6
|
-
* 避免运行时 page-meta 覆盖业务侧样式。
|
|
7
|
-
*
|
|
8
|
-
* 使用指南:
|
|
9
|
-
* - 业务样式里用 `var(--text-primary)` 代替硬编码 `#0f172a`
|
|
10
|
-
* - 用 `var(--surface-card)` 代替硬编码 `#ffffff`
|
|
11
|
-
* - 用 `var(--border-color-light)` 代替硬编码 `#f1f5f9`
|
|
12
|
-
*/
|
|
13
|
-
/** 外观模式选项类型:浅色模式、深色模式、跟随系统 */
|
|
14
|
-
export type Appearance = "light" | "dark" | "auto";
|
|
15
|
-
/** 实际生效的外观模式:仅浅色或深色 */
|
|
16
|
-
export type AppearanceMode = "light" | "dark";
|
|
17
|
-
/**
|
|
18
|
-
* 外观预设配置接口。
|
|
19
|
-
*/
|
|
20
|
-
export interface AppearancePreset {
|
|
21
|
-
/** 选项值 */
|
|
22
|
-
value: Appearance;
|
|
23
|
-
/** 选项展示名称 */
|
|
24
|
-
label: string;
|
|
25
|
-
}
|
|
26
|
-
/** 存储外观设置的 LocalStorage 键名 */
|
|
27
|
-
export declare const APPEARANCE_KEY = "hlw_appearance";
|
|
28
|
-
/** 预设外观模式列表,常供设置页渲染选择器使用 */
|
|
29
|
-
export declare const APPEARANCE_PRESETS: AppearancePreset[];
|
|
30
|
-
/** 不同外观模式的 CSS 变量映射 */
|
|
31
|
-
export declare const APPEARANCE_VAR_MAP: Record<AppearanceMode, Record<string, string>>;
|
|
32
|
-
/**
|
|
33
|
-
* 读取用户设置的外观配置(light / dark / auto)。
|
|
34
|
-
* 默认返回 'auto'。
|
|
35
|
-
* @returns 设定的外观模式类型
|
|
36
|
-
*/
|
|
37
|
-
export declare function getCurrentAppearance(): Appearance;
|
|
38
|
-
/**
|
|
39
|
-
* 将 auto 设置或用户选择解析为具体的 light/dark 实际模式。
|
|
40
|
-
* 当为 auto 时,将读取系统当前的配色偏好。
|
|
41
|
-
* @param appearance 输入的外观配置
|
|
42
|
-
* @returns 解析后最终生效的外观模式 (light 或 dark)
|
|
43
|
-
*/
|
|
44
|
-
export declare function resolveAppearance(appearance: Appearance): AppearanceMode;
|
|
45
|
-
/**
|
|
46
|
-
* 获取当前实际生效的外观模式 (light 或 dark)。
|
|
47
|
-
* 自动根据用户偏好及系统主题进行判定。
|
|
48
|
-
* @returns 实际生效的外观模式
|
|
49
|
-
*/
|
|
50
|
-
export declare function getCurrentAppearanceMode(): AppearanceMode;
|
|
51
|
-
/**
|
|
52
|
-
* 获取当前外观对应的 CSS 变量映射表。
|
|
53
|
-
* @returns 包含各 CSS 变量名与对应颜色值键值对
|
|
54
|
-
*/
|
|
55
|
-
export declare function getCurrentAppearanceVars(): Record<string, string>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 字体大小缩放档位类型。
|
|
3
|
-
* 从较小到特大,共 7 个档位。
|
|
4
|
-
*/
|
|
5
|
-
export type FontScale = "small" | "compact" | "normal" | "medium" | "large" | "xlarge" | "xxlarge";
|
|
6
|
-
/**
|
|
7
|
-
* 字体大小配置预设接口。
|
|
8
|
-
*/
|
|
9
|
-
export interface FontPreset {
|
|
10
|
-
/** 档位名称 */
|
|
11
|
-
label: string;
|
|
12
|
-
/** 该档位对应的全部 CSS 字号变量及对应尺寸 */
|
|
13
|
-
vars: Record<string, string>;
|
|
14
|
-
}
|
|
15
|
-
/** 存储字体字号档位设置的 LocalStorage 键名 */
|
|
16
|
-
export declare const FONT_SCALE_KEY = "hlw_font_scale";
|
|
17
|
-
/**
|
|
18
|
-
* 字体档位对应的尺寸变量预设表。
|
|
19
|
-
* 每个档位定义了从超小 (--font-xs) 到超大 (--font-xl) 的响应式字号。
|
|
20
|
-
*/
|
|
21
|
-
export declare const FONT_PRESETS: Record<FontScale, FontPreset>;
|
|
22
|
-
/**
|
|
23
|
-
* 获取当前用户配置的字体字号缩放档位。
|
|
24
|
-
* 默认返回 'normal'。
|
|
25
|
-
* @returns 字体档位
|
|
26
|
-
*/
|
|
27
|
-
export declare function getCurrentFontScale(): FontScale;
|
|
28
|
-
/**
|
|
29
|
-
* 获取当前字体字号档位所映射的 CSS 变量表。
|
|
30
|
-
* @returns CSS 变量名与具体字号的键值对
|
|
31
|
-
*/
|
|
32
|
-
export declare function getCurrentFontVars(): Record<string, string>;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ComputedRef } from 'vue';
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated 历史事件名;现已改用 pinia store 响应式驱动,emit 不再有效。
|
|
4
|
-
* 保留 export 仅为不破坏外部 import(不影响功能)。
|
|
5
|
-
*/
|
|
6
|
-
export declare const THEME_CHANGE_EVENT = "hlw:theme-change";
|
|
7
|
-
/**
|
|
8
|
-
* 构建仅注入运行时配置变量(字号档位、主题色)的行内样式字符串。
|
|
9
|
-
*
|
|
10
|
-
* 页面背景、卡片色、文字色、边框色等业务视觉变量统一由项目全局 CSS
|
|
11
|
-
* (static/css/style.scss)控制,避免 page-meta 运行时样式覆盖业务侧配置。
|
|
12
|
-
*
|
|
13
|
-
* @returns 扁平化后的 CSS 变量样式属性字符串
|
|
14
|
-
*/
|
|
15
|
-
export declare function buildThemeStyle(): string;
|
|
16
|
-
/**
|
|
17
|
-
* 获取及监听主题与字号变化,返回可注入到 `<page-meta :page-style="themePageStyle">` 的计算属性。
|
|
18
|
-
*
|
|
19
|
-
* 实现基于 pinia store 响应式:当 store 中的字号档位或主题色发生改变时,
|
|
20
|
-
* 触发计算属性重算并由 Vue 自动更新至 `<page-meta>` 的 setData 接口。
|
|
21
|
-
*
|
|
22
|
-
* @returns 包含 `themePageStyle` 计算属性的对象
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```vue
|
|
26
|
-
* <template>
|
|
27
|
-
* <page-meta :page-style="themePageStyle" />
|
|
28
|
-
* <view class="container">...</view>
|
|
29
|
-
* </template>
|
|
30
|
-
*
|
|
31
|
-
* <script setup>
|
|
32
|
-
* const { themePageStyle } = useThemePageStyle();
|
|
33
|
-
* </script>
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function useThemePageStyle(): {
|
|
37
|
-
themePageStyle: ComputedRef<string>;
|
|
38
|
-
};
|
|
39
|
-
export type { FontScale, FontPreset } from './font';
|
|
40
|
-
export { FONT_SCALE_KEY, FONT_PRESETS, getCurrentFontScale, getCurrentFontVars } from './font';
|
|
41
|
-
export type { ThemeColor } from './palette';
|
|
42
|
-
export { THEME_COLOR_KEY, THEME_SEMANTIC_COLORS, DEFAULT_THEMES, getCurrentThemeColor, getCurrentThemeVars, } from './palette';
|
|
43
|
-
export type { Appearance, AppearanceMode, AppearancePreset } from './appearance';
|
|
44
|
-
export { APPEARANCE_KEY, APPEARANCE_PRESETS, APPEARANCE_VAR_MAP, getCurrentAppearance, getCurrentAppearanceMode, getCurrentAppearanceVars, resolveAppearance, } from './appearance';
|
|
45
|
-
export type { TypographyRole } from './typography';
|
|
46
|
-
export { TYPOGRAPHY_ROLES, getCurrentTypographyVars } from './typography';
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 主题颜色配置项接口。
|
|
3
|
-
*/
|
|
4
|
-
export interface ThemeColor {
|
|
5
|
-
/** 颜色名称描述 */
|
|
6
|
-
label: string;
|
|
7
|
-
/** 主题色十六进制值 (Hex Color) */
|
|
8
|
-
value: string;
|
|
9
|
-
}
|
|
10
|
-
/** 存储当前主题色设置的 LocalStorage 键名 */
|
|
11
|
-
export declare const THEME_COLOR_KEY = "hlw_theme_color";
|
|
12
|
-
/**
|
|
13
|
-
* 预设的语义化颜色。
|
|
14
|
-
* 包含成功、警告、错误和提示的默认色彩配置。
|
|
15
|
-
*/
|
|
16
|
-
export declare const THEME_SEMANTIC_COLORS: {
|
|
17
|
-
readonly success: "#10b981";
|
|
18
|
-
readonly warning: "#f59e0b";
|
|
19
|
-
readonly error: "#ef4444";
|
|
20
|
-
readonly info: "#64748b";
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* 系统预设的默认主题色列表。
|
|
24
|
-
*/
|
|
25
|
-
export declare const DEFAULT_THEMES: ThemeColor[];
|
|
26
|
-
/**
|
|
27
|
-
* 读取当前配置的主题色 Hex 字符串。
|
|
28
|
-
* 默认使用 `DEFAULT_THEMES` 数组中首位颜色的值。
|
|
29
|
-
* @returns 十六进制颜色字符串
|
|
30
|
-
*/
|
|
31
|
-
export declare function getCurrentThemeColor(): string;
|
|
32
|
-
/**
|
|
33
|
-
* 获取当前主题色所对应的完整 CSS 颜色语义变量映射表。
|
|
34
|
-
* 会基于当前主题色,自动计算衍生出对应的亮色调、暗色调以及各状态色语义变量。
|
|
35
|
-
* @returns 包含各 CSS 变量名与对应颜色值键值对
|
|
36
|
-
*/
|
|
37
|
-
export declare function getCurrentThemeVars(): Record<string, string>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 语义化排版 token — 把"字号 + 字重 + 行高 + 颜色"打包成角色,统一各页面文字样式。
|
|
3
|
-
*
|
|
4
|
-
* 使用指南:
|
|
5
|
-
* - 页面样式里用 `var(--text-title-size)` 等变量代替硬编码,自动响应字体档位/外观模式切换
|
|
6
|
-
* - 或通过全局 utility class(见 qz2 项目的 static/css/style.scss)直接加 class
|
|
7
|
-
*
|
|
8
|
-
* 6 个语义角色:
|
|
9
|
-
* - title-lg: 页面大标题 / hero
|
|
10
|
-
* - title: 卡片 / 分区主标题
|
|
11
|
-
* - subtitle: 次级标题
|
|
12
|
-
* - body: 正文
|
|
13
|
-
* - desc: 卡片描述 / 副文
|
|
14
|
-
* - caption: 角标 / 底部小字 / 时间戳
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* 语义排版角色配置项接口。
|
|
18
|
-
*/
|
|
19
|
-
export interface TypographyRole {
|
|
20
|
-
/** 对应 `--text-{role}-size` 的值(通常引用字号档位 token) */
|
|
21
|
-
size: string;
|
|
22
|
-
/** 对应 `--text-{role}-weight` */
|
|
23
|
-
weight: string;
|
|
24
|
-
/** 对应 `--text-{role}-line-height` */
|
|
25
|
-
lineHeight: string;
|
|
26
|
-
/** 对应 `--text-{role}-color`(通常引用文字色 token) */
|
|
27
|
-
color: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 全局预设排版角色的参数配置表。
|
|
31
|
-
*/
|
|
32
|
-
export declare const TYPOGRAPHY_ROLES: Record<string, TypographyRole>;
|
|
33
|
-
/**
|
|
34
|
-
* 展开成 CSS 变量平铺 map,用于 buildThemeStyle 注入 page 元素。
|
|
35
|
-
*
|
|
36
|
-
* 每个角色产出 4 个变量:
|
|
37
|
-
* --text-${role}-size / -weight / -line-height / -color
|
|
38
|
-
*
|
|
39
|
-
* @returns 包含全部排版 CSS 变量键值对的对象
|
|
40
|
-
*/
|
|
41
|
-
export declare function getCurrentTypographyVars(): Record<string, string>;
|
package/dist/stores/theme.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { FontScale, ThemeColor, Appearance, AppearanceMode, AppearancePreset } from '../composables/theme';
|
|
2
|
-
import { StoreDefinition } from 'pinia';
|
|
3
|
-
import { Ref, ComputedRef } from 'vue';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 统一管理全局主题、字体缩放和外观模式的 Pinia Store。
|
|
7
|
-
*/
|
|
8
|
-
export declare const useThemeStore: StoreDefinition<"theme", Pick<{
|
|
9
|
-
scale: Ref<FontScale, FontScale>;
|
|
10
|
-
fontOptions: {
|
|
11
|
-
value: FontScale;
|
|
12
|
-
label: string;
|
|
13
|
-
}[];
|
|
14
|
-
setScale: (s: FontScale) => void;
|
|
15
|
-
primaryColor: Ref<string, string>;
|
|
16
|
-
themes: ThemeColor[];
|
|
17
|
-
activeTheme: ComputedRef<ThemeColor>;
|
|
18
|
-
setTheme: (color: string) => void;
|
|
19
|
-
appearance: Ref<Appearance, Appearance>;
|
|
20
|
-
appearanceOptions: AppearancePreset[];
|
|
21
|
-
appearanceMode: ComputedRef<AppearanceMode>;
|
|
22
|
-
isDark: ComputedRef<boolean>;
|
|
23
|
-
setAppearance: (a: Appearance) => void;
|
|
24
|
-
}, "scale" | "fontOptions" | "primaryColor" | "themes" | "appearance" | "appearanceOptions">, Pick<{
|
|
25
|
-
scale: Ref<FontScale, FontScale>;
|
|
26
|
-
fontOptions: {
|
|
27
|
-
value: FontScale;
|
|
28
|
-
label: string;
|
|
29
|
-
}[];
|
|
30
|
-
setScale: (s: FontScale) => void;
|
|
31
|
-
primaryColor: Ref<string, string>;
|
|
32
|
-
themes: ThemeColor[];
|
|
33
|
-
activeTheme: ComputedRef<ThemeColor>;
|
|
34
|
-
setTheme: (color: string) => void;
|
|
35
|
-
appearance: Ref<Appearance, Appearance>;
|
|
36
|
-
appearanceOptions: AppearancePreset[];
|
|
37
|
-
appearanceMode: ComputedRef<AppearanceMode>;
|
|
38
|
-
isDark: ComputedRef<boolean>;
|
|
39
|
-
setAppearance: (a: Appearance) => void;
|
|
40
|
-
}, "activeTheme" | "appearanceMode" | "isDark">, Pick<{
|
|
41
|
-
scale: Ref<FontScale, FontScale>;
|
|
42
|
-
fontOptions: {
|
|
43
|
-
value: FontScale;
|
|
44
|
-
label: string;
|
|
45
|
-
}[];
|
|
46
|
-
setScale: (s: FontScale) => void;
|
|
47
|
-
primaryColor: Ref<string, string>;
|
|
48
|
-
themes: ThemeColor[];
|
|
49
|
-
activeTheme: ComputedRef<ThemeColor>;
|
|
50
|
-
setTheme: (color: string) => void;
|
|
51
|
-
appearance: Ref<Appearance, Appearance>;
|
|
52
|
-
appearanceOptions: AppearancePreset[];
|
|
53
|
-
appearanceMode: ComputedRef<AppearanceMode>;
|
|
54
|
-
isDark: ComputedRef<boolean>;
|
|
55
|
-
setAppearance: (a: Appearance) => void;
|
|
56
|
-
}, "setScale" | "setTheme" | "setAppearance">>;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
# theme 调用文档
|
|
2
|
-
|
|
3
|
-
`theme` 模块提供字体档位、主题色、外观模式、排版 token 和 `page-meta` 样式注入能力。
|
|
4
|
-
|
|
5
|
-
## 引入
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import {
|
|
9
|
-
useThemePageStyle,
|
|
10
|
-
getCurrentFontScale,
|
|
11
|
-
getCurrentFontVars,
|
|
12
|
-
getCurrentThemeColor,
|
|
13
|
-
getCurrentThemeVars,
|
|
14
|
-
getCurrentAppearance,
|
|
15
|
-
getCurrentAppearanceMode,
|
|
16
|
-
getCurrentAppearanceVars,
|
|
17
|
-
getCurrentTypographyVars,
|
|
18
|
-
} from "@hlw-uni/mp-vue";
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## useThemePageStyle
|
|
22
|
-
|
|
23
|
-
页面需要把主题 CSS 变量注入到小程序 page 根时使用。
|
|
24
|
-
|
|
25
|
-
```vue
|
|
26
|
-
<template>
|
|
27
|
-
<page-meta :page-style="themePageStyle" />
|
|
28
|
-
<hlw-page>
|
|
29
|
-
页面内容
|
|
30
|
-
</hlw-page>
|
|
31
|
-
</template>
|
|
32
|
-
|
|
33
|
-
<script setup lang="ts">
|
|
34
|
-
import { useThemePageStyle } from "@hlw-uni/mp-vue";
|
|
35
|
-
|
|
36
|
-
const { themePageStyle } = useThemePageStyle();
|
|
37
|
-
</script>
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
如果项目启用了 `@hlw-uni/mp-vite-plugin` 的 `themePageMeta`,页面可由插件自动注入 `<page-meta>` 和 `useThemePageStyle`。
|
|
41
|
-
|
|
42
|
-
## 字体档位
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
const scale = getCurrentFontScale();
|
|
46
|
-
const vars = getCurrentFontVars();
|
|
47
|
-
|
|
48
|
-
console.log(scale, vars["--font-base"]);
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
支持的 `FontScale`:
|
|
52
|
-
|
|
53
|
-
| 值 | 说明 |
|
|
54
|
-
| --- | --- |
|
|
55
|
-
| `small` | 较小 |
|
|
56
|
-
| `compact` | 略小 |
|
|
57
|
-
| `normal` | 标准 |
|
|
58
|
-
| `medium` | 适中 |
|
|
59
|
-
| `large` | 较大 |
|
|
60
|
-
| `xlarge` | 超大 |
|
|
61
|
-
| `xxlarge` | 特大 |
|
|
62
|
-
|
|
63
|
-
## 主题色
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
const color = getCurrentThemeColor();
|
|
67
|
-
const vars = getCurrentThemeVars();
|
|
68
|
-
|
|
69
|
-
console.log(color, vars["--primary-color"]);
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
常用导出:
|
|
73
|
-
|
|
74
|
-
| 导出 | 说明 |
|
|
75
|
-
| --- | --- |
|
|
76
|
-
| `THEME_COLOR_KEY` | 主题色 storage key |
|
|
77
|
-
| `THEME_SEMANTIC_COLORS` | 语义色 |
|
|
78
|
-
| `DEFAULT_THEMES` | 内置主题色列表 |
|
|
79
|
-
| `getCurrentThemeColor()` | 读取当前主题色 |
|
|
80
|
-
| `getCurrentThemeVars()` | 生成主题色 CSS 变量 |
|
|
81
|
-
|
|
82
|
-
## 外观模式
|
|
83
|
-
|
|
84
|
-
```ts
|
|
85
|
-
const appearance = getCurrentAppearance();
|
|
86
|
-
const mode = getCurrentAppearanceMode();
|
|
87
|
-
const vars = getCurrentAppearanceVars();
|
|
88
|
-
|
|
89
|
-
console.log(appearance, mode, vars["--bg-page"]);
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
`Appearance` 支持:
|
|
93
|
-
|
|
94
|
-
| 值 | 说明 |
|
|
95
|
-
| --- | --- |
|
|
96
|
-
| `light` | 浅色模式 |
|
|
97
|
-
| `dark` | 深色模式 |
|
|
98
|
-
| `auto` | 跟随系统 |
|
|
99
|
-
|
|
100
|
-
## 排版 token
|
|
101
|
-
|
|
102
|
-
```ts
|
|
103
|
-
const vars = getCurrentTypographyVars();
|
|
104
|
-
|
|
105
|
-
console.log(vars["--text-title-size"]);
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
内置语义角色:
|
|
109
|
-
|
|
110
|
-
| 角色 | 用途 |
|
|
111
|
-
| --- | --- |
|
|
112
|
-
| `title-lg` | 页面大标题 |
|
|
113
|
-
| `title` | 卡片或分区主标题 |
|
|
114
|
-
| `subtitle` | 次级标题 |
|
|
115
|
-
| `body` | 正文 |
|
|
116
|
-
| `desc` | 描述文字 |
|
|
117
|
-
| `caption` | 角标、时间戳等小字 |
|
|
118
|
-
|
|
119
|
-
## 切换主题
|
|
120
|
-
|
|
121
|
-
主题状态由 `useThemeStore` 管理,store 会写入 storage,`useThemePageStyle` 会响应 `scale` 和 `primaryColor` 变化。
|
|
122
|
-
|
|
123
|
-
```ts
|
|
124
|
-
import { useThemeStore } from "@hlw-uni/mp-vue";
|
|
125
|
-
|
|
126
|
-
const theme = useThemeStore();
|
|
127
|
-
|
|
128
|
-
theme.setScale("large");
|
|
129
|
-
theme.setTheme("#3b82f6");
|
|
130
|
-
theme.setAppearance("auto");
|
|
131
|
-
```
|