hy-app 0.3.1 → 0.3.2
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 +6 -3
- package/common/shakeService.ts +31 -29
- package/components/avatar.zip +0 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
- package/components/hy-address-picker/hy-address-picker.vue +94 -83
- package/components/hy-avatar/hy-avatar.vue +84 -85
- package/components/hy-badge/hy-badge.vue +47 -46
- package/components/hy-button/hy-button.vue +117 -93
- package/components/hy-calendar/hy-calendar.vue +168 -160
- package/components/hy-card/hy-card.vue +50 -43
- package/components/hy-card/typing.d.ts +33 -32
- package/components/hy-cell/hy-cell.vue +73 -51
- package/components/hy-check-button/hy-check-button.vue +54 -47
- package/components/hy-checkbox/hy-checkbox.vue +97 -105
- package/components/hy-code-input/hy-code-input.vue +80 -89
- package/components/hy-config-provider/hy-config-provider.vue +19 -20
- package/components/hy-count-down/hy-count-down.vue +66 -67
- package/components/hy-count-to/hy-count-to.vue +105 -99
- package/components/hy-count-to/typing.d.ts +13 -12
- package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
- package/components/hy-datetime-picker/typing.d.ts +42 -40
- package/components/hy-divider/hy-divider.vue +68 -73
- package/components/hy-dropdown/hy-dropdown.vue +20 -19
- package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
- package/components/hy-dropdown-item/typing.d.ts +9 -9
- package/components/hy-empty/hy-empty.vue +42 -42
- package/components/hy-flex/hy-flex.vue +52 -26
- package/components/hy-float-button/hy-float-button.vue +218 -210
- package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
- package/components/hy-form/hy-form.vue +264 -259
- package/components/hy-grid/hy-grid.vue +44 -43
- package/components/hy-icon/hy-icon.vue +61 -67
- package/components/hy-image/hy-image.vue +112 -88
- package/components/hy-image/typing.d.ts +27 -23
- package/components/hy-input/hy-input.vue +157 -127
- package/components/hy-input/typing.d.ts +53 -47
- package/components/hy-line/hy-line.vue +26 -26
- package/components/hy-line-progress/hy-line-progress.vue +42 -35
- package/components/hy-list/hy-list.vue +76 -85
- package/components/hy-loading/hy-loading.vue +26 -23
- package/components/hy-menu/hy-menu.vue +48 -43
- package/components/hy-menu/typing.d.ts +18 -17
- package/components/hy-modal/hy-modal.vue +39 -35
- package/components/hy-navbar/hy-navbar.vue +25 -25
- package/components/hy-navbar/typing.d.ts +24 -22
- package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
- package/components/hy-notify/hy-notify.vue +53 -53
- package/components/hy-number-step/hy-number-step.vue +134 -146
- package/components/hy-number-step/typing.d.ts +35 -35
- package/components/hy-overlay/hy-overlay.vue +23 -21
- package/components/hy-pagination/hy-pagination.vue +41 -36
- package/components/hy-picker/hy-picker.vue +184 -154
- package/components/hy-picker/typing.d.ts +39 -39
- package/components/hy-popover/hy-popover.vue +97 -77
- package/components/hy-popup/hy-popup.vue +107 -98
- package/components/hy-price/hy-price.vue +38 -34
- package/components/hy-qrcode/hy-qrcode.vue +50 -51
- package/components/hy-radio/hy-radio.vue +101 -113
- package/components/hy-rate/hy-rate.vue +107 -88
- package/components/hy-read-more/hy-read-more.vue +64 -49
- package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
- package/components/hy-search/hy-search.vue +73 -66
- package/components/hy-search/typing.d.ts +36 -35
- package/components/hy-signature/hy-signature.vue +282 -240
- package/components/hy-slider/hy-slider.vue +195 -153
- package/components/hy-slider/typing.d.ts +21 -21
- package/components/hy-steps/hy-steps.vue +118 -90
- package/components/hy-steps/index.scss +31 -21
- package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
- package/components/hy-subsection/hy-subsection.vue +99 -102
- package/components/hy-subsection/typing.d.ts +19 -19
- package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
- package/components/hy-swiper/hy-swiper.vue +85 -71
- package/components/hy-switch/hy-switch.vue +67 -72
- package/components/hy-switch/typing.d.ts +21 -19
- package/components/hy-tabs/hy-tabs.vue +168 -113
- package/components/hy-tag/hy-tag.vue +90 -86
- package/components/hy-tag/typing.d.ts +26 -21
- package/components/hy-text/hy-text.vue +119 -111
- package/components/hy-textarea/hy-textarea.vue +100 -93
- package/components/hy-textarea/typing.d.ts +36 -31
- package/components/hy-toast/hy-toast.vue +77 -67
- package/components/hy-tooltip/hy-tooltip.vue +109 -91
- package/components/hy-transition/hy-transition.vue +62 -66
- package/components/hy-upload/hy-upload.vue +294 -152
- package/components/hy-upload/typing.d.ts +41 -36
- package/components/hy-warn/hy-warn.vue +34 -27
- package/components/hy-waterfall/hy-waterfall.vue +83 -74
- package/components/hy-watermark/hy-watermark.vue +134 -115
- package/composables/usePopover.ts +236 -221
- package/composables/useQueue.ts +53 -52
- package/package.json +2 -2
- package/store/index.ts +9 -1
- package/typing/index.ts +0 -1
- package/typing/modules/common.d.ts +0 -2
- package/web-types.json +1 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view
|
|
2
|
+
<view
|
|
3
|
+
class="hy-avatar"
|
|
4
|
+
:class="avatarClass"
|
|
5
|
+
:style="avatarStyle"
|
|
6
|
+
@tap="clickHandler"
|
|
7
|
+
>
|
|
3
8
|
<slot>
|
|
4
9
|
<!-- #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU -->
|
|
5
10
|
<open-data
|
|
@@ -16,7 +21,12 @@
|
|
|
16
21
|
<!-- #ifndef MP-WEIXIN && MP-QQ && MP-BAIDU -->
|
|
17
22
|
<template v-if="mpAvatar && allowMp"></template>
|
|
18
23
|
<!-- #endif -->
|
|
19
|
-
<HyIcon
|
|
24
|
+
<HyIcon
|
|
25
|
+
v-else-if="icon"
|
|
26
|
+
:name="icon"
|
|
27
|
+
:size="fontSize"
|
|
28
|
+
:color="color"
|
|
29
|
+
></HyIcon>
|
|
20
30
|
<text
|
|
21
31
|
v-else-if="text"
|
|
22
32
|
:style="{
|
|
@@ -42,27 +52,28 @@
|
|
|
42
52
|
|
|
43
53
|
<script lang="ts">
|
|
44
54
|
export default {
|
|
45
|
-
name:
|
|
55
|
+
name: "hy-avatar",
|
|
46
56
|
options: {
|
|
47
57
|
addGlobalClass: true,
|
|
48
58
|
virtualHost: true,
|
|
49
|
-
styleIsolation:
|
|
59
|
+
styleIsolation: "shared",
|
|
50
60
|
},
|
|
51
|
-
}
|
|
61
|
+
};
|
|
52
62
|
</script>
|
|
53
63
|
|
|
54
64
|
<script setup lang="ts">
|
|
65
|
+
import { computed, toRefs, ref, watch } from "vue";
|
|
66
|
+
import type { CSSProperties, PropType } from "vue";
|
|
67
|
+
import type { IAvatarEmit } from "./typing";
|
|
68
|
+
import { addUnit, isNumber, random } from "../../utils";
|
|
69
|
+
// 组件
|
|
70
|
+
import HyIcon from "../hy-icon/hy-icon.vue";
|
|
71
|
+
|
|
55
72
|
/**
|
|
56
73
|
* 本组件一般用于展示头像的地方,如个人中心,或者评论列表页的用户头像展示等场所
|
|
57
74
|
* @displayName hy-avatar
|
|
58
75
|
*/
|
|
59
|
-
defineOptions({})
|
|
60
|
-
import { computed, type CSSProperties, toRefs, ref, watch } from 'vue'
|
|
61
|
-
import type { IAvatarEmit } from './typing'
|
|
62
|
-
import { addUnit, random } from '../../utils'
|
|
63
|
-
|
|
64
|
-
// 组件
|
|
65
|
-
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
76
|
+
defineOptions({});
|
|
66
77
|
|
|
67
78
|
// const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
68
79
|
const props = defineProps({
|
|
@@ -74,7 +85,7 @@ const props = defineProps({
|
|
|
74
85
|
* */
|
|
75
86
|
shape: {
|
|
76
87
|
type: String,
|
|
77
|
-
default:
|
|
88
|
+
default: "circle",
|
|
78
89
|
},
|
|
79
90
|
/**
|
|
80
91
|
* 头像尺寸
|
|
@@ -82,7 +93,7 @@ const props = defineProps({
|
|
|
82
93
|
* */
|
|
83
94
|
size: {
|
|
84
95
|
type: [String, Number],
|
|
85
|
-
default:
|
|
96
|
+
default: "medium",
|
|
86
97
|
},
|
|
87
98
|
/**
|
|
88
99
|
* 头像图片的裁剪类型
|
|
@@ -90,19 +101,19 @@ const props = defineProps({
|
|
|
90
101
|
* */
|
|
91
102
|
mode: {
|
|
92
103
|
type: String,
|
|
93
|
-
default:
|
|
104
|
+
default: "scaleToFill",
|
|
94
105
|
},
|
|
95
106
|
/** 用文字替代图片,级别优先于src */
|
|
96
107
|
text: String,
|
|
97
108
|
/** 头像背景颜色 */
|
|
98
109
|
bgColor: {
|
|
99
110
|
type: String,
|
|
100
|
-
default:
|
|
111
|
+
default: "#c0c4cc",
|
|
101
112
|
},
|
|
102
113
|
/** 文字颜色 */
|
|
103
114
|
color: {
|
|
104
115
|
type: String,
|
|
105
|
-
default:
|
|
116
|
+
default: "#ffffff",
|
|
106
117
|
},
|
|
107
118
|
/** 文字大小 */
|
|
108
119
|
fontSize: {
|
|
@@ -133,117 +144,105 @@ const props = defineProps({
|
|
|
133
144
|
/** 自定义输入框外部样式 */
|
|
134
145
|
customStyle: {
|
|
135
146
|
type: Object as PropType<CSSProperties>,
|
|
147
|
+
default: () => {},
|
|
136
148
|
},
|
|
137
|
-
})
|
|
138
|
-
const
|
|
139
|
-
src,
|
|
140
|
-
defaultUrl,
|
|
141
|
-
text,
|
|
142
|
-
icon,
|
|
143
|
-
randomBgColor,
|
|
144
|
-
colorIndex,
|
|
145
|
-
bgColor,
|
|
146
|
-
size,
|
|
147
|
-
shape,
|
|
148
|
-
name,
|
|
149
|
-
customStyle,
|
|
150
|
-
} = toRefs(props)
|
|
151
|
-
const emit = defineEmits<IAvatarEmit>()
|
|
149
|
+
});
|
|
150
|
+
const emit = defineEmits<IAvatarEmit>();
|
|
152
151
|
|
|
153
152
|
const base64Avatar =
|
|
154
|
-
|
|
153
|
+
"data:image/jpg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW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VzRydt8pKn68ANcJwmqwkpLmnUDkAAAAfNy9atqtyagut0AxXt5xIV8Fbj6lRd7Am5G65V6qUvtwfyx94GMAAAAAAAAAAAAAAAAAAAOU2nVOj5gdsc3LiqRvTpyqwOxbnnrhdfpSfrQB7pnv/AGvuS9gHXPMy5/Fem1yq0v0A6W29XqwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf//Z";
|
|
155
154
|
// 如果配置randomBgColor参数为true,在图标或者文字的模式下,会随机从中取出一个颜色值当做背景色
|
|
156
155
|
const colors = ref<string[]>([
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
])
|
|
178
|
-
const avatarUrl = ref(src
|
|
179
|
-
const allowMp = ref<boolean>(false)
|
|
156
|
+
"#ffb34b",
|
|
157
|
+
"#f2bba9",
|
|
158
|
+
"#f7a196",
|
|
159
|
+
"#f18080",
|
|
160
|
+
"#88a867",
|
|
161
|
+
"#bfbf39",
|
|
162
|
+
"#89c152",
|
|
163
|
+
"#94d554",
|
|
164
|
+
"#f19ec2",
|
|
165
|
+
"#afaae4",
|
|
166
|
+
"#e1b0df",
|
|
167
|
+
"#c38cc1",
|
|
168
|
+
"#72dcdc",
|
|
169
|
+
"#9acdcb",
|
|
170
|
+
"#77b1cc",
|
|
171
|
+
"#448aca",
|
|
172
|
+
"#86cefa",
|
|
173
|
+
"#98d1ee",
|
|
174
|
+
"#73d1f1",
|
|
175
|
+
"#80a7dc",
|
|
176
|
+
]);
|
|
177
|
+
const avatarUrl = ref(props.src);
|
|
178
|
+
const allowMp = ref<boolean>(false);
|
|
180
179
|
|
|
181
180
|
watch(
|
|
182
|
-
() => src
|
|
181
|
+
() => props.src,
|
|
183
182
|
(newVal) => {
|
|
184
|
-
avatarUrl.value = newVal
|
|
183
|
+
avatarUrl.value = newVal;
|
|
185
184
|
// 如果没有传src,则主动触发error事件,用于显示默认的头像,否则src为''空字符等的时候,会无内容展示
|
|
186
185
|
if (!newVal) {
|
|
187
|
-
errorHandler()
|
|
186
|
+
errorHandler();
|
|
188
187
|
}
|
|
189
188
|
},
|
|
190
189
|
{ immediate: true },
|
|
191
|
-
)
|
|
190
|
+
);
|
|
192
191
|
|
|
193
192
|
const avatarStyle = computed<CSSProperties>(() => {
|
|
194
193
|
const style: CSSProperties = {
|
|
195
194
|
backgroundColor:
|
|
196
|
-
text
|
|
197
|
-
? randomBgColor
|
|
198
|
-
? colors.value[colorIndex
|
|
199
|
-
: bgColor
|
|
200
|
-
:
|
|
201
|
-
}
|
|
202
|
-
if (
|
|
203
|
-
style.width = addUnit(size
|
|
204
|
-
style.height = addUnit(size
|
|
195
|
+
props.text || props.icon
|
|
196
|
+
? props.randomBgColor
|
|
197
|
+
? colors.value[props.colorIndex ? props.colorIndex : random(0, 19)]
|
|
198
|
+
: props.bgColor
|
|
199
|
+
: "transparent",
|
|
200
|
+
};
|
|
201
|
+
if (isNumber(props.size)) {
|
|
202
|
+
style.width = addUnit(props.size);
|
|
203
|
+
style.height = addUnit(props.size);
|
|
205
204
|
}
|
|
206
205
|
|
|
207
|
-
return Object.assign(style, customStyle.value)
|
|
208
|
-
})
|
|
206
|
+
return Object.assign(style, customStyle.value);
|
|
207
|
+
});
|
|
209
208
|
const avatarClass = computed<string[]>(() => {
|
|
210
|
-
const classes: string[] = [`hy-avatar--${shape.value}`]
|
|
211
|
-
if (typeof size
|
|
212
|
-
classes.push(`hy-avatar--${size
|
|
209
|
+
const classes: string[] = [`hy-avatar--${shape.value}`];
|
|
210
|
+
if (typeof props.size === "string") {
|
|
211
|
+
classes.push(`hy-avatar--${props.size}`);
|
|
213
212
|
}
|
|
214
213
|
|
|
215
|
-
return classes
|
|
216
|
-
})
|
|
214
|
+
return classes;
|
|
215
|
+
});
|
|
217
216
|
|
|
218
217
|
const init = () => {
|
|
219
218
|
// 目前只有这几个小程序平台具有open-data标签
|
|
220
219
|
// 其他平台可以通过uni.getUserInfo类似接口获取信息,但是需要弹窗授权(首次),不合符组件逻辑
|
|
221
220
|
// 故目前自动获取小程序头像只支持这几个平台
|
|
222
221
|
// #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU
|
|
223
|
-
allowMp.value = true
|
|
222
|
+
allowMp.value = true;
|
|
224
223
|
// #endif
|
|
225
|
-
}
|
|
226
|
-
init()
|
|
224
|
+
};
|
|
225
|
+
init();
|
|
227
226
|
|
|
228
227
|
/**
|
|
229
228
|
* @description 判断传入的name属性,是否图片路径,只要带有"/"均认为是图片形式
|
|
230
229
|
* */
|
|
231
230
|
const isImg = () => {
|
|
232
|
-
return src.
|
|
233
|
-
}
|
|
231
|
+
return props.src.indexOf("/") !== -1;
|
|
232
|
+
};
|
|
234
233
|
// 图片加载时失败时触发
|
|
235
234
|
function errorHandler() {
|
|
236
|
-
avatarUrl.value = defaultUrl.value || base64Avatar
|
|
235
|
+
avatarUrl.value = defaultUrl.value || base64Avatar;
|
|
237
236
|
}
|
|
238
237
|
|
|
239
238
|
/**
|
|
240
239
|
* @description 点击头像
|
|
241
240
|
* */
|
|
242
241
|
const clickHandler = (e: Event) => {
|
|
243
|
-
emit(
|
|
244
|
-
}
|
|
242
|
+
emit("click", name.value, e);
|
|
243
|
+
};
|
|
245
244
|
</script>
|
|
246
245
|
|
|
247
246
|
<style lang="scss" scoped>
|
|
248
|
-
@import
|
|
247
|
+
@import "./index.scss";
|
|
249
248
|
</style>
|
|
@@ -11,31 +11,32 @@
|
|
|
11
11
|
:style="[customStyle, badgeStyle]"
|
|
12
12
|
@tap="onClick"
|
|
13
13
|
>
|
|
14
|
-
{{ isDot ?
|
|
14
|
+
{{ isDot ? "" : showValue }}
|
|
15
15
|
</text>
|
|
16
16
|
</template>
|
|
17
17
|
|
|
18
18
|
<script lang="ts">
|
|
19
19
|
export default {
|
|
20
|
-
name:
|
|
20
|
+
name: "hy-badge",
|
|
21
21
|
options: {
|
|
22
22
|
addGlobalClass: true,
|
|
23
23
|
virtualHost: true,
|
|
24
|
-
styleIsolation:
|
|
24
|
+
styleIsolation: "shared",
|
|
25
25
|
},
|
|
26
|
-
}
|
|
26
|
+
};
|
|
27
27
|
</script>
|
|
28
28
|
|
|
29
29
|
<script setup lang="ts">
|
|
30
|
+
import { computed } from "vue";
|
|
31
|
+
import type { CSSProperties, PropType } from "vue";
|
|
32
|
+
import type { IBadgeEmit } from "./typing";
|
|
33
|
+
import { addUnit } from "../../utils";
|
|
34
|
+
|
|
30
35
|
/**
|
|
31
36
|
* 该组件一般用于图标右上角显示未读的消息数量,提示用户点击,有圆点和圆包含文字两种形式。
|
|
32
37
|
* @displayName hy-badge
|
|
33
38
|
*/
|
|
34
|
-
defineOptions({})
|
|
35
|
-
import type { IBadgeEmit } from './typing'
|
|
36
|
-
import defaultProps from './props'
|
|
37
|
-
import { computed, type CSSProperties, PropType, toRefs } from 'vue'
|
|
38
|
-
import { addUnit } from '../../utils'
|
|
39
|
+
defineOptions({});
|
|
39
40
|
|
|
40
41
|
// const props = withDefaults(defineProps<IProps>(), defaultProps);
|
|
41
42
|
const props = defineProps({
|
|
@@ -65,7 +66,7 @@ const props = defineProps({
|
|
|
65
66
|
* */
|
|
66
67
|
type: {
|
|
67
68
|
type: String,
|
|
68
|
-
default:
|
|
69
|
+
default: "error",
|
|
69
70
|
},
|
|
70
71
|
/** 当数值为 0 时,是否展示 Badge */
|
|
71
72
|
showZero: {
|
|
@@ -82,7 +83,7 @@ const props = defineProps({
|
|
|
82
83
|
* */
|
|
83
84
|
shape: {
|
|
84
85
|
type: String,
|
|
85
|
-
default:
|
|
86
|
+
default: "circle",
|
|
86
87
|
},
|
|
87
88
|
/**
|
|
88
89
|
* 设置数字的显示方式
|
|
@@ -90,7 +91,7 @@ const props = defineProps({
|
|
|
90
91
|
* */
|
|
91
92
|
numberType: {
|
|
92
93
|
type: String,
|
|
93
|
-
default:
|
|
94
|
+
default: "overflow",
|
|
94
95
|
},
|
|
95
96
|
/** 设置badge的位置偏移,格式为 [x, y],也即设置的为top和right的值,absolute为true时有效 */
|
|
96
97
|
offset: Array<number>,
|
|
@@ -108,60 +109,60 @@ const props = defineProps({
|
|
|
108
109
|
customStyle: {
|
|
109
110
|
type: Object as PropType<CSSProperties>,
|
|
110
111
|
},
|
|
111
|
-
})
|
|
112
|
-
const
|
|
113
|
-
toRefs(props)
|
|
114
|
-
const emit = defineEmits<IBadgeEmit>()
|
|
112
|
+
});
|
|
113
|
+
const emit = defineEmits<IBadgeEmit>();
|
|
115
114
|
|
|
116
115
|
/**
|
|
117
116
|
* @description 整个组件的样式
|
|
118
117
|
* */
|
|
119
118
|
const badgeStyle = computed<CSSProperties>(() => {
|
|
120
|
-
const style: CSSProperties = {}
|
|
121
|
-
if (color
|
|
122
|
-
style.color = color
|
|
119
|
+
const style: CSSProperties = {};
|
|
120
|
+
if (props.color) {
|
|
121
|
+
style.color = props.color;
|
|
123
122
|
}
|
|
124
|
-
if (bgColor
|
|
125
|
-
style.backgroundColor = bgColor
|
|
123
|
+
if (props.bgColor && !props.inverted) {
|
|
124
|
+
style.backgroundColor = props.bgColor;
|
|
126
125
|
}
|
|
127
|
-
if (absolute
|
|
128
|
-
style.position =
|
|
126
|
+
if (props.absolute) {
|
|
127
|
+
style.position = "absolute";
|
|
129
128
|
// 如果有设置offset参数
|
|
130
|
-
if (offset
|
|
129
|
+
if (props.offset && Array.isArray(props.offset)) {
|
|
131
130
|
// top和right分为为offset的第一个和第二个值,如果没有第二个值,则right等于top
|
|
132
|
-
const top = offset
|
|
133
|
-
const right = offset
|
|
134
|
-
style.top = addUnit(top)
|
|
135
|
-
style.left = addUnit(right)
|
|
131
|
+
const top = props.offset[0];
|
|
132
|
+
const right = props.offset[1] || top;
|
|
133
|
+
style.top = addUnit(top);
|
|
134
|
+
style.left = addUnit(right);
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
|
-
return style
|
|
139
|
-
})
|
|
137
|
+
return style;
|
|
138
|
+
});
|
|
140
139
|
/**
|
|
141
140
|
* @description 显示值
|
|
142
141
|
* */
|
|
143
142
|
const showValue = computed(() => {
|
|
144
|
-
switch (numberType
|
|
145
|
-
case
|
|
146
|
-
return Number(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
case
|
|
150
|
-
return Number(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
switch (props.numberType) {
|
|
144
|
+
case "overflow":
|
|
145
|
+
return Number(props.value) > Number(props.max)
|
|
146
|
+
? props.max + "+"
|
|
147
|
+
: props.value;
|
|
148
|
+
case "ellipsis":
|
|
149
|
+
return Number(props.value) > Number(props.max) ? "..." : props.value;
|
|
150
|
+
case "limit":
|
|
151
|
+
return Number(props.value) > 999
|
|
152
|
+
? Number(props.value) >= 9999
|
|
153
|
+
? Math.floor((props.value / 1e4) * 100) / 100 + "w"
|
|
154
|
+
: Math.floor((props.value / 1e3) * 100) / 100 + "k"
|
|
155
|
+
: props.value;
|
|
155
156
|
default:
|
|
156
|
-
return Number(
|
|
157
|
+
return Number(props.value);
|
|
157
158
|
}
|
|
158
|
-
})
|
|
159
|
+
});
|
|
159
160
|
|
|
160
161
|
const onClick = (e: Event) => {
|
|
161
|
-
emit(
|
|
162
|
-
}
|
|
162
|
+
emit("click", e);
|
|
163
|
+
};
|
|
163
164
|
</script>
|
|
164
165
|
|
|
165
166
|
<style lang="scss" scoped>
|
|
166
|
-
@import
|
|
167
|
+
@import "./index.scss";
|
|
167
168
|
</style>
|