hy-app 0.4.2 → 0.4.3
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/components/hy-modal/hy-modal.vue +0 -2
- package/components/hy-picker/index.scss +1 -0
- package/components/hy-popover/hy-popover.vue +1 -0
- package/components/hy-price/hy-price.vue +13 -23
- package/components/hy-toast/hy-toast.vue +7 -17
- package/components/hy-toast/index.scss +36 -6
- package/components/hy-toast/typing.d.ts +1 -1
- package/composables/index.ts +5 -4
- package/composables/useToast.ts +51 -0
- package/config/icon.ts +15 -7
- package/package.json +2 -2
- package/static/font/iconfont.css +14 -6
- package/utils/utils.ts +17 -0
|
@@ -219,7 +219,6 @@ watch(
|
|
|
219
219
|
watch(
|
|
220
220
|
() => props.modelValue,
|
|
221
221
|
(newVal) => {
|
|
222
|
-
console.log(newVal, "newVal");
|
|
223
222
|
if (!newVal) load.value = false;
|
|
224
223
|
},
|
|
225
224
|
);
|
|
@@ -228,7 +227,6 @@ watch(
|
|
|
228
227
|
* @description 点击确定按钮
|
|
229
228
|
* */
|
|
230
229
|
const confirmHandler = async () => {
|
|
231
|
-
console.log(load.value, "props.loading");
|
|
232
230
|
if (load.value) return;
|
|
233
231
|
// 如果配置了异步关闭,将按钮值为loading状态
|
|
234
232
|
emit("confirm");
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
{{ priceOne?.[0] }}
|
|
13
13
|
</text>
|
|
14
14
|
<text class="hy-price__decimal">
|
|
15
|
-
{{ "." + priceOne?.[1]
|
|
15
|
+
{{ "." + addZero(priceOne?.[1], num) }}
|
|
16
16
|
</text>
|
|
17
17
|
</text>
|
|
18
18
|
</template>
|
|
@@ -29,9 +29,9 @@ export default {
|
|
|
29
29
|
</script>
|
|
30
30
|
|
|
31
31
|
<script setup lang="ts">
|
|
32
|
-
import { computed
|
|
32
|
+
import { computed } from "vue";
|
|
33
33
|
import type { CSSProperties, PropType } from "vue";
|
|
34
|
-
import { addUnit, getPx, error } from "../../utils";
|
|
34
|
+
import { addUnit, getPx, error, addZero } from "../../utils";
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* 业务组件,突出金额小数点前大,小数点后小
|
|
@@ -86,7 +86,6 @@ const props = defineProps({
|
|
|
86
86
|
/** 自定义外部类名 */
|
|
87
87
|
customClass: String,
|
|
88
88
|
});
|
|
89
|
-
const { text, color, weight, size, slant, customStyle } = toRefs(props);
|
|
90
89
|
const emit = defineEmits(["click"]);
|
|
91
90
|
|
|
92
91
|
/**
|
|
@@ -94,34 +93,25 @@ const emit = defineEmits(["click"]);
|
|
|
94
93
|
* */
|
|
95
94
|
const priceStyle = computed<CSSProperties>(() => {
|
|
96
95
|
const style: CSSProperties = {
|
|
97
|
-
color: color
|
|
98
|
-
fontWeight: weight
|
|
99
|
-
fontStyle: slant
|
|
100
|
-
fontSize: addUnit(size
|
|
96
|
+
color: props.color,
|
|
97
|
+
fontWeight: props.weight,
|
|
98
|
+
fontStyle: props.slant ? "oblique" : "",
|
|
99
|
+
fontSize: addUnit(props.size),
|
|
101
100
|
};
|
|
102
101
|
|
|
103
|
-
return Object.assign(style, customStyle
|
|
102
|
+
return Object.assign(style, props.customStyle);
|
|
104
103
|
});
|
|
105
104
|
|
|
106
105
|
/**
|
|
107
106
|
* @description 价格处理
|
|
108
107
|
* */
|
|
109
108
|
const priceOne = computed(() => {
|
|
110
|
-
if (props.text === undefined) return error("
|
|
109
|
+
if (props.text === undefined) return error("text值不能为空");
|
|
111
110
|
|
|
112
|
-
let value =
|
|
113
|
-
|
|
114
|
-
if (typeof price !== "string") {
|
|
115
|
-
value = price.toString();
|
|
116
|
-
} else {
|
|
117
|
-
value = price;
|
|
118
|
-
}
|
|
111
|
+
let value =
|
|
112
|
+
typeof props.text === "string" ? props.text : props.text.toString();
|
|
119
113
|
if (/\./g.test(value)) {
|
|
120
|
-
|
|
121
|
-
return value.split(".");
|
|
122
|
-
} else {
|
|
123
|
-
return ["0", "00"];
|
|
124
|
-
}
|
|
114
|
+
return Number(value) ? value.split(".") : ["0", "000000"];
|
|
125
115
|
} else {
|
|
126
116
|
return [value, "000000"];
|
|
127
117
|
}
|
|
@@ -131,7 +121,7 @@ const priceOne = computed(() => {
|
|
|
131
121
|
* @description 点击事件
|
|
132
122
|
* */
|
|
133
123
|
const handleClick = () => {
|
|
134
|
-
emit("click", text
|
|
124
|
+
emit("click", props.text);
|
|
135
125
|
};
|
|
136
126
|
</script>
|
|
137
127
|
|
|
@@ -22,20 +22,16 @@
|
|
|
22
22
|
size="25"
|
|
23
23
|
:customStyle="{ marginBottom: '20px' }"
|
|
24
24
|
></HyLoading>
|
|
25
|
-
<
|
|
25
|
+
<view
|
|
26
26
|
v-else-if="iconNameCom"
|
|
27
|
-
:name="iconNameCom"
|
|
28
|
-
size="17"
|
|
29
|
-
:color="tmpConfig.type"
|
|
30
|
-
:customStyle="iconStyle"
|
|
31
|
-
></HyIcon>
|
|
32
|
-
<text
|
|
33
27
|
:class="[
|
|
34
|
-
'hy-toast__content--
|
|
35
|
-
|
|
28
|
+
'hy-toast__content--icon',
|
|
29
|
+
`hy-toast__content--icon__${tmpConfig.type}`,
|
|
36
30
|
]"
|
|
37
|
-
style="max-width: 400rpx"
|
|
38
31
|
>
|
|
32
|
+
<HyIcon :name="iconNameCom" size="17" color="#FFFFFF"></HyIcon>
|
|
33
|
+
</view>
|
|
34
|
+
<text class="hy-toast__content--text" style="max-width: 400rpx">
|
|
39
35
|
{{ tmpConfig.message }}
|
|
40
36
|
</text>
|
|
41
37
|
</view>
|
|
@@ -113,12 +109,6 @@ const iconNameCom = computed(() => {
|
|
|
113
109
|
return tmpConfig.value.icon;
|
|
114
110
|
}
|
|
115
111
|
});
|
|
116
|
-
const iconStyle = computed(() => {
|
|
117
|
-
const style: CSSProperties = {};
|
|
118
|
-
// 图标需要一个右边距,以跟右边的文字有隔开的距离
|
|
119
|
-
style.marginRight = "4px";
|
|
120
|
-
return style;
|
|
121
|
-
});
|
|
122
112
|
|
|
123
113
|
/**
|
|
124
114
|
* @description 内容盒子的样式
|
|
@@ -157,7 +147,7 @@ const show = (options: ToastParamsVo) => {
|
|
|
157
147
|
clearTimer();
|
|
158
148
|
isShow.value = true;
|
|
159
149
|
// -1时不自动关闭
|
|
160
|
-
if (tmpConfig.value.duration !== -1) {
|
|
150
|
+
if (tmpConfig.value.duration !== -1 && !tmpConfig.value.loading) {
|
|
161
151
|
timer = setTimeout(() => {
|
|
162
152
|
// 倒计时结束,清除定时器,隐藏toast组件
|
|
163
153
|
clearTimer();
|
|
@@ -19,6 +19,42 @@
|
|
|
19
19
|
padding: 20px;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
@include m(icon) {
|
|
23
|
+
width: 32px;
|
|
24
|
+
height: 32px;
|
|
25
|
+
border-radius: $hy-border-radius-semicircle;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
margin-right: $hy-border-margin-padding-base;
|
|
28
|
+
display: flex;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
align-items: center;
|
|
31
|
+
|
|
32
|
+
@include e(info) {
|
|
33
|
+
background: $hy-info;
|
|
34
|
+
border: 6rpx solid $hy-info-dark;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@include e(primary) {
|
|
38
|
+
background: $hy-primary;
|
|
39
|
+
border: 6rpx solid $hy-primary-dark;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@include e(success) {
|
|
43
|
+
background: $hy-success;
|
|
44
|
+
border: 6rpx solid $hy-success-dark;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@include e(error) {
|
|
48
|
+
background: $hy-error;
|
|
49
|
+
border: 6rpx solid $hy-error-dark;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@include e(warning) {
|
|
53
|
+
background: $hy-warning;
|
|
54
|
+
border: 6rpx solid $hy-warning-dark;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
22
58
|
@include m(text) {
|
|
23
59
|
color: #ffffff;
|
|
24
60
|
font-size: 15px;
|
|
@@ -46,12 +82,6 @@
|
|
|
46
82
|
}
|
|
47
83
|
}
|
|
48
84
|
|
|
49
|
-
@include themeColor(success, $hy-success-light, #bef5c8, $hy-success);
|
|
50
|
-
@include themeColor(primary, $hy-primary-light, rgb(215, 234, 254), $hy-primary);
|
|
51
|
-
@include themeColor(error, $hy-error-light, #fde2e2, $hy-error);
|
|
52
|
-
@include themeColor(warning, $hy-warning-light, #faecd8, $hy-warning);
|
|
53
|
-
@include themeColor(info, $hy-info-light, $hy-info, $hy-info);
|
|
54
|
-
|
|
55
85
|
|
|
56
86
|
@include m(default) {
|
|
57
87
|
color: #ffffff;
|
package/composables/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./useShare";
|
|
2
|
+
export * from "./useTouch";
|
|
3
|
+
export * from "./usePopover";
|
|
4
|
+
export * from "./useQueue";
|
|
5
|
+
export * from "./useToast";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type ToastOptions from "../components/hy-toast/typing";
|
|
2
|
+
import { error } from "@/package";
|
|
3
|
+
|
|
4
|
+
// 用于缓存全局唯一实例
|
|
5
|
+
let toastInstance: any = null;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* useToast 适用于任意页面直接调用 toast
|
|
9
|
+
* 兼容 H5 + 微信小程序 + App
|
|
10
|
+
*/
|
|
11
|
+
export const useToast = () => {
|
|
12
|
+
// 如果已经有实例,直接复用
|
|
13
|
+
if (toastInstance) return toastInstance;
|
|
14
|
+
|
|
15
|
+
const info = (msg: string, opt?: ToastOptions) =>
|
|
16
|
+
createToast({ message: msg, type: "info", ...opt });
|
|
17
|
+
const success = (msg: string, opt?: ToastOptions) =>
|
|
18
|
+
createToast({ message: msg, type: "success", ...opt });
|
|
19
|
+
const error = (msg: string, opt?: ToastOptions) =>
|
|
20
|
+
createToast({ message: msg, type: "error", ...opt });
|
|
21
|
+
const warning = (msg: string, opt?: ToastOptions) =>
|
|
22
|
+
createToast({ message: msg, type: "warning", ...opt });
|
|
23
|
+
const primary = (msg: string, opt?: ToastOptions) =>
|
|
24
|
+
createToast({ message: msg, type: "primary", ...opt });
|
|
25
|
+
const loading = (msg: string, opt?: ToastOptions) =>
|
|
26
|
+
createToast({ message: msg, loading: true, ...opt });
|
|
27
|
+
const close = (all?: boolean) => {
|
|
28
|
+
if (toastInstance && toastInstance.hide) toastInstance.hide();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return { info, success, error, warning, primary, loading, close };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ✅ 实现
|
|
36
|
+
* 由于小程序不支持动态 mount vue 组件
|
|
37
|
+
* 所以需要依赖页面上放置 <HyToast ref="toastRef" /> 元素
|
|
38
|
+
*/
|
|
39
|
+
function createToast(options: ToastOptions) {
|
|
40
|
+
const pages = getCurrentPages();
|
|
41
|
+
const currentPage = pages[pages.length - 1];
|
|
42
|
+
const vm = currentPage.$vm || currentPage;
|
|
43
|
+
|
|
44
|
+
// 确保页面有 ref="toastRef" 的 hy-toast
|
|
45
|
+
if (vm?.$refs?.toastRef) {
|
|
46
|
+
vm.$refs.toastRef.show(options);
|
|
47
|
+
toastInstance = vm.$refs.toastRef;
|
|
48
|
+
} else {
|
|
49
|
+
error('[useToast] 请在页面 template 中添加 <HyToast ref="toastRef" />');
|
|
50
|
+
}
|
|
51
|
+
}
|
package/config/icon.ts
CHANGED
|
@@ -236,9 +236,13 @@ export const IconConfig = {
|
|
|
236
236
|
* */
|
|
237
237
|
CLOSE_CIRCLE_FILL: "close-circle-fill",
|
|
238
238
|
/**
|
|
239
|
-
*
|
|
239
|
+
* 感叹号
|
|
240
240
|
* */
|
|
241
241
|
NOTICE: "notice",
|
|
242
|
+
/**
|
|
243
|
+
* 注意
|
|
244
|
+
* */
|
|
245
|
+
NOTICE_CIRCLE: "notice-circle",
|
|
242
246
|
/**
|
|
243
247
|
* 注意-实心
|
|
244
248
|
* */
|
|
@@ -251,10 +255,14 @@ export const IconConfig = {
|
|
|
251
255
|
* 成功-实心
|
|
252
256
|
* */
|
|
253
257
|
SUCCESS_FILL: "success-fill",
|
|
258
|
+
/**
|
|
259
|
+
* 疑问
|
|
260
|
+
* */
|
|
261
|
+
QUERY: "query",
|
|
254
262
|
/**
|
|
255
263
|
* 帮助
|
|
256
264
|
* */
|
|
257
|
-
|
|
265
|
+
HELP_CIRCLE: "help-circle",
|
|
258
266
|
/**
|
|
259
267
|
* 帮助-实心
|
|
260
268
|
* */
|
|
@@ -407,16 +415,16 @@ export const IconConfig = {
|
|
|
407
415
|
export const iconName = (type: string) => {
|
|
408
416
|
switch (type) {
|
|
409
417
|
case "success":
|
|
410
|
-
return IconConfig.
|
|
418
|
+
return IconConfig.CHECK_MASK;
|
|
411
419
|
case "error":
|
|
412
|
-
return IconConfig.
|
|
420
|
+
return IconConfig.CLOSE;
|
|
413
421
|
case "warning":
|
|
414
|
-
return IconConfig.
|
|
422
|
+
return IconConfig.NOTICE;
|
|
415
423
|
case "info":
|
|
416
|
-
return IconConfig.
|
|
424
|
+
return IconConfig.QUERY;
|
|
417
425
|
case "primary":
|
|
418
426
|
return IconConfig.MESSAGE_FILL;
|
|
419
427
|
default:
|
|
420
|
-
return IconConfig.
|
|
428
|
+
return IconConfig.CLOSE;
|
|
421
429
|
}
|
|
422
430
|
};
|
package/package.json
CHANGED
package/static/font/iconfont.css
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
@font-face {
|
|
2
|
-
font-family:
|
|
3
|
-
src: url('https://at.alicdn.com/t/c/
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
font-family: "iconfont"; /* Project id 4305932 */
|
|
3
|
+
src: url('https://at.alicdn.com/t/c/font_4305932_qgtc1zvcqsm.woff2?t=1761211099193') format('woff2'),
|
|
4
|
+
url('https://at.alicdn.com/t/c/font_4305932_qgtc1zvcqsm.woff?t=1761211099193') format('woff'),
|
|
5
|
+
url('https://at.alicdn.com/t/c/font_4305932_qgtc1zvcqsm.ttficonfont.ttf?t=1761211099193') format('truetype');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
.iconfont {
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
-moz-osx-font-smoothing: grayscale;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
.hy-icon-query:before {
|
|
17
|
+
content: "\e617";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.hy-icon-notice:before {
|
|
21
|
+
content: "\e61f";
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
.hy-icon-telephone-fill:before {
|
|
17
25
|
content: "\e66d";
|
|
18
26
|
}
|
|
@@ -333,7 +341,7 @@
|
|
|
333
341
|
content: "\e621";
|
|
334
342
|
}
|
|
335
343
|
|
|
336
|
-
.hy-icon-help:before {
|
|
344
|
+
.hy-icon-help-circle:before {
|
|
337
345
|
content: "\e622";
|
|
338
346
|
}
|
|
339
347
|
|
|
@@ -357,7 +365,7 @@
|
|
|
357
365
|
content: "\e629";
|
|
358
366
|
}
|
|
359
367
|
|
|
360
|
-
.hy-icon-notice:before {
|
|
368
|
+
.hy-icon-notice-circle:before {
|
|
361
369
|
content: "\e62a";
|
|
362
370
|
}
|
|
363
371
|
|
package/utils/utils.ts
CHANGED
|
@@ -67,6 +67,22 @@ const padZero = (value: string | number): string => {
|
|
|
67
67
|
return `00${value}`.slice(-2);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* @description 后面补零
|
|
72
|
+
* @param {String | Number} value 需要补零的值
|
|
73
|
+
* @param {Number} length 多少位
|
|
74
|
+
* @returns {String}
|
|
75
|
+
*/
|
|
76
|
+
const addZero = (value: string | number, length: number): string => {
|
|
77
|
+
let val = value.toString();
|
|
78
|
+
if (length > val.length) {
|
|
79
|
+
val += "0".repeat(length - val.length);
|
|
80
|
+
} else {
|
|
81
|
+
val = val.slice(0, length);
|
|
82
|
+
}
|
|
83
|
+
return val;
|
|
84
|
+
};
|
|
85
|
+
|
|
70
86
|
/**
|
|
71
87
|
* @description 清空对象里面的值
|
|
72
88
|
* @param val 任意类型的值
|
|
@@ -459,6 +475,7 @@ export {
|
|
|
459
475
|
decryptData,
|
|
460
476
|
addUnit,
|
|
461
477
|
padZero,
|
|
478
|
+
addZero,
|
|
462
479
|
clearVal,
|
|
463
480
|
formatTime,
|
|
464
481
|
formatTimeToString,
|