hy-app 0.4.15 → 0.5.1

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.
Files changed (206) hide show
  1. package/components/hy-action-sheet/hy-action-sheet.vue +155 -238
  2. package/components/hy-action-sheet/props.ts +68 -15
  3. package/components/hy-action-sheet/typing.d.ts +115 -115
  4. package/components/hy-address-picker/hy-address-picker.vue +185 -289
  5. package/components/hy-address-picker/props.ts +97 -21
  6. package/components/hy-address-picker/typing.d.ts +90 -89
  7. package/components/hy-avatar/hy-avatar.vue +121 -204
  8. package/components/hy-avatar/props.ts +76 -18
  9. package/components/hy-avatar/typing.d.ts +63 -62
  10. package/components/hy-back-top/hy-back-top.vue +65 -120
  11. package/components/hy-back-top/props.ts +57 -16
  12. package/components/hy-back-top/typing.d.ts +43 -42
  13. package/components/hy-badge/hy-badge.vue +66 -138
  14. package/components/hy-badge/props.ts +73 -17
  15. package/components/hy-badge/typing.d.ts +59 -58
  16. package/components/hy-button/hy-button.vue +226 -375
  17. package/components/hy-button/props.ts +129 -158
  18. package/components/hy-calendar/header.vue +48 -64
  19. package/components/hy-calendar/hy-calendar.vue +274 -438
  20. package/components/hy-calendar/month.vue +508 -516
  21. package/components/hy-calendar/props.ts +157 -35
  22. package/components/hy-calendar/typing.d.ts +129 -128
  23. package/components/hy-card/hy-card.vue +118 -240
  24. package/components/hy-card/index.scss +1 -2
  25. package/components/hy-card/props.ts +122 -27
  26. package/components/hy-card/typing.d.ts +119 -118
  27. package/components/hy-cell/hy-cell.vue +176 -258
  28. package/components/hy-cell/props.ts +71 -17
  29. package/components/hy-cell/typing.d.ts +87 -86
  30. package/components/hy-check-button/hy-check-button.vue +69 -139
  31. package/components/hy-check-button/props.ts +72 -18
  32. package/components/hy-check-button/typing.d.ts +74 -73
  33. package/components/hy-checkbox/hy-checkbox.vue +170 -263
  34. package/components/hy-checkbox/props.ts +94 -24
  35. package/components/hy-checkbox/typing.d.ts +72 -72
  36. package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
  37. package/components/hy-checkbox-group/props.ts +80 -0
  38. package/components/hy-checkbox-group/typing.d.ts +65 -65
  39. package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
  40. package/components/hy-checkbox-item/props.ts +24 -0
  41. package/components/hy-checkbox-item/typing.d.ts +4 -3
  42. package/components/hy-code-input/hy-code-input.vue +179 -262
  43. package/components/hy-code-input/props.ts +84 -18
  44. package/components/hy-code-input/typing.d.ts +71 -71
  45. package/components/hy-config-provider/hy-config-provider.vue +28 -50
  46. package/components/hy-config-provider/props.ts +26 -11
  47. package/components/hy-config-provider/typing.d.ts +20 -20
  48. package/components/hy-count-down/hy-count-down.vue +103 -131
  49. package/components/hy-count-down/props.ts +30 -8
  50. package/components/hy-count-down/typing.d.ts +25 -25
  51. package/components/hy-count-to/hy-count-to.vue +148 -213
  52. package/components/hy-count-to/props.ts +60 -15
  53. package/components/hy-count-to/typing.d.ts +46 -46
  54. package/components/hy-coupon/hy-coupon.vue +10 -5
  55. package/components/hy-coupon/index.scss +148 -64
  56. package/components/hy-coupon/props.ts +35 -50
  57. package/components/hy-coupon/typing.d.ts +10 -0
  58. package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
  59. package/components/hy-datetime-picker/props.ts +142 -32
  60. package/components/hy-datetime-picker/typing.d.ts +132 -132
  61. package/components/hy-divider/hy-divider.vue +90 -169
  62. package/components/hy-divider/props.ts +78 -19
  63. package/components/hy-divider/typing.d.ts +60 -60
  64. package/components/hy-dropdown/hy-dropdown.vue +37 -71
  65. package/components/hy-dropdown/props.ts +38 -15
  66. package/components/hy-dropdown/typing.d.ts +44 -44
  67. package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
  68. package/components/hy-dropdown-item/props.ts +19 -8
  69. package/components/hy-empty/hy-empty.vue +75 -129
  70. package/components/hy-empty/props.ts +57 -15
  71. package/components/hy-empty/typing.d.ts +84 -84
  72. package/components/hy-flex/hy-flex.vue +33 -88
  73. package/components/hy-flex/props.ts +58 -0
  74. package/components/hy-flex/typing.d.ts +14 -16
  75. package/components/hy-float-button/hy-float-button.vue +289 -406
  76. package/components/hy-float-button/props.ts +109 -25
  77. package/components/hy-folding-panel/hy-folding-panel.vue +74 -114
  78. package/components/hy-folding-panel/props.ts +42 -0
  79. package/components/hy-folding-panel/typing.d.ts +57 -57
  80. package/components/hy-folding-panel-item/hy-folding-panel-item.vue +139 -231
  81. package/components/hy-folding-panel-item/props.ts +81 -0
  82. package/components/hy-folding-panel-item/typing.d.ts +23 -23
  83. package/components/hy-form/hy-form.vue +172 -212
  84. package/components/hy-form/props.ts +37 -0
  85. package/components/hy-form/typing.d.ts +68 -61
  86. package/components/hy-form-group/typing.d.ts +74 -74
  87. package/components/hy-form-item/hy-form-item.vue +100 -129
  88. package/components/hy-form-item/props.ts +25 -0
  89. package/components/hy-form-item/typing.d.ts +40 -37
  90. package/components/hy-grid/hy-grid.vue +76 -132
  91. package/components/hy-grid/props.ts +58 -16
  92. package/components/hy-grid/typing.d.ts +66 -66
  93. package/components/hy-icon/hy-icon.vue +84 -161
  94. package/components/hy-icon/props.ts +76 -22
  95. package/components/hy-icon/typing.d.ts +83 -82
  96. package/components/hy-image/hy-image.vue +142 -272
  97. package/components/hy-image/props.ts +105 -23
  98. package/components/hy-image/typing.d.ts +84 -87
  99. package/components/hy-input/hy-input.vue +230 -421
  100. package/components/hy-input/props.ts +183 -35
  101. package/components/hy-input/typing.d.ts +169 -169
  102. package/components/hy-line/hy-line.vue +34 -72
  103. package/components/hy-line/props.ts +41 -10
  104. package/components/hy-line/typing.d.ts +29 -29
  105. package/components/hy-line-progress/hy-line-progress.vue +66 -101
  106. package/components/hy-line-progress/props.ts +31 -10
  107. package/components/hy-line-progress/typing.d.ts +29 -29
  108. package/components/hy-list/hy-list.vue +151 -220
  109. package/components/hy-list/props.ts +67 -16
  110. package/components/hy-list/typing.d.ts +52 -52
  111. package/components/hy-loading/hy-loading.vue +63 -119
  112. package/components/hy-loading/props.ts +63 -15
  113. package/components/hy-loading/typing.d.ts +49 -49
  114. package/components/hy-menu/hy-menu.vue +124 -166
  115. package/components/hy-menu/props.ts +42 -10
  116. package/components/hy-menu/typing.d.ts +60 -60
  117. package/components/hy-modal/hy-modal.vue +127 -218
  118. package/components/hy-modal/props.ts +89 -24
  119. package/components/hy-navbar/hy-navbar.vue +104 -177
  120. package/components/hy-navbar/props.ts +76 -22
  121. package/components/hy-navbar/typing.d.ts +81 -81
  122. package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
  123. package/components/hy-notice-bar/props.ts +80 -19
  124. package/components/hy-notice-bar/typing.d.ts +62 -62
  125. package/components/hy-notify/hy-notify.vue +128 -177
  126. package/components/hy-notify/props.ts +49 -12
  127. package/components/hy-notify/typing.d.ts +45 -41
  128. package/components/hy-number-step/hy-number-step.vue +281 -394
  129. package/components/hy-number-step/props.ts +110 -27
  130. package/components/hy-number-step/typing.d.ts +120 -120
  131. package/components/hy-overlay/hy-overlay.vue +39 -66
  132. package/components/hy-overlay/props.ts +31 -8
  133. package/components/hy-pagination/hy-pagination.vue +100 -155
  134. package/components/hy-pagination/props.ts +53 -13
  135. package/components/hy-picker/hy-picker.vue +309 -430
  136. package/components/hy-picker/index.scss +8 -12
  137. package/components/hy-picker/props.ts +110 -26
  138. package/components/hy-popover/hy-popover.vue +190 -252
  139. package/components/hy-popover/props.ts +48 -10
  140. package/components/hy-popup/hy-popup.vue +162 -248
  141. package/components/hy-popup/props.ts +82 -18
  142. package/components/hy-price/hy-price.vue +45 -104
  143. package/components/hy-price/props.ts +52 -12
  144. package/components/hy-price/typing.d.ts +41 -36
  145. package/components/hy-qrcode/hy-qrcode.vue +115 -185
  146. package/components/hy-qrcode/props.ts +68 -18
  147. package/components/hy-qrcode/typing.d.ts +67 -66
  148. package/components/hy-radio/hy-radio.vue +161 -259
  149. package/components/hy-radio/props.ts +95 -25
  150. package/components/hy-radio/typing.d.ts +85 -84
  151. package/components/hy-rate/hy-rate.vue +185 -270
  152. package/components/hy-rate/props.ts +76 -18
  153. package/components/hy-rate/typing.d.ts +61 -60
  154. package/components/hy-read-more/hy-read-more.vue +93 -136
  155. package/components/hy-read-more/props.ts +43 -13
  156. package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
  157. package/components/hy-scroll-list/props.ts +22 -11
  158. package/components/hy-search/hy-search.vue +155 -284
  159. package/components/hy-search/props.ts +130 -25
  160. package/components/hy-signature/hy-signature.vue +491 -635
  161. package/components/hy-signature/props.ts +115 -26
  162. package/components/hy-signature/typing.d.ts +138 -138
  163. package/components/hy-slider/hy-slider.vue +388 -477
  164. package/components/hy-slider/props.ts +75 -19
  165. package/components/hy-steps/hy-steps.vue +212 -279
  166. package/components/hy-steps/props.ts +47 -13
  167. package/components/hy-submit-bar/hy-submit-bar.vue +136 -221
  168. package/components/hy-submit-bar/props.ts +89 -20
  169. package/components/hy-submit-bar/typing.d.ts +87 -87
  170. package/components/hy-subsection/hy-subsection.vue +132 -185
  171. package/components/hy-subsection/props.ts +50 -17
  172. package/components/hy-subsection/typing.d.ts +52 -52
  173. package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
  174. package/components/hy-swipe-action/props.ts +43 -18
  175. package/components/hy-swipe-action/typing.d.ts +46 -46
  176. package/components/hy-swiper/hy-swiper.vue +159 -286
  177. package/components/hy-swiper/props.ts +126 -28
  178. package/components/hy-swiper/typing.d.ts +115 -115
  179. package/components/hy-switch/hy-switch.vue +112 -176
  180. package/components/hy-switch/props.ts +60 -15
  181. package/components/hy-switch/typing.d.ts +63 -63
  182. package/components/hy-tabBar/hy-tabBar.vue +64 -60
  183. package/components/hy-tabs/hy-tabs.vue +277 -380
  184. package/components/hy-tabs/props.ts +75 -18
  185. package/components/hy-tag/hy-tag.vue +111 -204
  186. package/components/hy-tag/props.ts +81 -19
  187. package/components/hy-text/hy-text.vue +200 -322
  188. package/components/hy-text/props.ts +107 -28
  189. package/components/hy-textarea/hy-textarea.vue +147 -256
  190. package/components/hy-textarea/props.ts +112 -25
  191. package/components/hy-textarea/typing.d.ts +42 -42
  192. package/components/hy-toast/hy-toast.vue +135 -143
  193. package/components/hy-tooltip/hy-tooltip.vue +220 -306
  194. package/components/hy-tooltip/props.ts +79 -15
  195. package/components/hy-transition/hy-transition.vue +111 -138
  196. package/components/hy-transition/props.ts +30 -8
  197. package/components/hy-upload/hy-upload.vue +320 -469
  198. package/components/hy-upload/props.ts +130 -27
  199. package/components/hy-warn/hy-warn.vue +80 -129
  200. package/components/hy-warn/props.ts +47 -12
  201. package/components/hy-waterfall/hy-waterfall.vue +139 -163
  202. package/components/hy-waterfall/props.ts +19 -7
  203. package/components/hy-watermark/hy-watermark.vue +762 -870
  204. package/components/hy-watermark/props.ts +103 -22
  205. package/package.json +2 -2
  206. package/web-types.json +1 -1
@@ -1,295 +1,226 @@
1
1
  <template>
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
13
- v-if="slotDefault"
14
- :record="line === 1 ? virtualData : waterfall"
15
- ></slot>
16
- <template v-else>
17
- <view
18
- v-if="line === 1"
19
- class="hy-virtual-container__list--item"
20
- v-for="(item, i) in virtualData"
21
- :key="typeof item === 'string' ? i : item[keyField]"
22
- :style="itemStyle"
23
- @click="handleClick(item)"
24
- >
25
- <slot style="height: 100%" name="content" :record="item"></slot>
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
- <view
29
- v-if="line === 2"
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
- name: "hy-list",
71
- options: {
72
- addGlobalClass: true,
73
- virtualHost: true,
74
- styleIsolation: "shared",
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
- computed,
82
- getCurrentInstance,
83
- nextTick,
84
- onMounted,
85
- reactive,
86
- ref,
87
- useSlots,
88
- watch,
89
- } from "vue";
90
- import type { CSSProperties, PropType } from "vue";
91
- import { addUnit, getPx, getRect } from "../../libs";
92
- import type { IListEmits } from "./typing";
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 "@/package/components/hy-divider/hy-divider.vue";
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
- // const props = withDefaults(defineProps<IProps>(), defaultProps)
103
- const props = defineProps({
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
- left: AnyObject[];
177
- right: AnyObject[];
109
+ left: AnyObject[]
110
+ right: AnyObject[]
178
111
  } = reactive({
179
- left: [],
180
- right: [],
181
- });
112
+ left: [],
113
+ right: []
114
+ })
182
115
  // 排列方式
183
- const arrange = computed(() => (props.line === 1 ? "column" : "row"));
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
- nextTick(async () => {
190
- const res = await getRect(".hy-virtual-container", false, instance);
191
- viewHeight.value = (res as UniApp.NodeInfo).height || 0;
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
- return {
197
- height: addUnit(props.itemHeight),
198
- padding: addUnit(props.padding),
199
- marginBottom: addUnit(props.marginBottom),
200
- borderRadius: addUnit(props.borderRadius),
201
- background: props.background,
202
- border: props.border ? "1px solid #dadbde" : "",
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
- const s = Math.floor(scrollTop.value / boxHeight);
211
- return Math.max(0, s * props.line);
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
- const o = Math.floor(
219
- (scrollTop.value + viewHeight.value + 1) / boxHeight + 5,
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
- const paddingTop = start.value * boxHeight;
229
- const paddingBottom = (props.list.length - over.value) * boxHeight;
230
- return `${paddingTop / props.line}px 0 ${paddingBottom / props.line}px`;
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
- return props.list.slice(start.value, over.value);
238
- });
168
+ return props.list.slice(start.value, over.value)
169
+ })
239
170
 
240
171
  watch(
241
- () => virtualData.value,
242
- (newVal) => {
243
- waterfall.left.length = 0;
244
- waterfall.right.length = 0;
245
- if (props.line === 2 && newVal!.every((item) => typeof item !== "string")) {
246
- newVal.forEach((item, i) => {
247
- if (i % 2 === 0) {
248
- waterfall.left.push(item as AnyObject);
249
- } else {
250
- waterfall.right.push(item as AnyObject);
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
- scrollTop.value = e.detail.scrollTop || 0;
263
- };
193
+ scrollTop.value = e.detail.scrollTop || 0
194
+ }
264
195
 
265
196
  /**
266
197
  * @description 滚动底部函数
267
198
  * */
268
199
  const scrollToLower = () => {
269
- emit("scrollToLower");
270
- };
200
+ emit('scrollToLower')
201
+ }
271
202
 
272
203
  /**
273
204
  * @description 点击行触发函数
274
205
  * */
275
206
  const handleClick = (temp: string | AnyObject) => {
276
- emit("click", temp);
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 "./index.scss";
217
+ @import './index.scss';
287
218
  .hy-virtual-container {
288
- height: v-bind(listHeight);
289
- &__list {
290
- padding: v-bind(paddingAttr);
291
- display: flex;
292
- flex-direction: v-bind(arrange);
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 IProps from "./typing";
1
+ import type { PropType } from 'vue'
2
2
 
3
- const defaultProps: IProps = {
4
- list: [],
5
- containerHeight: "100%",
6
- itemHeight: 50,
7
- marginBottom: 10,
8
- padding: 10,
9
- borderRadius: "3px",
10
- background: "transparent",
11
- border: false,
12
- line: 1,
13
- keyField: "id",
14
- load: "loadMore",
15
- showDivider: true,
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 defaultProps;
69
+ export default listProps
@@ -1,57 +1,57 @@
1
1
  export default interface HyListProps {
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
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
- (e: 'click', temp: string | AnyObject): void
55
- /** 滚动底部触发 */
56
- (e: 'scrollToLower'): void
53
+ /** 点击行触发 */
54
+ (e: 'click', temp: string | AnyObject): void
55
+ /** 滚动底部触发 */
56
+ (e: 'scrollToLower'): void
57
57
  }