@puresnake/snake-ui 0.0.0-stage → 0.0.2
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 +83 -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 +134 -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,209 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="coupon">
|
|
3
|
+
<!-- 页面显示 -->
|
|
4
|
+
<view @click="handleReceiveCoupon" v-if="datas.modeType === 'page'">
|
|
5
|
+
<view v-show="isCouponCheck">
|
|
6
|
+
<image :src="datas.beforeImage" mode="widthFix" style="display: block; width: 100%" />
|
|
7
|
+
</view>
|
|
8
|
+
<view v-show="!isCouponCheck">
|
|
9
|
+
<image :src="datas.afterImage" mode="widthFix" style="display: block; width: 100%" />
|
|
10
|
+
</view>
|
|
11
|
+
</view>
|
|
12
|
+
<!-- 弹窗显示 -->
|
|
13
|
+
<template v-if="datas.modeType === 'popup'">
|
|
14
|
+
<snake-popup
|
|
15
|
+
v-model="show"
|
|
16
|
+
:mode="datas.popupMode"
|
|
17
|
+
:bg-color="datas.popupMode === 'bottom' ? 'var(--snake-color-surface, #fff)' : 'transparent'"
|
|
18
|
+
>
|
|
19
|
+
<view class="popup-container">
|
|
20
|
+
<view :class="[`coupon-popup coupon-popup--${datas.popupMode}`]">
|
|
21
|
+
<view
|
|
22
|
+
:class="[`close close--${datas.popupMode}`]"
|
|
23
|
+
@click.stop="show = false"
|
|
24
|
+
v-if="!datas.popupMode || datas.popupMode === 'bottom'"
|
|
25
|
+
>
|
|
26
|
+
<snake-icon name="close" color="var(--snake-color-text, #26273a)" size="18"></snake-icon>
|
|
27
|
+
</view>
|
|
28
|
+
<image
|
|
29
|
+
class="coupon-img"
|
|
30
|
+
mode="aspectFill"
|
|
31
|
+
:src="datas.beforeImage"
|
|
32
|
+
@click.stop="handleReceiveCoupon"
|
|
33
|
+
></image>
|
|
34
|
+
</view>
|
|
35
|
+
<view
|
|
36
|
+
:class="[`close close--${datas.popupMode}`]"
|
|
37
|
+
@click.stop="show = false"
|
|
38
|
+
v-if="datas.popupMode === 'center'"
|
|
39
|
+
>
|
|
40
|
+
<snake-icon name="close" color="#fff" size="28"></snake-icon>
|
|
41
|
+
</view>
|
|
42
|
+
</view>
|
|
43
|
+
</snake-popup>
|
|
44
|
+
</template>
|
|
45
|
+
</view>
|
|
46
|
+
</template>
|
|
47
|
+
|
|
48
|
+
<script setup lang="ts">
|
|
49
|
+
/**
|
|
50
|
+
* @component Coupon
|
|
51
|
+
* @description 检查领取资格,以页面图片或弹窗形式展示优惠券,并在领取后执行内部或外部跳转。
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
55
|
+
import { resolveCmsOptions } from '../../libs/cms';
|
|
56
|
+
import { sleep } from '../../libs/function/sleep';
|
|
57
|
+
import { toast } from '../../libs/function/toast';
|
|
58
|
+
import { CmsError } from '../snake-cms/types';
|
|
59
|
+
import type { CouponEmits, CouponProps } from './types';
|
|
60
|
+
|
|
61
|
+
defineOptions({ name: 'Coupon', options: { virtualHost: true, styleIsolation: 'shared' } });
|
|
62
|
+
|
|
63
|
+
const props = withDefaults(defineProps<CouponProps>(), {
|
|
64
|
+
datas: () => ({}),
|
|
65
|
+
couponService: undefined,
|
|
66
|
+
linkService: undefined,
|
|
67
|
+
pageInfo: () => ({})
|
|
68
|
+
});
|
|
69
|
+
const emit = defineEmits<CouponEmits>();
|
|
70
|
+
const resolved = computed(() => resolveCmsOptions());
|
|
71
|
+
const couponService = computed(() => props.couponService || resolved.value.services?.coupon);
|
|
72
|
+
const linkService = computed(() => props.linkService || resolved.value.services?.link);
|
|
73
|
+
const isCouponCheck = ref(true);
|
|
74
|
+
const tipMessage = ref('');
|
|
75
|
+
const show = ref(false);
|
|
76
|
+
|
|
77
|
+
let restoreTabBarTimer: ReturnType<typeof setTimeout> | undefined;
|
|
78
|
+
let tabBarHidden = false;
|
|
79
|
+
watch(show, value => {
|
|
80
|
+
if (props.datas.modeType !== 'popup' || props.datas.popupMode !== 'bottom') return;
|
|
81
|
+
if (restoreTabBarTimer) clearTimeout(restoreTabBarTimer);
|
|
82
|
+
if (value) {
|
|
83
|
+
uni.hideTabBar({ animation: true });
|
|
84
|
+
tabBarHidden = true;
|
|
85
|
+
} else {
|
|
86
|
+
restoreTabBarTimer = setTimeout(() => {
|
|
87
|
+
uni.showTabBar({ animation: true });
|
|
88
|
+
tabBarHidden = false;
|
|
89
|
+
}, 300);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
async function getCouponCheck(): Promise<void> {
|
|
94
|
+
if (!couponService.value) return;
|
|
95
|
+
try {
|
|
96
|
+
const result = await couponService.value.check({ config: props.datas, pageInfo: props.pageInfo });
|
|
97
|
+
isCouponCheck.value = result.claimable;
|
|
98
|
+
tipMessage.value = result.message || '';
|
|
99
|
+
if (props.datas.modeType === 'popup' && result.claimable) {
|
|
100
|
+
await sleep(30);
|
|
101
|
+
show.value = true;
|
|
102
|
+
}
|
|
103
|
+
} catch (cause) {
|
|
104
|
+
emit('error', new CmsError('coupon', '优惠券状态加载失败', cause));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function openAfterAction(): Promise<void> {
|
|
109
|
+
if (!props.datas.afterUrl) return;
|
|
110
|
+
if (!linkService.value) {
|
|
111
|
+
toast('未配置 CMS 跳转服务');
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
await linkService.value.open(
|
|
115
|
+
{ type: props.datas.type === '10' ? 'navigate' : 'external', url: props.datas.afterUrl },
|
|
116
|
+
{ pageInfo: props.pageInfo }
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function handleReceiveCoupon(): Promise<void> {
|
|
121
|
+
if (!isCouponCheck.value) {
|
|
122
|
+
toast(tipMessage.value || '您已经领取过啦');
|
|
123
|
+
await openAfterAction();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!couponService.value) {
|
|
127
|
+
const error = new CmsError('coupon', '未配置 CMS 优惠券服务');
|
|
128
|
+
emit('error', error);
|
|
129
|
+
toast(error.message);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const result = await couponService.value.receive({ config: props.datas, pageInfo: props.pageInfo });
|
|
134
|
+
if (!result.success) {
|
|
135
|
+
toast(result.message || '领取失败');
|
|
136
|
+
await getCouponCheck();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
isCouponCheck.value = false;
|
|
140
|
+
show.value = false;
|
|
141
|
+
toast(result.message || '领取成功');
|
|
142
|
+
emit('received');
|
|
143
|
+
await sleep(1000);
|
|
144
|
+
await openAfterAction();
|
|
145
|
+
} catch (cause) {
|
|
146
|
+
const error = new CmsError('coupon', '优惠券领取失败', cause);
|
|
147
|
+
emit('error', error);
|
|
148
|
+
toast(error.message);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
onMounted(() => {
|
|
153
|
+
void getCouponCheck();
|
|
154
|
+
});
|
|
155
|
+
onBeforeUnmount(() => {
|
|
156
|
+
if (restoreTabBarTimer) clearTimeout(restoreTabBarTimer);
|
|
157
|
+
if (tabBarHidden) {
|
|
158
|
+
uni.showTabBar({ animation: true });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
</script>
|
|
162
|
+
|
|
163
|
+
<style lang="scss" scoped>
|
|
164
|
+
.coupon {
|
|
165
|
+
width: 100%;
|
|
166
|
+
height: 100%;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.popup-container {
|
|
170
|
+
width: 100%;
|
|
171
|
+
height: 100%;
|
|
172
|
+
|
|
173
|
+
.coupon-popup {
|
|
174
|
+
box-sizing: border-box;
|
|
175
|
+
width: 100%;
|
|
176
|
+
height: 572rpx;
|
|
177
|
+
background-color: var(--snake-color-surface, #fff);
|
|
178
|
+
|
|
179
|
+
&--center {
|
|
180
|
+
width: 540rpx;
|
|
181
|
+
height: 740rpx;
|
|
182
|
+
background: var(--snake-color-surface, #fff);
|
|
183
|
+
|
|
184
|
+
.coupon-img {
|
|
185
|
+
height: 740rpx !important;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.coupon-img {
|
|
190
|
+
display: block;
|
|
191
|
+
width: 100%;
|
|
192
|
+
height: 524rpx;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.close {
|
|
197
|
+
display: flex;
|
|
198
|
+
justify-content: flex-end;
|
|
199
|
+
padding-top: 16rpx;
|
|
200
|
+
padding-right: 16rpx;
|
|
201
|
+
|
|
202
|
+
&--center {
|
|
203
|
+
display: flex;
|
|
204
|
+
justify-content: center;
|
|
205
|
+
margin-top: 70rpx;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CmsCouponService, CmsError, CmsLinkService, CmsPageInfo } from '../snake-cms/types';
|
|
2
|
+
|
|
3
|
+
/** Coupon 组件的公开属性。 */
|
|
4
|
+
export interface CouponProps<Data extends Record<string, any> = Record<string, any>> {
|
|
5
|
+
/** CMS 装修组件配置数据。 */
|
|
6
|
+
datas?: Data;
|
|
7
|
+
/** coupon service 配置。 */
|
|
8
|
+
couponService?: CmsCouponService;
|
|
9
|
+
/** link service 配置。 */
|
|
10
|
+
linkService?: CmsLinkService;
|
|
11
|
+
/** CMS 页面上下文信息。 */
|
|
12
|
+
pageInfo?: CmsPageInfo;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Coupon 组件的事件契约。 */
|
|
16
|
+
export type CouponEmits = {
|
|
17
|
+
/** error 事件携带的参数。 */
|
|
18
|
+
error: [error: CmsError];
|
|
19
|
+
/** received 事件携带的参数。 */
|
|
20
|
+
received: [];
|
|
21
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="custommodule">
|
|
3
|
+
<!-- <slot :name="datas.slotName" /> -->
|
|
4
|
+
<slot />
|
|
5
|
+
</view>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
/**
|
|
10
|
+
* @component CustomModule
|
|
11
|
+
* @description 为 CMS 配置中的自定义内容提供一个通用插槽容器。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { CustomModuleProps, CustomModuleSlots } from './types';
|
|
15
|
+
|
|
16
|
+
defineOptions({ name: 'CustomModule', options: { virtualHost: true, styleIsolation: 'shared' } });
|
|
17
|
+
withDefaults(defineProps<CustomModuleProps>(), { datas: () => ({}) });
|
|
18
|
+
defineSlots<CustomModuleSlots>();
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<style scoped lang="scss">
|
|
22
|
+
.custommodule {
|
|
23
|
+
height: 100%;
|
|
24
|
+
}
|
|
25
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** CustomModule 组件的公开属性。 */
|
|
2
|
+
export interface CustomModuleProps<Data extends Record<string, any> = Record<string, any>> {
|
|
3
|
+
/** CMS 装修组件配置数据。 */
|
|
4
|
+
datas?: Data;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** CustomModuleSlots 类型定义。 */
|
|
8
|
+
export interface CustomModuleSlots {
|
|
9
|
+
/** default 配置。 */
|
|
10
|
+
default?: () => unknown;
|
|
11
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="snake-drop-menu"
|
|
4
|
+
:class="[customClass, { 'snake-drop-menu--border': borderBottom }]"
|
|
5
|
+
:style="[{ height: addUnit(height, 'px'), zIndex: props.zIndex }, customStyle]"
|
|
6
|
+
>
|
|
7
|
+
<slot />
|
|
8
|
+
</view>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
/**
|
|
13
|
+
* @component DropMenu
|
|
14
|
+
* @description 负责多个 `DropMenuItem` 的布局、互斥展开和弹层定位。面板打开前会真实测量菜单底部位置,适用于普通布局和吸顶布局。
|
|
15
|
+
* @see /components/drop-menu
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { getCurrentInstance, onMounted, provide, ref, toRef, watch } from 'vue';
|
|
19
|
+
import zIndex from '../../libs/config/zIndex';
|
|
20
|
+
import { addUnit } from '../../libs/function/unit';
|
|
21
|
+
import { dropMenuKey } from './types';
|
|
22
|
+
import type { DropMenuEmits, DropMenuExpose, DropMenuProps } from './types';
|
|
23
|
+
|
|
24
|
+
defineOptions({ name: 'DropMenu', options: { virtualHost: true, styleIsolation: 'shared' } });
|
|
25
|
+
const props = withDefaults(defineProps<DropMenuProps>(), {
|
|
26
|
+
activeColor: 'var(--snake-color-primary, #06D290)',
|
|
27
|
+
inactiveColor: 'var(--snake-color-text-secondary, #606266)',
|
|
28
|
+
closeOnClickMask: true,
|
|
29
|
+
closeOnClickSelf: true,
|
|
30
|
+
duration: 300,
|
|
31
|
+
height: 40,
|
|
32
|
+
borderBottom: false,
|
|
33
|
+
titleSize: 28,
|
|
34
|
+
menuIcon: 'down',
|
|
35
|
+
menuIconSize: 18,
|
|
36
|
+
zIndex: zIndex.dropdown,
|
|
37
|
+
customClass: '',
|
|
38
|
+
customStyle: ''
|
|
39
|
+
});
|
|
40
|
+
const emit = defineEmits<DropMenuEmits>();
|
|
41
|
+
const instance = getCurrentInstance();
|
|
42
|
+
const activeItem = ref<symbol | null>(null);
|
|
43
|
+
const highlighted = ref<number>();
|
|
44
|
+
const menuTop = ref(0);
|
|
45
|
+
const items: symbol[] = [];
|
|
46
|
+
function register(item: symbol) {
|
|
47
|
+
if (!items.includes(item)) items.push(item);
|
|
48
|
+
return items.indexOf(item);
|
|
49
|
+
}
|
|
50
|
+
function unregister(item: symbol) {
|
|
51
|
+
const index = items.indexOf(item);
|
|
52
|
+
if (index >= 0) items.splice(index, 1);
|
|
53
|
+
if (activeItem.value === item) activeItem.value = null;
|
|
54
|
+
}
|
|
55
|
+
const indexOf = (item: symbol) => items.indexOf(item);
|
|
56
|
+
function openItem(item: symbol) {
|
|
57
|
+
activeItem.value = item;
|
|
58
|
+
}
|
|
59
|
+
function close() {
|
|
60
|
+
activeItem.value = null;
|
|
61
|
+
}
|
|
62
|
+
function open(index: number) {
|
|
63
|
+
if (items[index]) openItem(items[index]);
|
|
64
|
+
}
|
|
65
|
+
function highlight(index?: number) {
|
|
66
|
+
highlighted.value = index;
|
|
67
|
+
}
|
|
68
|
+
async function updateDropMenuRect() {
|
|
69
|
+
if (typeof uni === 'undefined') return;
|
|
70
|
+
await new Promise<void>(resolve => {
|
|
71
|
+
uni.createSelectorQuery()
|
|
72
|
+
.in(instance?.proxy as any)
|
|
73
|
+
.select('.snake-drop-menu')
|
|
74
|
+
.boundingClientRect((rect: any) => {
|
|
75
|
+
if (rect) menuTop.value = Number(rect.bottom) || 0;
|
|
76
|
+
})
|
|
77
|
+
.exec(() => resolve());
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function colseAll() {
|
|
81
|
+
close();
|
|
82
|
+
}
|
|
83
|
+
watch(activeItem, (value, previous) => {
|
|
84
|
+
if (previous) emit('close', indexOf(previous));
|
|
85
|
+
if (value) {
|
|
86
|
+
void updateDropMenuRect();
|
|
87
|
+
emit('open', indexOf(value));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
provide(dropMenuKey, {
|
|
91
|
+
activeItem,
|
|
92
|
+
highlighted,
|
|
93
|
+
menuTop,
|
|
94
|
+
activeColor: toRef(props, 'activeColor'),
|
|
95
|
+
inactiveColor: toRef(props, 'inactiveColor'),
|
|
96
|
+
titleSize: toRef(props, 'titleSize'),
|
|
97
|
+
menuIcon: toRef(props, 'menuIcon'),
|
|
98
|
+
menuIconSize: toRef(props, 'menuIconSize'),
|
|
99
|
+
duration: toRef(props, 'duration'),
|
|
100
|
+
closeOnClickMask: toRef(props, 'closeOnClickMask'),
|
|
101
|
+
closeOnClickSelf: toRef(props, 'closeOnClickSelf'),
|
|
102
|
+
zIndex: toRef(props, 'zIndex'),
|
|
103
|
+
register,
|
|
104
|
+
unregister,
|
|
105
|
+
indexOf,
|
|
106
|
+
open: openItem,
|
|
107
|
+
close,
|
|
108
|
+
updateRect: updateDropMenuRect
|
|
109
|
+
});
|
|
110
|
+
onMounted(() => void updateDropMenuRect());
|
|
111
|
+
defineExpose<DropMenuExpose>({ updateDropMenuRect, colseAll, close, open, highlight });
|
|
112
|
+
</script>
|
|
113
|
+
<style scoped>
|
|
114
|
+
.snake-drop-menu {
|
|
115
|
+
position: relative;
|
|
116
|
+
display: flex;
|
|
117
|
+
width: 100%;
|
|
118
|
+
background: var(--snake-color-surface, #fff);
|
|
119
|
+
}
|
|
120
|
+
.snake-drop-menu--border {
|
|
121
|
+
border-bottom: 1px solid var(--snake-color-divider, #e4e7ed);
|
|
122
|
+
}
|
|
123
|
+
</style>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { InjectionKey, Ref } from 'vue';
|
|
2
|
+
import type { UnitValue } from '../../libs/function/unit';
|
|
3
|
+
import type { StyleValue } from '../../types/global';
|
|
4
|
+
/** DropMenu 组件的公开属性。 */
|
|
5
|
+
export interface DropMenuProps {
|
|
6
|
+
/** 激活状态颜色。 */
|
|
7
|
+
activeColor?: string;
|
|
8
|
+
/** 未激活状态颜色。 */
|
|
9
|
+
inactiveColor?: string;
|
|
10
|
+
/** close on click mask 配置。 */
|
|
11
|
+
closeOnClickMask?: boolean;
|
|
12
|
+
/** close on click self 配置。 */
|
|
13
|
+
closeOnClickSelf?: boolean;
|
|
14
|
+
/** 动画持续时间。 */
|
|
15
|
+
duration?: number;
|
|
16
|
+
/** 组件高度。 */
|
|
17
|
+
height?: UnitValue;
|
|
18
|
+
/** 是否显示底部边框。 */
|
|
19
|
+
borderBottom?: boolean;
|
|
20
|
+
/** 标题文字尺寸,数值按 rpx 处理。 */
|
|
21
|
+
titleSize?: UnitValue;
|
|
22
|
+
/** menu icon 配置。 */
|
|
23
|
+
menuIcon?: string;
|
|
24
|
+
/** menu icon size 配置。 */
|
|
25
|
+
menuIconSize?: UnitValue;
|
|
26
|
+
/** 组件层级。 */
|
|
27
|
+
zIndex?: number;
|
|
28
|
+
/** 根节点自定义类名。 */
|
|
29
|
+
customClass?: string;
|
|
30
|
+
/** 根节点自定义样式。 */
|
|
31
|
+
customStyle?: StyleValue;
|
|
32
|
+
}
|
|
33
|
+
/** DropMenu 组件的事件契约。 */
|
|
34
|
+
export type DropMenuEmits = {
|
|
35
|
+
/** open 事件携带的参数。 */
|
|
36
|
+
open: [index: number];
|
|
37
|
+
/** close 事件携带的参数。 */
|
|
38
|
+
close: [index: number];
|
|
39
|
+
};
|
|
40
|
+
/** DropMenu 组件实例公开的方法和状态。 */
|
|
41
|
+
export interface DropMenuExpose {
|
|
42
|
+
/** updateDropMenuRect 方法。 */
|
|
43
|
+
updateDropMenuRect(): Promise<void>;
|
|
44
|
+
/** colseAll 方法。 */
|
|
45
|
+
colseAll(): void;
|
|
46
|
+
/** close 方法。 */
|
|
47
|
+
close(): void;
|
|
48
|
+
/** open 方法。 */
|
|
49
|
+
open(index: number): void;
|
|
50
|
+
/** highlight 方法。 */
|
|
51
|
+
highlight(index?: number): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** DropMenu 向 DropMenuItem 注入的配对上下文。 */
|
|
55
|
+
export interface DropMenuContext {
|
|
56
|
+
/** 当前展开项的标识,null 表示全部收起。 */
|
|
57
|
+
activeItem: Ref<symbol | null>;
|
|
58
|
+
/** 键盘导航高亮的选项下标。 */
|
|
59
|
+
highlighted: Ref<number | undefined>;
|
|
60
|
+
/** 菜单栏距页面顶部的偏移。 */
|
|
61
|
+
menuTop: Ref<number>;
|
|
62
|
+
/** 激活状态颜色。 */
|
|
63
|
+
activeColor: Ref<string>;
|
|
64
|
+
/** 未激活状态颜色。 */
|
|
65
|
+
inactiveColor: Ref<string>;
|
|
66
|
+
/** 标题文字尺寸。 */
|
|
67
|
+
titleSize: Ref<string | number | null | undefined>;
|
|
68
|
+
/** 标题右侧图标名。 */
|
|
69
|
+
menuIcon: Ref<string>;
|
|
70
|
+
/** 标题右侧图标尺寸。 */
|
|
71
|
+
menuIconSize: Ref<string | number | null | undefined>;
|
|
72
|
+
/** 面板动画时长。 */
|
|
73
|
+
duration: Ref<number>;
|
|
74
|
+
/** 点击遮罩是否关闭。 */
|
|
75
|
+
closeOnClickMask: Ref<boolean>;
|
|
76
|
+
/** 再次点击已展开标题是否关闭。 */
|
|
77
|
+
closeOnClickSelf: Ref<boolean>;
|
|
78
|
+
/** 组件层级。 */
|
|
79
|
+
zIndex: Ref<number>;
|
|
80
|
+
/** 注册一个菜单项并返回其下标。 */
|
|
81
|
+
register(item: symbol): number;
|
|
82
|
+
/** 注销一个菜单项。 */
|
|
83
|
+
unregister(item: symbol): void;
|
|
84
|
+
/** 查询菜单项下标。 */
|
|
85
|
+
indexOf(item: symbol): number;
|
|
86
|
+
/** 展开指定菜单项。 */
|
|
87
|
+
open(item: symbol): void;
|
|
88
|
+
/** 收起全部菜单项。 */
|
|
89
|
+
close(): void;
|
|
90
|
+
/** 重新测量菜单栏位置。 */
|
|
91
|
+
updateRect(): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** DropMenu ↔ DropMenuItem 配对注入键。 */
|
|
95
|
+
export const dropMenuKey: InjectionKey<DropMenuContext> = Symbol('snake-drop-menu');
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="snake-drop-item">
|
|
3
|
+
<view
|
|
4
|
+
class="snake-drop-item__trigger"
|
|
5
|
+
:style="{ color, fontSize: addUnit(menu?.titleSize.value || 28, 'rpx') }"
|
|
6
|
+
@click="toggle"
|
|
7
|
+
>
|
|
8
|
+
<text class="snake-drop-item__title">{{ displayTitle }}</text>
|
|
9
|
+
<snake-icon
|
|
10
|
+
class="snake-drop-item__arrow"
|
|
11
|
+
:name="isOpen ? 'arrow-up' : 'arrow-down'"
|
|
12
|
+
:size="menu?.menuIconSize.value || 18"
|
|
13
|
+
aria-hidden="true"
|
|
14
|
+
/>
|
|
15
|
+
</view>
|
|
16
|
+
<view
|
|
17
|
+
v-if="isOpen"
|
|
18
|
+
class="snake-drop-item__mask"
|
|
19
|
+
:style="{ top: `${menu?.menuTop.value || 0}px`, zIndex: menu?.zIndex.value || zIndex.dropdown }"
|
|
20
|
+
@click="maskClick"
|
|
21
|
+
/>
|
|
22
|
+
<snake-transition
|
|
23
|
+
:show="isOpen"
|
|
24
|
+
name="fade-down"
|
|
25
|
+
:duration="menu?.duration.value || 300"
|
|
26
|
+
custom-class="snake-drop-item__panel"
|
|
27
|
+
:custom-style="panelStyle"
|
|
28
|
+
>
|
|
29
|
+
<slot v-if="$slots.default" />
|
|
30
|
+
<scroll-view v-else class="snake-drop-item__options" scroll-y>
|
|
31
|
+
<view
|
|
32
|
+
v-for="(option, index) in options"
|
|
33
|
+
:key="index"
|
|
34
|
+
class="snake-drop-item__option"
|
|
35
|
+
:class="{ 'is-active': option.value === modelValue, 'is-disabled': option.disabled }"
|
|
36
|
+
@click="select(option.value, option.disabled)"
|
|
37
|
+
>
|
|
38
|
+
<text>{{ option.label }}</text>
|
|
39
|
+
<snake-icon v-if="option.value === modelValue" name="checkmark" />
|
|
40
|
+
</view>
|
|
41
|
+
</scroll-view>
|
|
42
|
+
</snake-transition>
|
|
43
|
+
</view>
|
|
44
|
+
</template>
|
|
45
|
+
|
|
46
|
+
<script setup lang="ts">
|
|
47
|
+
/**
|
|
48
|
+
* @component DropMenuItem
|
|
49
|
+
* @description 提供菜单触发器、遮罩和内容面板,必须作为 `DropMenu` 的直接子组件使用。可通过 options 快速生成选项,也可完全自定义内容。
|
|
50
|
+
* @see /components/drop-menu
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
import { computed, inject, onBeforeUnmount, watch, type CSSProperties } from 'vue';
|
|
54
|
+
import zIndex from '../../libs/config/zIndex';
|
|
55
|
+
import { addUnit } from '../../libs/function/unit';
|
|
56
|
+
import { dropMenuKey } from '../snake-drop-menu/types';
|
|
57
|
+
import Icon from '../snake-icon/snake-icon.vue';
|
|
58
|
+
import Transition from '../snake-transition/snake-transition.vue';
|
|
59
|
+
import type { DropMenuItemEmits, DropMenuItemProps } from './types';
|
|
60
|
+
|
|
61
|
+
defineOptions({ name: 'DropMenuItem', options: { virtualHost: true, styleIsolation: 'shared' } });
|
|
62
|
+
const props = withDefaults(defineProps<DropMenuItemProps>(), {
|
|
63
|
+
title: '',
|
|
64
|
+
options: () => [],
|
|
65
|
+
disabled: false,
|
|
66
|
+
height: 'auto',
|
|
67
|
+
beforeToggle: undefined,
|
|
68
|
+
customStyle: ''
|
|
69
|
+
});
|
|
70
|
+
const emit = defineEmits<DropMenuItemEmits>();
|
|
71
|
+
const menu = inject(dropMenuKey);
|
|
72
|
+
const itemId = Symbol('snake-drop-menu-item');
|
|
73
|
+
const itemIndex = menu?.register(itemId) ?? -1;
|
|
74
|
+
const isOpen = computed(() => menu?.activeItem.value === itemId || props.show === true);
|
|
75
|
+
const selected = computed(() => props.options.find(option => option.value === props.modelValue));
|
|
76
|
+
const displayTitle = computed(() => props.title || selected.value?.label || '请选择');
|
|
77
|
+
const color = computed(() =>
|
|
78
|
+
isOpen.value || menu?.highlighted.value === itemIndex ? menu?.activeColor.value : menu?.inactiveColor.value
|
|
79
|
+
);
|
|
80
|
+
const panelStyle = computed(() => [
|
|
81
|
+
{
|
|
82
|
+
// 面板定位/底色直接内联,避免依赖跨组件 scoped class(custom-class 应用在
|
|
83
|
+
// snake-transition 根节点上,而 scoped 样式带的是本组件 data-v,选择器匹配不上)。
|
|
84
|
+
position: 'fixed',
|
|
85
|
+
top: `${menu?.menuTop.value || 0}px`,
|
|
86
|
+
left: 0,
|
|
87
|
+
right: 0,
|
|
88
|
+
zIndex: (menu?.zIndex.value || zIndex.dropdown) + 1,
|
|
89
|
+
maxHeight: props.height === 'auto' ? '70vh' : addUnit(props.height, 'rpx'),
|
|
90
|
+
boxSizing: 'border-box',
|
|
91
|
+
overflow: 'hidden',
|
|
92
|
+
background: 'var(--snake-color-surface, #fff)',
|
|
93
|
+
boxShadow: '0 18rpx 48rpx var(--snake-color-shadow, rgba(15, 30, 24, 0.12))'
|
|
94
|
+
} as CSSProperties,
|
|
95
|
+
props.customStyle
|
|
96
|
+
]);
|
|
97
|
+
function requestOpen() {
|
|
98
|
+
if (!props.beforeToggle) return Promise.resolve(true);
|
|
99
|
+
return new Promise<boolean>(resolve => props.beforeToggle?.({ resolve }));
|
|
100
|
+
}
|
|
101
|
+
async function toggle() {
|
|
102
|
+
if (!menu || props.disabled) return;
|
|
103
|
+
if (isOpen.value) {
|
|
104
|
+
if (menu.closeOnClickSelf.value) menu.close();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (await requestOpen()) {
|
|
108
|
+
await menu.updateRect();
|
|
109
|
+
menu.open(itemId);
|
|
110
|
+
emit('open');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function close() {
|
|
114
|
+
menu?.close();
|
|
115
|
+
}
|
|
116
|
+
function maskClick() {
|
|
117
|
+
if (menu?.closeOnClickMask.value) close();
|
|
118
|
+
}
|
|
119
|
+
function select(value: unknown, disabled?: boolean) {
|
|
120
|
+
if (disabled) return;
|
|
121
|
+
emit('update:modelValue', value);
|
|
122
|
+
emit('change', value);
|
|
123
|
+
close();
|
|
124
|
+
}
|
|
125
|
+
watch(isOpen, (value, previous) => {
|
|
126
|
+
if (previous && !value) emit('close');
|
|
127
|
+
});
|
|
128
|
+
onBeforeUnmount(() => menu?.unregister(itemId));
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<style scoped>
|
|
132
|
+
.snake-drop-item {
|
|
133
|
+
flex: 1;
|
|
134
|
+
min-width: 0;
|
|
135
|
+
}
|
|
136
|
+
.snake-drop-item__trigger {
|
|
137
|
+
display: flex;
|
|
138
|
+
align-items: center;
|
|
139
|
+
justify-content: center;
|
|
140
|
+
gap: 8rpx;
|
|
141
|
+
width: 100%;
|
|
142
|
+
height: 100%;
|
|
143
|
+
padding: 0 12rpx;
|
|
144
|
+
line-height: 1;
|
|
145
|
+
}
|
|
146
|
+
.snake-drop-item__title {
|
|
147
|
+
overflow: hidden;
|
|
148
|
+
text-overflow: ellipsis;
|
|
149
|
+
white-space: nowrap;
|
|
150
|
+
}
|
|
151
|
+
.snake-drop-item__arrow {
|
|
152
|
+
flex: none;
|
|
153
|
+
line-height: 1;
|
|
154
|
+
}
|
|
155
|
+
.snake-drop-item__mask {
|
|
156
|
+
position: fixed;
|
|
157
|
+
right: 0;
|
|
158
|
+
bottom: 0;
|
|
159
|
+
left: 0;
|
|
160
|
+
background: rgba(0, 0, 0, 0.45);
|
|
161
|
+
}
|
|
162
|
+
/* 面板定位/底色已内联在 panelStyle(跨组件 custom-class 无法命中 scoped 选择器) */
|
|
163
|
+
.snake-drop-item__options {
|
|
164
|
+
max-height: 70vh;
|
|
165
|
+
}
|
|
166
|
+
.snake-drop-item__option {
|
|
167
|
+
display: flex;
|
|
168
|
+
min-height: 88rpx;
|
|
169
|
+
align-items: center;
|
|
170
|
+
justify-content: space-between;
|
|
171
|
+
padding: 0 32rpx;
|
|
172
|
+
border-bottom: 1px solid var(--snake-color-divider, #e4e7ed);
|
|
173
|
+
color: var(--snake-color-text-secondary, #606266);
|
|
174
|
+
}
|
|
175
|
+
.snake-drop-item__option.is-active {
|
|
176
|
+
color: var(--snake-color-primary, #06d290);
|
|
177
|
+
}
|
|
178
|
+
.snake-drop-item__option.is-disabled {
|
|
179
|
+
opacity: 0.45;
|
|
180
|
+
}
|
|
181
|
+
</style>
|