hy-app 0.6.9 → 0.7.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.
- package/attributes.json +1 -1
- package/components/hy-avatar/hy-avatar.vue +12 -5
- package/components/hy-avatar/props.ts +4 -2
- package/components/hy-avatar/typing.d.ts +8 -1
- package/components/hy-calendar/hy-calendar.vue +3 -2
- package/components/hy-calendar/month.vue +25 -5
- package/components/hy-calendar/props.ts +1 -1
- package/components/hy-calendar/typing.d.ts +9 -0
- package/components/hy-cascader/hy-cascader.vue +503 -0
- package/components/hy-cascader/index.scss +84 -0
- package/components/hy-cascader/props.ts +88 -0
- package/components/hy-cascader/typing.d.ts +34 -0
- package/components/hy-check-button/typing.d.ts +12 -7
- package/components/hy-code-input/hy-code-input.vue +33 -11
- package/components/hy-code-input/typing.d.ts +4 -0
- package/components/hy-config-provider/hy-config-provider.vue +58 -53
- package/components/hy-count-down/hy-count-down.vue +8 -8
- package/components/hy-count-down/typing.d.ts +16 -0
- package/components/hy-count-to/hy-count-to.vue +7 -7
- package/components/hy-count-to/typing.d.ts +24 -0
- package/components/hy-datetime-picker/props.ts +1 -1
- package/components/hy-datetime-picker/typing.d.ts +1 -1
- package/components/hy-dropdown/typing.d.ts +5 -0
- package/components/hy-dropdown-item/hy-dropdown-item.vue +1 -1
- package/components/hy-folding-panel/hy-folding-panel.vue +3 -3
- package/components/hy-folding-panel/typing.d.ts +23 -0
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +2 -2
- package/components/hy-folding-panel-item/typing.d.ts +21 -0
- package/components/hy-form/hy-form.vue +2 -2
- package/components/hy-form/typing.d.ts +37 -0
- package/components/hy-form-item/typing.d.ts +1 -1
- package/components/hy-grid/hy-grid.vue +12 -12
- package/components/hy-grid/index.scss +1 -2
- package/components/hy-grid/props.ts +7 -2
- package/components/hy-grid/typing.d.ts +1 -1
- package/components/hy-icon/typing.d.ts +52 -9
- package/components/hy-keyboard/constants.ts +83 -0
- package/components/hy-keyboard/hy-keyboard.vue +375 -0
- package/components/hy-keyboard/index.scss +73 -0
- package/components/hy-keyboard/key/index.scss +79 -0
- package/components/hy-keyboard/key/index.vue +91 -0
- package/components/hy-keyboard/key/types.ts +1 -0
- package/components/hy-keyboard/props.ts +108 -0
- package/components/hy-keyboard/typing.d.ts +18 -0
- package/components/hy-list/hy-list.vue +15 -13
- package/components/hy-list/props.ts +1 -1
- package/components/hy-modal/typing.d.ts +2 -2
- package/components/hy-notice-bar/hy-column-notice.vue +54 -94
- package/components/hy-notice-bar/hy-notice-bar.vue +128 -96
- package/components/hy-notice-bar/hy-row-notice.vue +89 -121
- package/components/hy-notice-bar/props.ts +86 -85
- package/components/hy-notify/hy-notify.vue +10 -10
- package/components/hy-notify/typing.d.ts +35 -0
- package/components/hy-number-step/hy-number-step.vue +370 -367
- package/components/hy-number-step/index.scss +1 -0
- package/components/hy-number-step/props.ts +1 -1
- package/components/hy-picker/hy-picker.vue +126 -149
- package/components/hy-picker/props.ts +4 -1
- package/components/hy-picker/typing.d.ts +22 -0
- package/components/hy-popover/hy-popover.vue +2 -2
- package/components/hy-popover/typing.d.ts +1 -1
- package/components/hy-popup/hy-popup.vue +1 -1
- package/components/hy-popup/index.scss +1 -0
- package/components/hy-price/hy-price.vue +52 -23
- package/components/hy-price/props.ts +54 -54
- package/components/hy-radio/props.ts +1 -1
- package/components/hy-radio/typing.d.ts +5 -1
- package/components/hy-rolling-num/typing.d.ts +1 -0
- package/components/hy-signature/hy-signature.vue +17 -17
- package/components/hy-signature/typing.d.ts +1 -1
- package/components/hy-skeleton/index.scss +17 -0
- package/components/hy-steps/hy-steps.vue +1 -1
- package/components/hy-submit-bar/typing.d.ts +3 -3
- package/components/hy-swipe-action/hy-swipe-action.vue +34 -15
- package/components/hy-swipe-action/index.scss +0 -1
- package/components/hy-switch/typing.d.ts +4 -0
- package/components/hy-tabbar/props.ts +2 -1
- package/components/hy-tabbar/typing.d.ts +5 -4
- package/components/hy-tabs/hy-tabs.vue +338 -336
- package/components/hy-tabs/index.scss +6 -6
- package/components/hy-tabs/typing.d.ts +41 -33
- package/components/hy-textarea/hy-textarea.vue +2 -2
- package/components/hy-textarea/typing.d.ts +4 -0
- package/components/hy-toast/hy-toast.vue +17 -9
- package/components/hy-toast/index.scss +1 -1
- package/components/hy-toast/typing.d.ts +56 -37
- package/components/hy-tooltip/hy-tooltip.vue +1 -1
- package/components/hy-tooltip/index.scss +1 -0
- package/components/hy-tooltip/props.ts +1 -1
- package/components/hy-upload/hy-upload.vue +16 -1
- package/components/hy-upload/index.scss +149 -144
- package/components/index.ts +6 -0
- package/global.d.ts +2 -0
- package/libs/api/http.ts +122 -119
- package/libs/config/icon.ts +442 -430
- package/libs/css/_function.scss +7 -13
- package/libs/css/iconfont.css +445 -441
- package/libs/css/theme.scss +3 -1
- package/libs/locale/lang/en-US.ts +4 -0
- package/libs/locale/lang/zh-CN.ts +4 -0
- package/libs/typing/index.ts +80 -0
- package/package.json +5 -2
- package/tags.json +1 -1
- package/web-types.json +1 -1
- package/components/hy-folding-panel/hy-folding-panel-group.vue +0 -163
- package/components/hy-qrcode/qrcode.js.bak +0 -1434
|
@@ -1,336 +1,338 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="hy-tabs">
|
|
3
|
-
<view class="hy-tabs__wrapper">
|
|
4
|
-
<slot name="left" />
|
|
5
|
-
<view class="hy-tabs__wrapper--scroll-view__wrapper">
|
|
6
|
-
<scroll-view
|
|
7
|
-
:scroll-x="scrollable"
|
|
8
|
-
:scroll-left="scrollLeft"
|
|
9
|
-
:scroll-with-animation="true"
|
|
10
|
-
class="hy-tabs__wrapper--scroll-view"
|
|
11
|
-
:show-scrollbar="false"
|
|
12
|
-
ref="hy-tabs__wrapper--scroll-view"
|
|
13
|
-
>
|
|
14
|
-
<view class="hy-tabs__wrapper--nav" ref="hy-tabs__wrapper__nav">
|
|
15
|
-
<view
|
|
16
|
-
v-for="(item, index) in list"
|
|
17
|
-
:key="index"
|
|
18
|
-
@tap="clickHandler(item, index)"
|
|
19
|
-
@longpress="longPressHandler(item, index)"
|
|
20
|
-
:ref="`u-tabs__wrapper--nav__item-${index}`"
|
|
21
|
-
:style="[itemStyle, { flex: scrollable ? '' : 1 }]"
|
|
22
|
-
:class="[
|
|
23
|
-
'hy-tabs__wrapper--nav__item',
|
|
24
|
-
`hy-tabs__wrapper--nav__item-${index}`,
|
|
25
|
-
item.disabled && 'hy-tabs__wrapper--nav__item--disabled',
|
|
26
|
-
innerCurrent == index ? 'hy-tabs__wrapper--nav__item--active' : ''
|
|
27
|
-
]"
|
|
28
|
-
>
|
|
29
|
-
<slot v-if="$slots.icon" name="icon" :record="item" :index="index" />
|
|
30
|
-
<view
|
|
31
|
-
class="hy-tabs__wrapper--nav__item--prefix-icon"
|
|
32
|
-
v-else-if="item.icon"
|
|
33
|
-
>
|
|
34
|
-
<hy-icon :name="item.icon" :customStyle="iconStyle"></hy-icon>
|
|
35
|
-
</view>
|
|
36
|
-
<slot
|
|
37
|
-
v-if="$slots.content"
|
|
38
|
-
name="content"
|
|
39
|
-
:record="item"
|
|
40
|
-
:index="index"
|
|
41
|
-
/>
|
|
42
|
-
<text
|
|
43
|
-
v-else
|
|
44
|
-
:class="[
|
|
45
|
-
'hy-tabs__wrapper--nav__item--test',
|
|
46
|
-
item.disabled && 'hy-tabs__wrapper--nav__item--text__disabled'
|
|
47
|
-
]"
|
|
48
|
-
:style="[textStyle(index)]"
|
|
49
|
-
>
|
|
50
|
-
{{ item[keyName] }}
|
|
51
|
-
</text>
|
|
52
|
-
<hy-badge
|
|
53
|
-
:show="
|
|
54
|
-
!!(
|
|
55
|
-
item?.badge &&
|
|
56
|
-
(item?.badge?.show ||
|
|
57
|
-
item?.badge?.isDot ||
|
|
58
|
-
item?.badge?.value)
|
|
59
|
-
)
|
|
60
|
-
"
|
|
61
|
-
:isDot="(item?.badge && item?.badge?.isDot) || badgeProps?.isDot"
|
|
62
|
-
:value="(item?.badge && item?.badge?.value) || badgeProps?.value"
|
|
63
|
-
:max="(item?.badge && item?.badge?.max) || badgeProps?.max"
|
|
64
|
-
:type="(item?.badge && item?.badge?.type) || badgeProps?.type"
|
|
65
|
-
:showZero="
|
|
66
|
-
(item?.badge && item?.badge?.showZero) || badgeProps?.showZero
|
|
67
|
-
"
|
|
68
|
-
:bgColor="
|
|
69
|
-
(item?.badge && item?.badge?.bgColor) || badgeProps?.bgColor
|
|
70
|
-
"
|
|
71
|
-
:color="(item?.badge && item?.badge?.color) || badgeProps?.color"
|
|
72
|
-
:shape="(item?.badge && item?.badge?.shape) || badgeProps?.shape"
|
|
73
|
-
:numberType="
|
|
74
|
-
(item?.badge && item?.badge?.numberType) ||
|
|
75
|
-
badgeProps?.numberType
|
|
76
|
-
"
|
|
77
|
-
:inverted="
|
|
78
|
-
(item?.badge && item?.badge?.inverted) || badgeProps?.inverted
|
|
79
|
-
"
|
|
80
|
-
:customStyle="{
|
|
81
|
-
marginLeft: '4px'
|
|
82
|
-
}"
|
|
83
|
-
></hy-badge>
|
|
84
|
-
</view>
|
|
85
|
-
<!-- #ifndef APP-NVUE -->
|
|
86
|
-
<view
|
|
87
|
-
class="hy-tabs__wrapper--nav__line"
|
|
88
|
-
ref="hy-tabs__wrapper--nav__line"
|
|
89
|
-
:style="[
|
|
90
|
-
{
|
|
91
|
-
width: addUnit(lineWidth),
|
|
92
|
-
transform: `translate(${lineOffsetLeft}px)`,
|
|
93
|
-
transitionDuration: `${firstTime ? 0 : duration}ms`,
|
|
94
|
-
height: addUnit(lineHeight),
|
|
95
|
-
background: lineColor,
|
|
96
|
-
backgroundSize: lineBgSize
|
|
97
|
-
}
|
|
98
|
-
]"
|
|
99
|
-
></view>
|
|
100
|
-
<!-- #endif -->
|
|
101
|
-
</view>
|
|
102
|
-
</scroll-view>
|
|
103
|
-
</view>
|
|
104
|
-
<slot name="right" />
|
|
105
|
-
</view>
|
|
106
|
-
</view>
|
|
107
|
-
|
|
108
|
-
<!-- 内容轮播图 -->
|
|
109
|
-
<slot v-if="$slots.main" name="main"></slot>
|
|
110
|
-
<swiper
|
|
111
|
-
v-else-if="isSwiper || list.length"
|
|
112
|
-
:current="innerCurrent"
|
|
113
|
-
@animationfinish="animationFinish"
|
|
114
|
-
:style="{ height: swiperHeight }"
|
|
115
|
-
>
|
|
116
|
-
<swiper-item class="swiper-item" v-for="(item, i) in list" :key="i">
|
|
117
|
-
<slot :record="item" :index="i" />
|
|
118
|
-
</swiper-item>
|
|
119
|
-
</swiper>
|
|
120
|
-
</template>
|
|
121
|
-
|
|
122
|
-
<script lang="ts">
|
|
123
|
-
export default {
|
|
124
|
-
name: 'hy-tabs',
|
|
125
|
-
options: {
|
|
126
|
-
addGlobalClass: true,
|
|
127
|
-
virtualHost: true,
|
|
128
|
-
styleIsolation: 'shared'
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
</script>
|
|
132
|
-
|
|
133
|
-
<script setup lang="ts">
|
|
134
|
-
import { computed, ref, watch, nextTick, onMounted, getCurrentInstance } from 'vue'
|
|
135
|
-
import type { CSSProperties } from 'vue'
|
|
136
|
-
import type { ITabsEmits, TabsItemVo } from './typing'
|
|
137
|
-
import { addUnit, getPx, getRect, sleep } from '../../libs'
|
|
138
|
-
import tabsProps from './props'
|
|
139
|
-
// 组件
|
|
140
|
-
import HyBadge from '../hy-badge/hy-badge.vue'
|
|
141
|
-
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 该组件是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
|
|
145
|
-
* @displayName hy-tabs
|
|
146
|
-
*/
|
|
147
|
-
defineOptions({})
|
|
148
|
-
|
|
149
|
-
const props = defineProps(tabsProps)
|
|
150
|
-
const emit = defineEmits<ITabsEmits>()
|
|
151
|
-
|
|
152
|
-
const instance = getCurrentInstance()
|
|
153
|
-
const firstTime = ref<boolean>(true)
|
|
154
|
-
const scrollLeft = ref<number>(0)
|
|
155
|
-
const scrollViewWidth = ref<number>(0)
|
|
156
|
-
const lineOffsetLeft = ref<number>(0)
|
|
157
|
-
const tabsRect = ref<UniApp.NodeInfo>({
|
|
158
|
-
left: 0
|
|
159
|
-
})
|
|
160
|
-
const innerCurrent = ref<number>(0)
|
|
161
|
-
|
|
162
|
-
watch(
|
|
163
|
-
() => props.current,
|
|
164
|
-
(newValue: number) => {
|
|
165
|
-
// 内外部值不相等时,才尝试移动滑块
|
|
166
|
-
if (newValue !== innerCurrent.value) {
|
|
167
|
-
innerCurrent.value = newValue
|
|
168
|
-
nextTick(() =>
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
//
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
tabsRect_1.
|
|
276
|
-
tabsRect_1.width
|
|
277
|
-
|
|
278
|
-
tabsRect_1.
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
//
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<view class="hy-tabs">
|
|
3
|
+
<view class="hy-tabs__wrapper">
|
|
4
|
+
<slot name="left" />
|
|
5
|
+
<view class="hy-tabs__wrapper--scroll-view__wrapper">
|
|
6
|
+
<scroll-view
|
|
7
|
+
:scroll-x="scrollable"
|
|
8
|
+
:scroll-left="scrollLeft"
|
|
9
|
+
:scroll-with-animation="true"
|
|
10
|
+
class="hy-tabs__wrapper--scroll-view"
|
|
11
|
+
:show-scrollbar="false"
|
|
12
|
+
ref="hy-tabs__wrapper--scroll-view"
|
|
13
|
+
>
|
|
14
|
+
<view class="hy-tabs__wrapper--nav" ref="hy-tabs__wrapper__nav">
|
|
15
|
+
<view
|
|
16
|
+
v-for="(item, index) in list"
|
|
17
|
+
:key="index"
|
|
18
|
+
@tap="clickHandler(item, index)"
|
|
19
|
+
@longpress="longPressHandler(item, index)"
|
|
20
|
+
:ref="`u-tabs__wrapper--nav__item-${index}`"
|
|
21
|
+
:style="[itemStyle, { flex: scrollable ? '' : 1 }]"
|
|
22
|
+
:class="[
|
|
23
|
+
'hy-tabs__wrapper--nav__item',
|
|
24
|
+
`hy-tabs__wrapper--nav__item-${index}`,
|
|
25
|
+
item.disabled && 'hy-tabs__wrapper--nav__item--disabled',
|
|
26
|
+
innerCurrent == index ? 'hy-tabs__wrapper--nav__item--active' : ''
|
|
27
|
+
]"
|
|
28
|
+
>
|
|
29
|
+
<slot v-if="$slots.icon" name="icon" :record="item" :index="index" />
|
|
30
|
+
<view
|
|
31
|
+
class="hy-tabs__wrapper--nav__item--prefix-icon"
|
|
32
|
+
v-else-if="item.icon"
|
|
33
|
+
>
|
|
34
|
+
<hy-icon :name="item.icon" :customStyle="iconStyle"></hy-icon>
|
|
35
|
+
</view>
|
|
36
|
+
<slot
|
|
37
|
+
v-if="$slots.content"
|
|
38
|
+
name="content"
|
|
39
|
+
:record="item"
|
|
40
|
+
:index="index"
|
|
41
|
+
/>
|
|
42
|
+
<text
|
|
43
|
+
v-else
|
|
44
|
+
:class="[
|
|
45
|
+
'hy-tabs__wrapper--nav__item--test',
|
|
46
|
+
item.disabled && 'hy-tabs__wrapper--nav__item--text__disabled'
|
|
47
|
+
]"
|
|
48
|
+
:style="[textStyle(index)]"
|
|
49
|
+
>
|
|
50
|
+
{{ item[keyName] }}
|
|
51
|
+
</text>
|
|
52
|
+
<hy-badge
|
|
53
|
+
:show="
|
|
54
|
+
!!(
|
|
55
|
+
item?.badge &&
|
|
56
|
+
(item?.badge?.show ||
|
|
57
|
+
item?.badge?.isDot ||
|
|
58
|
+
item?.badge?.value)
|
|
59
|
+
)
|
|
60
|
+
"
|
|
61
|
+
:isDot="(item?.badge && item?.badge?.isDot) || badgeProps?.isDot"
|
|
62
|
+
:value="(item?.badge && item?.badge?.value) || badgeProps?.value"
|
|
63
|
+
:max="(item?.badge && item?.badge?.max) || badgeProps?.max"
|
|
64
|
+
:type="(item?.badge && item?.badge?.type) || badgeProps?.type"
|
|
65
|
+
:showZero="
|
|
66
|
+
(item?.badge && item?.badge?.showZero) || badgeProps?.showZero
|
|
67
|
+
"
|
|
68
|
+
:bgColor="
|
|
69
|
+
(item?.badge && item?.badge?.bgColor) || badgeProps?.bgColor
|
|
70
|
+
"
|
|
71
|
+
:color="(item?.badge && item?.badge?.color) || badgeProps?.color"
|
|
72
|
+
:shape="(item?.badge && item?.badge?.shape) || badgeProps?.shape"
|
|
73
|
+
:numberType="
|
|
74
|
+
(item?.badge && item?.badge?.numberType) ||
|
|
75
|
+
badgeProps?.numberType
|
|
76
|
+
"
|
|
77
|
+
:inverted="
|
|
78
|
+
(item?.badge && item?.badge?.inverted) || badgeProps?.inverted
|
|
79
|
+
"
|
|
80
|
+
:customStyle="{
|
|
81
|
+
marginLeft: '4px'
|
|
82
|
+
}"
|
|
83
|
+
></hy-badge>
|
|
84
|
+
</view>
|
|
85
|
+
<!-- #ifndef APP-NVUE -->
|
|
86
|
+
<view
|
|
87
|
+
class="hy-tabs__wrapper--nav__line"
|
|
88
|
+
ref="hy-tabs__wrapper--nav__line"
|
|
89
|
+
:style="[
|
|
90
|
+
{
|
|
91
|
+
width: addUnit(lineWidth),
|
|
92
|
+
transform: `translate(${lineOffsetLeft}px)`,
|
|
93
|
+
transitionDuration: `${firstTime ? 0 : duration}ms`,
|
|
94
|
+
height: addUnit(lineHeight),
|
|
95
|
+
background: lineColor,
|
|
96
|
+
backgroundSize: lineBgSize
|
|
97
|
+
}
|
|
98
|
+
]"
|
|
99
|
+
></view>
|
|
100
|
+
<!-- #endif -->
|
|
101
|
+
</view>
|
|
102
|
+
</scroll-view>
|
|
103
|
+
</view>
|
|
104
|
+
<slot name="right" />
|
|
105
|
+
</view>
|
|
106
|
+
</view>
|
|
107
|
+
|
|
108
|
+
<!-- 内容轮播图 -->
|
|
109
|
+
<slot v-if="$slots.main" name="main"></slot>
|
|
110
|
+
<swiper
|
|
111
|
+
v-else-if="isSwiper || list.length"
|
|
112
|
+
:current="innerCurrent"
|
|
113
|
+
@animationfinish="animationFinish"
|
|
114
|
+
:style="{ height: swiperHeight }"
|
|
115
|
+
>
|
|
116
|
+
<swiper-item class="swiper-item" v-for="(item, i) in list" :key="i">
|
|
117
|
+
<slot :record="item" :index="i" />
|
|
118
|
+
</swiper-item>
|
|
119
|
+
</swiper>
|
|
120
|
+
</template>
|
|
121
|
+
|
|
122
|
+
<script lang="ts">
|
|
123
|
+
export default {
|
|
124
|
+
name: 'hy-tabs',
|
|
125
|
+
options: {
|
|
126
|
+
addGlobalClass: true,
|
|
127
|
+
virtualHost: true,
|
|
128
|
+
styleIsolation: 'shared'
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
</script>
|
|
132
|
+
|
|
133
|
+
<script setup lang="ts">
|
|
134
|
+
import { computed, ref, watch, nextTick, onMounted, getCurrentInstance } from 'vue'
|
|
135
|
+
import type { CSSProperties } from 'vue'
|
|
136
|
+
import type { ITabsEmits, ITabsExpose, TabsItemVo } from './typing'
|
|
137
|
+
import { addUnit, getPx, getRect, sleep } from '../../libs'
|
|
138
|
+
import tabsProps from './props'
|
|
139
|
+
// 组件
|
|
140
|
+
import HyBadge from '../hy-badge/hy-badge.vue'
|
|
141
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 该组件是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
|
|
145
|
+
* @displayName hy-tabs
|
|
146
|
+
*/
|
|
147
|
+
defineOptions({})
|
|
148
|
+
|
|
149
|
+
const props = defineProps(tabsProps)
|
|
150
|
+
const emit = defineEmits<ITabsEmits>()
|
|
151
|
+
|
|
152
|
+
const instance = getCurrentInstance()
|
|
153
|
+
const firstTime = ref<boolean>(true)
|
|
154
|
+
const scrollLeft = ref<number>(0)
|
|
155
|
+
const scrollViewWidth = ref<number>(0)
|
|
156
|
+
const lineOffsetLeft = ref<number>(0)
|
|
157
|
+
const tabsRect = ref<UniApp.NodeInfo>({
|
|
158
|
+
left: 0
|
|
159
|
+
})
|
|
160
|
+
const innerCurrent = ref<number>(0)
|
|
161
|
+
|
|
162
|
+
watch(
|
|
163
|
+
() => props.current,
|
|
164
|
+
(newValue: number) => {
|
|
165
|
+
// 内外部值不相等时,才尝试移动滑块
|
|
166
|
+
if (newValue !== innerCurrent.value) {
|
|
167
|
+
innerCurrent.value = newValue
|
|
168
|
+
nextTick(() => resize())
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
{ immediate: true }
|
|
172
|
+
)
|
|
173
|
+
watch(
|
|
174
|
+
() => props.list,
|
|
175
|
+
() => nextTick(() => resize())
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
const textStyle = computed(() => {
|
|
179
|
+
return (index: number): CSSProperties => {
|
|
180
|
+
const style: CSSProperties = {}
|
|
181
|
+
// 取当期是否激活的样式
|
|
182
|
+
const customStyle_1 = index == innerCurrent.value ? props.activeStyle : props.inactiveStyle
|
|
183
|
+
// 如果当前菜单被禁用,则加上对应颜色,需要在此做处理,是因为nvue下,无法在style样式中通过!import覆盖标签的内联样式
|
|
184
|
+
if (props.list[index]?.disabled) {
|
|
185
|
+
style.color = '#c8c9cc'
|
|
186
|
+
}
|
|
187
|
+
return Object.assign(customStyle_1, style)
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
onMounted(() => {
|
|
192
|
+
nextTick(() => resize())
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 设置线左边距离
|
|
197
|
+
*/
|
|
198
|
+
const setLineLeft = () => {
|
|
199
|
+
const tabItem = props.list[innerCurrent.value]
|
|
200
|
+
if (!tabItem) {
|
|
201
|
+
return
|
|
202
|
+
}
|
|
203
|
+
// 获取滑块该移动的位置
|
|
204
|
+
let lineOffsetLeft_1 = props.list
|
|
205
|
+
.slice(0, innerCurrent.value)
|
|
206
|
+
.reduce((total, curr) => total + curr.rect.width, 0)
|
|
207
|
+
// 获取下划线的数值px表示法
|
|
208
|
+
lineOffsetLeft.value = lineOffsetLeft_1 + (tabItem.rect.width - getPx(props.lineWidth)) / 2
|
|
209
|
+
|
|
210
|
+
// 如果是第一次执行此方法,让滑块在初始化时,瞬间滑动到第一个tab item的中间
|
|
211
|
+
// 这里需要一个定时器,因为在非nvue下,是直接通过style绑定过渡时间,需要等其过渡完成后,再设置为false(非第一次移动滑块)
|
|
212
|
+
if (firstTime.value) {
|
|
213
|
+
sleep().then(() => {
|
|
214
|
+
firstTime.value = false
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// 点击某一个标签
|
|
219
|
+
const clickHandler = (item: TabsItemVo, index: number) => {
|
|
220
|
+
// 因为标签可能为disabled状态,所以click是一定会发出的,但是change事件是需要可用的状态才发出
|
|
221
|
+
emit('click', {
|
|
222
|
+
...item,
|
|
223
|
+
index
|
|
224
|
+
})
|
|
225
|
+
// 如果disabled状态,返回
|
|
226
|
+
if (item.disabled) return
|
|
227
|
+
innerCurrent.value = index
|
|
228
|
+
resize()
|
|
229
|
+
emit('update:current', index)
|
|
230
|
+
emit('change', item, index)
|
|
231
|
+
}
|
|
232
|
+
// 长按事件
|
|
233
|
+
const longPressHandler = (item: TabsItemVo, index: number) => {
|
|
234
|
+
emit('longPress', {
|
|
235
|
+
...item,
|
|
236
|
+
index
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
const setScrollLeft = () => {
|
|
240
|
+
// 当前活动tab的布局信息,有tab菜单的width和left(为元素左边界到父元素左边界的距离)等信息
|
|
241
|
+
if (innerCurrent.value < 0) {
|
|
242
|
+
innerCurrent.value = 0
|
|
243
|
+
}
|
|
244
|
+
const tabRect = props.list[innerCurrent.value]
|
|
245
|
+
// 累加得到当前item到左边的距离
|
|
246
|
+
const offsetLeft = props.list.slice(0, innerCurrent.value).reduce((total: number, curr) => {
|
|
247
|
+
return total + curr.rect.width
|
|
248
|
+
}, 0)
|
|
249
|
+
// 此处为屏幕宽度
|
|
250
|
+
const windowWidth = uni.getWindowInfo().windowWidth
|
|
251
|
+
// 将活动的tabs-item移动到屏幕正中间,实际上是对scroll-view的移动
|
|
252
|
+
let scrollLeft_1 =
|
|
253
|
+
offsetLeft -
|
|
254
|
+
((tabsRect.value.width || 0) - tabRect.rect.width) / 2 -
|
|
255
|
+
(windowWidth - (tabsRect.value.right || 0)) / 2 +
|
|
256
|
+
(tabsRect.value.left || 0) / 2
|
|
257
|
+
// 这里做一个限制,限制scrollLeft的最大值为整个scroll-view宽度减去tabs组件的宽度
|
|
258
|
+
scrollLeft_1 = Math.min(scrollLeft_1, scrollViewWidth.value - (tabsRect.value.width || 0))
|
|
259
|
+
scrollLeft.value = Math.max(0, scrollLeft_1)
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* 获取所有标签的尺寸
|
|
263
|
+
* */
|
|
264
|
+
const resize = () => {
|
|
265
|
+
// 如果不存在list,则不处理
|
|
266
|
+
if (props.list.length === 0) {
|
|
267
|
+
return
|
|
268
|
+
}
|
|
269
|
+
Promise.all([getTabsRect(), getAllItemRect()]).then(
|
|
270
|
+
([tabsRect_1, itemRect = []]: (UniApp.NodeInfo | any)[]) => {
|
|
271
|
+
// 兼容在swiper组件中使用
|
|
272
|
+
if (
|
|
273
|
+
tabsRect_1.left &&
|
|
274
|
+
tabsRect_1.width &&
|
|
275
|
+
tabsRect_1.right &&
|
|
276
|
+
tabsRect_1.left > tabsRect_1.width
|
|
277
|
+
) {
|
|
278
|
+
tabsRect_1.right =
|
|
279
|
+
tabsRect_1.right -
|
|
280
|
+
Math.floor(tabsRect_1.left / tabsRect_1.width) * tabsRect_1.width
|
|
281
|
+
tabsRect_1.left = tabsRect_1.left % tabsRect_1.width
|
|
282
|
+
}
|
|
283
|
+
// console.log(tabsRect)
|
|
284
|
+
tabsRect.value = tabsRect_1
|
|
285
|
+
scrollViewWidth.value = 0
|
|
286
|
+
itemRect.map((item: UniApp.NodeInfo, index: number) => {
|
|
287
|
+
// 计算scroll-view的宽度,这里
|
|
288
|
+
scrollViewWidth.value += item.width || 0
|
|
289
|
+
// 另外计算每一个item的中心点X轴坐标
|
|
290
|
+
if (props.list[index]) props.list[index].rect = item
|
|
291
|
+
})
|
|
292
|
+
// 获取了tabs的尺寸之后,设置滑块的位置
|
|
293
|
+
setLineLeft()
|
|
294
|
+
setScrollLeft()
|
|
295
|
+
}
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* 获取导航菜单的尺寸
|
|
300
|
+
* */
|
|
301
|
+
const getTabsRect = () => {
|
|
302
|
+
return new Promise((resolve) => {
|
|
303
|
+
getRect('.hy-tabs__wrapper--scroll-view', false, instance).then((size) => resolve(size))
|
|
304
|
+
})
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* 获取所有标签的尺寸
|
|
308
|
+
* */
|
|
309
|
+
const getAllItemRect = () => {
|
|
310
|
+
return new Promise((resolve) => {
|
|
311
|
+
const promiseAllArr = props.list.map((item, index) =>
|
|
312
|
+
getRect(`.hy-tabs__wrapper--nav__item-${index}`, false, instance)
|
|
313
|
+
)
|
|
314
|
+
Promise.all(promiseAllArr).then((sizes) => resolve(sizes))
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 滑动页面改变当前值
|
|
320
|
+
* */
|
|
321
|
+
const animationFinish = (e: any) => {
|
|
322
|
+
// 轮播图选项值
|
|
323
|
+
innerCurrent.value = e.detail.current
|
|
324
|
+
resize()
|
|
325
|
+
if (e.detail.source === 'touch') {
|
|
326
|
+
emit('update:current', innerCurrent.value)
|
|
327
|
+
emit('change', props.list[innerCurrent.value], innerCurrent.value)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
defineExpose<ITabsExpose>({
|
|
332
|
+
resize
|
|
333
|
+
})
|
|
334
|
+
</script>
|
|
335
|
+
|
|
336
|
+
<style lang="scss" scoped>
|
|
337
|
+
@import './index.scss';
|
|
338
|
+
</style>
|