@hlw-uni/mp-vue 2.1.60 → 2.1.70
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/core/theme.d.ts +15 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +123 -2
- package/dist/index.mjs +123 -1
- package/dist/stores/index.d.ts +1 -0
- package/dist/stores/theme.d.ts +27 -0
- package/package.json +1 -1
- package/src/components/hlw-add-mini/index.vue +147 -77
- package/src/components/hlw-avatar/index.vue +28 -20
- package/src/components/hlw-card-header/index.vue +3 -0
- package/src/components/hlw-cell/index.vue +6 -0
- package/src/components/hlw-custom/hlw-custom.vue +6 -5
- package/src/components/hlw-menu/index.vue +9 -3
- package/src/components/hlw-nav-bar/index.vue +75 -15
- package/src/components/hlw-page/index.vue +94 -4
- package/src/core/theme.ts +54 -4
- package/src/index.ts +10 -3
- package/src/stores/index.ts +1 -0
- package/src/stores/theme.ts +126 -0
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view :class="`hlw-avatar hlw-avatar--${size ?? 'medium'}`" :style="avatarStyle">
|
|
3
|
-
<image
|
|
4
|
-
v-if="src && !loadError"
|
|
5
|
-
class="hlw-avatar__image"
|
|
6
|
-
:src="src"
|
|
7
|
-
mode="aspectFill"
|
|
8
|
-
@error="loadError = true"
|
|
9
|
-
/>
|
|
3
|
+
<image v-if="src && !loadError" class="hlw-avatar__image" :src="src" mode="aspectFill" @error="loadError = true" />
|
|
10
4
|
<view v-else class="hlw-avatar__placeholder">
|
|
11
5
|
<text class="hlw-avatar__initial">{{ initial }}</text>
|
|
12
6
|
</view>
|
|
@@ -30,12 +24,12 @@
|
|
|
30
24
|
* <HlwAvatar src="/avatar.png" name="张三" size="large" />
|
|
31
25
|
* ```
|
|
32
26
|
*/
|
|
33
|
-
import { ref, computed } from
|
|
27
|
+
import { ref, computed } from "vue";
|
|
34
28
|
|
|
35
29
|
const props = defineProps<{
|
|
36
30
|
src?: string;
|
|
37
31
|
name?: string;
|
|
38
|
-
size?:
|
|
32
|
+
size?: "small" | "medium" | "large";
|
|
39
33
|
border?: number;
|
|
40
34
|
}>();
|
|
41
35
|
|
|
@@ -43,11 +37,11 @@ const loadError = ref(false);
|
|
|
43
37
|
const avatarStyle = computed(() => {
|
|
44
38
|
const border = Math.max(0, Number(props.border ?? 0));
|
|
45
39
|
return {
|
|
46
|
-
border: border > 0 ? `${border}px solid #fff` :
|
|
40
|
+
border: border > 0 ? `${border}px solid #fff` : "0",
|
|
47
41
|
};
|
|
48
42
|
});
|
|
49
43
|
const initial = computed(() => {
|
|
50
|
-
if (!props.name) return
|
|
44
|
+
if (!props.name) return "?";
|
|
51
45
|
return props.name.charAt(0).toUpperCase();
|
|
52
46
|
});
|
|
53
47
|
</script>
|
|
@@ -60,9 +54,18 @@ const initial = computed(() => {
|
|
|
60
54
|
flex-shrink: 0;
|
|
61
55
|
}
|
|
62
56
|
|
|
63
|
-
.hlw-avatar--small
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
.hlw-avatar--small {
|
|
58
|
+
width: 56rpx;
|
|
59
|
+
height: 56rpx;
|
|
60
|
+
}
|
|
61
|
+
.hlw-avatar--medium {
|
|
62
|
+
width: 80rpx;
|
|
63
|
+
height: 80rpx;
|
|
64
|
+
}
|
|
65
|
+
.hlw-avatar--large {
|
|
66
|
+
width: 120rpx;
|
|
67
|
+
height: 120rpx;
|
|
68
|
+
}
|
|
66
69
|
|
|
67
70
|
.hlw-avatar__image {
|
|
68
71
|
width: 100%;
|
|
@@ -72,18 +75,23 @@ const initial = computed(() => {
|
|
|
72
75
|
.hlw-avatar__placeholder {
|
|
73
76
|
width: 100%;
|
|
74
77
|
height: 100%;
|
|
75
|
-
background: #
|
|
78
|
+
background: #f1f5f9;
|
|
76
79
|
display: flex;
|
|
77
80
|
align-items: center;
|
|
78
81
|
justify-content: center;
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
.hlw-avatar__initial {
|
|
82
|
-
color: #
|
|
83
|
-
font-weight: bold;
|
|
85
|
+
color: #94a3b8;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
.hlw-avatar--small
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
.hlw-avatar--small .hlw-avatar__initial {
|
|
89
|
+
font-size: var(--font-xs, 20rpx);
|
|
90
|
+
}
|
|
91
|
+
.hlw-avatar--medium .hlw-avatar__initial {
|
|
92
|
+
font-size: var(--font-base, 28rpx);
|
|
93
|
+
}
|
|
94
|
+
.hlw-avatar--large .hlw-avatar__initial {
|
|
95
|
+
font-size: var(--font-xl, 40rpx);
|
|
96
|
+
}
|
|
89
97
|
</style>
|
|
@@ -105,6 +105,12 @@ defineEmits<{ click: [] }>();
|
|
|
105
105
|
font-size: var(--font-lg, 36rpx);
|
|
106
106
|
color: var(--primary-color, #3b82f6);
|
|
107
107
|
flex-shrink: 0;
|
|
108
|
+
|
|
109
|
+
view {
|
|
110
|
+
width: var(--font-lg, 36rpx);
|
|
111
|
+
height: var(--font-lg, 36rpx);
|
|
112
|
+
display: inline-block;
|
|
113
|
+
}
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
.hlw-cell-body {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
:send-message-img="resolvedContact.img"
|
|
13
13
|
:show-message-card="resolvedContact.show"
|
|
14
14
|
>
|
|
15
|
-
<text class="
|
|
15
|
+
<text class="i-ri-customer-service-line contact-button-icon" />
|
|
16
16
|
<text class="contact-button-text">{{ resolvedBtnTitle }}</text>
|
|
17
17
|
</button>
|
|
18
18
|
</view>
|
|
@@ -64,7 +64,7 @@ const resolvedContact = computed(() => {
|
|
|
64
64
|
padding: var(--card-padding);
|
|
65
65
|
border: 1rpx solid var(--border-color-light);
|
|
66
66
|
border-radius: var(--card-radius);
|
|
67
|
-
background: linear-gradient(135deg, #ffffff 0%, rgba(
|
|
67
|
+
background: linear-gradient(135deg, #ffffff 0%, var(--primary-light, rgba(76, 68, 239, 0.05)) 100%);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
.contact-copy {
|
|
@@ -100,14 +100,15 @@ const resolvedContact = computed(() => {
|
|
|
100
100
|
flex-shrink: 0;
|
|
101
101
|
margin: 0;
|
|
102
102
|
border-radius: var(--radius-full);
|
|
103
|
-
background: #
|
|
103
|
+
background: var(--primary-color, #3b82f6);
|
|
104
104
|
color: #ffffff;
|
|
105
105
|
font: inherit;
|
|
106
106
|
line-height: 68rpx;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
.contact-button
|
|
110
|
-
|
|
109
|
+
.contact-button-icon {
|
|
110
|
+
width: var(--font-sm);
|
|
111
|
+
height: var(--font-sm);
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
.contact-button-text {
|
|
@@ -335,7 +335,10 @@ const handleGetPhoneNumber = (item: HlwMenuItem, event: unknown) => {
|
|
|
335
335
|
flex-shrink: 0;
|
|
336
336
|
|
|
337
337
|
text {
|
|
338
|
+
width: var(--hlw-menu-icon-size);
|
|
339
|
+
height: var(--hlw-menu-icon-size);
|
|
338
340
|
font-size: var(--hlw-menu-icon-size);
|
|
341
|
+
display: inline-block;
|
|
339
342
|
}
|
|
340
343
|
|
|
341
344
|
&--grid {
|
|
@@ -343,7 +346,10 @@ const handleGetPhoneNumber = (item: HlwMenuItem, event: unknown) => {
|
|
|
343
346
|
height: var(--hlw-menu-grid-icon-box-size);
|
|
344
347
|
border-radius: var(--radius-lg, 24rpx);
|
|
345
348
|
text {
|
|
349
|
+
width: var(--hlw-menu-grid-icon-size);
|
|
350
|
+
height: var(--hlw-menu-grid-icon-size);
|
|
346
351
|
font-size: var(--hlw-menu-grid-icon-size);
|
|
352
|
+
display: inline-block;
|
|
347
353
|
}
|
|
348
354
|
}
|
|
349
355
|
|
|
@@ -376,8 +382,8 @@ const handleGetPhoneNumber = (item: HlwMenuItem, event: unknown) => {
|
|
|
376
382
|
color: #f43f5e;
|
|
377
383
|
}
|
|
378
384
|
&--blue {
|
|
379
|
-
background:
|
|
380
|
-
color: #3b82f6;
|
|
385
|
+
background: var(--primary-light, rgba(76, 68, 239, 0.12));
|
|
386
|
+
color: var(--primary-color, #3b82f6);
|
|
381
387
|
}
|
|
382
388
|
&--red {
|
|
383
389
|
background: #fef2f2;
|
|
@@ -418,7 +424,7 @@ const handleGetPhoneNumber = (item: HlwMenuItem, event: unknown) => {
|
|
|
418
424
|
background: #f43f5e;
|
|
419
425
|
}
|
|
420
426
|
.hlw-menu-tag--blue {
|
|
421
|
-
background: #3b82f6;
|
|
427
|
+
background: var(--primary-color, #3b82f6);
|
|
422
428
|
}
|
|
423
429
|
|
|
424
430
|
.hlw-menu-tag-pulse {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view class="navbar">
|
|
2
|
+
<view class="navbar" :class="theme">
|
|
3
3
|
<view :style="bar_style"></view>
|
|
4
4
|
<view class="header" :style="{ height: header_height + 'px' }">
|
|
5
5
|
<view @tap="tapBack" class="left" v-if="props.isBack">
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</view>
|
|
8
8
|
<text class="title">{{ title }}</text>
|
|
9
9
|
</view>
|
|
10
|
-
<view class="status-bar" v-if="theme
|
|
10
|
+
<view class="status-bar" v-if="theme === 'color-theme'">
|
|
11
11
|
<view class="within"></view>
|
|
12
12
|
</view>
|
|
13
13
|
</view>
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
<script lang="ts" setup>
|
|
18
18
|
import { computed, ref } from "vue";
|
|
19
19
|
import { useTheme } from "@/core";
|
|
20
|
+
|
|
20
21
|
const { theme } = useTheme();
|
|
21
22
|
|
|
22
23
|
const statusBarHeight: number = uni.getSystemInfoSync()?.statusBarHeight || 0;
|
|
@@ -48,7 +49,7 @@ if (props.isBar) {
|
|
|
48
49
|
status_bar_height = 15;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
const header_height = ref<number>(menuButtonInfo.bottom - statusBarHeight +
|
|
52
|
+
const header_height = ref<number>(menuButtonInfo.bottom - statusBarHeight + 6);
|
|
52
53
|
const navbar_height = ref(header_height.value + statusBarHeight);
|
|
53
54
|
const status_bar_height_style = `${status_bar_height}px`;
|
|
54
55
|
|
|
@@ -67,11 +68,69 @@ function tapBack() {
|
|
|
67
68
|
.navbar {
|
|
68
69
|
display: flex;
|
|
69
70
|
flex-direction: column;
|
|
70
|
-
background-color: var(--navbar-bg-color);
|
|
71
71
|
position: fixed;
|
|
72
72
|
width: 750rpx;
|
|
73
73
|
z-index: 999;
|
|
74
|
-
border-bottom:
|
|
74
|
+
border-bottom: 1rpx solid rgba(226, 232, 240, 0);
|
|
75
|
+
transition:
|
|
76
|
+
background-color 0.2s ease,
|
|
77
|
+
border-bottom 0.2s ease;
|
|
78
|
+
|
|
79
|
+
/* 白色主题:白色导航栏,下方加一条灰色的细边框 */
|
|
80
|
+
&.white-theme {
|
|
81
|
+
background-color: var(--navbar-bg-color, #ffffff);
|
|
82
|
+
border-bottom: var(--navbar-border-bottom, 1rpx solid #e7e7e7);
|
|
83
|
+
|
|
84
|
+
.title {
|
|
85
|
+
color: var(--font-color, #303048);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.icon-left {
|
|
89
|
+
color: var(--font-color, #303048);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* 简洁主题:背景色与页面全局背景色一致,无明显界限,无边框 */
|
|
94
|
+
&.light-theme {
|
|
95
|
+
background-color: var(--bg-page, #f8f8f8);
|
|
96
|
+
border-bottom: 1rpx solid rgba(226, 232, 240, 0);
|
|
97
|
+
|
|
98
|
+
.title {
|
|
99
|
+
color: var(--font-color, #303048);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.icon-left {
|
|
103
|
+
color: var(--font-color, #303048);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* 单色主题:纯主题色导航栏,无边框,无圆角 */
|
|
108
|
+
&.mono-theme {
|
|
109
|
+
background-color: var(--primary-color, #3b82f6);
|
|
110
|
+
border-bottom: 1rpx solid rgba(226, 232, 240, 0);
|
|
111
|
+
|
|
112
|
+
.title {
|
|
113
|
+
color: #ffffff;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.icon-left {
|
|
117
|
+
color: #ffffff;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* 颜色主题:导航栏使用立体光影感的主题色渐变背景(反向:左上偏深,右下偏亮),下方带有白色圆角过渡 */
|
|
122
|
+
&.color-theme {
|
|
123
|
+
background: linear-gradient(135deg, rgba(0, 0, 0, 0.15) 0%, rgba(255, 255, 255, 0.15) 100%), var(--primary-color, #3b82f6);
|
|
124
|
+
border-bottom: 1rpx solid rgba(226, 232, 240, 0);
|
|
125
|
+
|
|
126
|
+
.title {
|
|
127
|
+
color: #ffffff;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.icon-left {
|
|
131
|
+
color: #ffffff;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
75
134
|
|
|
76
135
|
.header {
|
|
77
136
|
display: flex;
|
|
@@ -90,31 +149,32 @@ function tapBack() {
|
|
|
90
149
|
height: 100%;
|
|
91
150
|
|
|
92
151
|
.icon-left {
|
|
93
|
-
|
|
152
|
+
font-size: 30rpx;
|
|
94
153
|
}
|
|
95
154
|
}
|
|
96
155
|
|
|
97
156
|
.title {
|
|
98
|
-
font-size: var(--navbar-font-size);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
font-weight: bold;
|
|
157
|
+
font-size: var(--navbar-font-size, 26rpx);
|
|
158
|
+
letter-spacing: 1rpx;
|
|
159
|
+
font-weight: normal;
|
|
102
160
|
}
|
|
103
161
|
}
|
|
104
162
|
|
|
105
163
|
.status-bar {
|
|
106
|
-
background-color:
|
|
164
|
+
background-color: transparent;
|
|
107
165
|
height: v-bind(status_bar_height_style);
|
|
108
166
|
width: 750rpx;
|
|
109
167
|
position: relative;
|
|
110
168
|
|
|
111
169
|
.within {
|
|
112
170
|
position: absolute;
|
|
171
|
+
left: 0;
|
|
172
|
+
top: 0;
|
|
113
173
|
width: 750rpx;
|
|
114
|
-
height: v-bind(status_bar_height_style);
|
|
115
|
-
background-color: var(--bg-color);
|
|
116
|
-
border-top-left-radius: var(--status-bar-border);
|
|
117
|
-
border-top-right-radius: var(--status-bar-border);
|
|
174
|
+
height: calc(v-bind(status_bar_height_style) + 2rpx);
|
|
175
|
+
background-color: var(--bg-color, var(--bg-page, #f8f8f8));
|
|
176
|
+
border-top-left-radius: var(--status-bar-border, var(--card-radius, 32rpx));
|
|
177
|
+
border-top-right-radius: var(--status-bar-border, var(--card-radius, 32rpx));
|
|
118
178
|
}
|
|
119
179
|
}
|
|
120
180
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view :class="theme
|
|
3
|
-
<hlw-nav-bar :is-back="props.isBack" :title="title" :is-bar="props.isBar"></hlw-nav-bar>
|
|
2
|
+
<view :class="[theme, fontSizeClass, fontFamilyClass]">
|
|
3
|
+
<hlw-nav-bar v-if="isBar" :is-back="props.isBack" :title="title" :is-bar="props.isBar"></hlw-nav-bar>
|
|
4
4
|
<slot></slot>
|
|
5
5
|
</view>
|
|
6
6
|
</template>
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { useTheme } from "@/core";
|
|
10
10
|
import { onLoad, onShow } from "@dcloudio/uni-app";
|
|
11
11
|
import { ref } from "vue";
|
|
12
|
-
const { theme } = useTheme();
|
|
12
|
+
const { theme, fontSizeClass, fontFamilyClass } = useTheme();
|
|
13
13
|
|
|
14
14
|
const props = defineProps({
|
|
15
15
|
isBar: {
|
|
@@ -29,4 +29,94 @@ const props = defineProps({
|
|
|
29
29
|
const title = ref(props.title);
|
|
30
30
|
</script>
|
|
31
31
|
|
|
32
|
-
<style
|
|
32
|
+
<style lang="scss">
|
|
33
|
+
/* 全局系统字体大小缩放配置 */
|
|
34
|
+
.font-size-small {
|
|
35
|
+
--font-xs: 18rpx;
|
|
36
|
+
--font-sm: 22rpx;
|
|
37
|
+
--font-base: 24rpx;
|
|
38
|
+
--font-md: 28rpx;
|
|
39
|
+
--font-lg: 32rpx;
|
|
40
|
+
--font-xl: 36rpx;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.font-size-standard {
|
|
44
|
+
--font-xs: 20rpx;
|
|
45
|
+
--font-sm: 24rpx;
|
|
46
|
+
--font-base: 28rpx;
|
|
47
|
+
--font-md: 32rpx;
|
|
48
|
+
--font-lg: 36rpx;
|
|
49
|
+
--font-xl: 40rpx;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.font-size-large {
|
|
53
|
+
--font-xs: 22rpx;
|
|
54
|
+
--font-sm: 28rpx;
|
|
55
|
+
--font-base: 32rpx;
|
|
56
|
+
--font-md: 36rpx;
|
|
57
|
+
--font-lg: 40rpx;
|
|
58
|
+
--font-xl: 44rpx;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.font-size-extra-large {
|
|
62
|
+
--font-xs: 24rpx;
|
|
63
|
+
--font-sm: 32rpx;
|
|
64
|
+
--font-base: 36rpx;
|
|
65
|
+
--font-md: 40rpx;
|
|
66
|
+
--font-lg: 44rpx;
|
|
67
|
+
--font-xl: 48rpx;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* 全局字体样式配置 */
|
|
71
|
+
.font-family-system {
|
|
72
|
+
font-family:
|
|
73
|
+
system-ui,
|
|
74
|
+
-apple-system,
|
|
75
|
+
BlinkMacSystemFont,
|
|
76
|
+
"Segoe UI",
|
|
77
|
+
Roboto,
|
|
78
|
+
Helvetica,
|
|
79
|
+
Arial,
|
|
80
|
+
sans-serif !important;
|
|
81
|
+
view,
|
|
82
|
+
text,
|
|
83
|
+
button,
|
|
84
|
+
input,
|
|
85
|
+
textarea {
|
|
86
|
+
font-family: inherit !important;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.font-family-sans {
|
|
91
|
+
font-family: "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif !important;
|
|
92
|
+
view,
|
|
93
|
+
text,
|
|
94
|
+
button,
|
|
95
|
+
input,
|
|
96
|
+
textarea {
|
|
97
|
+
font-family: inherit !important;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.font-family-serif {
|
|
102
|
+
font-family: "Songti SC", "STSong", "SimSun", "Georgia", serif !important;
|
|
103
|
+
view,
|
|
104
|
+
text,
|
|
105
|
+
button,
|
|
106
|
+
input,
|
|
107
|
+
textarea {
|
|
108
|
+
font-family: inherit !important;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.font-family-kaiti {
|
|
113
|
+
font-family: "Kaiti SC", "STKaiti", "KaiTi", "SimKai", serif !important;
|
|
114
|
+
view,
|
|
115
|
+
text,
|
|
116
|
+
button,
|
|
117
|
+
input,
|
|
118
|
+
textarea {
|
|
119
|
+
font-family: inherit !important;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
</style>
|
package/src/core/theme.ts
CHANGED
|
@@ -1,12 +1,62 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
2
|
import type { ComputedRef } from "vue";
|
|
3
|
+
import {
|
|
4
|
+
useThemeStore,
|
|
5
|
+
themePresets,
|
|
6
|
+
fontSizePresets,
|
|
7
|
+
fontFamilyPresets
|
|
8
|
+
} from "../stores/theme";
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
themePresets,
|
|
12
|
+
type ThemePreset,
|
|
13
|
+
fontSizePresets,
|
|
14
|
+
type FontSizePreset,
|
|
15
|
+
fontFamilyPresets,
|
|
16
|
+
type FontFamilyPreset
|
|
17
|
+
} from "../stores/theme";
|
|
18
|
+
|
|
19
|
+
// ==========================================
|
|
20
|
+
// 统一个性化外观配置 Hook (useTheme)
|
|
21
|
+
// ==========================================
|
|
3
22
|
|
|
4
23
|
export function useTheme() {
|
|
5
|
-
const
|
|
24
|
+
const store = useThemeStore();
|
|
25
|
+
|
|
26
|
+
// 主题
|
|
27
|
+
const theme: ComputedRef<string> = computed(() => store.theme);
|
|
28
|
+
|
|
29
|
+
// 字体大小
|
|
30
|
+
const fontSize: ComputedRef<string> = computed(() => store.fontSize);
|
|
31
|
+
const fontSizeClass: ComputedRef<string> = computed(() => {
|
|
32
|
+
const found = fontSizePresets.find((p) => p.id === store.fontSize);
|
|
33
|
+
return found ? found.class : "font-size-standard";
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 字体样式
|
|
37
|
+
const fontFamily: ComputedRef<string> = computed(() => store.fontFamily);
|
|
38
|
+
const fontFamilyClass: ComputedRef<string> = computed(() => {
|
|
39
|
+
const found = fontFamilyPresets.find((p) => p.id === store.fontFamily);
|
|
40
|
+
return found ? found.class : "font-family-system";
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// 动作方法
|
|
44
|
+
function setFontSize(size: string): void {
|
|
45
|
+
store.setFontSize(size);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function setFontFamily(font: string): void {
|
|
49
|
+
store.setFontFamily(font);
|
|
50
|
+
}
|
|
51
|
+
|
|
6
52
|
return {
|
|
7
53
|
theme,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
54
|
+
fontSize,
|
|
55
|
+
fontSizeClass,
|
|
56
|
+
setFontSize,
|
|
57
|
+
fontFamily,
|
|
58
|
+
fontFamilyClass,
|
|
59
|
+
setFontFamily,
|
|
60
|
+
store,
|
|
11
61
|
};
|
|
12
62
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,20 +3,27 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 2.0 起合并了原 @hlw-uni/mp-core 全部内容。
|
|
5
5
|
* 业务方一处 import,无需再分包:
|
|
6
|
-
* import { useMsg,
|
|
6
|
+
* import { useMsg, useTheme, ... } from "@hlw-uni/mp-vue";
|
|
7
7
|
*
|
|
8
8
|
* UI 组件(hlw-page / hlw-button / hlw-ad 等)走 easycom 自动注册,不在这里 export。
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
// Composables / 工具 / Theme
|
|
12
12
|
export * from "./composables";
|
|
13
|
+
export {
|
|
14
|
+
useTheme,
|
|
15
|
+
themePresets,
|
|
16
|
+
type ThemePreset,
|
|
17
|
+
fontFamilyPresets,
|
|
18
|
+
type FontFamilyPreset,
|
|
19
|
+
fontSizePresets,
|
|
20
|
+
type FontSizePreset
|
|
21
|
+
} from "./core/theme";
|
|
13
22
|
|
|
14
23
|
// 类型
|
|
15
24
|
export type { HlwMenuItem } from "./components/hlw-menu/types";
|
|
16
25
|
export type { HlwPagingRef, HlwPagingInstance } from "./components/hlw-paging/types";
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
|
|
20
27
|
// App 根上下文
|
|
21
28
|
export { useApp } from "./app";
|
|
22
29
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./theme";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { defineStore } from "pinia";
|
|
2
|
+
|
|
3
|
+
// ==========================================
|
|
4
|
+
// 1. 主题 (Theme) 预设与类型
|
|
5
|
+
// ==========================================
|
|
6
|
+
|
|
7
|
+
export interface ThemePreset {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
color: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const themePresets: ThemePreset[] = [
|
|
14
|
+
{
|
|
15
|
+
id: "white-theme",
|
|
16
|
+
name: "白色主题",
|
|
17
|
+
color: "#ffffff",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "light-theme",
|
|
21
|
+
name: "简洁主题",
|
|
22
|
+
color: "var(--bg-page, #f8f8f8)",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "mono-theme",
|
|
26
|
+
name: "单色主题",
|
|
27
|
+
color: "var(--primary-color, #3b82f6)",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "color-theme",
|
|
31
|
+
name: "颜色主题",
|
|
32
|
+
color: "var(--primary-color, #3b82f6)",
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
// ==========================================
|
|
37
|
+
// 2. 字体大小 (FontSize) 预设与类型
|
|
38
|
+
// ==========================================
|
|
39
|
+
|
|
40
|
+
export interface FontSizePreset {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
class: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const fontSizePresets: FontSizePreset[] = [
|
|
47
|
+
{
|
|
48
|
+
id: "small",
|
|
49
|
+
name: "较小",
|
|
50
|
+
class: "font-size-small",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "standard",
|
|
54
|
+
name: "标准",
|
|
55
|
+
class: "font-size-standard",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "large",
|
|
59
|
+
name: "较大",
|
|
60
|
+
class: "font-size-large",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: "extra-large",
|
|
64
|
+
name: "超大",
|
|
65
|
+
class: "font-size-extra-large",
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
// ==========================================
|
|
70
|
+
// 3. 字体样式 (FontFamily) 预设与类型
|
|
71
|
+
// ==========================================
|
|
72
|
+
|
|
73
|
+
export interface FontFamilyPreset {
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
class: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const fontFamilyPresets: FontFamilyPreset[] = [
|
|
80
|
+
{
|
|
81
|
+
id: "system",
|
|
82
|
+
name: "系统默认",
|
|
83
|
+
class: "font-family-system",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "sans",
|
|
87
|
+
name: "现代黑体",
|
|
88
|
+
class: "font-family-sans",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "serif",
|
|
92
|
+
name: "经典宋体",
|
|
93
|
+
class: "font-family-serif",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "kaiti",
|
|
97
|
+
name: "优雅楷体",
|
|
98
|
+
class: "font-family-kaiti",
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
// ==========================================
|
|
103
|
+
// 4. 统一个性化配置 Store (Theme / Font)
|
|
104
|
+
// ==========================================
|
|
105
|
+
|
|
106
|
+
export const useThemeStore = defineStore("theme", {
|
|
107
|
+
state: () => ({
|
|
108
|
+
theme: "white-theme",
|
|
109
|
+
fontSize: "standard",
|
|
110
|
+
fontFamily: "system",
|
|
111
|
+
}),
|
|
112
|
+
getters: {},
|
|
113
|
+
actions: {
|
|
114
|
+
setFontSize(size: string) {
|
|
115
|
+
if (["small", "standard", "large", "extra-large"].includes(size)) {
|
|
116
|
+
this.fontSize = size;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
setFontFamily(font: string) {
|
|
120
|
+
if (["system", "sans", "serif", "kaiti"].includes(font)) {
|
|
121
|
+
this.fontFamily = font;
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
unistorage: true,
|
|
126
|
+
});
|