hy-app 0.2.13 → 0.2.15
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-action-sheet/hy-action-sheet.vue +81 -13
- package/components/hy-action-sheet/typing.d.ts +1 -3
- package/components/hy-address-picker/hy-address-picker.vue +109 -8
- package/components/hy-address-picker/index.scss +2 -2
- package/components/hy-address-picker/typing.d.ts +39 -30
- package/components/hy-avatar/hy-avatar.vue +78 -4
- package/components/hy-avatar/typing.d.ts +21 -16
- package/components/hy-back-top/hy-back-top.vue +86 -28
- package/components/hy-back-top/typing.d.ts +17 -12
- package/components/hy-badge/hy-badge.vue +114 -43
- package/components/hy-badge/typing.d.ts +20 -15
- package/components/hy-button/HyButton.docgen.js +6 -0
- package/components/hy-button/hy-button.vue +70 -77
- package/components/hy-button/props.ts +40 -41
- package/components/hy-calendar/hy-calendar.vue +290 -143
- package/components/hy-calendar/typing.d.ts +38 -31
- package/components/hy-card/hy-card.vue +139 -36
- package/components/hy-card/typing.d.ts +39 -28
- package/components/hy-cell/hy-cell.vue +131 -67
- package/components/hy-cell/typing.d.ts +6 -1
- package/components/hy-check-button/hy-check-button.vue +101 -32
- package/components/hy-check-button/typing.d.ts +26 -19
- package/components/hy-checkbox/hy-checkbox.vue +167 -78
- package/components/hy-checkbox/typing.d.ts +26 -19
- package/components/hy-code-input/hy-code-input.vue +101 -5
- package/components/hy-code-input/typing.d.ts +9 -0
- package/components/hy-config-provider/hy-config-provider.vue +44 -24
- package/components/hy-config-provider/typing.d.ts +0 -4
- package/components/hy-count-down/hy-count-down.vue +99 -62
- package/components/hy-count-down/typing.d.ts +18 -5
- package/components/hy-count-to/hy-count-to.vue +165 -113
- package/components/hy-count-to/typing.d.ts +15 -11
- package/components/hy-datetime-picker/hy-datetime-picker.vue +338 -232
- package/components/hy-datetime-picker/typing.d.ts +49 -39
- package/components/hy-divider/hy-divider.vue +128 -64
- package/components/hy-divider/typing.d.ts +16 -16
- package/components/hy-dropdown/hy-dropdown.vue +57 -19
- package/components/hy-dropdown/typing.d.ts +14 -14
- package/components/hy-dropdown-item/hy-dropdown-item.vue +34 -5
- package/components/hy-dropdown-item/typing.d.ts +13 -6
- package/components/hy-empty/hy-empty.vue +64 -6
- package/components/hy-empty/typing.d.ts +5 -0
- package/components/hy-float-button/hy-float-button.vue +117 -5
- package/components/hy-float-button/typing.d.ts +7 -0
- package/components/hy-folding-panel/hy-folding-panel.vue +87 -25
- package/components/hy-folding-panel/typing.d.ts +24 -15
- package/components/hy-grid/hy-grid.vue +95 -35
- package/components/hy-grid/typing.d.ts +24 -19
- package/components/hy-icon/hy-icon.vue +84 -6
- package/components/hy-icon/typing.d.ts +5 -0
- package/components/hy-image/hy-image.vue +105 -6
- package/components/hy-image/typing.d.ts +9 -0
- package/components/hy-input/hy-input.vue +277 -130
- package/components/hy-input/props.ts +13 -14
- package/components/hy-input/typing.d.ts +59 -38
- package/components/hy-line/hy-line.vue +65 -25
- package/components/hy-line-progress/hy-line-progress.vue +68 -35
- package/components/hy-list/hy-list.vue +127 -61
- package/components/hy-list/typing.d.ts +19 -12
- package/components/hy-loading/hy-loading.vue +79 -25
- package/components/hy-menu/hy-menu.vue +69 -45
- package/components/hy-menu/typing.d.ts +22 -15
- package/components/hy-modal/hy-modal.vue +91 -4
- package/components/hy-modal/typing.d.ts +11 -0
- package/components/hy-navbar/hy-navbar.vue +105 -25
- package/components/hy-navbar/typing.d.ts +25 -20
- package/components/hy-notice-bar/hy-notice-bar.vue +97 -19
- package/components/hy-notice-bar/typing.d.ts +22 -17
- package/components/hy-notify/hy-notify.vue +106 -54
- package/components/hy-number-step/hy-number-step.vue +211 -120
- package/components/hy-number-step/typing.d.ts +45 -28
- package/components/hy-overlay/hy-overlay.vue +60 -16
- package/components/hy-overlay/typing.d.ts +11 -6
- package/components/hy-pagination/hy-pagination.vue +94 -37
- package/components/hy-pagination/typing.d.ts +20 -11
- package/components/hy-picker/hy-picker.vue +225 -160
- package/components/hy-picker/typing.d.ts +51 -28
- package/components/hy-popover/hy-popover.vue +55 -7
- package/components/hy-popover/typing.d.ts +21 -1
- package/components/hy-popup/hy-popup.vue +164 -99
- package/components/hy-popup/typing.d.ts +11 -0
- package/components/hy-price/hy-price.vue +77 -30
- package/components/hy-price/typing.d.ts +10 -10
- package/components/hy-qrcode/hy-qrcode.vue +75 -5
- package/components/hy-qrcode/typing.d.ts +25 -16
- package/components/hy-radio/hy-radio.vue +169 -88
- package/components/hy-radio/typing.d.ts +29 -22
- package/components/hy-rate/hy-rate.vue +155 -104
- package/components/hy-rate/typing.d.ts +23 -16
- package/components/hy-read-more/hy-read-more.vue +83 -56
- package/components/hy-read-more/typing.d.ts +18 -11
- package/components/hy-scroll-list/hy-scroll-list.vue +69 -58
- package/components/hy-scroll-list/typing.d.ts +14 -7
- package/components/hy-search/hy-search.vue +168 -62
- package/components/hy-search/typing.d.ts +47 -26
- package/components/hy-signature/hy-signature.vue +354 -272
- package/components/hy-signature/typing.d.ts +65 -52
- package/components/hy-slider/hy-slider.vue +208 -160
- package/components/hy-slider/typing.d.ts +28 -17
- package/components/hy-steps/hy-steps.vue +125 -99
- package/components/hy-steps/typing.d.ts +21 -14
- package/components/hy-submit-bar/hy-submit-bar.vue +129 -48
- package/components/hy-submit-bar/typing.d.ts +30 -23
- package/components/hy-subsection/hy-subsection.vue +139 -96
- package/components/hy-subsection/typing.d.ts +23 -16
- package/components/hy-swipe-action/hy-swipe-action.vue +161 -135
- package/components/hy-swipe-action/typing.d.ts +26 -17
- package/components/hy-swiper/hy-swiper.vue +178 -73
- package/components/hy-swiper/typing.d.ts +37 -28
- package/components/hy-switch/hy-switch.vue +107 -60
- package/components/hy-switch/typing.d.ts +25 -18
- package/components/hy-tabs/hy-tabs.vue +170 -160
- package/components/hy-tabs/typing.d.ts +36 -22
- package/components/hy-tag/hy-tag.vue +133 -58
- package/components/hy-tag/typing.d.ts +26 -18
- package/components/hy-text/hy-text.vue +106 -6
- package/components/hy-text/typing.d.ts +31 -26
- package/components/hy-textarea/hy-textarea.vue +183 -89
- package/components/hy-textarea/typing.d.ts +41 -24
- package/components/hy-tooltip/hy-tooltip.vue +145 -101
- package/components/hy-tooltip/typing.d.ts +18 -13
- package/components/hy-transition/hy-transition.vue +48 -13
- package/components/hy-transition/typing.d.ts +17 -0
- package/components/hy-upload/hy-upload.vue +113 -148
- package/components/hy-upload/typing.d.ts +71 -71
- package/components/hy-warn/hy-warn.vue +79 -36
- package/components/hy-warn/typing.d.ts +18 -11
- package/components/hy-waterfall/hy-waterfall.vue +90 -77
- package/components/hy-watermark/hy-watermark.vue +82 -5
- package/components/hy-watermark/typing.d.ts +20 -20
- package/global.d.ts +39 -59
- package/package.json +5 -13
- package/utils/inspect.ts +3 -1
- package/web-types.json +1 -1
- package/component-helper.ts +0 -177
- package/components.json +0 -3287
- package/dist/attributes.json +0 -1
- package/dist/docs/components/hy-action-sheet/hy-action-sheet.md +0 -41
- package/dist/docs/components/hy-address-picker/hy-address-picker.md +0 -25
- package/dist/docs/components/hy-avatar/hy-avatar.md +0 -19
- package/dist/docs/components/hy-back-top/hy-back-top.md +0 -19
- package/dist/docs/components/hy-badge/hy-badge.md +0 -13
- package/dist/docs/components/hy-button/hy-button.md +0 -61
- package/dist/docs/components/hy-calendar/header.md +0 -17
- package/dist/docs/components/hy-calendar/hy-calendar.md +0 -27
- package/dist/docs/components/hy-calendar/month.md +0 -38
- package/dist/docs/components/hy-card/hy-card.md +0 -24
- package/dist/docs/components/hy-cell/hy-cell.md +0 -26
- package/dist/docs/components/hy-check-button/hy-check-button.md +0 -14
- package/dist/docs/components/hy-checkbox/hy-checkbox.md +0 -21
- package/dist/docs/components/hy-code-input/hy-code-input.md +0 -15
- package/dist/docs/components/hy-config-provider/hy-config-provider.md +0 -13
- package/dist/docs/components/hy-count-down/hy-count-down.md +0 -34
- package/dist/docs/components/hy-count-to/hy-count-to.md +0 -31
- package/dist/docs/components/hy-datetime-picker/hy-datetime-picker.md +0 -25
- package/dist/docs/components/hy-divider/hy-divider.md +0 -13
- package/dist/docs/components/hy-dropdown/hy-dropdown.md +0 -13
- package/dist/docs/components/hy-dropdown-item/hy-dropdown-item.md +0 -20
- package/dist/docs/components/hy-empty/hy-empty.md +0 -20
- package/dist/docs/components/hy-float-button/hy-float-button.md +0 -20
- package/dist/docs/components/hy-folding-panel/hy-folding-panel.md +0 -24
- package/dist/docs/components/hy-form/hy-form.md +0 -29
- package/dist/docs/components/hy-grid/hy-grid.md +0 -19
- package/dist/docs/components/hy-icon/hy-icon.md +0 -13
- package/dist/docs/components/hy-image/hy-image.md +0 -22
- package/dist/docs/components/hy-input/hy-input.md +0 -29
- package/dist/docs/components/hy-line/hy-line.md +0 -7
- package/dist/docs/components/hy-line-progress/hy-line-progress.md +0 -13
- package/dist/docs/components/hy-list/hy-list.md +0 -25
- package/dist/docs/components/hy-loading/hy-loading.md +0 -14
- package/dist/docs/components/hy-login/ThePhoneLogin.md +0 -20
- package/dist/docs/components/hy-login/TheUserLogin.md +0 -44
- package/dist/docs/components/hy-login/hy-login.md +0 -14
- package/dist/docs/components/hy-menu/hy-menu.md +0 -21
- package/dist/docs/components/hy-modal/hy-modal.md +0 -23
- package/dist/docs/components/hy-navbar/hy-navbar.md +0 -22
- package/dist/docs/components/hy-notice-bar/hy-column-notice.md +0 -20
- package/dist/docs/components/hy-notice-bar/hy-notice-bar.md +0 -14
- package/dist/docs/components/hy-notice-bar/hy-row-notice.md +0 -20
- package/dist/docs/components/hy-notify/hy-notify.md +0 -23
- package/dist/docs/components/hy-number-step/hy-number-step.md +0 -27
- package/dist/docs/components/hy-overlay/hy-overlay.md +0 -19
- package/dist/docs/components/hy-pagination/hy-pagination.md +0 -14
- package/dist/docs/components/hy-parse/hy-parse.md +0 -46
- package/dist/docs/components/hy-parse/node/node.md +0 -7
- package/dist/docs/components/hy-picker/hy-picker.md +0 -32
- package/dist/docs/components/hy-popover/hy-popover.md +0 -34
- package/dist/docs/components/hy-popup/hy-popup.md +0 -22
- package/dist/docs/components/hy-price/hy-price.md +0 -13
- package/dist/docs/components/hy-qrcode/hy-qrcode.md +0 -15
- package/dist/docs/components/hy-radio/hy-radio.md +0 -21
- package/dist/docs/components/hy-rate/hy-rate.md +0 -14
- package/dist/docs/components/hy-read-more/hy-read-more.md +0 -21
- package/dist/docs/components/hy-scroll-list/hy-scroll-list.md +0 -21
- package/dist/docs/components/hy-search/hy-search.md +0 -27
- package/dist/docs/components/hy-signature/hy-signature.md +0 -45
- package/dist/docs/components/hy-slider/hy-slider.md +0 -24
- package/dist/docs/components/hy-status-bar/hy-status-bar.md +0 -13
- package/dist/docs/components/hy-steps/hy-steps.md +0 -23
- package/dist/docs/components/hy-submit-bar/hy-submit-bar.md +0 -21
- package/dist/docs/components/hy-subsection/hy-subsection.md +0 -14
- package/dist/docs/components/hy-swipe-action/hy-swipe-action.md +0 -29
- package/dist/docs/components/hy-swiper/hy-swiper-indicator.md +0 -23
- package/dist/docs/components/hy-swiper/hy-swiper.md +0 -22
- package/dist/docs/components/hy-switch/hy-switch.md +0 -20
- package/dist/docs/components/hy-tabBar/hy-tabBar.md +0 -13
- package/dist/docs/components/hy-tabs/hy-tabs.md +0 -27
- package/dist/docs/components/hy-tag/hy-tag.md +0 -21
- package/dist/docs/components/hy-text/hy-text.md +0 -13
- package/dist/docs/components/hy-textarea/hy-textarea.md +0 -19
- package/dist/docs/components/hy-toast/hy-toast.md +0 -17
- package/dist/docs/components/hy-tooltip/hy-tooltip.md +0 -13
- package/dist/docs/components/hy-transition/hy-transition.md +0 -25
- package/dist/docs/components/hy-upload/hy-upload.md +0 -25
- package/dist/docs/components/hy-warn/hy-warn.md +0 -14
- package/dist/docs/components/hy-waterfall/hy-waterfall.md +0 -30
- package/dist/docs/components/hy-watermark/hy-watermark.md +0 -7
- package/dist/docs/components/message/TheMessage.md +0 -17
- package/dist/docs/components/yk-dialog/yk-dialog.md +0 -7
- package/dist/tags.json +0 -1
- package/dist/web-types.json +0 -1
- package/docgen.config.js +0 -14
- package/web-types.config.js +0 -7
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="hy-rate" :id="elId" ref="hy-rate" :style="[customStyle]">
|
|
3
|
-
<view
|
|
4
|
-
class="hy-rate__content"
|
|
5
|
-
@touchmove.stop="touchMove"
|
|
6
|
-
@touchend.stop="touchEnd"
|
|
7
|
-
>
|
|
3
|
+
<view class="hy-rate__content" @touchmove.stop="touchMove" @touchend.stop="touchEnd">
|
|
8
4
|
<view
|
|
9
5
|
class="hy-rate__content__item cursor-pointer"
|
|
10
6
|
v-for="(item, index) in Number(count)"
|
|
@@ -19,11 +15,7 @@
|
|
|
19
15
|
<HyIcon
|
|
20
16
|
:name="Math.floor(activeIndex) > index ? activeIcon : inactiveIcon"
|
|
21
17
|
:color="
|
|
22
|
-
disabled
|
|
23
|
-
? '#c8c9cc'
|
|
24
|
-
: Math.floor(activeIndex) > index
|
|
25
|
-
? activeColor
|
|
26
|
-
: inactiveColor
|
|
18
|
+
disabled ? '#c8c9cc' : Math.floor(activeIndex) > index ? activeColor : inactiveColor
|
|
27
19
|
"
|
|
28
20
|
:custom-style="{
|
|
29
21
|
padding: `0 ${addUnit(gutter / 2)}`,
|
|
@@ -45,11 +37,7 @@
|
|
|
45
37
|
<HyIcon
|
|
46
38
|
:name="Math.ceil(activeIndex) > index ? activeIcon : inactiveIcon"
|
|
47
39
|
:color="
|
|
48
|
-
disabled
|
|
49
|
-
? '#c8c9cc'
|
|
50
|
-
: Math.ceil(activeIndex) > index
|
|
51
|
-
? activeColor
|
|
52
|
-
: inactiveColor
|
|
40
|
+
disabled ? '#c8c9cc' : Math.ceil(activeIndex) > index ? activeColor : inactiveColor
|
|
53
41
|
"
|
|
54
42
|
:custom-style="{
|
|
55
43
|
padding: `0 ${addUnit(gutter / 2)}`,
|
|
@@ -63,85 +51,152 @@
|
|
|
63
51
|
</template>
|
|
64
52
|
|
|
65
53
|
<script lang="ts">
|
|
54
|
+
/**
|
|
55
|
+
* 该组件一般用于满意度调查,星型评分的场景。
|
|
56
|
+
* @displayName hy-rate
|
|
57
|
+
*/
|
|
58
|
+
defineOptions({})
|
|
66
59
|
export default {
|
|
67
60
|
name: 'hy-rate',
|
|
68
61
|
options: {
|
|
69
62
|
addGlobalClass: true,
|
|
70
63
|
virtualHost: true,
|
|
71
|
-
styleIsolation: 'shared'
|
|
72
|
-
}
|
|
64
|
+
styleIsolation: 'shared',
|
|
65
|
+
},
|
|
73
66
|
}
|
|
74
67
|
</script>
|
|
75
68
|
|
|
76
69
|
<script setup lang="ts">
|
|
77
|
-
import { addUnit, getRect, guid, range, sleep } from
|
|
78
|
-
import { ref, watch, toRefs, onMounted, getCurrentInstance } from
|
|
79
|
-
import type
|
|
80
|
-
import
|
|
70
|
+
import { addUnit, getRect, guid, range, sleep } from '../../utils'
|
|
71
|
+
import { ref, watch, toRefs, onMounted, getCurrentInstance } from 'vue'
|
|
72
|
+
import type { CSSProperties, PropType } from 'vue'
|
|
73
|
+
import type { IRateEmits } from './typing'
|
|
81
74
|
|
|
82
75
|
// 组件
|
|
83
|
-
import HyIcon from
|
|
76
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
77
|
+
import { IconConfig } from '@/package'
|
|
84
78
|
|
|
85
|
-
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
86
|
-
const {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
79
|
+
// const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
80
|
+
const props = defineProps({
|
|
81
|
+
/** v-model绑定的值 */
|
|
82
|
+
modelValue: {
|
|
83
|
+
type: Number,
|
|
84
|
+
default: 1,
|
|
85
|
+
},
|
|
86
|
+
/** 星星的默认最多数 */
|
|
87
|
+
count: {
|
|
88
|
+
type: Number,
|
|
89
|
+
default: 5,
|
|
90
|
+
},
|
|
91
|
+
/** 是否禁用 */
|
|
92
|
+
disabled: {
|
|
93
|
+
type: Boolean,
|
|
94
|
+
default: false,
|
|
95
|
+
},
|
|
96
|
+
/** 是否只读 */
|
|
97
|
+
readonly: {
|
|
98
|
+
type: Boolean,
|
|
99
|
+
default: false,
|
|
100
|
+
},
|
|
101
|
+
/** 星星的大小 */
|
|
102
|
+
size: {
|
|
103
|
+
type: Number,
|
|
104
|
+
default: 18,
|
|
105
|
+
},
|
|
106
|
+
/** 未激活星星的颜色 */
|
|
107
|
+
inactiveColor: {
|
|
108
|
+
type: String,
|
|
109
|
+
default: '#b2b2b2',
|
|
110
|
+
},
|
|
111
|
+
/** 激活星星的颜色 */
|
|
112
|
+
activeColor: {
|
|
113
|
+
type: String,
|
|
114
|
+
default: '#FFF00D',
|
|
115
|
+
},
|
|
116
|
+
/** 星星之间的间距 */
|
|
117
|
+
gutter: {
|
|
118
|
+
type: Number,
|
|
119
|
+
default: 4,
|
|
120
|
+
},
|
|
121
|
+
/** 最小星星数量 */
|
|
122
|
+
minCount: {
|
|
123
|
+
type: Number,
|
|
124
|
+
default: 1,
|
|
125
|
+
},
|
|
126
|
+
/** 是否允许半星 */
|
|
127
|
+
allowHalf: {
|
|
128
|
+
type: Boolean,
|
|
129
|
+
default: false,
|
|
130
|
+
},
|
|
131
|
+
/** 激活状态的图标 */
|
|
132
|
+
activeIcon: {
|
|
133
|
+
type: String,
|
|
134
|
+
default: IconConfig.STAR_FILL,
|
|
135
|
+
},
|
|
136
|
+
/** 未激活状态的图标 */
|
|
137
|
+
inactiveIcon: {
|
|
138
|
+
type: String,
|
|
139
|
+
default: IconConfig.STAR,
|
|
140
|
+
},
|
|
141
|
+
/** 是否可触摸 */
|
|
142
|
+
touchable: {
|
|
143
|
+
type: Boolean,
|
|
144
|
+
default: true,
|
|
145
|
+
},
|
|
146
|
+
/** 定义需要用到的外部样式 */
|
|
147
|
+
customStyle: {
|
|
148
|
+
type: Object as PropType<CSSProperties>,
|
|
149
|
+
},
|
|
150
|
+
/** 自定义外部类名 */
|
|
151
|
+
customClass: String,
|
|
152
|
+
})
|
|
153
|
+
const { modelValue, touchable, minCount, count, disabled, readonly, allowHalf } = toRefs(props)
|
|
154
|
+
const emit = defineEmits<IRateEmits>()
|
|
96
155
|
|
|
97
|
-
const elId = guid()
|
|
98
|
-
const elClass = guid()
|
|
99
|
-
const rateBoxLeft = ref<number>(0)
|
|
100
|
-
const activeIndex = ref(modelValue.value)
|
|
156
|
+
const elId = guid()
|
|
157
|
+
const elClass = guid()
|
|
158
|
+
const rateBoxLeft = ref<number>(0)
|
|
159
|
+
const activeIndex = ref(modelValue.value)
|
|
101
160
|
// 每个星星的宽度
|
|
102
|
-
const rateWidth = ref(0)
|
|
161
|
+
const rateWidth = ref(0)
|
|
103
162
|
// 标识是否正在滑动,由于iOS事件上touch比click先触发,导致快速滑动结束后,接着触发click,导致事件混乱而出错
|
|
104
|
-
const moving = ref(false)
|
|
163
|
+
const moving = ref(false)
|
|
105
164
|
|
|
106
165
|
watch(
|
|
107
166
|
() => modelValue.value,
|
|
108
167
|
(newValue) => {
|
|
109
|
-
activeIndex.value = newValue
|
|
168
|
+
activeIndex.value = newValue
|
|
110
169
|
},
|
|
111
|
-
)
|
|
170
|
+
)
|
|
112
171
|
watch(
|
|
113
172
|
() => activeIndex.value,
|
|
114
173
|
(newVal) => {
|
|
115
|
-
emitEvent()
|
|
174
|
+
emitEvent()
|
|
116
175
|
},
|
|
117
|
-
)
|
|
118
|
-
const instance = getCurrentInstance()
|
|
176
|
+
)
|
|
177
|
+
const instance = getCurrentInstance()
|
|
119
178
|
|
|
120
179
|
onMounted(() => {
|
|
121
|
-
init()
|
|
122
|
-
})
|
|
180
|
+
init()
|
|
181
|
+
})
|
|
123
182
|
|
|
124
183
|
const init = () => {
|
|
125
184
|
sleep(300).then(async () => {
|
|
126
|
-
await getRateItemRect()
|
|
127
|
-
await getRateIconWrapRect()
|
|
128
|
-
})
|
|
129
|
-
}
|
|
185
|
+
await getRateItemRect()
|
|
186
|
+
await getRateIconWrapRect()
|
|
187
|
+
})
|
|
188
|
+
}
|
|
130
189
|
|
|
131
190
|
/**
|
|
132
191
|
* @description 获取评分组件盒子的布局信息
|
|
133
192
|
* */
|
|
134
193
|
const getRateItemRect = async () => {
|
|
135
|
-
await sleep()
|
|
194
|
+
await sleep()
|
|
136
195
|
// #ifndef APP-NVUE
|
|
137
|
-
const res: UniApp.NodeInfo = (await getRect(
|
|
138
|
-
|
|
139
|
-
false,
|
|
140
|
-
instance,
|
|
141
|
-
)) as UniApp.NodeInfo;
|
|
142
|
-
rateBoxLeft.value = res.left || 0;
|
|
196
|
+
const res: UniApp.NodeInfo = (await getRect(`#${elId}`, false, instance)) as UniApp.NodeInfo
|
|
197
|
+
rateBoxLeft.value = res.left || 0
|
|
143
198
|
// #endif
|
|
144
|
-
}
|
|
199
|
+
}
|
|
145
200
|
|
|
146
201
|
/**
|
|
147
202
|
* @description 获取单个星星的尺寸
|
|
@@ -149,104 +204,100 @@ const getRateItemRect = async () => {
|
|
|
149
204
|
const getRateIconWrapRect = async () => {
|
|
150
205
|
// uView封装的获取节点的方法,详见文档
|
|
151
206
|
// #ifndef APP-NVUE
|
|
152
|
-
const res: UniApp.NodeInfo = (await getRect(
|
|
153
|
-
|
|
154
|
-
false,
|
|
155
|
-
instance,
|
|
156
|
-
)) as UniApp.NodeInfo;
|
|
157
|
-
rateWidth.value = res.width || 0;
|
|
207
|
+
const res: UniApp.NodeInfo = (await getRect(`.${elClass}`, false, instance)) as UniApp.NodeInfo
|
|
208
|
+
rateWidth.value = res.width || 0
|
|
158
209
|
// #endif
|
|
159
|
-
}
|
|
210
|
+
}
|
|
160
211
|
// 手指滑动
|
|
161
212
|
const touchMove = (e: TouchEvent) => {
|
|
162
213
|
// 如果禁止通过手动滑动选择,返回
|
|
163
214
|
if (!touchable.value) {
|
|
164
|
-
return
|
|
215
|
+
return
|
|
165
216
|
}
|
|
166
|
-
e.stopPropagation()
|
|
167
|
-
const x = e.changedTouches[0].pageX
|
|
168
|
-
getActiveIndex(x)
|
|
169
|
-
}
|
|
217
|
+
e.stopPropagation()
|
|
218
|
+
const x = e.changedTouches[0].pageX
|
|
219
|
+
getActiveIndex(x)
|
|
220
|
+
}
|
|
170
221
|
// 停止滑动
|
|
171
222
|
const touchEnd = (e: TouchEvent) => {
|
|
172
223
|
// 如果禁止通过手动滑动选择,返回
|
|
173
224
|
if (!touchable.value) {
|
|
174
|
-
return
|
|
225
|
+
return
|
|
175
226
|
}
|
|
176
|
-
e.stopPropagation()
|
|
177
|
-
const x = e.changedTouches[0].pageX
|
|
178
|
-
getActiveIndex(x)
|
|
179
|
-
}
|
|
227
|
+
e.stopPropagation()
|
|
228
|
+
const x = e.changedTouches[0].pageX
|
|
229
|
+
getActiveIndex(x)
|
|
230
|
+
}
|
|
180
231
|
// 通过点击,直接选中
|
|
181
232
|
const clickHandler = (e: TouchEvent) => {
|
|
182
233
|
// if (moving.value) {
|
|
183
234
|
// return;
|
|
184
235
|
// }
|
|
185
|
-
e.stopPropagation()
|
|
186
|
-
let x = 0
|
|
236
|
+
e.stopPropagation()
|
|
237
|
+
let x = 0
|
|
187
238
|
// #ifndef APP-NVUE
|
|
188
|
-
x = e.changedTouches[0].pageX
|
|
239
|
+
x = e.changedTouches[0].pageX
|
|
189
240
|
// #endif
|
|
190
|
-
getActiveIndex(x, true)
|
|
191
|
-
}
|
|
241
|
+
getActiveIndex(x, true)
|
|
242
|
+
}
|
|
192
243
|
// 发出事件
|
|
193
244
|
const emitEvent = () => {
|
|
194
245
|
// 发出change事件
|
|
195
|
-
emit(
|
|
246
|
+
emit('change', activeIndex.value)
|
|
196
247
|
// 同时修改双向绑定的值
|
|
197
|
-
emit(
|
|
198
|
-
}
|
|
248
|
+
emit('update:modelValue', activeIndex.value)
|
|
249
|
+
}
|
|
199
250
|
// 获取当前激活的评分图标
|
|
200
251
|
const getActiveIndex = (x: number, isClick = false) => {
|
|
201
252
|
if (disabled.value || readonly.value) {
|
|
202
|
-
return
|
|
253
|
+
return
|
|
203
254
|
}
|
|
204
255
|
// 判断当前操作的点的x坐标值,是否在允许的边界范围内
|
|
205
|
-
const allRateWidth = rateWidth.value * count.value + rateBoxLeft.value
|
|
256
|
+
const allRateWidth = rateWidth.value * count.value + rateBoxLeft.value
|
|
206
257
|
// 如果小于第一个图标的左边界,设置为最小值,如果大于所有图标的宽度,则设置为最大值
|
|
207
|
-
x = range(rateBoxLeft.value, allRateWidth, x) - rateBoxLeft.value
|
|
258
|
+
x = range(rateBoxLeft.value, allRateWidth, x) - rateBoxLeft.value
|
|
208
259
|
// 滑动点相对于评分盒子左边的距离
|
|
209
|
-
const distance = x
|
|
260
|
+
const distance = x
|
|
210
261
|
// 滑动的距离,相当于多少颗星星
|
|
211
|
-
let index
|
|
262
|
+
let index
|
|
212
263
|
// 判断是否允许半星
|
|
213
264
|
if (allowHalf.value) {
|
|
214
|
-
index = Math.floor(distance / rateWidth.value)
|
|
265
|
+
index = Math.floor(distance / rateWidth.value)
|
|
215
266
|
// 取余,判断小数的区间范围
|
|
216
|
-
const decimal = distance % rateWidth.value
|
|
267
|
+
const decimal = distance % rateWidth.value
|
|
217
268
|
if (decimal <= rateWidth.value / 2 && decimal > 0) {
|
|
218
|
-
index += 0.5
|
|
269
|
+
index += 0.5
|
|
219
270
|
} else if (decimal > rateWidth.value / 2) {
|
|
220
|
-
index
|
|
271
|
+
index++
|
|
221
272
|
}
|
|
222
273
|
} else {
|
|
223
|
-
index = Math.floor(distance / rateWidth.value)
|
|
274
|
+
index = Math.floor(distance / rateWidth.value)
|
|
224
275
|
// 取余,判断小数的区间范围
|
|
225
|
-
const decimal = distance % rateWidth.value
|
|
276
|
+
const decimal = distance % rateWidth.value
|
|
226
277
|
// 非半星时,只有超过了图标的一半距离,才认为是选择了这颗星
|
|
227
278
|
if (isClick) {
|
|
228
|
-
if (decimal > 0) index
|
|
279
|
+
if (decimal > 0) index++
|
|
229
280
|
} else {
|
|
230
|
-
if (decimal > rateWidth.value / 2) index
|
|
281
|
+
if (decimal > rateWidth.value / 2) index++
|
|
231
282
|
}
|
|
232
283
|
}
|
|
233
|
-
activeIndex.value = Math.min(index, count.value)
|
|
284
|
+
activeIndex.value = Math.min(index, count.value)
|
|
234
285
|
// 对最少颗星星的限制
|
|
235
286
|
if (activeIndex.value < minCount.value) {
|
|
236
|
-
activeIndex.value = minCount.value
|
|
287
|
+
activeIndex.value = minCount.value
|
|
237
288
|
}
|
|
238
289
|
|
|
239
290
|
// 设置延时为了让click事件在touchmove之前触发
|
|
240
291
|
setTimeout(() => {
|
|
241
|
-
moving.value = true
|
|
242
|
-
}, 10)
|
|
292
|
+
moving.value = true
|
|
293
|
+
}, 10)
|
|
243
294
|
// 一定时间后,取消标识为移动中状态,是为了让click事件无效
|
|
244
295
|
setTimeout(() => {
|
|
245
|
-
moving.value = false
|
|
246
|
-
}, 10)
|
|
247
|
-
}
|
|
296
|
+
moving.value = false
|
|
297
|
+
}, 10)
|
|
298
|
+
}
|
|
248
299
|
</script>
|
|
249
300
|
|
|
250
301
|
<style lang="scss" scoped>
|
|
251
|
-
@import
|
|
302
|
+
@import './index.scss';
|
|
252
303
|
</style>
|
|
@@ -1,60 +1,67 @@
|
|
|
1
|
-
import type { CSSProperties } from
|
|
1
|
+
import type { CSSProperties } from 'vue'
|
|
2
2
|
|
|
3
3
|
export default interface HyRateProps {
|
|
4
4
|
/**
|
|
5
5
|
* @description v-model绑定的值
|
|
6
6
|
* */
|
|
7
|
-
modelValue: number
|
|
7
|
+
modelValue: number
|
|
8
8
|
/**
|
|
9
|
-
* @description
|
|
9
|
+
* @description 星星的默认最多数
|
|
10
10
|
* */
|
|
11
|
-
count?: number
|
|
11
|
+
count?: number
|
|
12
12
|
/**
|
|
13
13
|
* @description 是否禁用
|
|
14
14
|
* */
|
|
15
|
-
disabled?: boolean
|
|
15
|
+
disabled?: boolean
|
|
16
16
|
/**
|
|
17
17
|
* @description 是否只读
|
|
18
18
|
* */
|
|
19
|
-
readonly?: boolean
|
|
19
|
+
readonly?: boolean
|
|
20
20
|
/**
|
|
21
21
|
* @description 星星的大小
|
|
22
22
|
* */
|
|
23
|
-
size?: number | string
|
|
23
|
+
size?: number | string
|
|
24
24
|
/**
|
|
25
25
|
* @description 未激活星星的颜色
|
|
26
26
|
* */
|
|
27
|
-
inactiveColor?: string
|
|
27
|
+
inactiveColor?: string
|
|
28
28
|
/**
|
|
29
29
|
* @description 激活星星的颜色
|
|
30
30
|
* */
|
|
31
|
-
activeColor?: string
|
|
31
|
+
activeColor?: string
|
|
32
32
|
/**
|
|
33
33
|
* @description 星星之间的间距
|
|
34
34
|
* */
|
|
35
|
-
gutter?: number
|
|
35
|
+
gutter?: number
|
|
36
36
|
/**
|
|
37
37
|
* @description 最小星星数量
|
|
38
38
|
* */
|
|
39
|
-
minCount?: number
|
|
39
|
+
minCount?: number
|
|
40
40
|
/**
|
|
41
41
|
* @description 是否允许半星
|
|
42
42
|
* */
|
|
43
|
-
allowHalf?: boolean
|
|
43
|
+
allowHalf?: boolean
|
|
44
44
|
/**
|
|
45
45
|
* @description 激活状态的图标
|
|
46
46
|
* */
|
|
47
|
-
activeIcon?: string
|
|
47
|
+
activeIcon?: string
|
|
48
48
|
/**
|
|
49
49
|
* @description 未激活状态的图标
|
|
50
50
|
* */
|
|
51
|
-
inactiveIcon?: string
|
|
51
|
+
inactiveIcon?: string
|
|
52
52
|
/**
|
|
53
53
|
* @description 是否可触摸
|
|
54
54
|
* */
|
|
55
|
-
touchable?: boolean
|
|
55
|
+
touchable?: boolean
|
|
56
56
|
/**
|
|
57
57
|
* @description 自定义样式
|
|
58
58
|
* */
|
|
59
|
-
customStyle?: CSSProperties
|
|
59
|
+
customStyle?: CSSProperties
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface IRateEmits {
|
|
63
|
+
/** 选中的星星发生变化时触发 */
|
|
64
|
+
(e: 'change', index: number): void
|
|
65
|
+
/** 更新值触发 */
|
|
66
|
+
(e: 'update:modelValue', index: number): void
|
|
60
67
|
}
|
|
@@ -3,26 +3,16 @@
|
|
|
3
3
|
<view
|
|
4
4
|
class="hy-read-more__content"
|
|
5
5
|
:style="{
|
|
6
|
-
height:
|
|
7
|
-
isLongContent && status === 'close'
|
|
8
|
-
? addUnit(showHeight)
|
|
9
|
-
: addUnit(contentHeight),
|
|
6
|
+
height: isLongContent && status === 'close' ? addUnit(showHeight) : addUnit(contentHeight),
|
|
10
7
|
textIndent: textIndent,
|
|
11
8
|
}"
|
|
12
9
|
>
|
|
13
|
-
<view
|
|
14
|
-
class="hy-read-more__content__inner"
|
|
15
|
-
ref="hy-read-more__content__inner"
|
|
16
|
-
:class="[elId]"
|
|
17
|
-
>
|
|
10
|
+
<view class="hy-read-more__content__inner" ref="hy-read-more__content__inner" :class="[elId]">
|
|
18
11
|
<slot></slot>
|
|
19
12
|
</view>
|
|
20
13
|
</view>
|
|
21
14
|
<view
|
|
22
|
-
:class="[
|
|
23
|
-
'hy-read-more__toggle',
|
|
24
|
-
status !== 'open' && 'hy-read-more__toggle--mask',
|
|
25
|
-
]"
|
|
15
|
+
:class="['hy-read-more__toggle', status !== 'open' && 'hy-read-more__toggle--mask']"
|
|
26
16
|
:style="[innerShadowStyle]"
|
|
27
17
|
v-if="isLongContent"
|
|
28
18
|
>
|
|
@@ -35,8 +25,9 @@
|
|
|
35
25
|
lineHeight: addUnit(fontSize),
|
|
36
26
|
marginRight: '5px',
|
|
37
27
|
}"
|
|
38
|
-
>{{ status === "close" ? closeText : openText }}</text
|
|
39
28
|
>
|
|
29
|
+
{{ status === 'close' ? closeText : openText }}
|
|
30
|
+
</text>
|
|
40
31
|
<view class="hy-read-more__toggle__icon">
|
|
41
32
|
<HyIcon
|
|
42
33
|
:color="color"
|
|
@@ -51,82 +42,118 @@
|
|
|
51
42
|
</template>
|
|
52
43
|
|
|
53
44
|
<script lang="ts">
|
|
45
|
+
/**
|
|
46
|
+
* 该组件一般用于内容较长,预先收起一部分,点击展开全部内容的场景。
|
|
47
|
+
* @displayName hy-read-more
|
|
48
|
+
*/
|
|
49
|
+
defineOptions({})
|
|
54
50
|
export default {
|
|
55
51
|
name: 'hy-read-more',
|
|
56
52
|
options: {
|
|
57
53
|
addGlobalClass: true,
|
|
58
54
|
virtualHost: true,
|
|
59
|
-
styleIsolation: 'shared'
|
|
60
|
-
}
|
|
55
|
+
styleIsolation: 'shared',
|
|
56
|
+
},
|
|
61
57
|
}
|
|
62
58
|
</script>
|
|
63
59
|
|
|
64
60
|
<script setup lang="ts">
|
|
65
|
-
import {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
onMounted,
|
|
71
|
-
getCurrentInstance,
|
|
72
|
-
} from "vue";
|
|
73
|
-
import defaultProps from "./props";
|
|
74
|
-
import type IProps from "./typing";
|
|
75
|
-
import { addUnit, getRect, guid, sleep } from "../../utils";
|
|
76
|
-
import { IconConfig } from "../../config";
|
|
61
|
+
import { computed, toRefs, ref, onMounted, getCurrentInstance } from 'vue'
|
|
62
|
+
import type { CSSProperties, PropType } from 'vue'
|
|
63
|
+
import type { IReadMoreEmits } from './typing'
|
|
64
|
+
import { addUnit, getRect, guid, sleep } from '../../utils'
|
|
65
|
+
import { IconConfig } from '../../config'
|
|
77
66
|
|
|
78
67
|
// 组件
|
|
79
|
-
import HyIcon from
|
|
68
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
80
69
|
|
|
81
|
-
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
82
|
-
const
|
|
83
|
-
|
|
70
|
+
// const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
71
|
+
const props = defineProps({
|
|
72
|
+
/** 内容超出此高度才会显示展开全文按钮,单位px */
|
|
73
|
+
showHeight: {
|
|
74
|
+
type: [String, Number],
|
|
75
|
+
default: 200,
|
|
76
|
+
},
|
|
77
|
+
/** 展开后是否显示收起按钮 */
|
|
78
|
+
toggle: {
|
|
79
|
+
type: Boolean,
|
|
80
|
+
default: true,
|
|
81
|
+
},
|
|
82
|
+
/** 关闭时的提示文字 */
|
|
83
|
+
closeText: {
|
|
84
|
+
type: String,
|
|
85
|
+
default: '展开阅读全文',
|
|
86
|
+
},
|
|
87
|
+
/** 展开时的提示文字 */
|
|
88
|
+
openText: {
|
|
89
|
+
type: String,
|
|
90
|
+
default: '收起',
|
|
91
|
+
},
|
|
92
|
+
/** 提示文字的颜色 */
|
|
93
|
+
color: String,
|
|
94
|
+
/** 提示文字的大小,单位px */
|
|
95
|
+
fontSize: {
|
|
96
|
+
type: [String, Number],
|
|
97
|
+
default: 14,
|
|
98
|
+
},
|
|
99
|
+
/** 段落首行缩进的字符个数 */
|
|
100
|
+
textIndent: {
|
|
101
|
+
type: String,
|
|
102
|
+
default: '2em',
|
|
103
|
+
},
|
|
104
|
+
/** 用于在 open 和 close 事件中当作回调参数返回 */
|
|
105
|
+
name: String,
|
|
106
|
+
/** 显示阴影的样式 */
|
|
107
|
+
shadowStyle: Object as PropType<CSSProperties>,
|
|
108
|
+
})
|
|
109
|
+
const { shadowStyle, toggle, name, showHeight } = toRefs(props)
|
|
110
|
+
const emit = defineEmits<IReadMoreEmits>()
|
|
84
111
|
|
|
85
|
-
const isLongContent = ref<boolean>(false)
|
|
86
|
-
const status = ref<
|
|
87
|
-
const elId = ref<string>(guid())
|
|
88
|
-
const contentHeight = ref<number>(100)
|
|
112
|
+
const isLongContent = ref<boolean>(false) // 是否需要隐藏一部分内容
|
|
113
|
+
const status = ref<'close' | 'open'>('close') // 当前隐藏与显示的状态,close-收起状态,open-展开状态
|
|
114
|
+
const elId = ref<string>(guid()) // 生成唯一class
|
|
115
|
+
const contentHeight = ref<number>(100) // 内容高度
|
|
89
116
|
|
|
90
117
|
const innerShadowStyle = computed<CSSProperties>(() => {
|
|
91
|
-
if (status.value ===
|
|
92
|
-
else return shadowStyle.value
|
|
93
|
-
})
|
|
118
|
+
if (status.value === 'open') return {}
|
|
119
|
+
else return shadowStyle.value
|
|
120
|
+
})
|
|
94
121
|
|
|
95
122
|
onMounted(() => {
|
|
96
|
-
getContentHeight()
|
|
97
|
-
})
|
|
123
|
+
getContentHeight()
|
|
124
|
+
})
|
|
98
125
|
|
|
99
126
|
/**
|
|
100
127
|
* @description 获取内容的高度
|
|
101
128
|
* */
|
|
102
129
|
const getContentHeight = async () => {
|
|
103
|
-
const instance = getCurrentInstance()
|
|
130
|
+
const instance = getCurrentInstance()
|
|
104
131
|
// 延时一定时间再获取节点
|
|
105
|
-
await sleep(30)
|
|
106
|
-
getRect(
|
|
107
|
-
contentHeight.value = res.height || 0
|
|
132
|
+
await sleep(30)
|
|
133
|
+
getRect('.' + elId.value, false, instance).then((res: any) => {
|
|
134
|
+
contentHeight.value = res.height || 0
|
|
108
135
|
// 判断高度,如果真实内容高度大于占位高度,则显示收起与展开的控制按钮
|
|
109
136
|
if (res.height && res.height > showHeight.value / 2) {
|
|
110
|
-
isLongContent.value = true
|
|
111
|
-
status.value =
|
|
137
|
+
isLongContent.value = true
|
|
138
|
+
status.value = 'close'
|
|
112
139
|
} else {
|
|
113
|
-
isLongContent.value = false
|
|
114
|
-
status.value =
|
|
140
|
+
isLongContent.value = false
|
|
141
|
+
status.value = 'close'
|
|
115
142
|
}
|
|
116
|
-
})
|
|
117
|
-
}
|
|
143
|
+
})
|
|
144
|
+
}
|
|
118
145
|
/**
|
|
119
146
|
* @description 展开或者收起
|
|
120
147
|
* */
|
|
121
148
|
const toggleReadMore = () => {
|
|
122
|
-
status.value = status.value ===
|
|
149
|
+
status.value = status.value === 'close' ? 'open' : 'close'
|
|
123
150
|
// 如果toggle为false,隐藏"收起"部分的内容
|
|
124
|
-
if (!toggle.value) isLongContent.value = false
|
|
151
|
+
if (!toggle.value) isLongContent.value = false
|
|
125
152
|
// 发出打开或者收齐的事件
|
|
126
|
-
emit(status.value, name.value)
|
|
127
|
-
}
|
|
153
|
+
emit(status.value, name.value)
|
|
154
|
+
}
|
|
128
155
|
</script>
|
|
129
156
|
|
|
130
157
|
<style lang="scss" scoped>
|
|
131
|
-
@import
|
|
158
|
+
@import './index.scss';
|
|
132
159
|
</style>
|