hy-app 0.4.13 → 0.5.0
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 +155 -238
- package/components/hy-action-sheet/props.ts +68 -15
- package/components/hy-action-sheet/typing.d.ts +115 -115
- package/components/hy-address-picker/hy-address-picker.vue +185 -289
- package/components/hy-address-picker/props.ts +97 -21
- package/components/hy-address-picker/typing.d.ts +90 -89
- package/components/hy-avatar/hy-avatar.vue +121 -204
- package/components/hy-avatar/props.ts +76 -18
- package/components/hy-avatar/typing.d.ts +63 -62
- package/components/hy-back-top/hy-back-top.vue +65 -120
- package/components/hy-back-top/props.ts +57 -16
- package/components/hy-back-top/typing.d.ts +43 -42
- package/components/hy-badge/hy-badge.vue +66 -138
- package/components/hy-badge/props.ts +73 -17
- package/components/hy-badge/typing.d.ts +59 -58
- package/components/hy-button/hy-button.vue +226 -375
- package/components/hy-button/props.ts +129 -158
- package/components/hy-calendar/header.vue +48 -64
- package/components/hy-calendar/hy-calendar.vue +274 -438
- package/components/hy-calendar/month.vue +508 -516
- package/components/hy-calendar/props.ts +157 -35
- package/components/hy-calendar/typing.d.ts +129 -128
- package/components/hy-card/hy-card.vue +118 -240
- package/components/hy-card/index.scss +1 -2
- package/components/hy-card/props.ts +122 -27
- package/components/hy-card/typing.d.ts +119 -118
- package/components/hy-cell/hy-cell.vue +176 -258
- package/components/hy-cell/props.ts +71 -17
- package/components/hy-cell/typing.d.ts +87 -86
- package/components/hy-check-button/hy-check-button.vue +69 -139
- package/components/hy-check-button/props.ts +72 -18
- package/components/hy-check-button/typing.d.ts +74 -73
- package/components/hy-checkbox/hy-checkbox.vue +170 -263
- package/components/hy-checkbox/props.ts +94 -24
- package/components/hy-checkbox/typing.d.ts +72 -72
- package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
- package/components/hy-checkbox-group/props.ts +80 -0
- package/components/hy-checkbox-group/typing.d.ts +65 -65
- package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
- package/components/hy-checkbox-item/props.ts +24 -0
- package/components/hy-checkbox-item/typing.d.ts +4 -3
- package/components/hy-code-input/hy-code-input.vue +179 -262
- package/components/hy-code-input/props.ts +84 -18
- package/components/hy-code-input/typing.d.ts +71 -71
- package/components/hy-config-provider/hy-config-provider.vue +28 -50
- package/components/hy-config-provider/props.ts +26 -11
- package/components/hy-config-provider/typing.d.ts +20 -20
- package/components/hy-count-down/hy-count-down.vue +103 -131
- package/components/hy-count-down/props.ts +30 -8
- package/components/hy-count-down/typing.d.ts +25 -25
- package/components/hy-count-to/hy-count-to.vue +148 -213
- package/components/hy-count-to/props.ts +60 -15
- package/components/hy-count-to/typing.d.ts +46 -46
- package/components/hy-coupon/README.md +133 -0
- package/components/hy-coupon/hy-coupon.vue +180 -0
- package/components/hy-coupon/index.scss +553 -0
- package/components/hy-coupon/props.ts +129 -0
- package/components/hy-coupon/typing.d.ts +146 -0
- package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
- package/components/hy-datetime-picker/props.ts +142 -32
- package/components/hy-datetime-picker/typing.d.ts +132 -132
- package/components/hy-divider/hy-divider.vue +90 -169
- package/components/hy-divider/props.ts +78 -19
- package/components/hy-divider/typing.d.ts +60 -60
- package/components/hy-dropdown/hy-dropdown.vue +37 -71
- package/components/hy-dropdown/props.ts +38 -15
- package/components/hy-dropdown/typing.d.ts +44 -44
- package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
- package/components/hy-dropdown-item/props.ts +19 -8
- package/components/hy-empty/hy-empty.vue +75 -129
- package/components/hy-empty/props.ts +57 -15
- package/components/hy-empty/typing.d.ts +84 -84
- package/components/hy-flex/hy-flex.vue +33 -88
- package/components/hy-flex/props.ts +58 -0
- package/components/hy-flex/typing.d.ts +14 -16
- package/components/hy-float-button/hy-float-button.vue +289 -406
- package/components/hy-float-button/props.ts +109 -25
- package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
- package/components/hy-folding-panel/props.ts +40 -15
- package/components/hy-folding-panel/typing.d.ts +52 -63
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
- package/components/hy-folding-panel-item/index.scss +87 -0
- package/components/hy-folding-panel-item/props.ts +81 -0
- package/components/hy-folding-panel-item/typing.d.ts +23 -0
- package/components/hy-form/hy-form.vue +172 -212
- package/components/hy-form/props.ts +37 -0
- package/components/hy-form/typing.d.ts +68 -61
- package/components/hy-form-group/typing.d.ts +74 -74
- package/components/hy-form-item/hy-form-item.vue +100 -129
- package/components/hy-form-item/props.ts +25 -0
- package/components/hy-form-item/typing.d.ts +40 -37
- package/components/hy-grid/hy-grid.vue +76 -132
- package/components/hy-grid/props.ts +58 -16
- package/components/hy-grid/typing.d.ts +66 -66
- package/components/hy-icon/hy-icon.vue +84 -161
- package/components/hy-icon/props.ts +76 -22
- package/components/hy-icon/typing.d.ts +83 -82
- package/components/hy-image/hy-image.vue +142 -272
- package/components/hy-image/props.ts +105 -23
- package/components/hy-image/typing.d.ts +84 -87
- package/components/hy-input/hy-input.vue +230 -421
- package/components/hy-input/props.ts +183 -35
- package/components/hy-input/typing.d.ts +169 -169
- package/components/hy-line/hy-line.vue +34 -72
- package/components/hy-line/props.ts +41 -10
- package/components/hy-line/typing.d.ts +29 -29
- package/components/hy-line-progress/hy-line-progress.vue +66 -101
- package/components/hy-line-progress/props.ts +31 -10
- package/components/hy-line-progress/typing.d.ts +29 -29
- package/components/hy-list/hy-list.vue +151 -220
- package/components/hy-list/props.ts +67 -16
- package/components/hy-list/typing.d.ts +52 -52
- package/components/hy-loading/hy-loading.vue +63 -119
- package/components/hy-loading/props.ts +63 -15
- package/components/hy-loading/typing.d.ts +49 -49
- package/components/hy-menu/hy-menu.vue +124 -166
- package/components/hy-menu/props.ts +42 -10
- package/components/hy-menu/typing.d.ts +60 -60
- package/components/hy-modal/hy-modal.vue +127 -218
- package/components/hy-modal/props.ts +89 -24
- package/components/hy-navbar/hy-navbar.vue +104 -177
- package/components/hy-navbar/props.ts +76 -22
- package/components/hy-navbar/typing.d.ts +81 -81
- package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
- package/components/hy-notice-bar/props.ts +80 -19
- package/components/hy-notice-bar/typing.d.ts +62 -62
- package/components/hy-notify/hy-notify.vue +128 -177
- package/components/hy-notify/props.ts +49 -12
- package/components/hy-notify/typing.d.ts +45 -41
- package/components/hy-number-step/hy-number-step.vue +281 -394
- package/components/hy-number-step/props.ts +110 -27
- package/components/hy-number-step/typing.d.ts +120 -120
- package/components/hy-overlay/hy-overlay.vue +39 -66
- package/components/hy-overlay/props.ts +31 -8
- package/components/hy-pagination/hy-pagination.vue +100 -155
- package/components/hy-pagination/props.ts +53 -13
- package/components/hy-picker/hy-picker.vue +309 -430
- package/components/hy-picker/index.scss +8 -12
- package/components/hy-picker/props.ts +110 -26
- package/components/hy-popover/hy-popover.vue +190 -252
- package/components/hy-popover/props.ts +48 -10
- package/components/hy-popup/hy-popup.vue +162 -248
- package/components/hy-popup/props.ts +82 -18
- package/components/hy-price/hy-price.vue +45 -104
- package/components/hy-price/props.ts +52 -12
- package/components/hy-price/typing.d.ts +41 -36
- package/components/hy-qrcode/hy-qrcode.vue +115 -185
- package/components/hy-qrcode/props.ts +68 -18
- package/components/hy-qrcode/typing.d.ts +67 -66
- package/components/hy-radio/hy-radio.vue +161 -259
- package/components/hy-radio/props.ts +95 -25
- package/components/hy-radio/typing.d.ts +85 -84
- package/components/hy-rate/hy-rate.vue +185 -270
- package/components/hy-rate/props.ts +76 -18
- package/components/hy-rate/typing.d.ts +61 -60
- package/components/hy-read-more/hy-read-more.vue +93 -136
- package/components/hy-read-more/props.ts +43 -13
- package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
- package/components/hy-scroll-list/props.ts +22 -11
- package/components/hy-search/hy-search.vue +155 -284
- package/components/hy-search/props.ts +130 -25
- package/components/hy-signature/hy-signature.vue +491 -635
- package/components/hy-signature/props.ts +115 -26
- package/components/hy-signature/typing.d.ts +138 -138
- package/components/hy-slider/hy-slider.vue +388 -477
- package/components/hy-slider/props.ts +75 -19
- package/components/hy-steps/hy-steps.vue +212 -279
- package/components/hy-steps/props.ts +47 -13
- package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
- package/components/hy-submit-bar/props.ts +89 -20
- package/components/hy-submit-bar/typing.d.ts +86 -85
- package/components/hy-subsection/hy-subsection.vue +132 -185
- package/components/hy-subsection/props.ts +50 -17
- package/components/hy-subsection/typing.d.ts +52 -52
- package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
- package/components/hy-swipe-action/props.ts +43 -18
- package/components/hy-swipe-action/typing.d.ts +46 -46
- package/components/hy-swiper/hy-swiper.vue +159 -286
- package/components/hy-swiper/props.ts +126 -28
- package/components/hy-swiper/typing.d.ts +115 -115
- package/components/hy-switch/hy-switch.vue +112 -176
- package/components/hy-switch/props.ts +60 -15
- package/components/hy-switch/typing.d.ts +63 -63
- package/components/hy-tabBar/hy-tabBar.vue +64 -60
- package/components/hy-tabs/hy-tabs.vue +277 -380
- package/components/hy-tabs/props.ts +75 -18
- package/components/hy-tag/hy-tag.vue +111 -204
- package/components/hy-tag/props.ts +81 -19
- package/components/hy-text/hy-text.vue +200 -322
- package/components/hy-text/props.ts +107 -28
- package/components/hy-textarea/hy-textarea.vue +147 -256
- package/components/hy-textarea/props.ts +112 -25
- package/components/hy-textarea/typing.d.ts +42 -42
- package/components/hy-toast/hy-toast.vue +135 -143
- package/components/hy-tooltip/hy-tooltip.vue +220 -306
- package/components/hy-tooltip/props.ts +79 -15
- package/components/hy-transition/hy-transition.vue +111 -138
- package/components/hy-transition/props.ts +30 -8
- package/components/hy-upload/hy-upload.vue +320 -469
- package/components/hy-upload/props.ts +130 -27
- package/components/hy-warn/hy-warn.vue +80 -129
- package/components/hy-warn/props.ts +47 -12
- package/components/hy-waterfall/hy-waterfall.vue +139 -163
- package/components/hy-waterfall/props.ts +19 -7
- package/components/hy-watermark/hy-watermark.vue +762 -870
- package/components/hy-watermark/props.ts +103 -22
- package/global.d.ts +2 -0
- package/libs/css/theme.scss +3 -3
- package/package.json +2 -2
- package/web-types.json +1 -1
- package/components/hy-folding-panel/index.scss +0 -9
|
@@ -1,295 +1,226 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
2
|
+
<scroll-view
|
|
3
|
+
ref="hyVirtualContainer"
|
|
4
|
+
@scroll="onScroll"
|
|
5
|
+
@scrolltolower="scrollToLower"
|
|
6
|
+
:lower-threshold="showDivider ? 100 : 50"
|
|
7
|
+
:scroll-y="true"
|
|
8
|
+
scroll-with-animation
|
|
9
|
+
class="hy-virtual-container"
|
|
10
|
+
>
|
|
11
|
+
<view class="hy-virtual-container__list">
|
|
12
|
+
<slot v-if="slotDefault" :record="line === 1 ? virtualData : waterfall"></slot>
|
|
13
|
+
<template v-else>
|
|
14
|
+
<view
|
|
15
|
+
v-if="line === 1"
|
|
16
|
+
class="hy-virtual-container__list--item"
|
|
17
|
+
v-for="(item, i) in virtualData"
|
|
18
|
+
:key="typeof item === 'string' ? i : item[keyField]"
|
|
19
|
+
:style="itemStyle"
|
|
20
|
+
@click="handleClick(item)"
|
|
21
|
+
>
|
|
22
|
+
<slot style="height: 100%" name="content" :record="item"></slot>
|
|
23
|
+
</view>
|
|
24
|
+
|
|
25
|
+
<view
|
|
26
|
+
v-if="line === 2"
|
|
27
|
+
class="hy-virtual-container__list--left hy-virtual-container__list--box"
|
|
28
|
+
>
|
|
29
|
+
<view
|
|
30
|
+
v-if="slots.left"
|
|
31
|
+
class="hy-virtual-container__list--box-item"
|
|
32
|
+
v-for="item in waterfall.left"
|
|
33
|
+
:key="item[keyField]"
|
|
34
|
+
:style="itemStyle"
|
|
35
|
+
@click="handleClick(item)"
|
|
36
|
+
>
|
|
37
|
+
<slot name="left" :record="item"></slot>
|
|
38
|
+
</view>
|
|
39
|
+
<slot v-else name="left-list" :record="waterfall.left"></slot>
|
|
40
|
+
</view>
|
|
41
|
+
<view
|
|
42
|
+
v-if="line === 2"
|
|
43
|
+
class="hy-virtual-container__list--right hy-virtual-container__list--box"
|
|
44
|
+
>
|
|
45
|
+
<view
|
|
46
|
+
v-if="slots.right"
|
|
47
|
+
class="hy-virtual-container__list--box-item"
|
|
48
|
+
v-for="item in waterfall.right"
|
|
49
|
+
:key="item[keyField]"
|
|
50
|
+
:style="itemStyle"
|
|
51
|
+
@click="handleClick(item)"
|
|
52
|
+
>
|
|
53
|
+
<slot name="right" :record="item"></slot>
|
|
54
|
+
</view>
|
|
55
|
+
<slot v-else name="right-list" :record="waterfall.right"></slot>
|
|
56
|
+
</view>
|
|
57
|
+
</template>
|
|
58
|
+
<!--加载更多样式-->
|
|
26
59
|
</view>
|
|
27
|
-
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
class="hy-virtual-container__list--left hy-virtual-container__list--box"
|
|
31
|
-
>
|
|
32
|
-
<view
|
|
33
|
-
v-if="slots.left"
|
|
34
|
-
class="hy-virtual-container__list--box-item"
|
|
35
|
-
v-for="item in waterfall.left"
|
|
36
|
-
:key="item[keyField]"
|
|
37
|
-
:style="itemStyle"
|
|
38
|
-
@click="handleClick(item)"
|
|
39
|
-
>
|
|
40
|
-
<slot name="left" :record="item"></slot>
|
|
41
|
-
</view>
|
|
42
|
-
<slot v-else name="left-list" :record="waterfall.left"></slot>
|
|
43
|
-
</view>
|
|
44
|
-
<view
|
|
45
|
-
v-if="line === 2"
|
|
46
|
-
class="hy-virtual-container__list--right hy-virtual-container__list--box"
|
|
47
|
-
>
|
|
48
|
-
<view
|
|
49
|
-
v-if="slots.right"
|
|
50
|
-
class="hy-virtual-container__list--box-item"
|
|
51
|
-
v-for="item in waterfall.right"
|
|
52
|
-
:key="item[keyField]"
|
|
53
|
-
:style="itemStyle"
|
|
54
|
-
@click="handleClick(item)"
|
|
55
|
-
>
|
|
56
|
-
<slot name="right" :record="item"></slot>
|
|
57
|
-
</view>
|
|
58
|
-
<slot v-else name="right-list" :record="waterfall.right"></slot>
|
|
59
|
-
</view>
|
|
60
|
-
</template>
|
|
61
|
-
<!--加载更多样式-->
|
|
62
|
-
</view>
|
|
63
|
-
<slot v-if="$slots.footer" name="footer"></slot>
|
|
64
|
-
<hy-divider :text="load" v-else-if="showDivider"></hy-divider>
|
|
65
|
-
</scroll-view>
|
|
60
|
+
<slot v-if="$slots.footer" name="footer"></slot>
|
|
61
|
+
<hy-divider :text="load" v-else-if="showDivider"></hy-divider>
|
|
62
|
+
</scroll-view>
|
|
66
63
|
</template>
|
|
67
64
|
|
|
68
65
|
<script lang="ts">
|
|
69
66
|
export default {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
67
|
+
name: 'hy-list',
|
|
68
|
+
options: {
|
|
69
|
+
addGlobalClass: true,
|
|
70
|
+
virtualHost: true,
|
|
71
|
+
styleIsolation: 'shared'
|
|
72
|
+
}
|
|
73
|
+
}
|
|
77
74
|
</script>
|
|
78
75
|
|
|
79
76
|
<script lang="ts" setup>
|
|
80
77
|
import {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
} from
|
|
90
|
-
import type { CSSProperties
|
|
91
|
-
import { addUnit, getPx, getRect } from
|
|
92
|
-
import type { IListEmits } from
|
|
78
|
+
computed,
|
|
79
|
+
getCurrentInstance,
|
|
80
|
+
nextTick,
|
|
81
|
+
onMounted,
|
|
82
|
+
reactive,
|
|
83
|
+
ref,
|
|
84
|
+
useSlots,
|
|
85
|
+
watch
|
|
86
|
+
} from 'vue'
|
|
87
|
+
import type { CSSProperties } from 'vue'
|
|
88
|
+
import { addUnit, getPx, getRect } from '../../libs'
|
|
89
|
+
import type { IListEmits } from './typing'
|
|
90
|
+
import listProps from './props'
|
|
93
91
|
// 组件
|
|
94
|
-
import HyDivider from
|
|
92
|
+
import HyDivider from '../hy-divider/hy-divider.vue'
|
|
95
93
|
|
|
96
94
|
/**
|
|
97
95
|
* 实现只展示可视内容的dom,减少dom创建,优化滚动性能
|
|
98
96
|
* @displayName hy-list
|
|
99
97
|
*/
|
|
100
|
-
defineOptions({})
|
|
98
|
+
defineOptions({})
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
/** 数据列表 */
|
|
105
|
-
list: {
|
|
106
|
-
type: Array as PropType<(string | Record<string, any>)[]>,
|
|
107
|
-
default: () => [],
|
|
108
|
-
},
|
|
109
|
-
/** 容器高度,必须给个高度,否则加载全部数据 */
|
|
110
|
-
containerHeight: {
|
|
111
|
-
type: String,
|
|
112
|
-
default: "100%",
|
|
113
|
-
},
|
|
114
|
-
/** 子容器的高度,必须和内容一致,否则计算有问题 */
|
|
115
|
-
itemHeight: {
|
|
116
|
-
type: [String, Number],
|
|
117
|
-
default: "40px",
|
|
118
|
-
},
|
|
119
|
-
/** 子容器的底部,会计算到容器内 */
|
|
120
|
-
marginBottom: {
|
|
121
|
-
type: [String, Number],
|
|
122
|
-
default: 10,
|
|
123
|
-
},
|
|
124
|
-
/** 子容器的内边距 */
|
|
125
|
-
padding: {
|
|
126
|
-
type: [String, Number],
|
|
127
|
-
default: 10,
|
|
128
|
-
},
|
|
129
|
-
/** 子容器的圆角,单位px */
|
|
130
|
-
borderRadius: {
|
|
131
|
-
type: [String, Number],
|
|
132
|
-
default: "3px",
|
|
133
|
-
},
|
|
134
|
-
/** 容器背景色 */
|
|
135
|
-
background: {
|
|
136
|
-
type: String,
|
|
137
|
-
default: "transparent",
|
|
138
|
-
},
|
|
139
|
-
/** 是否显示边框 */
|
|
140
|
-
border: {
|
|
141
|
-
type: Boolean,
|
|
142
|
-
default: false,
|
|
143
|
-
},
|
|
144
|
-
/** 展示几列 */
|
|
145
|
-
line: {
|
|
146
|
-
type: Number,
|
|
147
|
-
default: 1,
|
|
148
|
-
},
|
|
149
|
-
/** 每一项的唯一标识key */
|
|
150
|
-
keyField: {
|
|
151
|
-
type: String,
|
|
152
|
-
default: "id",
|
|
153
|
-
},
|
|
154
|
-
/**
|
|
155
|
-
* 加载状态
|
|
156
|
-
* @values loadMore,loading,noMore
|
|
157
|
-
* */
|
|
158
|
-
load: {
|
|
159
|
-
type: String,
|
|
160
|
-
default: "loadMore",
|
|
161
|
-
},
|
|
162
|
-
/** 显示底部加载状态 */
|
|
163
|
-
showDivider: {
|
|
164
|
-
type: Boolean,
|
|
165
|
-
default: true,
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
const emit = defineEmits<IListEmits>();
|
|
100
|
+
const props = defineProps(listProps)
|
|
101
|
+
const emit = defineEmits<IListEmits>()
|
|
169
102
|
|
|
170
|
-
const slots = useSlots()
|
|
103
|
+
const slots = useSlots()
|
|
171
104
|
// 滚动条距离顶部距离
|
|
172
|
-
const scrollTop = ref(0)
|
|
105
|
+
const scrollTop = ref(0)
|
|
173
106
|
// 可视区域的高度
|
|
174
|
-
const viewHeight = ref(0)
|
|
107
|
+
const viewHeight = ref(0)
|
|
175
108
|
const waterfall: {
|
|
176
|
-
|
|
177
|
-
|
|
109
|
+
left: AnyObject[]
|
|
110
|
+
right: AnyObject[]
|
|
178
111
|
} = reactive({
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
})
|
|
112
|
+
left: [],
|
|
113
|
+
right: []
|
|
114
|
+
})
|
|
182
115
|
// 排列方式
|
|
183
|
-
const arrange = computed(() => (props.line === 1 ?
|
|
184
|
-
const boxHeight = getPx(props.itemHeight) + getPx(props.marginBottom)
|
|
185
|
-
const listHeight = addUnit(props.containerHeight)
|
|
186
|
-
const instance = getCurrentInstance()
|
|
116
|
+
const arrange = computed(() => (props.line === 1 ? 'column' : 'row'))
|
|
117
|
+
const boxHeight = getPx(props.itemHeight) + getPx(props.marginBottom)
|
|
118
|
+
const listHeight = addUnit(props.containerHeight)
|
|
119
|
+
const instance = getCurrentInstance()
|
|
187
120
|
|
|
188
121
|
onMounted(() => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
})
|
|
122
|
+
nextTick(async () => {
|
|
123
|
+
const res = await getRect('.hy-virtual-container', false, instance)
|
|
124
|
+
viewHeight.value = (res as UniApp.NodeInfo).height || 0
|
|
125
|
+
})
|
|
126
|
+
})
|
|
194
127
|
|
|
195
128
|
const itemStyle = computed((): CSSProperties => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
})
|
|
129
|
+
return {
|
|
130
|
+
height: addUnit(props.itemHeight),
|
|
131
|
+
padding: addUnit(props.padding),
|
|
132
|
+
marginBottom: addUnit(props.marginBottom),
|
|
133
|
+
borderRadius: addUnit(props.borderRadius),
|
|
134
|
+
background: props.background,
|
|
135
|
+
border: props.border ? '1px solid #dadbde' : ''
|
|
136
|
+
}
|
|
137
|
+
})
|
|
205
138
|
|
|
206
139
|
/**
|
|
207
140
|
* @description 虚拟列表真实展示数据:起始下标
|
|
208
141
|
*/
|
|
209
142
|
const start = computed(() => {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
})
|
|
143
|
+
const s = Math.floor(scrollTop.value / boxHeight)
|
|
144
|
+
return Math.max(0, s * props.line)
|
|
145
|
+
})
|
|
213
146
|
|
|
214
147
|
/**
|
|
215
148
|
* @description 虚拟列表真实展示数据:结束下标
|
|
216
149
|
*/
|
|
217
150
|
const over = computed(() => {
|
|
218
|
-
|
|
219
|
-
(
|
|
220
|
-
|
|
221
|
-
return Math.min(props.list.length, o * props.line);
|
|
222
|
-
});
|
|
151
|
+
const o = Math.floor((scrollTop.value + viewHeight.value + 1) / boxHeight + 5)
|
|
152
|
+
return Math.min(props.list.length, o * props.line)
|
|
153
|
+
})
|
|
223
154
|
|
|
224
155
|
/**
|
|
225
156
|
* @description 计算虚拟列表的padding(保持列表高度完整且滚动条能正常滚动)
|
|
226
157
|
*/
|
|
227
158
|
const paddingAttr = computed(() => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
})
|
|
159
|
+
const paddingTop = start.value * boxHeight
|
|
160
|
+
const paddingBottom = (props.list.length - over.value) * boxHeight
|
|
161
|
+
return `${paddingTop / props.line}px 0 ${paddingBottom / props.line}px`
|
|
162
|
+
})
|
|
232
163
|
|
|
233
164
|
/**
|
|
234
165
|
* @description 虚拟列表真实展示数据
|
|
235
166
|
*/
|
|
236
167
|
const virtualData = computed<(string | Record<string, any>)[]>(() => {
|
|
237
|
-
|
|
238
|
-
})
|
|
168
|
+
return props.list.slice(start.value, over.value)
|
|
169
|
+
})
|
|
239
170
|
|
|
240
171
|
watch(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
172
|
+
() => virtualData.value,
|
|
173
|
+
(newVal) => {
|
|
174
|
+
waterfall.left.length = 0
|
|
175
|
+
waterfall.right.length = 0
|
|
176
|
+
if (props.line === 2 && newVal!.every((item) => typeof item !== 'string')) {
|
|
177
|
+
newVal.forEach((item, i) => {
|
|
178
|
+
if (i % 2 === 0) {
|
|
179
|
+
waterfall.left.push(item as AnyObject)
|
|
180
|
+
} else {
|
|
181
|
+
waterfall.right.push(item as AnyObject)
|
|
182
|
+
}
|
|
183
|
+
})
|
|
251
184
|
}
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
{ immediate: true, deep: true },
|
|
256
|
-
);
|
|
185
|
+
},
|
|
186
|
+
{ immediate: true, deep: true }
|
|
187
|
+
)
|
|
257
188
|
|
|
258
189
|
/**
|
|
259
190
|
* @description 监听滚动条距离顶部距离,实时更新
|
|
260
191
|
*/
|
|
261
192
|
const onScroll = async (e: any) => {
|
|
262
|
-
|
|
263
|
-
}
|
|
193
|
+
scrollTop.value = e.detail.scrollTop || 0
|
|
194
|
+
}
|
|
264
195
|
|
|
265
196
|
/**
|
|
266
197
|
* @description 滚动底部函数
|
|
267
198
|
* */
|
|
268
199
|
const scrollToLower = () => {
|
|
269
|
-
|
|
270
|
-
}
|
|
200
|
+
emit('scrollToLower')
|
|
201
|
+
}
|
|
271
202
|
|
|
272
203
|
/**
|
|
273
204
|
* @description 点击行触发函数
|
|
274
205
|
* */
|
|
275
206
|
const handleClick = (temp: string | AnyObject) => {
|
|
276
|
-
|
|
277
|
-
}
|
|
207
|
+
emit('click', temp)
|
|
208
|
+
}
|
|
278
209
|
|
|
279
210
|
/**
|
|
280
211
|
* @description 获取默认插槽
|
|
281
212
|
*/
|
|
282
|
-
const slotDefault = useSlots().default
|
|
213
|
+
const slotDefault = useSlots().default
|
|
283
214
|
</script>
|
|
284
215
|
|
|
285
216
|
<style lang="scss" scoped>
|
|
286
|
-
@import
|
|
217
|
+
@import './index.scss';
|
|
287
218
|
.hy-virtual-container {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
219
|
+
height: v-bind(listHeight);
|
|
220
|
+
&__list {
|
|
221
|
+
padding: v-bind(paddingAttr);
|
|
222
|
+
display: flex;
|
|
223
|
+
flex-direction: v-bind(arrange);
|
|
224
|
+
}
|
|
294
225
|
}
|
|
295
226
|
</style>
|
|
@@ -1,18 +1,69 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { PropType } from 'vue'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
const listProps = {
|
|
4
|
+
/** 数据列表 */
|
|
5
|
+
list: {
|
|
6
|
+
type: Array as PropType<(string | Record<string, any>)[]>,
|
|
7
|
+
default: () => []
|
|
8
|
+
},
|
|
9
|
+
/** 容器高度,必须给个高度,否则加载全部数据 */
|
|
10
|
+
containerHeight: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: '100%'
|
|
13
|
+
},
|
|
14
|
+
/** 子容器的高度,必须和内容一致,否则计算有问题 */
|
|
15
|
+
itemHeight: {
|
|
16
|
+
type: [String, Number],
|
|
17
|
+
default: '40px'
|
|
18
|
+
},
|
|
19
|
+
/** 子容器的底部,会计算到容器内 */
|
|
20
|
+
marginBottom: {
|
|
21
|
+
type: [String, Number],
|
|
22
|
+
default: 10
|
|
23
|
+
},
|
|
24
|
+
/** 子容器的内边距 */
|
|
25
|
+
padding: {
|
|
26
|
+
type: [String, Number],
|
|
27
|
+
default: 10
|
|
28
|
+
},
|
|
29
|
+
/** 子容器的圆角,单位px */
|
|
30
|
+
borderRadius: {
|
|
31
|
+
type: [String, Number],
|
|
32
|
+
default: '3px'
|
|
33
|
+
},
|
|
34
|
+
/** 容器背景色 */
|
|
35
|
+
background: {
|
|
36
|
+
type: String,
|
|
37
|
+
default: 'transparent'
|
|
38
|
+
},
|
|
39
|
+
/** 是否显示边框 */
|
|
40
|
+
border: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: false
|
|
43
|
+
},
|
|
44
|
+
/** 展示几列 */
|
|
45
|
+
line: {
|
|
46
|
+
type: Number,
|
|
47
|
+
default: 1
|
|
48
|
+
},
|
|
49
|
+
/** 每一项的唯一标识key */
|
|
50
|
+
keyField: {
|
|
51
|
+
type: String,
|
|
52
|
+
default: 'id'
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* 加载状态
|
|
56
|
+
* @values loadMore,loading,noMore
|
|
57
|
+
* */
|
|
58
|
+
load: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: 'loadMore'
|
|
61
|
+
},
|
|
62
|
+
/** 显示底部加载状态 */
|
|
63
|
+
showDivider: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
default: true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
17
68
|
|
|
18
|
-
export default
|
|
69
|
+
export default listProps
|
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
export default interface HyListProps {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @description 数据列表
|
|
4
|
+
* */
|
|
5
|
+
list: (AnyObject | string)[]
|
|
6
|
+
/**
|
|
7
|
+
* @description 容器高度,必须给个高度,否则加载全部数据
|
|
8
|
+
* */
|
|
9
|
+
containerHeight: string
|
|
10
|
+
/**
|
|
11
|
+
* @description 子容器的高度,必须和内容一致,否则计算有问题
|
|
12
|
+
* */
|
|
13
|
+
itemHeight?: number | string
|
|
14
|
+
/**
|
|
15
|
+
* @description 子容器的内边距
|
|
16
|
+
* */
|
|
17
|
+
padding?: number | string
|
|
18
|
+
/**
|
|
19
|
+
* @description 子容器的底部,会计算到容器内
|
|
20
|
+
* */
|
|
21
|
+
marginBottom?: number | string
|
|
22
|
+
/**
|
|
23
|
+
* @description 子容器的圆角,单位px
|
|
24
|
+
* */
|
|
25
|
+
borderRadius?: number | string
|
|
26
|
+
/**
|
|
27
|
+
* @description 容器背景色
|
|
28
|
+
* */
|
|
29
|
+
background?: string
|
|
30
|
+
/**
|
|
31
|
+
* @description 是否显示边框(默认false)
|
|
32
|
+
* */
|
|
33
|
+
border?: boolean
|
|
34
|
+
/**
|
|
35
|
+
* @description 展示几列
|
|
36
|
+
* */
|
|
37
|
+
line?: number
|
|
38
|
+
/**
|
|
39
|
+
* @description 加载状态
|
|
40
|
+
* */
|
|
41
|
+
load?: 'loadMore' | 'loading' | 'noMore'
|
|
42
|
+
/**
|
|
43
|
+
* @description 每一项的唯一标识key
|
|
44
|
+
* */
|
|
45
|
+
keyField?: string
|
|
46
|
+
/**
|
|
47
|
+
* @description 显示底部加载状态
|
|
48
|
+
* */
|
|
49
|
+
showDivider?: boolean
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export interface IListEmits {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
/** 点击行触发 */
|
|
54
|
+
(e: 'click', temp: string | AnyObject): void
|
|
55
|
+
/** 滚动底部触发 */
|
|
56
|
+
(e: 'scrollToLower'): void
|
|
57
57
|
}
|