@wot-ui/ui 1.0.0 → 2.0.0-alpha.3
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/README.md +134 -0
- package/attributes.json +1 -0
- package/changelog.md +53 -0
- package/common/AbortablePromise.ts +28 -0
- package/common/canvasHelper.ts +49 -0
- package/common/clickoutside.ts +25 -0
- package/common/event.ts +8 -0
- package/common/formatDate.ts +68 -0
- package/common/interceptor.ts +43 -0
- package/common/props.ts +53 -0
- package/common/util.ts +836 -0
- package/components/wd-action-sheet/index.scss +232 -0
- package/components/wd-action-sheet/types.ts +155 -0
- package/components/wd-action-sheet/wd-action-sheet.vue +176 -0
- package/components/wd-avatar/index.scss +150 -0
- package/components/wd-avatar/types.ts +98 -0
- package/components/wd-avatar/wd-avatar.vue +184 -0
- package/components/wd-avatar-group/index.scss +11 -0
- package/components/wd-avatar-group/types.ts +61 -0
- package/components/wd-avatar-group/wd-avatar-group.vue +115 -0
- package/components/wd-backtop/index.scss +67 -0
- package/components/wd-backtop/types.ts +66 -0
- package/components/wd-backtop/wd-backtop.vue +57 -0
- package/components/wd-badge/index.scss +116 -0
- package/components/wd-badge/types.ts +94 -0
- package/components/wd-badge/wd-badge.vue +78 -0
- package/components/wd-button/index.scss +436 -0
- package/components/wd-button/types.ts +204 -0
- package/components/wd-button/wd-button.vue +210 -0
- package/components/wd-calendar/index.scss +97 -0
- package/components/wd-calendar/types.ts +221 -0
- package/components/wd-calendar/wd-calendar.vue +339 -0
- package/components/wd-calendar-view/index.scss +41 -0
- package/components/wd-calendar-view/month/index.scss +144 -0
- package/components/wd-calendar-view/month/month.vue +389 -0
- package/components/wd-calendar-view/month/types.ts +70 -0
- package/components/wd-calendar-view/monthPanel/index.scss +84 -0
- package/components/wd-calendar-view/monthPanel/month-panel.vue +541 -0
- package/components/wd-calendar-view/monthPanel/types.ts +151 -0
- package/components/wd-calendar-view/types.ts +166 -0
- package/components/wd-calendar-view/utils.ts +318 -0
- package/components/wd-calendar-view/wd-calendar-view.vue +117 -0
- package/components/wd-calendar-view/year/index.scss +148 -0
- package/components/wd-calendar-view/year/types.ts +74 -0
- package/components/wd-calendar-view/year/year.vue +206 -0
- package/components/wd-calendar-view/yearPanel/index.scss +42 -0
- package/components/wd-calendar-view/yearPanel/types.ts +96 -0
- package/components/wd-calendar-view/yearPanel/year-panel.vue +249 -0
- package/components/wd-card/index.scss +104 -0
- package/components/wd-card/types.ts +47 -0
- package/components/wd-card/wd-card.vue +38 -0
- package/components/wd-cascader/index.scss +154 -0
- package/components/wd-cascader/types.ts +191 -0
- package/components/wd-cascader/wd-cascader.vue +589 -0
- package/components/wd-cell/index.scss +244 -0
- package/components/wd-cell/types.ts +205 -0
- package/components/wd-cell/wd-cell.vue +172 -0
- package/components/wd-cell-group/index.scss +53 -0
- package/components/wd-cell-group/types.ts +97 -0
- package/components/wd-cell-group/wd-cell-group.vue +48 -0
- package/components/wd-checkbox/index.scss +166 -0
- package/components/wd-checkbox/types.ts +118 -0
- package/components/wd-checkbox/wd-checkbox.vue +216 -0
- package/components/wd-checkbox-group/index.scss +5 -0
- package/components/wd-checkbox-group/types.ts +93 -0
- package/components/wd-checkbox-group/wd-checkbox-group.vue +148 -0
- package/components/wd-circle/index.scss +28 -0
- package/components/wd-circle/types.ts +54 -0
- package/components/wd-circle/wd-circle.vue +306 -0
- package/components/wd-col/index.scss +5 -0
- package/components/wd-col/types.ts +16 -0
- package/components/wd-col/wd-col.vue +83 -0
- package/components/wd-collapse/index.scss +71 -0
- package/components/wd-collapse/types.ts +68 -0
- package/components/wd-collapse/wd-collapse.vue +165 -0
- package/components/wd-collapse-item/index.scss +86 -0
- package/components/wd-collapse-item/types.ts +62 -0
- package/components/wd-collapse-item/wd-collapse-item.vue +184 -0
- package/components/wd-config-provider/index.scss +10 -0
- package/components/wd-config-provider/types.ts +2063 -0
- package/components/wd-config-provider/wd-config-provider.vue +61 -0
- package/components/wd-count-down/index.scss +16 -0
- package/components/wd-count-down/types.ts +58 -0
- package/components/wd-count-down/utils.ts +52 -0
- package/components/wd-count-down/wd-count-down.vue +62 -0
- package/components/wd-count-to/index.scss +25 -0
- package/components/wd-count-to/types.ts +121 -0
- package/components/wd-count-to/wd-count-to.vue +126 -0
- package/components/wd-curtain/index.scss +96 -0
- package/components/wd-curtain/types.ts +82 -0
- package/components/wd-curtain/wd-curtain.vue +172 -0
- package/components/wd-datetime-picker/index.scss +133 -0
- package/components/wd-datetime-picker/types.ts +198 -0
- package/components/wd-datetime-picker/wd-datetime-picker.vue +526 -0
- package/components/wd-datetime-picker-view/types.ts +171 -0
- package/components/wd-datetime-picker-view/util.ts +30 -0
- package/components/wd-datetime-picker-view/wd-datetime-picker-view.vue +402 -0
- package/components/wd-dialog/index.scss +281 -0
- package/components/wd-dialog/index.ts +168 -0
- package/components/wd-dialog/types.ts +452 -0
- package/components/wd-dialog/wd-dialog.vue +586 -0
- package/components/wd-divider/index.scss +122 -0
- package/components/wd-divider/types.ts +50 -0
- package/components/wd-divider/wd-divider.vue +54 -0
- package/components/wd-drop-menu/index.scss +90 -0
- package/components/wd-drop-menu/types.ts +38 -0
- package/components/wd-drop-menu/wd-drop-menu.vue +168 -0
- package/components/wd-drop-menu-item/index.scss +96 -0
- package/components/wd-drop-menu-item/types.ts +93 -0
- package/components/wd-drop-menu-item/wd-drop-menu-item.vue +205 -0
- package/components/wd-empty/index.scss +46 -0
- package/components/wd-empty/types.ts +37 -0
- package/components/wd-empty/wd-empty.vue +47 -0
- package/components/wd-fab/index.scss +124 -0
- package/components/wd-fab/types.ts +119 -0
- package/components/wd-fab/wd-fab.vue +322 -0
- package/components/wd-floating-panel/index.scss +73 -0
- package/components/wd-floating-panel/type.ts +32 -0
- package/components/wd-floating-panel/wd-floating-panel.vue +142 -0
- package/components/wd-form/adapters/zod.ts +56 -0
- package/components/wd-form/types.ts +147 -0
- package/components/wd-form/wd-form.vue +121 -0
- package/components/wd-form-item/index.scss +26 -0
- package/components/wd-form-item/types.ts +134 -0
- package/components/wd-form-item/wd-form-item.vue +182 -0
- package/components/wd-gap/index.scss +9 -0
- package/components/wd-gap/types.ts +26 -0
- package/components/wd-gap/wd-gap.vue +38 -0
- package/components/wd-grid/index.scss +11 -0
- package/components/wd-grid/types.ts +97 -0
- package/components/wd-grid/wd-grid.vue +48 -0
- package/components/wd-grid-item/index.scss +187 -0
- package/components/wd-grid-item/types.ts +98 -0
- package/components/wd-grid-item/wd-grid-item.vue +295 -0
- package/components/wd-icon/index.scss +46 -0
- package/components/wd-icon/types.ts +44 -0
- package/components/wd-icon/wd-icon.vue +66 -0
- package/components/wd-image-preview/index.scss +94 -0
- package/components/wd-image-preview/index.ts +95 -0
- package/components/wd-image-preview/types.ts +165 -0
- package/components/wd-image-preview/wd-image-preview.vue +233 -0
- package/components/wd-img/index.scss +82 -0
- package/components/wd-img/types.ts +96 -0
- package/components/wd-img/wd-img.vue +91 -0
- package/components/wd-img-cropper/index.scss +259 -0
- package/components/wd-img-cropper/types.ts +101 -0
- package/components/wd-img-cropper/wd-img-cropper.vue +653 -0
- package/components/wd-index-anchor/index.scss +34 -0
- package/components/wd-index-anchor/type.ts +9 -0
- package/components/wd-index-anchor/wd-index-anchor.vue +55 -0
- package/components/wd-index-bar/index.scss +68 -0
- package/components/wd-index-bar/type.ts +23 -0
- package/components/wd-index-bar/wd-index-bar.vue +157 -0
- package/components/wd-input/index.scss +129 -0
- package/components/wd-input/types.ts +165 -0
- package/components/wd-input/wd-input.vue +237 -0
- package/components/wd-input-number/index.scss +233 -0
- package/components/wd-input-number/types.ts +131 -0
- package/components/wd-input-number/wd-input-number.vue +473 -0
- package/components/wd-keyboard/constants.ts +81 -0
- package/components/wd-keyboard/index.scss +104 -0
- package/components/wd-keyboard/key/index.scss +103 -0
- package/components/wd-keyboard/key/index.vue +84 -0
- package/components/wd-keyboard/key/types.ts +44 -0
- package/components/wd-keyboard/types.ts +138 -0
- package/components/wd-keyboard/wd-keyboard.vue +236 -0
- package/components/wd-loading/index.scss +205 -0
- package/components/wd-loading/types.ts +61 -0
- package/components/wd-loading/wd-loading.vue +70 -0
- package/components/wd-loadmore/index.scss +62 -0
- package/components/wd-loadmore/types.ts +42 -0
- package/components/wd-loadmore/wd-loadmore.vue +68 -0
- package/components/wd-navbar/index.scss +96 -0
- package/components/wd-navbar/types.ts +74 -0
- package/components/wd-navbar/wd-navbar.vue +136 -0
- package/components/wd-navbar-capsule/index.scss +70 -0
- package/components/wd-navbar-capsule/types.ts +11 -0
- package/components/wd-navbar-capsule/wd-navbar-capsule.vue +48 -0
- package/components/wd-notice-bar/index.scss +94 -0
- package/components/wd-notice-bar/types.ts +97 -0
- package/components/wd-notice-bar/wd-notice-bar.vue +270 -0
- package/components/wd-notify/index.scss +114 -0
- package/components/wd-notify/index.ts +63 -0
- package/components/wd-notify/types.ts +130 -0
- package/components/wd-notify/wd-notify.vue +162 -0
- package/components/wd-overlay/index.scss +14 -0
- package/components/wd-overlay/types.ts +42 -0
- package/components/wd-overlay/wd-overlay.vue +55 -0
- package/components/wd-pagination/index.scss +71 -0
- package/components/wd-pagination/types.ts +69 -0
- package/components/wd-pagination/wd-pagination.vue +118 -0
- package/components/wd-password-input/index.scss +134 -0
- package/components/wd-password-input/types.ts +42 -0
- package/components/wd-password-input/wd-password-input.vue +51 -0
- package/components/wd-picker/index.scss +72 -0
- package/components/wd-picker/types.ts +141 -0
- package/components/wd-picker/wd-picker.vue +220 -0
- package/components/wd-picker-view/index.scss +93 -0
- package/components/wd-picker-view/types.ts +145 -0
- package/components/wd-picker-view/useSelection.ts +385 -0
- package/components/wd-picker-view/wd-picker-view.vue +227 -0
- package/components/wd-popover/index.scss +117 -0
- package/components/wd-popover/types.ts +106 -0
- package/components/wd-popover/wd-popover.vue +212 -0
- package/components/wd-popup/index.scss +89 -0
- package/components/wd-popup/types.ts +110 -0
- package/components/wd-popup/wd-popup.vue +174 -0
- package/components/wd-progress/index.scss +155 -0
- package/components/wd-progress/types.ts +94 -0
- package/components/wd-progress/wd-progress.vue +249 -0
- package/components/wd-radio/index.scss +189 -0
- package/components/wd-radio/types.ts +64 -0
- package/components/wd-radio/wd-radio.vue +164 -0
- package/components/wd-radio-group/index.scss +5 -0
- package/components/wd-radio-group/types.ts +70 -0
- package/components/wd-radio-group/wd-radio-group.vue +53 -0
- package/components/wd-rate/index.scss +57 -0
- package/components/wd-rate/types.ts +86 -0
- package/components/wd-rate/wd-rate.vue +168 -0
- package/components/wd-resize/index.scss +31 -0
- package/components/wd-resize/types.ts +14 -0
- package/components/wd-resize/wd-resize.vue +157 -0
- package/components/wd-root-portal/wd-root-portal.vue +77 -0
- package/components/wd-row/index.scss +6 -0
- package/components/wd-row/types.ts +36 -0
- package/components/wd-row/wd-row.vue +88 -0
- package/components/wd-search/index.scss +171 -0
- package/components/wd-search/types.ts +107 -0
- package/components/wd-search/wd-search.vue +198 -0
- package/components/wd-segmented/index.scss +155 -0
- package/components/wd-segmented/types.ts +81 -0
- package/components/wd-segmented/wd-segmented.vue +169 -0
- package/components/wd-select-picker/index.scss +72 -0
- package/components/wd-select-picker/types.ts +72 -0
- package/components/wd-select-picker/wd-select-picker.vue +371 -0
- package/components/wd-sidebar/index.scss +25 -0
- package/components/wd-sidebar/types.ts +34 -0
- package/components/wd-sidebar/wd-sidebar.vue +57 -0
- package/components/wd-sidebar-item/index.scss +91 -0
- package/components/wd-sidebar-item/types.ts +28 -0
- package/components/wd-sidebar-item/wd-sidebar-item.vue +118 -0
- package/components/wd-signature/index.scss +42 -0
- package/components/wd-signature/types.ts +295 -0
- package/components/wd-signature/wd-signature.vue +664 -0
- package/components/wd-skeleton/index.scss +112 -0
- package/components/wd-skeleton/types.ts +124 -0
- package/components/wd-skeleton/wd-skeleton.vue +110 -0
- package/components/wd-slide-verify/index.scss +112 -0
- package/components/wd-slide-verify/types.ts +98 -0
- package/components/wd-slide-verify/wd-slide-verify.vue +222 -0
- package/components/wd-slider/index.scss +485 -0
- package/components/wd-slider/types.ts +166 -0
- package/components/wd-slider/wd-slider.vue +529 -0
- package/components/wd-sort-button/index.scss +126 -0
- package/components/wd-sort-button/types.ts +68 -0
- package/components/wd-sort-button/wd-sort-button.vue +67 -0
- package/components/wd-step/index.scss +366 -0
- package/components/wd-step/types.ts +43 -0
- package/components/wd-step/wd-step.vue +181 -0
- package/components/wd-steps/index.scss +7 -0
- package/components/wd-steps/types.ts +50 -0
- package/components/wd-steps/wd-steps.vue +39 -0
- package/components/wd-sticky/index.scss +9 -0
- package/components/wd-sticky/types.ts +13 -0
- package/components/wd-sticky/wd-sticky.vue +192 -0
- package/components/wd-sticky-box/index.scss +6 -0
- package/components/wd-sticky-box/types.ts +20 -0
- package/components/wd-sticky-box/wd-sticky-box.vue +157 -0
- package/components/wd-swipe-action/index.scss +22 -0
- package/components/wd-swipe-action/types.ts +87 -0
- package/components/wd-swipe-action/wd-swipe-action.vue +320 -0
- package/components/wd-swiper/index.scss +69 -0
- package/components/wd-swiper/types.ts +275 -0
- package/components/wd-swiper/wd-swiper.vue +332 -0
- package/components/wd-swiper-nav/index.scss +179 -0
- package/components/wd-swiper-nav/types.ts +42 -0
- package/components/wd-swiper-nav/wd-swiper-nav.vue +42 -0
- package/components/wd-switch/index.scss +177 -0
- package/components/wd-switch/types.ts +93 -0
- package/components/wd-switch/wd-switch.vue +107 -0
- package/components/wd-tab/index.scss +16 -0
- package/components/wd-tab/types.ts +45 -0
- package/components/wd-tab/wd-tab.vue +99 -0
- package/components/wd-tabbar/index.scss +71 -0
- package/components/wd-tabbar/types.ts +79 -0
- package/components/wd-tabbar/wd-tabbar.vue +109 -0
- package/components/wd-tabbar-item/index.scss +50 -0
- package/components/wd-tabbar-item/types.ts +45 -0
- package/components/wd-tabbar-item/wd-tabbar-item.vue +101 -0
- package/components/wd-table/index.scss +128 -0
- package/components/wd-table/types.ts +160 -0
- package/components/wd-table/wd-table.vue +331 -0
- package/components/wd-table-column/index.scss +15 -0
- package/components/wd-table-column/types.ts +81 -0
- package/components/wd-table-column/wd-table-column.vue +198 -0
- package/components/wd-tabs/index.scss +332 -0
- package/components/wd-tabs/types.ts +155 -0
- package/components/wd-tabs/wd-tabs.vue +508 -0
- package/components/wd-tag/index.scss +325 -0
- package/components/wd-tag/types.ts +90 -0
- package/components/wd-tag/wd-tag.vue +158 -0
- package/components/wd-text/index.scss +52 -0
- package/components/wd-text/types.ts +107 -0
- package/components/wd-text/wd-text.vue +141 -0
- package/components/wd-textarea/index.scss +112 -0
- package/components/wd-textarea/types.ts +151 -0
- package/components/wd-textarea/wd-textarea.vue +212 -0
- package/components/wd-toast/index.scss +92 -0
- package/components/wd-toast/index.ts +97 -0
- package/components/wd-toast/types.ts +190 -0
- package/components/wd-toast/wd-toast.vue +158 -0
- package/components/wd-tooltip/index.scss +77 -0
- package/components/wd-tooltip/types.ts +105 -0
- package/components/wd-tooltip/wd-tooltip.vue +169 -0
- package/components/wd-tour/index.scss +106 -0
- package/components/wd-tour/types.ts +268 -0
- package/components/wd-tour/wd-tour.vue +518 -0
- package/components/wd-transition/index.scss +67 -0
- package/components/wd-transition/types.ts +106 -0
- package/components/wd-transition/wd-transition.vue +238 -0
- package/components/wd-upload/index.scss +204 -0
- package/components/wd-upload/types.ts +390 -0
- package/components/wd-upload/wd-upload.vue +565 -0
- package/components/wd-video-preview/index.scss +54 -0
- package/components/wd-video-preview/index.ts +64 -0
- package/components/wd-video-preview/types.ts +66 -0
- package/components/wd-video-preview/wd-video-preview.vue +141 -0
- package/components/wd-watermark/index.scss +21 -0
- package/components/wd-watermark/types.ts +130 -0
- package/components/wd-watermark/wd-watermark.vue +718 -0
- package/components/wot-ui/wot-ui.vue +5 -0
- package/composables/index.ts +12 -0
- package/composables/useCell.ts +34 -0
- package/composables/useChildren.ts +120 -0
- package/composables/useConfigProvider.ts +45 -0
- package/composables/useCountDown.ts +138 -0
- package/composables/useDeviceInfo.ts +136 -0
- package/composables/useLockScroll.ts +37 -0
- package/composables/useParent.ts +51 -0
- package/composables/usePopover.ts +212 -0
- package/composables/useQueue.ts +52 -0
- package/composables/useRaf.ts +37 -0
- package/composables/useTouch.ts +43 -0
- package/composables/useTranslate.ts +12 -0
- package/composables/useUpload.ts +366 -0
- package/global.d.ts +106 -0
- package/index.ts +11 -0
- package/locale/index.ts +32 -0
- package/locale/lang/ar-SA.ts +150 -0
- package/locale/lang/de-DE.ts +150 -0
- package/locale/lang/en-US.ts +150 -0
- package/locale/lang/es-ES.ts +150 -0
- package/locale/lang/fr-FR.ts +150 -0
- package/locale/lang/ja-JP.ts +150 -0
- package/locale/lang/ko-KR.ts +150 -0
- package/locale/lang/pt-PT.ts +150 -0
- package/locale/lang/ru-RU.ts +150 -0
- package/locale/lang/th-TH.ts +150 -0
- package/locale/lang/tr-TR.ts +155 -0
- package/locale/lang/ug-CN.ts +154 -0
- package/locale/lang/vi-VN.ts +89 -0
- package/locale/lang/zh-CN.ts +154 -0
- package/locale/lang/zh-HK.ts +78 -0
- package/locale/lang/zh-TW.ts +78 -0
- package/package.json +1 -11
- package/styles/iconfont/iconfont.scss +1243 -0
- package/styles/mixin/_config.scss +7 -0
- package/styles/mixin/_function.scss +44 -0
- package/styles/mixin/_mixin.scss +473 -0
- package/styles/theme/base/color.scss +210 -0
- package/styles/theme/base/font.scss +13 -0
- package/styles/theme/base/index.scss +8 -0
- package/styles/theme/base/insets.scss +32 -0
- package/styles/theme/base/number.scss +36 -0
- package/styles/theme/base/opacity.scss +9 -0
- package/styles/theme/base/radius.scss +13 -0
- package/styles/theme/base/stroke.scss +9 -0
- package/styles/theme/base/typography.scss +44 -0
- package/styles/theme/dark.scss +101 -0
- package/styles/theme/index.scss +16 -0
- package/styles/theme/light.scss +101 -0
- package/styles/variable.scss +472 -0
- package/tags.json +1 -0
- package/web-types.json +1 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
@touchmove.stop.prevent="handleTouchMove"
|
|
4
|
+
@touchstart="handleTouchStart"
|
|
5
|
+
@touchend="handleTouchEnd"
|
|
6
|
+
:class="`wd-fab ${customClass}`"
|
|
7
|
+
:style="rootStyle"
|
|
8
|
+
@click.stop=""
|
|
9
|
+
>
|
|
10
|
+
<view @click.stop="" :style="{ visibility: inited ? 'visible' : 'hidden' }" id="trigger">
|
|
11
|
+
<slot name="trigger" :disabled="disabled">
|
|
12
|
+
<wd-button
|
|
13
|
+
@click="handleClick"
|
|
14
|
+
:icon="isActive ? activeIcon : inactiveIcon"
|
|
15
|
+
custom-class="wd-fab__trigger"
|
|
16
|
+
round
|
|
17
|
+
:type="type"
|
|
18
|
+
:disabled="disabled"
|
|
19
|
+
></wd-button>
|
|
20
|
+
</slot>
|
|
21
|
+
</view>
|
|
22
|
+
<wd-transition
|
|
23
|
+
v-if="expandable"
|
|
24
|
+
:enter-class="`wd-fab__transition-enter--${fabDirection}`"
|
|
25
|
+
enter-active-class="wd-fab__transition-enter-active"
|
|
26
|
+
:leave-to-class="`wd-fab__transition-leave-to--${fabDirection}`"
|
|
27
|
+
leave-active-class="wd-fab__transition-leave-active"
|
|
28
|
+
:custom-class="`wd-fab__actions wd-fab__actions--${fabDirection}`"
|
|
29
|
+
:show="isActive"
|
|
30
|
+
:duration="300"
|
|
31
|
+
>
|
|
32
|
+
<slot></slot>
|
|
33
|
+
</wd-transition>
|
|
34
|
+
</view>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script lang="ts">
|
|
38
|
+
export default {
|
|
39
|
+
name: 'wd-fab',
|
|
40
|
+
options: {
|
|
41
|
+
// #ifndef MP-TOUTIAO
|
|
42
|
+
virtualHost: true,
|
|
43
|
+
// #endif
|
|
44
|
+
addGlobalClass: true,
|
|
45
|
+
styleIsolation: 'shared'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<script lang="ts" setup>
|
|
51
|
+
import wdButton from '../wd-button/wd-button.vue'
|
|
52
|
+
import wdTransition from '../wd-transition/wd-transition.vue'
|
|
53
|
+
import { type CSSProperties, computed, ref, watch, inject, getCurrentInstance, onBeforeUnmount, onMounted, nextTick } from 'vue'
|
|
54
|
+
import { getRect, getSystemInfo, isDef, isH5, objToStyle } from '../../common/util'
|
|
55
|
+
import { type Queue, queueKey } from '../../composables/useQueue'
|
|
56
|
+
import { closeOther, pushToQueue, removeFromQueue } from '../../common/clickoutside'
|
|
57
|
+
import { fabProps, type FabExpose } from './types'
|
|
58
|
+
import { reactive } from 'vue'
|
|
59
|
+
import { useRaf } from '../../composables/useRaf'
|
|
60
|
+
|
|
61
|
+
const props = defineProps(fabProps)
|
|
62
|
+
const emit = defineEmits(['update:active', 'click'])
|
|
63
|
+
|
|
64
|
+
/** 是否完成初始化 */
|
|
65
|
+
const inited = ref<boolean>(false)
|
|
66
|
+
/** 是否处于激活(展开)状态 */
|
|
67
|
+
const isActive = ref<boolean>(false)
|
|
68
|
+
const queue = inject<Queue | null>(queueKey, null)
|
|
69
|
+
const { proxy } = getCurrentInstance() as any
|
|
70
|
+
|
|
71
|
+
watch(
|
|
72
|
+
() => props.active,
|
|
73
|
+
(newValue) => {
|
|
74
|
+
isActive.value = newValue
|
|
75
|
+
},
|
|
76
|
+
{ immediate: true, deep: true }
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
watch(
|
|
80
|
+
() => isActive.value,
|
|
81
|
+
(newValue) => {
|
|
82
|
+
if (newValue) {
|
|
83
|
+
if (queue && queue.closeOther) {
|
|
84
|
+
queue.closeOther(proxy)
|
|
85
|
+
} else {
|
|
86
|
+
closeOther(proxy)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
const fabDirection = ref(props.direction)
|
|
93
|
+
|
|
94
|
+
watch(
|
|
95
|
+
() => props.direction,
|
|
96
|
+
(direction) => (fabDirection.value = direction)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
watch(
|
|
100
|
+
() => props.position,
|
|
101
|
+
() => initPosition()
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
/** 浮动按钮顶部位置 */
|
|
105
|
+
const top = ref<number>(0)
|
|
106
|
+
/** 浮动按钮左侧位置 */
|
|
107
|
+
const left = ref<number>(0)
|
|
108
|
+
/** 屏幕尺寸信息 */
|
|
109
|
+
const screen = reactive({ width: 0, height: 0 })
|
|
110
|
+
/** 浮动按钮尺寸 */
|
|
111
|
+
const fabSize = reactive({ width: 56, height: 56 })
|
|
112
|
+
/** 浮动按钮可移动边界 */
|
|
113
|
+
const bounding = reactive({
|
|
114
|
+
minTop: 0,
|
|
115
|
+
minLeft: 0,
|
|
116
|
+
maxTop: 0,
|
|
117
|
+
maxLeft: 0
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 获取浮动按钮和屏幕的边界信息
|
|
122
|
+
*/
|
|
123
|
+
async function getBounding() {
|
|
124
|
+
const sysInfo = getSystemInfo()
|
|
125
|
+
try {
|
|
126
|
+
const trigerInfo = await getRect('#trigger', false, proxy)
|
|
127
|
+
fabSize.width = trigerInfo.width || 56
|
|
128
|
+
fabSize.height = trigerInfo.height || 56
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.log(error)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const { top = 16, left = 16, right = 16, bottom = 16 } = props.gap
|
|
134
|
+
screen.width = sysInfo.windowWidth
|
|
135
|
+
screen.height = isH5 ? sysInfo.windowTop + sysInfo.windowHeight : sysInfo.windowHeight
|
|
136
|
+
bounding.minTop = isH5 ? sysInfo.windowTop + top : top
|
|
137
|
+
bounding.minLeft = left
|
|
138
|
+
bounding.maxLeft = screen.width - fabSize.width - right
|
|
139
|
+
bounding.maxTop = screen.height - fabSize.height - bottom
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 根据 position 属性初始化浮动按钮位置
|
|
144
|
+
*/
|
|
145
|
+
function initPosition() {
|
|
146
|
+
const pos = props.position
|
|
147
|
+
const { minLeft, minTop, maxLeft, maxTop } = bounding
|
|
148
|
+
const centerY = (maxTop + minTop) / 2
|
|
149
|
+
const centerX = (maxLeft + minLeft) / 2
|
|
150
|
+
|
|
151
|
+
switch (pos) {
|
|
152
|
+
case 'left-top':
|
|
153
|
+
top.value = minTop
|
|
154
|
+
left.value = minLeft
|
|
155
|
+
break
|
|
156
|
+
case 'right-top':
|
|
157
|
+
top.value = minTop
|
|
158
|
+
left.value = maxLeft
|
|
159
|
+
break
|
|
160
|
+
case 'left-bottom':
|
|
161
|
+
top.value = maxTop
|
|
162
|
+
left.value = minLeft
|
|
163
|
+
break
|
|
164
|
+
case 'right-bottom':
|
|
165
|
+
top.value = maxTop
|
|
166
|
+
left.value = maxLeft
|
|
167
|
+
break
|
|
168
|
+
case 'left-center':
|
|
169
|
+
top.value = centerY
|
|
170
|
+
left.value = minLeft
|
|
171
|
+
break
|
|
172
|
+
case 'right-center':
|
|
173
|
+
top.value = centerY
|
|
174
|
+
left.value = maxLeft
|
|
175
|
+
break
|
|
176
|
+
case 'top-center':
|
|
177
|
+
top.value = minTop
|
|
178
|
+
left.value = centerX
|
|
179
|
+
break
|
|
180
|
+
case 'bottom-center':
|
|
181
|
+
top.value = maxTop
|
|
182
|
+
left.value = centerX
|
|
183
|
+
break
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** 按下时触摸点相对于元素的偏移量 */
|
|
188
|
+
const touchOffset = reactive({ x: 0, y: 0 })
|
|
189
|
+
/** 是否启用吸附动画 */
|
|
190
|
+
const attractTransition = ref<boolean>(false)
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* 处理触摸开始事件
|
|
194
|
+
* @param {TouchEvent} e 触摸事件对象
|
|
195
|
+
*/
|
|
196
|
+
function handleTouchStart(e: TouchEvent) {
|
|
197
|
+
if (props.draggable === false) return
|
|
198
|
+
|
|
199
|
+
const touch = e.touches[0]
|
|
200
|
+
touchOffset.x = touch.clientX - left.value
|
|
201
|
+
touchOffset.y = touch.clientY - top.value
|
|
202
|
+
attractTransition.value = false
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 处理触摸移动事件,实现拖动功能
|
|
207
|
+
* @param {TouchEvent} e 触摸事件对象
|
|
208
|
+
*/
|
|
209
|
+
function handleTouchMove(e: TouchEvent) {
|
|
210
|
+
if (props.draggable === false) return
|
|
211
|
+
|
|
212
|
+
const touch = e.touches[0]
|
|
213
|
+
const { minLeft, minTop, maxLeft, maxTop } = bounding
|
|
214
|
+
let x = touch.clientX - touchOffset.x
|
|
215
|
+
let y = touch.clientY - touchOffset.y
|
|
216
|
+
|
|
217
|
+
if (x < minLeft) x = minLeft
|
|
218
|
+
else if (x > maxLeft) x = maxLeft
|
|
219
|
+
|
|
220
|
+
if (y < minTop) y = minTop
|
|
221
|
+
else if (y > maxTop) y = maxTop
|
|
222
|
+
|
|
223
|
+
top.value = y
|
|
224
|
+
left.value = x
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* 处理触摸结束事件,实现吸附效果
|
|
229
|
+
*/
|
|
230
|
+
function handleTouchEnd() {
|
|
231
|
+
if (props.draggable === false) return
|
|
232
|
+
|
|
233
|
+
const screenCenterX = screen.width / 2
|
|
234
|
+
const fabCenterX = left.value + fabSize.width / 2
|
|
235
|
+
attractTransition.value = true
|
|
236
|
+
if (fabCenterX < screenCenterX) {
|
|
237
|
+
left.value = bounding.minLeft
|
|
238
|
+
fabDirection.value = 'right'
|
|
239
|
+
} else {
|
|
240
|
+
left.value = bounding.maxLeft
|
|
241
|
+
fabDirection.value = 'left'
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 计算浮动按钮的根元素样式
|
|
247
|
+
*/
|
|
248
|
+
const rootStyle = computed(() => {
|
|
249
|
+
const style: CSSProperties = {
|
|
250
|
+
top: top.value + 'px',
|
|
251
|
+
left: left.value + 'px',
|
|
252
|
+
transition: attractTransition.value ? 'all ease 0.3s' : 'none'
|
|
253
|
+
}
|
|
254
|
+
if (isDef(props.zIndex)) {
|
|
255
|
+
style['z-index'] = props.zIndex
|
|
256
|
+
}
|
|
257
|
+
return `${objToStyle(style)}${props.customStyle}`
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
onMounted(() => {
|
|
261
|
+
if (queue && queue.pushToQueue) {
|
|
262
|
+
queue.pushToQueue(proxy)
|
|
263
|
+
} else {
|
|
264
|
+
pushToQueue(proxy)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const { start } = useRaf(async () => {
|
|
268
|
+
await getBounding()
|
|
269
|
+
initPosition()
|
|
270
|
+
inited.value = true
|
|
271
|
+
})
|
|
272
|
+
start()
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
onBeforeUnmount(() => {
|
|
276
|
+
if (queue && queue.removeFromQueue) {
|
|
277
|
+
queue.removeFromQueue(proxy)
|
|
278
|
+
} else {
|
|
279
|
+
removeFromQueue(proxy)
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 处理点击事件
|
|
285
|
+
*/
|
|
286
|
+
function handleClick() {
|
|
287
|
+
if (props.disabled) {
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
if (!props.expandable) {
|
|
291
|
+
emit('click')
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
isActive.value = !isActive.value
|
|
295
|
+
emit('update:active', isActive.value)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 展开菜单
|
|
300
|
+
*/
|
|
301
|
+
function open() {
|
|
302
|
+
isActive.value = true
|
|
303
|
+
emit('update:active', true)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* 收起菜单
|
|
308
|
+
*/
|
|
309
|
+
function close() {
|
|
310
|
+
isActive.value = false
|
|
311
|
+
emit('update:active', false)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
defineExpose<FabExpose>({
|
|
315
|
+
open,
|
|
316
|
+
close
|
|
317
|
+
})
|
|
318
|
+
</script>
|
|
319
|
+
|
|
320
|
+
<style lang="scss">
|
|
321
|
+
@use './index.scss';
|
|
322
|
+
</style>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
@use '../../styles/mixin/mixin.scss' as *;
|
|
2
|
+
@use '../../styles/variable.scss' as *;
|
|
3
|
+
|
|
4
|
+
// 面板背景色
|
|
5
|
+
$floating-panel-bg: var(--wot-floating-panel-bg, $filled-oppo) !default;
|
|
6
|
+
// 面板圆角
|
|
7
|
+
$floating-panel-radius: var(--wot-floating-panel-radius, $radius-large) !default;
|
|
8
|
+
// 面板 z-index
|
|
9
|
+
$floating-panel-z-index: var(--wot-floating-panel-z-index, 99) !default;
|
|
10
|
+
// 头部高度
|
|
11
|
+
$floating-panel-header-height: var(--wot-floating-panel-header-height, $n-32) !default;
|
|
12
|
+
// 拖拽条宽度
|
|
13
|
+
$floating-panel-bar-width: var(--wot-floating-panel-bar-width, $n-36) !default;
|
|
14
|
+
// 拖拽条高度
|
|
15
|
+
$floating-panel-bar-height: var(--wot-floating-panel-bar-height, $n-4) !default;
|
|
16
|
+
// 拖拽条背景色
|
|
17
|
+
$floating-panel-bar-bg: var(--wot-floating-panel-bar-bg, $filled-strong) !default;
|
|
18
|
+
// 拖拽条圆角
|
|
19
|
+
$floating-panel-bar-radius: var(--wot-floating-panel-bar-radius, $radius-main) !default;
|
|
20
|
+
// 内容区域背景色
|
|
21
|
+
$floating-panel-content-bg: var(--wot-floating-panel-content-bg, $filled-oppo) !default;
|
|
22
|
+
|
|
23
|
+
@include b(floating-panel) {
|
|
24
|
+
position: fixed;
|
|
25
|
+
bottom: 0;
|
|
26
|
+
left: 0;
|
|
27
|
+
z-index: $floating-panel-z-index;
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
width: 100vw;
|
|
32
|
+
border-top-left-radius: $floating-panel-radius;
|
|
33
|
+
border-top-right-radius: $floating-panel-radius;
|
|
34
|
+
background-color: $floating-panel-bg;
|
|
35
|
+
touch-action: none;
|
|
36
|
+
will-change: transform;
|
|
37
|
+
@include when(safe) {
|
|
38
|
+
padding-bottom: constant(safe-area-inset-bottom);
|
|
39
|
+
padding-bottom: env(safe-area-inset-bottom);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&::after {
|
|
43
|
+
position: absolute;
|
|
44
|
+
bottom: -100vh;
|
|
45
|
+
display: block;
|
|
46
|
+
width: 100vw;
|
|
47
|
+
height: 100vh;
|
|
48
|
+
content: '';
|
|
49
|
+
background-color: inherit;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@include e(header) {
|
|
53
|
+
display: flex;
|
|
54
|
+
justify-content: center;
|
|
55
|
+
align-items: center;
|
|
56
|
+
height: $floating-panel-header-height;
|
|
57
|
+
cursor: grab;
|
|
58
|
+
user-select: none;
|
|
59
|
+
&-bar {
|
|
60
|
+
width: $floating-panel-bar-width;
|
|
61
|
+
height: $floating-panel-bar-height;
|
|
62
|
+
background-color: $floating-panel-bar-bg;
|
|
63
|
+
border-radius: $floating-panel-bar-radius;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@include e(content) {
|
|
68
|
+
flex: 1;
|
|
69
|
+
min-width: 0;
|
|
70
|
+
min-height: 0;
|
|
71
|
+
background-color: $floating-panel-content-bg;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ExtractPropTypes } from 'vue'
|
|
2
|
+
import { baseProps, makeArrayProp, makeBooleanProp, makeNumberProp, makeNumericProp, truthProp } from '../../common/props'
|
|
3
|
+
|
|
4
|
+
export const floatingPanelProps = {
|
|
5
|
+
...baseProps,
|
|
6
|
+
/**
|
|
7
|
+
* 面板的显示高度
|
|
8
|
+
*/
|
|
9
|
+
height: makeNumberProp(0),
|
|
10
|
+
/**
|
|
11
|
+
* 设置自定义锚点,默认值 [100, windowHeight * 0.6]
|
|
12
|
+
*/
|
|
13
|
+
anchors: makeArrayProp<number>(),
|
|
14
|
+
/**
|
|
15
|
+
* 弹出面板是否设置底部安全距离(iphone X 类型的机型)
|
|
16
|
+
*/
|
|
17
|
+
safeAreaInsetBottom: makeBooleanProp(false),
|
|
18
|
+
/**
|
|
19
|
+
* 是否显示滚动条,默认值为 true
|
|
20
|
+
*/
|
|
21
|
+
showScrollbar: truthProp,
|
|
22
|
+
/**
|
|
23
|
+
* 动画时长,单位毫秒,默认值为 300ms
|
|
24
|
+
*/
|
|
25
|
+
duration: makeNumericProp(300),
|
|
26
|
+
/**
|
|
27
|
+
* 是否允许内容区容器拖拽,默认值为 true
|
|
28
|
+
*/
|
|
29
|
+
contentDraggable: truthProp
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type FloatingPanelProps = ExtractPropTypes<typeof floatingPanelProps>
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
:class="`wd-floating-panel ${customClass} ${safeAreaInsetBottom ? 'is-safe' : ''}`"
|
|
4
|
+
:style="rootStyle"
|
|
5
|
+
@touchstart.passive="handleTouchStart"
|
|
6
|
+
@touchmove.passive="handleTouchMove"
|
|
7
|
+
@touchend="handleTouchEnd"
|
|
8
|
+
@touchcancel="handleTouchEnd"
|
|
9
|
+
>
|
|
10
|
+
<view :class="`wd-floating-panel__header`">
|
|
11
|
+
<view :class="`wd-floating-panel__header-bar`"></view>
|
|
12
|
+
</view>
|
|
13
|
+
|
|
14
|
+
<scroll-view
|
|
15
|
+
:class="`wd-floating-panel__content`"
|
|
16
|
+
data-id="content"
|
|
17
|
+
:show-scrollbar="showScrollbar"
|
|
18
|
+
scroll-y
|
|
19
|
+
@touchmove.stop.prevent="handleTouchMove"
|
|
20
|
+
>
|
|
21
|
+
<slot />
|
|
22
|
+
</scroll-view>
|
|
23
|
+
</view>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
export default {
|
|
28
|
+
name: 'wd-floating-panel',
|
|
29
|
+
options: {
|
|
30
|
+
// #ifndef MP-TOUTIAO
|
|
31
|
+
virtualHost: true,
|
|
32
|
+
// #endif
|
|
33
|
+
addGlobalClass: true,
|
|
34
|
+
styleIsolation: 'shared'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<script lang="ts" setup>
|
|
40
|
+
import { computed, onBeforeMount, ref, watch, type CSSProperties } from 'vue'
|
|
41
|
+
import { floatingPanelProps } from './type'
|
|
42
|
+
import { addUnit, closest, getSystemInfo, objToStyle } from '../../common/util'
|
|
43
|
+
import { useTouch } from '../../composables/useTouch'
|
|
44
|
+
|
|
45
|
+
const touch = useTouch()
|
|
46
|
+
|
|
47
|
+
const props = defineProps(floatingPanelProps)
|
|
48
|
+
const emit = defineEmits(['update:height', 'height-change'])
|
|
49
|
+
|
|
50
|
+
const heightValue = ref<number>(props.height)
|
|
51
|
+
|
|
52
|
+
const DAMP = 0.2 // 阻尼系数
|
|
53
|
+
let startY: number // 起始位置
|
|
54
|
+
const windowHeight = ref<number>(0)
|
|
55
|
+
const dragging = ref<boolean>(false) // 是否正在拖拽
|
|
56
|
+
|
|
57
|
+
const boundary = computed(() => ({
|
|
58
|
+
min: props.anchors[0] ? props.anchors[0] : 100,
|
|
59
|
+
max: props.anchors[props.anchors.length - 1] ? props.anchors[props.anchors.length - 1] : Math.round(windowHeight.value * 0.6)
|
|
60
|
+
}))
|
|
61
|
+
|
|
62
|
+
const anchors = computed(() => (props.anchors.length >= 2 ? props.anchors : [boundary.value.min, boundary.value.max]))
|
|
63
|
+
|
|
64
|
+
const rootStyle = computed(() => {
|
|
65
|
+
const style: CSSProperties = {
|
|
66
|
+
height: addUnit(boundary.value.max),
|
|
67
|
+
transform: `translateY(calc(100% + ${addUnit(-heightValue.value)}))`,
|
|
68
|
+
transition: !dragging.value ? `transform ${props.duration}ms cubic-bezier(0.18, 0.89, 0.32, 1.28)` : 'none'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return `${objToStyle(style)}${props.customStyle}`
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const updateHeight = (value: number) => {
|
|
75
|
+
heightValue.value = value
|
|
76
|
+
emit('update:height', value)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const handleTouchStart = (event: TouchEvent) => {
|
|
80
|
+
touch.touchStart(event)
|
|
81
|
+
dragging.value = true
|
|
82
|
+
startY = -heightValue.value
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const handleTouchMove = (event: TouchEvent) => {
|
|
86
|
+
const target = event.currentTarget as any
|
|
87
|
+
if (target.dataset.id == 'content') {
|
|
88
|
+
if (!props.contentDraggable) return
|
|
89
|
+
}
|
|
90
|
+
touch.touchMove(event)
|
|
91
|
+
const moveY = touch.deltaY.value + startY
|
|
92
|
+
updateHeight(-ease(moveY))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const handleTouchEnd = () => {
|
|
96
|
+
dragging.value = false
|
|
97
|
+
updateHeight(closest(anchors.value, heightValue.value))
|
|
98
|
+
|
|
99
|
+
if (heightValue.value !== -startY) {
|
|
100
|
+
emit('height-change', { height: heightValue.value })
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const ease = (y: number) => {
|
|
105
|
+
const absDistance = Math.abs(y)
|
|
106
|
+
const { min, max } = boundary.value
|
|
107
|
+
|
|
108
|
+
if (absDistance > max) {
|
|
109
|
+
return -(max + (absDistance - max) * DAMP)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (absDistance < min) {
|
|
113
|
+
return -(min - (min - absDistance) * DAMP)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return y
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
watch(
|
|
120
|
+
() => props.height,
|
|
121
|
+
(value) => {
|
|
122
|
+
heightValue.value = value
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
watch(
|
|
127
|
+
boundary,
|
|
128
|
+
() => {
|
|
129
|
+
updateHeight(closest(anchors.value, heightValue.value))
|
|
130
|
+
},
|
|
131
|
+
{ immediate: true }
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
onBeforeMount(() => {
|
|
135
|
+
const { windowHeight: _windowHeight } = getSystemInfo()
|
|
136
|
+
windowHeight.value = _windowHeight
|
|
137
|
+
})
|
|
138
|
+
</script>
|
|
139
|
+
|
|
140
|
+
<style lang="scss">
|
|
141
|
+
@use './index.scss';
|
|
142
|
+
</style>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { FormSchema, FormSchemaIssue } from '../types'
|
|
2
|
+
|
|
3
|
+
type ZodLikeIssue = {
|
|
4
|
+
path?: PropertyKey[]
|
|
5
|
+
message?: string
|
|
6
|
+
code?: string
|
|
7
|
+
received?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type ZodLikeSafeParseResult = {
|
|
11
|
+
success: boolean
|
|
12
|
+
error?: {
|
|
13
|
+
issues?: ZodLikeIssue[]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type ZodLikeParseContext = {
|
|
18
|
+
jitless?: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type ZodLikeSchema = {
|
|
22
|
+
safeParse: (model: Record<string, any>, context?: ZodLikeParseContext) => ZodLikeSafeParseResult
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type ZodAdapterOptions = {
|
|
26
|
+
isRequired?: FormSchema['isRequired']
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function normalizeIssues(result: ZodLikeSafeParseResult): FormSchemaIssue[] {
|
|
30
|
+
if (result.success || !result.error?.issues) return []
|
|
31
|
+
return result.error.issues
|
|
32
|
+
.filter((issue) => Array.isArray(issue.path) && issue.path.length > 0 && issue.message)
|
|
33
|
+
.map((issue) => ({
|
|
34
|
+
path: (issue.path as PropertyKey[]).map((item) => (typeof item === 'number' ? item : String(item))),
|
|
35
|
+
message: issue.message as string
|
|
36
|
+
}))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function zodAdapter(schema: ZodLikeSchema, options: ZodAdapterOptions = {}): FormSchema {
|
|
40
|
+
const formSchema: FormSchema = {
|
|
41
|
+
validate(model) {
|
|
42
|
+
return normalizeIssues(
|
|
43
|
+
schema.safeParse(
|
|
44
|
+
model,
|
|
45
|
+
// #ifndef H5
|
|
46
|
+
{ jitless: true }
|
|
47
|
+
// #endif
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (options.isRequired) {
|
|
53
|
+
formSchema.isRequired = options.isRequired
|
|
54
|
+
}
|
|
55
|
+
return formSchema
|
|
56
|
+
}
|