@puresnake/snake-ui 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/changelog.md +1 -0
- package/components/snake-activity-list/snake-activity-list.vue +365 -0
- package/components/snake-activity-list/types.ts +29 -0
- package/components/snake-auxiliary-segmentation/snake-auxiliary-segmentation.vue +44 -0
- package/components/snake-auxiliary-segmentation/types.ts +5 -0
- package/components/snake-button/snake-button.vue +357 -0
- package/components/snake-button/types.ts +103 -0
- package/components/snake-button-sort/snake-button-sort.vue +72 -0
- package/components/snake-button-sort/types.ts +22 -0
- package/components/snake-calendar/snake-calendar.vue +998 -0
- package/components/snake-calendar/types.ts +189 -0
- package/components/snake-cell-group/snake-cell-group.vue +55 -0
- package/components/snake-cell-group/types.ts +19 -0
- package/components/snake-cell-item/snake-cell-item.vue +159 -0
- package/components/snake-cell-item/types.ts +66 -0
- package/components/snake-checkbox/snake-checkbox.vue +264 -0
- package/components/snake-checkbox/types.ts +70 -0
- package/components/snake-checkbox-group/snake-checkbox-group.vue +154 -0
- package/components/snake-checkbox-group/types.ts +52 -0
- package/components/snake-cms/blocks/v2/cms-v2-carousel.vue +87 -0
- package/components/snake-cms/blocks/v2/cms-v2-coupon.vue +25 -0
- package/components/snake-cms/blocks/v2/cms-v2-custom.vue +12 -0
- package/components/snake-cms/blocks/v2/cms-v2-divider.vue +33 -0
- package/components/snake-cms/blocks/v2/cms-v2-floatbutton.vue +28 -0
- package/components/snake-cms/blocks/v2/cms-v2-goods-list.vue +150 -0
- package/components/snake-cms/blocks/v2/cms-v2-hotzone.vue +41 -0
- package/components/snake-cms/blocks/v2/cms-v2-images.vue +41 -0
- package/components/snake-cms/blocks/v2/cms-v2-magiccube.vue +93 -0
- package/components/snake-cms/blocks/v2/cms-v2-notice.vue +80 -0
- package/components/snake-cms/blocks/v2/cms-v2-popup.vue +46 -0
- package/components/snake-cms/blocks/v2/cms-v2-richtext.vue +18 -0
- package/components/snake-cms/blocks/v2/cms-v2-search.vue +115 -0
- package/components/snake-cms/blocks/v2/cms-v2-video.vue +25 -0
- package/components/snake-cms/blocks/v2/shared.ts +84 -0
- package/components/snake-cms/snake-cms.vue +409 -0
- package/components/snake-cms/types.ts +50 -0
- package/components/snake-commodity-search/snake-commodity-search.vue +234 -0
- package/components/snake-commodity-search/types.ts +11 -0
- package/components/snake-config-provider/snake-config-provider.vue +61 -0
- package/components/snake-config-provider/types.ts +22 -0
- package/components/snake-count-down/snake-count-down.vue +231 -0
- package/components/snake-count-down/types.ts +103 -0
- package/components/snake-coupon/snake-coupon.vue +209 -0
- package/components/snake-coupon/types.ts +21 -0
- package/components/snake-custom-module/snake-custom-module.vue +25 -0
- package/components/snake-custom-module/types.ts +11 -0
- package/components/snake-drop-menu/snake-drop-menu.vue +123 -0
- package/components/snake-drop-menu/types.ts +95 -0
- package/components/snake-drop-menu-item/snake-drop-menu-item.vue +181 -0
- package/components/snake-drop-menu-item/types.ts +48 -0
- package/components/snake-empty/snake-empty.vue +100 -0
- package/components/snake-empty/types.ts +48 -0
- package/components/snake-filter-sorts/filter-page.vue +695 -0
- package/components/snake-filter-sorts/snake-filter-sorts.vue +185 -0
- package/components/snake-filter-sorts/types.ts +57 -0
- package/components/snake-floating-bubble/snake-floating-bubble.vue +157 -0
- package/components/snake-floating-bubble/types.ts +43 -0
- package/components/snake-follow/snake-follow.vue +18 -0
- package/components/snake-follow/types.ts +2 -0
- package/components/snake-form/snake-form.vue +124 -0
- package/components/snake-form/types.ts +96 -0
- package/components/snake-form-item/snake-form-item.vue +331 -0
- package/components/snake-form-item/types.ts +70 -0
- package/components/snake-goods-list/snake-goods-list.vue +792 -0
- package/components/snake-goods-list/types.ts +55 -0
- package/components/snake-graphic-navigation/snake-graphic-navigation.vue +198 -0
- package/components/snake-graphic-navigation/types.ts +43 -0
- package/components/snake-icon/icon-names.ts +222 -0
- package/components/snake-icon/snake-icon.vue +220 -0
- package/components/snake-icon/types.ts +45 -0
- package/components/snake-image/snake-image.vue +230 -0
- package/components/snake-image/types.ts +70 -0
- package/components/snake-images/snake-images.vue +80 -0
- package/components/snake-images/types.ts +5 -0
- package/components/snake-index-anchor/snake-index-anchor.vue +83 -0
- package/components/snake-index-anchor/types.ts +14 -0
- package/components/snake-index-list/anchor-registry.ts +80 -0
- package/components/snake-index-list/snake-index-list.vue +259 -0
- package/components/snake-index-list/types.ts +115 -0
- package/components/snake-index-list-panel/snake-index-list-panel.vue +277 -0
- package/components/snake-index-list-panel/types.ts +10 -0
- package/components/snake-input/snake-input.vue +225 -0
- package/components/snake-input/types.ts +99 -0
- package/components/snake-jump-applet/snake-jump-applet.vue +99 -0
- package/components/snake-jump-applet/types.ts +17 -0
- package/components/snake-line/snake-line.vue +42 -0
- package/components/snake-line/types.ts +30 -0
- package/components/snake-line-progress/snake-line-progress.vue +105 -0
- package/components/snake-line-progress/types.ts +26 -0
- package/components/snake-link/snake-link.vue +74 -0
- package/components/snake-link/types.ts +30 -0
- package/components/snake-list-switching/components/tree-select/index.vue +156 -0
- package/components/snake-list-switching/snake-list-switching.vue +1285 -0
- package/components/snake-list-switching/types.ts +11 -0
- package/components/snake-loading/snake-loading.vue +241 -0
- package/components/snake-loading/types.ts +34 -0
- package/components/snake-loadmore/snake-loadmore.vue +103 -0
- package/components/snake-loadmore/types.ts +56 -0
- package/components/snake-magic-cube/snake-magic-cube.vue +622 -0
- package/components/snake-magic-cube/types.ts +5 -0
- package/components/snake-modal/snake-modal.vue +434 -0
- package/components/snake-modal/types.ts +71 -0
- package/components/snake-navbar/snake-navbar.vue +194 -0
- package/components/snake-navbar/types.ts +54 -0
- package/components/snake-no-network/snake-no-network.vue +125 -0
- package/components/snake-no-network/types.ts +27 -0
- package/components/snake-notice/snake-notice.vue +44 -0
- package/components/snake-notice/types.ts +5 -0
- package/components/snake-notice-bar/snake-notice-bar.vue +336 -0
- package/components/snake-notice-bar/types.ts +82 -0
- package/components/snake-overlay/snake-overlay.vue +73 -0
- package/components/snake-overlay/types.ts +35 -0
- package/components/snake-page-popup/snake-page-popup.vue +146 -0
- package/components/snake-page-popup/types.ts +28 -0
- package/components/snake-parse/audio/audio.vue +286 -0
- package/components/snake-parse/audio/context.js +11 -0
- package/components/snake-parse/audio/index.js +34 -0
- package/components/snake-parse/node/node.vue +830 -0
- package/components/snake-parse/parser.js +1480 -0
- package/components/snake-parse/snake-parse.vue +548 -0
- package/components/snake-parse/static/app-plus/snake-parse/js/handler.js +109 -0
- package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.js +0 -0
- package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.min.js +1 -0
- package/components/snake-parse/static/app-plus/snake-parse/local.html +3 -0
- package/components/snake-parse/style/index.js +132 -0
- package/components/snake-parse/style/parser.js +175 -0
- package/components/snake-parse/types.ts +49 -0
- package/components/snake-picture-ads/snake-picture-ads.vue +292 -0
- package/components/snake-picture-ads/types.ts +5 -0
- package/components/snake-popup/snake-popup.vue +348 -0
- package/components/snake-popup/types.ts +88 -0
- package/components/snake-qr-code/qrcode.ts +1214 -0
- package/components/snake-qr-code/snake-qr-code.vue +408 -0
- package/components/snake-qr-code/types.ts +78 -0
- package/components/snake-radio/snake-radio.vue +271 -0
- package/components/snake-radio/types.ts +64 -0
- package/components/snake-radio-group/snake-radio-group.vue +98 -0
- package/components/snake-radio-group/types.ts +48 -0
- package/components/snake-read-more/snake-read-more.vue +140 -0
- package/components/snake-read-more/types.ts +53 -0
- package/components/snake-rich-text/snake-rich-text.vue +24 -0
- package/components/snake-rich-text/types.ts +5 -0
- package/components/snake-root-portal/snake-root-portal.vue +92 -0
- package/components/snake-root-portal/types.ts +9 -0
- package/components/snake-search/snake-search.vue +202 -0
- package/components/snake-search/types.ts +84 -0
- package/components/snake-select/snake-select.vue +371 -0
- package/components/snake-select/types.ts +75 -0
- package/components/snake-skeleton/snake-skeleton.vue +104 -0
- package/components/snake-skeleton/types.ts +32 -0
- package/components/snake-skeleton-item/snake-skeleton-item.vue +90 -0
- package/components/snake-skeleton-item/types.ts +30 -0
- package/components/snake-slider/snake-slider.vue +249 -0
- package/components/snake-slider/types.ts +59 -0
- package/components/snake-sticky/snake-sticky.vue +178 -0
- package/components/snake-sticky/types.ts +48 -0
- package/components/snake-subsection/snake-subsection.vue +188 -0
- package/components/snake-subsection/types.ts +54 -0
- package/components/snake-swiper/snake-swiper.vue +229 -0
- package/components/snake-swiper/types.ts +79 -0
- package/components/snake-switch/snake-switch.vue +100 -0
- package/components/snake-switch/types.ts +41 -0
- package/components/snake-tabbar/snake-tabbar.vue +306 -0
- package/components/snake-tabbar/types.ts +93 -0
- package/components/snake-tabs/snake-tabs.vue +305 -0
- package/components/snake-tabs/types.ts +79 -0
- package/components/snake-text/snake-text.vue +292 -0
- package/components/snake-text/types.ts +100 -0
- package/components/snake-textarea/snake-textarea.vue +171 -0
- package/components/snake-textarea/types.ts +79 -0
- package/components/snake-toast/snake-toast.vue +330 -0
- package/components/snake-toast/types.ts +55 -0
- package/components/snake-tooltip/position.ts +33 -0
- package/components/snake-tooltip/snake-tooltip.vue +339 -0
- package/components/snake-tooltip/types.ts +80 -0
- package/components/snake-transition/snake-transition.vue +315 -0
- package/components/snake-transition/types.ts +65 -0
- package/components/snake-upload/snake-upload.vue +1801 -0
- package/components/snake-upload/types.ts +256 -0
- package/components/snake-videos/snake-videos.vue +122 -0
- package/components/snake-videos/types.ts +7 -0
- package/iconfont.css +881 -0
- package/index.d.ts +7 -0
- package/index.scss +26 -0
- package/index.ts +94 -0
- package/libs/cms/blocks.ts +103 -0
- package/libs/cms/config.ts +25 -0
- package/libs/cms/index.ts +7 -0
- package/libs/cms/normalize.ts +135 -0
- package/libs/cms/resolve.ts +12 -0
- package/libs/cms/types.ts +164 -0
- package/libs/cms/use-commerce.ts +385 -0
- package/libs/cms/v2.ts +193 -0
- package/libs/config/index.ts +4 -0
- package/libs/config/modal.ts +93 -0
- package/libs/config/state.ts +33 -0
- package/libs/config/theme.ts +351 -0
- package/libs/config/toast.ts +71 -0
- package/libs/config/types.ts +135 -0
- package/libs/config/zIndex.ts +44 -0
- package/libs/css/color.scss +105 -0
- package/libs/css/common.scss +171 -0
- package/libs/css/style.h5.scss +7 -0
- package/libs/css/style.mp.scss +7 -0
- package/libs/css/style.theme.scss +70 -0
- package/libs/css/style.vue.scss +140 -0
- package/libs/form/async-validator.min.d.ts +75 -0
- package/libs/form/async-validator.min.js +3 -0
- package/libs/form/index.ts +3 -0
- package/libs/form/path.ts +40 -0
- package/libs/form/types.ts +51 -0
- package/libs/form/validate.ts +149 -0
- package/libs/foundation.ts +96 -0
- package/libs/function/$parent.ts +33 -0
- package/libs/function/clipboard.ts +13 -0
- package/libs/function/color.ts +55 -0
- package/libs/function/debounce.ts +34 -0
- package/libs/function/deepClone.ts +30 -0
- package/libs/function/deepMerge.ts +25 -0
- package/libs/function/emitter.ts +30 -0
- package/libs/function/format.ts +27 -0
- package/libs/function/getParent.ts +53 -0
- package/libs/function/getRect.ts +29 -0
- package/libs/function/guid.ts +11 -0
- package/libs/function/index.ts +31 -0
- package/libs/function/queryParams.ts +73 -0
- package/libs/function/random.ts +6 -0
- package/libs/function/randomArray.ts +14 -0
- package/libs/function/route.ts +155 -0
- package/libs/function/sleep.ts +7 -0
- package/libs/function/style.ts +58 -0
- package/libs/function/styleUtils.ts +83 -0
- package/libs/function/system.ts +14 -0
- package/libs/function/test.ts +202 -0
- package/libs/function/throttle.ts +36 -0
- package/libs/function/timeFormat.ts +27 -0
- package/libs/function/timeFrom.ts +27 -0
- package/libs/function/toast.ts +10 -0
- package/libs/function/trim.ts +11 -0
- package/libs/function/type2icon.ts +11 -0
- package/libs/function/unit.ts +45 -0
- package/libs/hooks/index.ts +11 -0
- package/libs/hooks/useChildren.ts +125 -0
- package/libs/hooks/useColor.ts +5 -0
- package/libs/hooks/useDebounce.ts +5 -0
- package/libs/hooks/useLocale.ts +13 -0
- package/libs/hooks/useModal.ts +131 -0
- package/libs/hooks/useParent.ts +62 -0
- package/libs/hooks/useRect.ts +44 -0
- package/libs/hooks/useRouter.ts +5 -0
- package/libs/hooks/useTheme.ts +31 -0
- package/libs/hooks/useThrottle.ts +5 -0
- package/libs/hooks/useToast.ts +116 -0
- package/libs/index.ts +18 -0
- package/libs/request/auto-http.ts +1 -0
- package/libs/request/index.ts +343 -0
- package/libs/runtime/accessors.ts +55 -0
- package/libs/runtime/context.ts +40 -0
- package/libs/runtime/index.ts +18 -0
- package/libs/runtime/types.ts +49 -0
- package/libs/util/calendar.ts +6 -0
- package/locale/index.ts +130 -0
- package/locale/lang/en-US.ts +67 -0
- package/locale/lang/zh-CN.ts +67 -0
- package/package.json +130 -5
- package/plugins/index.ts +1 -0
- package/plugins/root/README.md +86 -0
- package/plugins/root/index.ts +123 -0
- package/plugins/root/page.ts +77 -0
- package/plugins/root/root.ts +53 -0
- package/plugins/root/utils.ts +137 -0
- package/readme.md +79 -0
- package/theme.scss +118 -0
- package/types/components.d.ts +236 -0
- package/types/global.d.ts +21 -0
- package/types/index.d.ts +6 -0
- package/types/uni-app.d.ts +16 -0
- package/README.md +0 -3
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view v-if="show" class="snake-tabbar-spacer" :style="spacerStyle" />
|
|
3
|
+
<view
|
|
4
|
+
v-if="show"
|
|
5
|
+
:class="[
|
|
6
|
+
'snake-tabbar',
|
|
7
|
+
customClass,
|
|
8
|
+
{
|
|
9
|
+
'snake-tabbar--fixed': fixed,
|
|
10
|
+
'snake-tabbar--safe': safeAreaInsetBottom,
|
|
11
|
+
'snake-tabbar--border': borderTop
|
|
12
|
+
}
|
|
13
|
+
]"
|
|
14
|
+
:style="rootStyle"
|
|
15
|
+
role="navigation"
|
|
16
|
+
@touchmove.stop.prevent="() => {}"
|
|
17
|
+
>
|
|
18
|
+
<view class="snake-tabbar__inner" :style="{ height: addUnit(height, 'rpx') }">
|
|
19
|
+
<view
|
|
20
|
+
v-for="(item, index) in tabItems"
|
|
21
|
+
:key="String(itemKey(item, index))"
|
|
22
|
+
:class="[
|
|
23
|
+
'snake-tabbar__item',
|
|
24
|
+
{
|
|
25
|
+
'snake-tabbar__item--active': isActive(item, index),
|
|
26
|
+
'snake-tabbar__item--disabled': item.disabled,
|
|
27
|
+
'snake-tabbar__item--mid': midButton && item.midButton
|
|
28
|
+
}
|
|
29
|
+
]"
|
|
30
|
+
hover-class="snake-tabbar__item--hover"
|
|
31
|
+
:style="itemStyle(item)"
|
|
32
|
+
:aria-label="item.text || ''"
|
|
33
|
+
:aria-current="isActive(item, index) ? 'page' : undefined"
|
|
34
|
+
@tap.stop="clickItem(item, index)"
|
|
35
|
+
>
|
|
36
|
+
<view class="snake-tabbar__icon-wrap" :style="{ gap: addUnit(item.gap ?? gap, 'rpx') }">
|
|
37
|
+
<SnakeIcon
|
|
38
|
+
v-if="iconName(item, index)"
|
|
39
|
+
:name="iconName(item, index)"
|
|
40
|
+
:size="itemIconSize(item)"
|
|
41
|
+
:bold="isActive(item, index)"
|
|
42
|
+
:color="isActive(item, index) ? activeColor : inactiveColor"
|
|
43
|
+
:custom-prefix="iconPrefix(item)"
|
|
44
|
+
/>
|
|
45
|
+
<text
|
|
46
|
+
v-if="item.badge !== undefined || item.count !== undefined || item.isDot"
|
|
47
|
+
class="snake-tabbar__badge"
|
|
48
|
+
>
|
|
49
|
+
{{ item.isDot ? '' : (item.badge ?? item.count) }}
|
|
50
|
+
</text>
|
|
51
|
+
</view>
|
|
52
|
+
<text class="snake-tabbar__label" :style="{ fontSize: addUnit(itemTextSize(item), 'rpx') }">
|
|
53
|
+
{{ item.text }}
|
|
54
|
+
</text>
|
|
55
|
+
</view>
|
|
56
|
+
</view>
|
|
57
|
+
</view>
|
|
58
|
+
</template>
|
|
59
|
+
|
|
60
|
+
<script setup lang="ts">
|
|
61
|
+
/**
|
|
62
|
+
* @component Tabbar
|
|
63
|
+
* @description 底部导航栏,提供跨端安全区、激活态、徽标和禁用状态。
|
|
64
|
+
* @see /components/tabbar
|
|
65
|
+
*/
|
|
66
|
+
import { computed, getCurrentInstance, onMounted } from 'vue';
|
|
67
|
+
import { addUnit } from '../../libs/function/unit';
|
|
68
|
+
import SnakeIcon from '../snake-icon/snake-icon.vue';
|
|
69
|
+
import type { TabbarEmits, TabbarItem, TabbarProps } from './types';
|
|
70
|
+
|
|
71
|
+
defineOptions({
|
|
72
|
+
name: 'Tabbar',
|
|
73
|
+
options: { addGlobalClass: true, styleIsolation: 'shared' }
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const props = withDefaults(defineProps<TabbarProps>(), {
|
|
77
|
+
items: () => [],
|
|
78
|
+
list: () => [],
|
|
79
|
+
current: '',
|
|
80
|
+
modelValue: 0,
|
|
81
|
+
show: true,
|
|
82
|
+
fixed: true,
|
|
83
|
+
safeAreaInsetBottom: true,
|
|
84
|
+
customStyle: '',
|
|
85
|
+
customClass: '',
|
|
86
|
+
activeColor: 'var(--snake-color-primary, #06D290)',
|
|
87
|
+
inactiveColor: 'var(--snake-color-text-muted, #909399)',
|
|
88
|
+
bgColor: 'var(--snake-color-surface)',
|
|
89
|
+
borderTop: true,
|
|
90
|
+
hideTabBar: true,
|
|
91
|
+
midButton: false,
|
|
92
|
+
iconSize: 40,
|
|
93
|
+
midButtonSize: 100,
|
|
94
|
+
textSize: 22,
|
|
95
|
+
gap: 5,
|
|
96
|
+
height: 104,
|
|
97
|
+
zIndex: 120
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const emit = defineEmits<TabbarEmits>();
|
|
101
|
+
// `items` 是推荐字段;`list` 保留为旧配置字段。
|
|
102
|
+
const tabItems = computed(() => (props.items.length ? props.items : props.list));
|
|
103
|
+
// 只有调用方显式传入 v-model 时才按索引高亮,避免默认值覆盖 `current`。
|
|
104
|
+
const usesModelValue = computed(() => 'modelValue' in (getCurrentInstance()?.vnode.props ?? {}));
|
|
105
|
+
// 任一项指定宽度后,未指定项必须改为填充剩余空间,不能再按百分比分配。
|
|
106
|
+
const hasCustomWidth = computed(() =>
|
|
107
|
+
tabItems.value.some(item => item.width !== undefined && item.width !== null && item.width !== '')
|
|
108
|
+
);
|
|
109
|
+
const currentPage = computed(() => {
|
|
110
|
+
const pages = getCurrentPages();
|
|
111
|
+
return pages.length ? `/${pages[pages.length - 1].route}` : '';
|
|
112
|
+
});
|
|
113
|
+
const rootStyle = computed(() => [
|
|
114
|
+
{
|
|
115
|
+
'--snake-tabbar-active': props.activeColor,
|
|
116
|
+
'--snake-tabbar-inactive': props.inactiveColor,
|
|
117
|
+
zIndex: props.zIndex,
|
|
118
|
+
backgroundColor: props.bgColor
|
|
119
|
+
},
|
|
120
|
+
props.customStyle
|
|
121
|
+
]);
|
|
122
|
+
const spacerStyle = computed(() => {
|
|
123
|
+
if (!props.fixed) return { height: '0' };
|
|
124
|
+
|
|
125
|
+
// 凸起按钮会越过栏顶;占位同步增加 60rpx,防止页面末尾内容被遮住。
|
|
126
|
+
const midButtonHeight = props.midButton ? '60rpx' : '1px';
|
|
127
|
+
const safeAreaHeight = props.safeAreaInsetBottom ? ' + env(safe-area-inset-bottom)' : '';
|
|
128
|
+
return { height: `calc(${addUnit(props.height, 'rpx')} + ${midButtonHeight}${safeAreaHeight})` };
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
onMounted(() => {
|
|
132
|
+
if (!props.hideTabBar) return;
|
|
133
|
+
|
|
134
|
+
// uni-app only permits this API on pages declared in the native tabBar.
|
|
135
|
+
// A component library cannot inspect the consumer's pages.json at runtime,
|
|
136
|
+
// so explicitly consume that expected failure on ordinary pages.
|
|
137
|
+
uni.hideTabBar({ fail: () => {} });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
function isActive(item: TabbarItem, index: number) {
|
|
141
|
+
// pagePath 模式以真实路由为准;纯组件模式才由 v-model/current 控制。
|
|
142
|
+
if (item.pagePath) return item.pagePath === currentPage.value;
|
|
143
|
+
if (usesModelValue.value) return index === props.modelValue;
|
|
144
|
+
return item.key === props.current;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function iconName(item: TabbarItem, index: number) {
|
|
148
|
+
const normal = item.iconPath ?? item.icon;
|
|
149
|
+
return isActive(item, index) ? item.selectedIconPath || normal : normal;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function iconPrefix(item: TabbarItem) {
|
|
153
|
+
if (typeof item.customIcon === 'string') return item.customIcon;
|
|
154
|
+
return item.customIcon ? 'custom-icon' : 'sicon';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function itemIconSize(item: TabbarItem) {
|
|
158
|
+
if (props.midButton && item.midButton) return props.midButtonSize;
|
|
159
|
+
return item.iconSize ?? props.iconSize;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function itemTextSize(item: TabbarItem) {
|
|
163
|
+
return item.textSize ?? props.textSize;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function itemKey(item: TabbarItem, index: number) {
|
|
167
|
+
return item.key ?? index;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function itemStyle(item: TabbarItem): Record<string, string> {
|
|
171
|
+
const style: Record<string, string> = {};
|
|
172
|
+
if (item.width !== undefined && item.width !== null && item.width !== '') {
|
|
173
|
+
const width = addUnit(item.width, 'rpx');
|
|
174
|
+
style.flex = `0 0 ${width}`;
|
|
175
|
+
style.width = width;
|
|
176
|
+
} else if (hasCustomWidth.value) {
|
|
177
|
+
style.flex = '1 1 auto';
|
|
178
|
+
style.width = 'auto';
|
|
179
|
+
} else if (tabItems.value.length) {
|
|
180
|
+
const width = `${100 / tabItems.value.length}%`;
|
|
181
|
+
style.flex = `0 0 ${width}`;
|
|
182
|
+
style.width = width;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (props.midButton && item.midButton) {
|
|
186
|
+
// 图标绝对定位后不再参与文档流,额外顶部内边距为标签留出空间。
|
|
187
|
+
const size =
|
|
188
|
+
Number.parseFloat(String(itemIconSize(item))) || Number.parseFloat(String(props.midButtonSize)) || 100;
|
|
189
|
+
style.paddingTop = addUnit(size / 2 + 8, 'rpx');
|
|
190
|
+
style.boxSizing = 'border-box';
|
|
191
|
+
}
|
|
192
|
+
return style;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function clickItem(item: TabbarItem, index: number) {
|
|
196
|
+
if (item.disabled) return;
|
|
197
|
+
|
|
198
|
+
if (props.beforeSwitch) {
|
|
199
|
+
try {
|
|
200
|
+
// 同步场景必须明确返回 true;Promise resolve 即表示放行。
|
|
201
|
+
const result = props.beforeSwitch(index);
|
|
202
|
+
if (typeof result === 'object' && result !== null && 'then' in result) await result;
|
|
203
|
+
else if (result !== true) return;
|
|
204
|
+
} catch {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
emit('change', itemKey(item, index), item);
|
|
210
|
+
// 原生 tabBar 页面只能通过 switchTab 切换;没有 pagePath 时才更新本地 v-model。
|
|
211
|
+
if (item.pagePath) uni.switchTab({ url: item.pagePath });
|
|
212
|
+
else emit('update:modelValue', index);
|
|
213
|
+
}
|
|
214
|
+
</script>
|
|
215
|
+
|
|
216
|
+
<style lang="scss" scoped>
|
|
217
|
+
.snake-tabbar-spacer {
|
|
218
|
+
width: 100%;
|
|
219
|
+
}
|
|
220
|
+
.snake-tabbar {
|
|
221
|
+
box-shadow: 0 -6rpx 24rpx rgba(6, 39, 28, 0.07);
|
|
222
|
+
color: var(--snake-tabbar-inactive);
|
|
223
|
+
}
|
|
224
|
+
.snake-tabbar--border {
|
|
225
|
+
border-top: 1px solid var(--snake-color-divider);
|
|
226
|
+
}
|
|
227
|
+
.snake-tabbar--fixed {
|
|
228
|
+
position: fixed;
|
|
229
|
+
right: 0;
|
|
230
|
+
bottom: 0;
|
|
231
|
+
left: 0;
|
|
232
|
+
}
|
|
233
|
+
.snake-tabbar--safe {
|
|
234
|
+
padding-bottom: env(safe-area-inset-bottom);
|
|
235
|
+
}
|
|
236
|
+
.snake-tabbar__inner {
|
|
237
|
+
display: flex;
|
|
238
|
+
max-width: 760px;
|
|
239
|
+
margin: 0 auto;
|
|
240
|
+
align-items: stretch;
|
|
241
|
+
}
|
|
242
|
+
.snake-tabbar__item {
|
|
243
|
+
display: flex;
|
|
244
|
+
min-width: 0;
|
|
245
|
+
flex: 1;
|
|
246
|
+
flex-direction: column;
|
|
247
|
+
align-items: center;
|
|
248
|
+
justify-content: center;
|
|
249
|
+
gap: 5rpx;
|
|
250
|
+
color: var(--snake-tabbar-inactive);
|
|
251
|
+
transition:
|
|
252
|
+
background-color 0.2s,
|
|
253
|
+
color 0.2s;
|
|
254
|
+
}
|
|
255
|
+
.snake-tabbar__item--active {
|
|
256
|
+
color: var(--snake-tabbar-active);
|
|
257
|
+
font-weight: 650;
|
|
258
|
+
}
|
|
259
|
+
.snake-tabbar__item--disabled {
|
|
260
|
+
opacity: 0.45;
|
|
261
|
+
}
|
|
262
|
+
.snake-tabbar__item--mid {
|
|
263
|
+
position: relative;
|
|
264
|
+
}
|
|
265
|
+
.snake-tabbar__item--mid .snake-tabbar__icon-wrap {
|
|
266
|
+
position: absolute;
|
|
267
|
+
top: -55rpx;
|
|
268
|
+
width: 100rpx;
|
|
269
|
+
height: 100rpx;
|
|
270
|
+
border-radius: 50%;
|
|
271
|
+
background: var(--snake-color-surface);
|
|
272
|
+
box-shadow: 0 0 0 1px var(--snake-color-divider);
|
|
273
|
+
}
|
|
274
|
+
.snake-tabbar__item--hover {
|
|
275
|
+
background: var(--snake-color-surface-muted);
|
|
276
|
+
}
|
|
277
|
+
.snake-tabbar__icon-wrap {
|
|
278
|
+
position: relative;
|
|
279
|
+
display: flex;
|
|
280
|
+
height: 42rpx;
|
|
281
|
+
align-items: center;
|
|
282
|
+
justify-content: center;
|
|
283
|
+
}
|
|
284
|
+
.snake-tabbar__badge {
|
|
285
|
+
position: absolute;
|
|
286
|
+
top: -8rpx;
|
|
287
|
+
right: -24rpx;
|
|
288
|
+
min-width: 24rpx;
|
|
289
|
+
padding: 2rpx 6rpx;
|
|
290
|
+
border-radius: 999rpx;
|
|
291
|
+
color: #fff;
|
|
292
|
+
background: var(--snake-color-error, #f56c6c);
|
|
293
|
+
font-size: 16rpx;
|
|
294
|
+
line-height: 20rpx;
|
|
295
|
+
text-align: center;
|
|
296
|
+
}
|
|
297
|
+
.snake-tabbar__label {
|
|
298
|
+
font-size: 22rpx;
|
|
299
|
+
line-height: 1.2;
|
|
300
|
+
}
|
|
301
|
+
@media (prefers-reduced-motion: reduce) {
|
|
302
|
+
.snake-tabbar__item {
|
|
303
|
+
transition: none;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
</style>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { StyleValue } from '../../types/global';
|
|
2
|
+
|
|
3
|
+
/** Tabbar 导航项。 */
|
|
4
|
+
export interface TabbarItem {
|
|
5
|
+
/** 导航项唯一标识。 */
|
|
6
|
+
key?: string | number;
|
|
7
|
+
/** 展示文字。 */
|
|
8
|
+
text?: string;
|
|
9
|
+
/** 图标名称。 */
|
|
10
|
+
icon?: string;
|
|
11
|
+
/** 未选中时的图标名称。 */
|
|
12
|
+
iconPath?: string;
|
|
13
|
+
/** 选中时的图标名称。 */
|
|
14
|
+
selectedIconPath?: string;
|
|
15
|
+
/** 图标字体前缀;`true` 使用 `custom-icon`,字符串直接作为前缀。 */
|
|
16
|
+
customIcon?: boolean | string;
|
|
17
|
+
/** 页面路径;提供后会根据当前页面自动确定激活状态。 */
|
|
18
|
+
pagePath?: string;
|
|
19
|
+
/** 是否作为中间凸起按钮显示。 */
|
|
20
|
+
midButton?: boolean;
|
|
21
|
+
/** 单项宽度;设置任意一项后,其余未设置项自动填充剩余空间。 */
|
|
22
|
+
width?: string | number;
|
|
23
|
+
/** 单项图标尺寸。 */
|
|
24
|
+
iconSize?: string | number;
|
|
25
|
+
/** 单项文字尺寸。 */
|
|
26
|
+
textSize?: string | number;
|
|
27
|
+
/** 单项图标和文字间距。 */
|
|
28
|
+
gap?: string | number;
|
|
29
|
+
/** 角标数量。 */
|
|
30
|
+
count?: string | number;
|
|
31
|
+
/** 是否显示点状角标。 */
|
|
32
|
+
isDot?: boolean;
|
|
33
|
+
/** 是否禁用。 */
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
/** 徽标文字或数字。 */
|
|
36
|
+
badge?: string | number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Tabbar 组件的公开属性。 */
|
|
40
|
+
export interface TabbarProps {
|
|
41
|
+
/** 导航项列表。 */
|
|
42
|
+
items?: TabbarItem[];
|
|
43
|
+
/** 备用导航项列表;未传 `items` 时使用。 */
|
|
44
|
+
list?: TabbarItem[];
|
|
45
|
+
/** 当前激活项 key。 */
|
|
46
|
+
current?: string | number;
|
|
47
|
+
/** 通过 v-model 绑定的激活项索引。 */
|
|
48
|
+
modelValue?: string | number;
|
|
49
|
+
/** 是否显示 tabbar。 */
|
|
50
|
+
show?: boolean;
|
|
51
|
+
/** 是否固定在底部。 */
|
|
52
|
+
fixed?: boolean;
|
|
53
|
+
/** 是否预留底部安全区。 */
|
|
54
|
+
safeAreaInsetBottom?: boolean;
|
|
55
|
+
/** 根节点自定义样式。 */
|
|
56
|
+
customStyle?: StyleValue;
|
|
57
|
+
/** 根节点自定义类名。 */
|
|
58
|
+
customClass?: string;
|
|
59
|
+
/** 激活颜色。 */
|
|
60
|
+
activeColor?: string;
|
|
61
|
+
/** 未激活颜色。 */
|
|
62
|
+
inactiveColor?: string;
|
|
63
|
+
/** tabbar 背景色。 */
|
|
64
|
+
bgColor?: string;
|
|
65
|
+
/** 是否展示顶部边框。 */
|
|
66
|
+
borderTop?: boolean;
|
|
67
|
+
/** 是否在挂载后隐藏原生 tabBar;默认开启。非原生 tabBar 页面会安全忽略。 */
|
|
68
|
+
hideTabBar?: boolean;
|
|
69
|
+
/** 切换前的拦截器;返回 `true` 或 resolve 的 Promise 才会继续切换。 */
|
|
70
|
+
beforeSwitch?: (index: number) => boolean | Promise<unknown>;
|
|
71
|
+
/** 是否启用中间凸起按钮。 */
|
|
72
|
+
midButton?: boolean;
|
|
73
|
+
/** 常规图标尺寸。 */
|
|
74
|
+
iconSize?: string | number;
|
|
75
|
+
/** 中间凸起按钮图标尺寸。 */
|
|
76
|
+
midButtonSize?: string | number;
|
|
77
|
+
/** 常规文字尺寸。 */
|
|
78
|
+
textSize?: string | number;
|
|
79
|
+
/** 图标和文字间距。 */
|
|
80
|
+
gap?: string | number;
|
|
81
|
+
/** 导航栏高度,单位 rpx。 */
|
|
82
|
+
height?: string | number;
|
|
83
|
+
/** 层级。 */
|
|
84
|
+
zIndex?: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Tabbar 组件事件。 */
|
|
88
|
+
export type TabbarEmits = {
|
|
89
|
+
/** 点击导航项时返回 key 和完整项。 */
|
|
90
|
+
change: [key: string | number, item: TabbarItem];
|
|
91
|
+
/** 更新 v-model 激活项索引。 */
|
|
92
|
+
'update:modelValue': [value: string | number];
|
|
93
|
+
};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="snake-tabs" :style="rootStyle" :class="customClass">
|
|
3
|
+
<view>
|
|
4
|
+
<scroll-view
|
|
5
|
+
scroll-x
|
|
6
|
+
class="snake-tabs__scroll-view"
|
|
7
|
+
:scroll-left="scrollLeft"
|
|
8
|
+
:show-scrollbar="false"
|
|
9
|
+
scroll-with-animation
|
|
10
|
+
>
|
|
11
|
+
<view :id="id" class="snake-tabs__scroll-box" :class="{ 'snake-tabs__scroll-flex': !isScroll }">
|
|
12
|
+
<view
|
|
13
|
+
v-for="(item, index) in list"
|
|
14
|
+
:id="`${id}-item-${index}`"
|
|
15
|
+
:key="index"
|
|
16
|
+
class="snake-tabs__item snake-line-1"
|
|
17
|
+
:class="{ 'snake-tabs__item--hidden': item.hidden }"
|
|
18
|
+
:style="tabItemStyle(index)"
|
|
19
|
+
@tap="clickTab(index)"
|
|
20
|
+
>
|
|
21
|
+
<view
|
|
22
|
+
v-if="Number(badgeCount(item)) !== 0"
|
|
23
|
+
class="snake-tabs__badge"
|
|
24
|
+
:class="{ 'snake-tabs__badge--dot': isDot }"
|
|
25
|
+
:style="{ top: `${offset[0]}rpx`, right: `${offset[1]}rpx` }"
|
|
26
|
+
>
|
|
27
|
+
{{ badgeText(item) }}
|
|
28
|
+
</view>
|
|
29
|
+
{{ itemValue(item, name, 'name') }}
|
|
30
|
+
</view>
|
|
31
|
+
<view v-if="showBar" class="snake-tabs__bar" :style="tabBarStyle" />
|
|
32
|
+
</view>
|
|
33
|
+
</scroll-view>
|
|
34
|
+
</view>
|
|
35
|
+
</view>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<script setup lang="ts">
|
|
39
|
+
/**
|
|
40
|
+
* @component Tabs
|
|
41
|
+
* @description tabs 标签组件,支持横向滚动、激活项居中、徽标和滑块。
|
|
42
|
+
* @see /components/tabs
|
|
43
|
+
*/
|
|
44
|
+
import { computed, getCurrentInstance, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
45
|
+
import { addUnit } from '../../libs/function/unit';
|
|
46
|
+
import type { TabItem, TabsEmits, TabsProps } from './types';
|
|
47
|
+
|
|
48
|
+
defineOptions({
|
|
49
|
+
name: 'Tabs',
|
|
50
|
+
options: {
|
|
51
|
+
addGlobalClass: true,
|
|
52
|
+
// #ifndef MP-TOUTIAO
|
|
53
|
+
virtualHost: true,
|
|
54
|
+
// #endif
|
|
55
|
+
styleIsolation: 'shared'
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const props = withDefaults(defineProps<TabsProps>(), {
|
|
60
|
+
customStyle: '',
|
|
61
|
+
customClass: '',
|
|
62
|
+
isScroll: true,
|
|
63
|
+
list: () => [],
|
|
64
|
+
current: 0,
|
|
65
|
+
height: 80,
|
|
66
|
+
fontSize: 30,
|
|
67
|
+
duration: 0.5,
|
|
68
|
+
activeColor: 'var(--snake-color-primary, #06D290)',
|
|
69
|
+
inactiveColor: 'var(--snake-color-text, #303133)',
|
|
70
|
+
barWidth: 40,
|
|
71
|
+
barHeight: 6,
|
|
72
|
+
gutter: 30,
|
|
73
|
+
bgColor: '#fff',
|
|
74
|
+
name: 'name',
|
|
75
|
+
count: 'count',
|
|
76
|
+
offset: () => [5, 20],
|
|
77
|
+
isDot: false,
|
|
78
|
+
bold: true,
|
|
79
|
+
activeItemStyle: () => ({}),
|
|
80
|
+
showBar: true,
|
|
81
|
+
barStyle: () => ({}),
|
|
82
|
+
itemWidth: 'auto'
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const emit = defineEmits<TabsEmits>();
|
|
86
|
+
const instance = getCurrentInstance();
|
|
87
|
+
const scrollLeft = ref(0);
|
|
88
|
+
const tabQueryInfo = ref<UniApp.NodeInfo[]>([]);
|
|
89
|
+
const componentWidth = ref(0);
|
|
90
|
+
const scrollBarLeft = ref(0);
|
|
91
|
+
const parentLeft = ref(0);
|
|
92
|
+
const id = `snake-tabs-${instance?.uid ?? 0}`;
|
|
93
|
+
const currentIndex = ref<number | string>(props.current);
|
|
94
|
+
const barFirstTimeMove = ref(true);
|
|
95
|
+
let initTimer: ReturnType<typeof setTimeout> | undefined;
|
|
96
|
+
let firstMoveTimer: ReturnType<typeof setTimeout> | undefined;
|
|
97
|
+
|
|
98
|
+
const rootStyle = computed(() => [{ background: props.bgColor }, props.customStyle]);
|
|
99
|
+
const tabBarStyle = computed(() => [
|
|
100
|
+
{
|
|
101
|
+
width: addUnit(props.barWidth, 'rpx'),
|
|
102
|
+
transform: `translate(${scrollBarLeft.value}px, -100%)`,
|
|
103
|
+
transitionDuration: `${barFirstTimeMove.value ? 0 : props.duration}s`,
|
|
104
|
+
backgroundColor: props.activeColor,
|
|
105
|
+
height: addUnit(props.barHeight, 'rpx'),
|
|
106
|
+
opacity: barFirstTimeMove.value ? 0 : 1,
|
|
107
|
+
borderRadius: `${Number(props.barHeight) / 2}px`
|
|
108
|
+
},
|
|
109
|
+
props.barStyle
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
function itemValue(item: TabItem, key: string, fallback: 'name' | 'count') {
|
|
113
|
+
return item[key] || item[fallback];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function badgeCount(item: TabItem) {
|
|
117
|
+
return itemValue(item, props.count, 'count') || 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function badgeText(item: TabItem) {
|
|
121
|
+
if (props.isDot) return '';
|
|
122
|
+
const value = badgeCount(item);
|
|
123
|
+
return Number(value) > 99 ? '99+' : value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function tabItemStyle(index: number) {
|
|
127
|
+
const style: Record<string, string> = {
|
|
128
|
+
height: addUnit(props.height, 'rpx'),
|
|
129
|
+
lineHeight: addUnit(props.height, 'rpx'),
|
|
130
|
+
fontSize: addUnit(props.fontSize, 'rpx'),
|
|
131
|
+
transitionDuration: `${props.duration}s`,
|
|
132
|
+
padding: props.isScroll ? `0 ${addUnit(props.gutter, 'rpx')}` : '',
|
|
133
|
+
flex: props.isScroll ? 'auto' : '1',
|
|
134
|
+
width: addUnit(props.itemWidth),
|
|
135
|
+
color: index === Number(currentIndex.value) ? props.activeColor : props.inactiveColor
|
|
136
|
+
};
|
|
137
|
+
if (index === Number(currentIndex.value) && props.bold) style.fontWeight = 'bold';
|
|
138
|
+
return [style, index === Number(currentIndex.value) ? props.activeItemStyle : {}];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function getRect(selector: string) {
|
|
142
|
+
return new Promise<UniApp.NodeInfo | null>(resolve => {
|
|
143
|
+
uni.createSelectorQuery()
|
|
144
|
+
.in(instance?.proxy as any)
|
|
145
|
+
.select(selector)
|
|
146
|
+
.boundingClientRect(rect => resolve((rect as UniApp.NodeInfo | null) ?? null))
|
|
147
|
+
.exec();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function init() {
|
|
152
|
+
await nextTick();
|
|
153
|
+
if (typeof uni === 'undefined' || typeof uni.createSelectorQuery !== 'function') return;
|
|
154
|
+
const tabRect = await getRect(`#${id}`);
|
|
155
|
+
if (!tabRect) return;
|
|
156
|
+
parentLeft.value = Number(tabRect.left) || 0;
|
|
157
|
+
componentWidth.value = Number(tabRect.width) || 0;
|
|
158
|
+
getTabRect();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function clickTab(index: number) {
|
|
162
|
+
if (index === Number(currentIndex.value)) return;
|
|
163
|
+
emit('change', index);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function getTabRect() {
|
|
167
|
+
const query = uni.createSelectorQuery().in(instance?.proxy as any);
|
|
168
|
+
for (let index = 0; index < props.list.length; index += 1) {
|
|
169
|
+
query.select(`#${id}-item-${index}`).fields({ size: true, rect: true }, () => {});
|
|
170
|
+
}
|
|
171
|
+
query.exec(results => {
|
|
172
|
+
tabQueryInfo.value = (results ?? []) as UniApp.NodeInfo[];
|
|
173
|
+
scrollByIndex();
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function scrollByIndex() {
|
|
178
|
+
const tabInfo = tabQueryInfo.value[Number(currentIndex.value)];
|
|
179
|
+
if (!tabInfo) return;
|
|
180
|
+
const tabWidth = Number(tabInfo.width) || 0;
|
|
181
|
+
const offsetLeft = (Number(tabInfo.left) || 0) - parentLeft.value;
|
|
182
|
+
const nextScrollLeft = offsetLeft - (componentWidth.value - tabWidth) / 2;
|
|
183
|
+
scrollLeft.value = nextScrollLeft < 0 ? 0 : nextScrollLeft;
|
|
184
|
+
const left = (Number(tabInfo.left) || 0) + tabWidth / 2 - parentLeft.value;
|
|
185
|
+
scrollBarLeft.value = left - uni.upx2px(Number(props.barWidth)) / 2;
|
|
186
|
+
if (!barFirstTimeMove.value) return;
|
|
187
|
+
if (firstMoveTimer) clearTimeout(firstMoveTimer);
|
|
188
|
+
firstMoveTimer = setTimeout(() => {
|
|
189
|
+
barFirstTimeMove.value = false;
|
|
190
|
+
firstMoveTimer = undefined;
|
|
191
|
+
}, 100);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
watch(
|
|
195
|
+
() => props.list,
|
|
196
|
+
(nextList, previousList) => {
|
|
197
|
+
if (nextList.length !== previousList.length) currentIndex.value = 0;
|
|
198
|
+
void nextTick(init);
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
watch(
|
|
203
|
+
() => props.current,
|
|
204
|
+
value => {
|
|
205
|
+
void nextTick(() => {
|
|
206
|
+
currentIndex.value = value;
|
|
207
|
+
scrollByIndex();
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
{ immediate: true }
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
onMounted(() => {
|
|
214
|
+
void nextTick(() => {
|
|
215
|
+
initTimer = setTimeout(() => {
|
|
216
|
+
initTimer = undefined;
|
|
217
|
+
void init();
|
|
218
|
+
}, 500);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
onBeforeUnmount(() => {
|
|
223
|
+
if (initTimer) clearTimeout(initTimer);
|
|
224
|
+
if (firstMoveTimer) clearTimeout(firstMoveTimer);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
defineExpose({ init, clickTab, scrollByIndex });
|
|
228
|
+
</script>
|
|
229
|
+
|
|
230
|
+
<style scoped>
|
|
231
|
+
.snake-tabs,
|
|
232
|
+
.snake-tabs__scroll-view,
|
|
233
|
+
.snake-tabs__scroll-box,
|
|
234
|
+
.snake-tabs__item {
|
|
235
|
+
box-sizing: border-box;
|
|
236
|
+
}
|
|
237
|
+
.snake-tabs__scroll-box {
|
|
238
|
+
position: relative;
|
|
239
|
+
white-space: nowrap;
|
|
240
|
+
}
|
|
241
|
+
.snake-tabs__scroll-view {
|
|
242
|
+
position: relative;
|
|
243
|
+
width: 100%;
|
|
244
|
+
white-space: nowrap;
|
|
245
|
+
}
|
|
246
|
+
.snake-tabs__item {
|
|
247
|
+
position: relative;
|
|
248
|
+
display: inline-block;
|
|
249
|
+
overflow: hidden;
|
|
250
|
+
text-align: center;
|
|
251
|
+
text-overflow: ellipsis;
|
|
252
|
+
white-space: nowrap;
|
|
253
|
+
transition-property: background-color, color;
|
|
254
|
+
}
|
|
255
|
+
.snake-tabs__item--hidden {
|
|
256
|
+
display: none;
|
|
257
|
+
}
|
|
258
|
+
.snake-tabs__bar {
|
|
259
|
+
position: absolute;
|
|
260
|
+
bottom: 0;
|
|
261
|
+
}
|
|
262
|
+
.snake-tabs__scroll-flex {
|
|
263
|
+
display: flex;
|
|
264
|
+
justify-content: space-between;
|
|
265
|
+
}
|
|
266
|
+
.snake-tabs__badge {
|
|
267
|
+
position: absolute;
|
|
268
|
+
z-index: 9;
|
|
269
|
+
display: inline-flex;
|
|
270
|
+
min-width: 28rpx;
|
|
271
|
+
height: 28rpx;
|
|
272
|
+
align-items: center;
|
|
273
|
+
justify-content: center;
|
|
274
|
+
padding: 0 7rpx;
|
|
275
|
+
border-radius: 100rpx;
|
|
276
|
+
color: #fff;
|
|
277
|
+
background: var(--snake-color-error, #fa3534);
|
|
278
|
+
font-size: 18rpx;
|
|
279
|
+
line-height: 28rpx;
|
|
280
|
+
transform: scale(0.8);
|
|
281
|
+
transform-origin: center;
|
|
282
|
+
}
|
|
283
|
+
.snake-tabs__badge--dot {
|
|
284
|
+
width: 16rpx;
|
|
285
|
+
min-width: 16rpx;
|
|
286
|
+
height: 16rpx;
|
|
287
|
+
padding: 0;
|
|
288
|
+
}
|
|
289
|
+
::-webkit-scrollbar {
|
|
290
|
+
display: none;
|
|
291
|
+
width: 0 !important;
|
|
292
|
+
height: 0 !important;
|
|
293
|
+
background: transparent;
|
|
294
|
+
-webkit-appearance: none;
|
|
295
|
+
}
|
|
296
|
+
/* #ifdef H5 */
|
|
297
|
+
.snake-tabs__scroll-view :deep(::-webkit-scrollbar) {
|
|
298
|
+
display: none;
|
|
299
|
+
width: 0 !important;
|
|
300
|
+
height: 0 !important;
|
|
301
|
+
background: transparent;
|
|
302
|
+
-webkit-appearance: none;
|
|
303
|
+
}
|
|
304
|
+
/* #endif */
|
|
305
|
+
</style>
|