@wot-ui/ui 1.0.0 → 2.0.0-alpha.4
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 +63 -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 +2061 -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/index.ts +2 -0
- package/components/wd-form/types.ts +133 -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 +16 -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 +6 -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,165 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: weisheng
|
|
3
|
+
* @Date: 2024-03-15 11:36:12
|
|
4
|
+
* @LastEditTime: 2026-03-03 12:57:28
|
|
5
|
+
* @LastEditors: weisheng
|
|
6
|
+
* @Description: ImagePreview 图片预览
|
|
7
|
+
* @FilePath: /wot-ui/src/uni_modules/wot-ui/components/wd-image-preview/types.ts
|
|
8
|
+
* 记得注释
|
|
9
|
+
*/
|
|
10
|
+
import type { ComponentPublicInstance, ExtractPropTypes, PropType } from 'vue'
|
|
11
|
+
import { baseProps, makeBooleanProp, makeNumberProp, makeStringProp } from '../../common/props'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 关闭图标位置
|
|
15
|
+
*/
|
|
16
|
+
export type ImagePreviewCloseIconPosition = 'top-left' | 'top-right'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 函数式调用选项
|
|
20
|
+
*/
|
|
21
|
+
export type ImagePreviewOptions = {
|
|
22
|
+
/** 图片 URL 数组 */
|
|
23
|
+
images?: string[]
|
|
24
|
+
/** 起始位置索引 */
|
|
25
|
+
startPosition?: number
|
|
26
|
+
/** 是否显示页码 */
|
|
27
|
+
showIndex?: boolean
|
|
28
|
+
/** 是否循环播放 */
|
|
29
|
+
loop?: boolean
|
|
30
|
+
/** 是否显示关闭按钮 */
|
|
31
|
+
closeable?: boolean
|
|
32
|
+
/** 关闭图标名称 */
|
|
33
|
+
closeIcon?: string
|
|
34
|
+
/** 关闭图标位置 */
|
|
35
|
+
closeIconPosition?: ImagePreviewCloseIconPosition
|
|
36
|
+
/** 是否点击图片或遮罩时关闭 */
|
|
37
|
+
closeOnClick?: boolean
|
|
38
|
+
/** 开启长按图片显示识别小程序码菜单 */
|
|
39
|
+
showMenuByLongpress?: boolean
|
|
40
|
+
/** 是否显示 */
|
|
41
|
+
show?: boolean
|
|
42
|
+
/** zIndex 层级 */
|
|
43
|
+
zIndex?: number
|
|
44
|
+
/** 打开时的回调 */
|
|
45
|
+
onOpen?: () => void
|
|
46
|
+
/** 关闭时的回调 */
|
|
47
|
+
onClose?: () => void
|
|
48
|
+
/** 切换图片时的回调 */
|
|
49
|
+
onChange?: (index: number) => void
|
|
50
|
+
/** 长按图片时的回调 */
|
|
51
|
+
onLongPress?: (image: string) => void
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* ImagePreview 接口
|
|
56
|
+
*/
|
|
57
|
+
export interface ImagePreview {
|
|
58
|
+
/** 打开图片预览 */
|
|
59
|
+
previewImage: (options: ImagePreviewOptions | string[]) => void
|
|
60
|
+
/** 关闭图片预览 */
|
|
61
|
+
closeImagePreview: () => void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const imagePreviewProps = {
|
|
65
|
+
...baseProps,
|
|
66
|
+
/**
|
|
67
|
+
* 选择器
|
|
68
|
+
* 类型: string
|
|
69
|
+
* 默认值: ''
|
|
70
|
+
*/
|
|
71
|
+
selector: makeStringProp(''),
|
|
72
|
+
/**
|
|
73
|
+
* 图片 URL 数组
|
|
74
|
+
* 类型: string[]
|
|
75
|
+
* 默认值: []
|
|
76
|
+
*/
|
|
77
|
+
images: {
|
|
78
|
+
type: Array as PropType<string[]>,
|
|
79
|
+
default: () => []
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* 起始位置索引
|
|
83
|
+
* 类型: number
|
|
84
|
+
* 默认值: 0
|
|
85
|
+
*/
|
|
86
|
+
startPosition: makeNumberProp(0),
|
|
87
|
+
/**
|
|
88
|
+
* 是否显示页码
|
|
89
|
+
* 类型: boolean
|
|
90
|
+
* 默认值: true
|
|
91
|
+
*/
|
|
92
|
+
showIndex: makeBooleanProp(true),
|
|
93
|
+
/**
|
|
94
|
+
* 是否循环播放
|
|
95
|
+
* 类型: boolean
|
|
96
|
+
* 默认值: true
|
|
97
|
+
*/
|
|
98
|
+
loop: makeBooleanProp(true),
|
|
99
|
+
/**
|
|
100
|
+
* 是否显示关闭按钮
|
|
101
|
+
* 类型: boolean
|
|
102
|
+
* 默认值: true
|
|
103
|
+
*/
|
|
104
|
+
closeable: makeBooleanProp(true),
|
|
105
|
+
/**
|
|
106
|
+
* 关闭图标名称
|
|
107
|
+
* 类型: string
|
|
108
|
+
* 默认值: 'close'
|
|
109
|
+
*/
|
|
110
|
+
closeIcon: makeStringProp('close'),
|
|
111
|
+
/**
|
|
112
|
+
* 关闭图标位置
|
|
113
|
+
* 类型: string
|
|
114
|
+
* 可选值: 'top-left' | 'top-right'
|
|
115
|
+
* 默认值: 'top-right'
|
|
116
|
+
*/
|
|
117
|
+
closeIconPosition: makeStringProp<ImagePreviewCloseIconPosition>('top-right'),
|
|
118
|
+
/**
|
|
119
|
+
* 是否点击图片或遮罩时关闭
|
|
120
|
+
* 类型: boolean
|
|
121
|
+
* 默认值: true
|
|
122
|
+
*/
|
|
123
|
+
closeOnClick: makeBooleanProp(true),
|
|
124
|
+
/**
|
|
125
|
+
* 开启长按图片显示识别小程序码菜单
|
|
126
|
+
* 类型: boolean
|
|
127
|
+
* 默认值: true
|
|
128
|
+
*/
|
|
129
|
+
showMenuByLongpress: makeBooleanProp(true),
|
|
130
|
+
/**
|
|
131
|
+
* 打开时的回调
|
|
132
|
+
*/
|
|
133
|
+
onOpen: Function as PropType<() => void>,
|
|
134
|
+
/**
|
|
135
|
+
* 关闭时的回调
|
|
136
|
+
*/
|
|
137
|
+
onClose: Function as PropType<() => void>,
|
|
138
|
+
/**
|
|
139
|
+
* 切换图片时的回调
|
|
140
|
+
*/
|
|
141
|
+
onChange: Function as PropType<(index: number) => void>,
|
|
142
|
+
/**
|
|
143
|
+
* 长按图片时的回调
|
|
144
|
+
*/
|
|
145
|
+
onLongPress: Function as PropType<(image: string) => void>,
|
|
146
|
+
/**
|
|
147
|
+
* 层级
|
|
148
|
+
* 类型: number
|
|
149
|
+
* 默认值: 1000
|
|
150
|
+
*/
|
|
151
|
+
zIndex: makeNumberProp(1000)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export type ImagePreviewProps = ExtractPropTypes<typeof imagePreviewProps>
|
|
155
|
+
|
|
156
|
+
export type ImagePreviewExpose = {
|
|
157
|
+
/** 打开图片预览 */
|
|
158
|
+
open: (options?: ImagePreviewOptions | string[]) => void
|
|
159
|
+
/** 关闭图片预览 */
|
|
160
|
+
close: () => void
|
|
161
|
+
/** 切换到指定图片 */
|
|
162
|
+
setActive: (index: number) => void
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export type ImagePreviewInstance = ComponentPublicInstance<ImagePreviewExpose, ImagePreviewProps>
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<wd-overlay
|
|
3
|
+
:show="state.show"
|
|
4
|
+
:z-index="options.zIndex"
|
|
5
|
+
:lock-scroll="true"
|
|
6
|
+
:custom-class="`wd-image-preview ${customClass}`"
|
|
7
|
+
:custom-style="customStyle"
|
|
8
|
+
@enter="handleEnter"
|
|
9
|
+
@after-leave="handleAfterLeave"
|
|
10
|
+
>
|
|
11
|
+
<!-- 关闭按钮插槽 -->
|
|
12
|
+
<slot name="close" :close="close">
|
|
13
|
+
<view v-if="options.closeable" :class="`wd-image-preview__close wd-image-preview__close--${options.closeIconPosition}`" @click.stop="close">
|
|
14
|
+
<wd-icon custom-class="wd-image-preview__close-icon" :name="options.closeIcon" />
|
|
15
|
+
</view>
|
|
16
|
+
</slot>
|
|
17
|
+
|
|
18
|
+
<!-- 图片轮播 -->
|
|
19
|
+
<wd-swiper
|
|
20
|
+
v-if="state.visible"
|
|
21
|
+
custom-class="wd-image-preview__swiper"
|
|
22
|
+
:list="state.images"
|
|
23
|
+
v-model:current="state.currentIndex"
|
|
24
|
+
:autoplay="false"
|
|
25
|
+
:loop="options.loop"
|
|
26
|
+
:show-menu-by-longpress="options.showMenuByLongpress"
|
|
27
|
+
image-mode="aspectFit"
|
|
28
|
+
height="100%"
|
|
29
|
+
@click="handleImageClick"
|
|
30
|
+
@change="handleSwiperChange"
|
|
31
|
+
>
|
|
32
|
+
<template #indicator="{ total, current }">
|
|
33
|
+
<!-- 指示器插槽 -->
|
|
34
|
+
<slot name="indicator" :total="total" :current="current">
|
|
35
|
+
<view v-if="options.showIndex && total > 1" class="wd-image-preview__index">{{ current + 1 }} / {{ total }}</view>
|
|
36
|
+
</slot>
|
|
37
|
+
</template>
|
|
38
|
+
</wd-swiper>
|
|
39
|
+
|
|
40
|
+
<!-- 默认插槽(用于自定义底部内容等) -->
|
|
41
|
+
<slot :current="state.currentIndex" :total="state.images.length" :images="state.images" :close="close"></slot>
|
|
42
|
+
</wd-overlay>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script lang="ts">
|
|
46
|
+
export default {
|
|
47
|
+
name: 'wd-image-preview',
|
|
48
|
+
options: {
|
|
49
|
+
addGlobalClass: true,
|
|
50
|
+
// #ifndef MP-TOUTIAO
|
|
51
|
+
virtualHost: true,
|
|
52
|
+
// #endif
|
|
53
|
+
styleIsolation: 'shared'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<script lang="ts" setup>
|
|
59
|
+
import { computed, inject, nextTick, reactive, ref, watch } from 'vue'
|
|
60
|
+
import wdIcon from '../wd-icon/wd-icon.vue'
|
|
61
|
+
import wdOverlay from '../wd-overlay/wd-overlay.vue'
|
|
62
|
+
import wdSwiper from '../wd-swiper/wd-swiper.vue'
|
|
63
|
+
import { imagePreviewProps, type ImagePreviewExpose, type ImagePreviewOptions } from './types'
|
|
64
|
+
import { defaultOptions, getImagePreviewOptionKey, getImageUrl } from './index'
|
|
65
|
+
import { isDef, isFunction } from '../../common/util'
|
|
66
|
+
import { type SwiperItem } from '../wd-swiper/types'
|
|
67
|
+
|
|
68
|
+
const props = defineProps(imagePreviewProps)
|
|
69
|
+
|
|
70
|
+
const emit = defineEmits<{
|
|
71
|
+
open: []
|
|
72
|
+
close: []
|
|
73
|
+
click: [{ index: number }]
|
|
74
|
+
change: [{ index: number }]
|
|
75
|
+
'long-press': [{ image: string }]
|
|
76
|
+
}>()
|
|
77
|
+
|
|
78
|
+
// 组件状态
|
|
79
|
+
const state = reactive({
|
|
80
|
+
show: false,
|
|
81
|
+
visible: false,
|
|
82
|
+
currentIndex: 0,
|
|
83
|
+
images: [] as string[]
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
// 获取注入的选项
|
|
87
|
+
const imagePreviewOptionKey = getImagePreviewOptionKey(props.selector)
|
|
88
|
+
const imagePreviewOption = inject(imagePreviewOptionKey, ref<ImagePreviewOptions>(defaultOptions))
|
|
89
|
+
|
|
90
|
+
// 合并后的选项
|
|
91
|
+
const options = computed(() => ({
|
|
92
|
+
showIndex: isDef(imagePreviewOption.value.showIndex) ? imagePreviewOption.value.showIndex : props.showIndex,
|
|
93
|
+
loop: isDef(imagePreviewOption.value.loop) ? imagePreviewOption.value.loop : props.loop,
|
|
94
|
+
closeable: isDef(imagePreviewOption.value.closeable) ? imagePreviewOption.value.closeable : props.closeable,
|
|
95
|
+
closeIcon: isDef(imagePreviewOption.value.closeIcon) ? imagePreviewOption.value.closeIcon : props.closeIcon,
|
|
96
|
+
closeIconPosition: isDef(imagePreviewOption.value.closeIconPosition) ? imagePreviewOption.value.closeIconPosition : props.closeIconPosition,
|
|
97
|
+
closeOnClick: isDef(imagePreviewOption.value.closeOnClick) ? imagePreviewOption.value.closeOnClick : props.closeOnClick,
|
|
98
|
+
showMenuByLongpress: isDef(imagePreviewOption.value.showMenuByLongpress) ? imagePreviewOption.value.showMenuByLongpress : props.showMenuByLongpress,
|
|
99
|
+
zIndex: isDef(imagePreviewOption.value.zIndex) ? imagePreviewOption.value.zIndex! : props.zIndex,
|
|
100
|
+
onOpen: imagePreviewOption.value.onOpen || props.onOpen || null,
|
|
101
|
+
onClose: imagePreviewOption.value.onClose || props.onClose || null,
|
|
102
|
+
onChange: imagePreviewOption.value.onChange || props.onChange || null,
|
|
103
|
+
onLongPress: imagePreviewOption.value.onLongPress || props.onLongPress || null
|
|
104
|
+
}))
|
|
105
|
+
|
|
106
|
+
// 监听选项变化
|
|
107
|
+
watch(
|
|
108
|
+
() => imagePreviewOption.value,
|
|
109
|
+
(newVal: ImagePreviewOptions) => {
|
|
110
|
+
reset(newVal)
|
|
111
|
+
},
|
|
112
|
+
{ deep: true, immediate: true }
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
// 监听 show 变化,触发事件
|
|
116
|
+
watch(
|
|
117
|
+
() => state.show,
|
|
118
|
+
(newVal, oldVal) => {
|
|
119
|
+
if (newVal && !oldVal) {
|
|
120
|
+
emit('open')
|
|
121
|
+
if (isFunction(options.value.onOpen)) {
|
|
122
|
+
options.value.onOpen()
|
|
123
|
+
}
|
|
124
|
+
} else if (!newVal && oldVal) {
|
|
125
|
+
emit('close')
|
|
126
|
+
if (isFunction(options.value.onClose)) {
|
|
127
|
+
options.value.onClose()
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 重置选项
|
|
135
|
+
*/
|
|
136
|
+
function reset(option: ImagePreviewOptions) {
|
|
137
|
+
state.show = isDef(option.show) ? option.show! : false
|
|
138
|
+
|
|
139
|
+
if (state.show) {
|
|
140
|
+
state.images = isDef(option.images) ? option.images! : props.images || []
|
|
141
|
+
state.currentIndex = isDef(option.startPosition) ? option.startPosition! : props.startPosition
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 进入动画完成
|
|
147
|
+
*/
|
|
148
|
+
function handleEnter() {
|
|
149
|
+
state.visible = true
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 离开动画完成
|
|
154
|
+
*/
|
|
155
|
+
function handleAfterLeave() {
|
|
156
|
+
state.visible = false
|
|
157
|
+
state.images = []
|
|
158
|
+
state.currentIndex = 0
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 打开预览
|
|
163
|
+
*/
|
|
164
|
+
function open(opts?: ImagePreviewOptions | string[]) {
|
|
165
|
+
if (opts) {
|
|
166
|
+
if (Array.isArray(opts)) {
|
|
167
|
+
state.images = opts
|
|
168
|
+
} else {
|
|
169
|
+
state.images = isDef(opts.images) ? opts.images! : props.images || []
|
|
170
|
+
state.currentIndex = isDef(opts.startPosition) ? opts.startPosition! : props.startPosition
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
state.show = true
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 关闭预览
|
|
178
|
+
*/
|
|
179
|
+
function close() {
|
|
180
|
+
state.show = false
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 设置当前图片
|
|
185
|
+
*/
|
|
186
|
+
function setActive(index: number) {
|
|
187
|
+
if (index >= 0 && index < state.images.length) {
|
|
188
|
+
state.currentIndex = index
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* 处理轮播切换
|
|
194
|
+
*/
|
|
195
|
+
function handleSwiperChange({ current }: { current: number }) {
|
|
196
|
+
state.currentIndex = current
|
|
197
|
+
emit('change', { index: current })
|
|
198
|
+
if (isFunction(options.value.onChange)) {
|
|
199
|
+
options.value.onChange(current)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 处理图片点击
|
|
205
|
+
*/
|
|
206
|
+
function handleImageClick({ index }: { index: number }) {
|
|
207
|
+
emit('click', { index })
|
|
208
|
+
if (options.value.closeOnClick) {
|
|
209
|
+
close()
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 处理长按
|
|
215
|
+
*/
|
|
216
|
+
function handleLongPress(image: string | SwiperItem) {
|
|
217
|
+
const url = getImageUrl(image)
|
|
218
|
+
emit('long-press', { image: url })
|
|
219
|
+
if (isFunction(options.value.onLongPress)) {
|
|
220
|
+
options.value.onLongPress(url)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
defineExpose<ImagePreviewExpose>({
|
|
225
|
+
open,
|
|
226
|
+
close,
|
|
227
|
+
setActive
|
|
228
|
+
})
|
|
229
|
+
</script>
|
|
230
|
+
|
|
231
|
+
<style lang="scss">
|
|
232
|
+
@use './index.scss';
|
|
233
|
+
</style>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
@use '../../styles/mixin/mixin.scss' as *;
|
|
2
|
+
@use '../../styles/variable.scss' as *;
|
|
3
|
+
|
|
4
|
+
// 圆形模式圆角
|
|
5
|
+
$img-border-radius: var(--wot-img-border-radius, $radius-radius-full) !default;
|
|
6
|
+
// 加载态文字颜色
|
|
7
|
+
$img-loading-color: var(--wot-img-loading-color, $text-placeholder) !default;
|
|
8
|
+
// 加载态背景色
|
|
9
|
+
$img-loading-bg: var(--wot-img-loading-bg, $filled-bottom) !default;
|
|
10
|
+
// 加载态文字字号
|
|
11
|
+
$img-loading-font-size: var(--wot-img-loading-font-size, $typography-body-size-main) !default;
|
|
12
|
+
// 加载态图标颜色
|
|
13
|
+
$img-loading-icon-color: var(--wot-img-loading-icon-color, $text-placeholder) !default;
|
|
14
|
+
// 加载态图标尺寸
|
|
15
|
+
$img-loading-icon-size: var(--wot-img-loading-icon-size, $n-32) !default;
|
|
16
|
+
// 失败态文字颜色
|
|
17
|
+
$img-error-color: var(--wot-img-error-color, $text-placeholder) !default;
|
|
18
|
+
// 失败态背景色
|
|
19
|
+
$img-error-bg: var(--wot-img-error-bg, $filled-bottom) !default;
|
|
20
|
+
// 失败态文字字号
|
|
21
|
+
$img-error-font-size: var(--wot-img-error-font-size, $typography-body-size-main) !default;
|
|
22
|
+
// 失败态图标颜色
|
|
23
|
+
$img-error-icon-color: var(--wot-img-error-icon-color, $text-placeholder) !default;
|
|
24
|
+
// 失败态图标尺寸
|
|
25
|
+
$img-error-icon-size: var(--wot-img-error-icon-size, $n-32) !default;
|
|
26
|
+
|
|
27
|
+
@include b(img) {
|
|
28
|
+
position: relative;
|
|
29
|
+
display: inline-block;
|
|
30
|
+
|
|
31
|
+
@include e(image) {
|
|
32
|
+
display: block;
|
|
33
|
+
width: 100%;
|
|
34
|
+
height: 100%;
|
|
35
|
+
box-sizing: border-box;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@include e(loading) {
|
|
39
|
+
position: absolute;
|
|
40
|
+
top: 0;
|
|
41
|
+
left: 0;
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
align-items: center;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
width: 100%;
|
|
47
|
+
height: 100%;
|
|
48
|
+
color: $img-loading-color;
|
|
49
|
+
font-size: $img-loading-font-size;
|
|
50
|
+
background-color: $img-loading-bg;
|
|
51
|
+
|
|
52
|
+
@include edeep(loading-icon) {
|
|
53
|
+
color: $img-loading-icon-color;
|
|
54
|
+
font-size: $img-loading-icon-size;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@include e(error) {
|
|
59
|
+
position: absolute;
|
|
60
|
+
top: 0;
|
|
61
|
+
left: 0;
|
|
62
|
+
display: flex;
|
|
63
|
+
flex-direction: column;
|
|
64
|
+
align-items: center;
|
|
65
|
+
justify-content: center;
|
|
66
|
+
width: 100%;
|
|
67
|
+
height: 100%;
|
|
68
|
+
color: $img-error-color;
|
|
69
|
+
font-size: $img-error-font-size;
|
|
70
|
+
background-color: $img-error-bg;
|
|
71
|
+
|
|
72
|
+
@include edeep(error-icon) {
|
|
73
|
+
color: $img-error-icon-color;
|
|
74
|
+
font-size: $img-error-icon-size;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@include when(round) {
|
|
79
|
+
overflow: hidden;
|
|
80
|
+
border-radius: $img-border-radius;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type ExtractPropTypes } from 'vue'
|
|
2
|
+
import { baseProps, makeBooleanProp, makeStringProp, numericProp } from '../../common/props'
|
|
3
|
+
export type ImageMode =
|
|
4
|
+
| 'scaleToFill'
|
|
5
|
+
| 'aspectFit'
|
|
6
|
+
| 'aspectFill'
|
|
7
|
+
| 'widthFix'
|
|
8
|
+
| 'heightFix'
|
|
9
|
+
| 'top'
|
|
10
|
+
| 'bottom'
|
|
11
|
+
| 'center'
|
|
12
|
+
| 'left'
|
|
13
|
+
| 'right'
|
|
14
|
+
| 'top left'
|
|
15
|
+
| 'top right'
|
|
16
|
+
| 'bottom left'
|
|
17
|
+
| 'bottom right'
|
|
18
|
+
|
|
19
|
+
export const imgProps = {
|
|
20
|
+
...baseProps,
|
|
21
|
+
/**
|
|
22
|
+
* 图片自定义类名
|
|
23
|
+
* 类型: string
|
|
24
|
+
*/
|
|
25
|
+
customImage: makeStringProp(''),
|
|
26
|
+
/**
|
|
27
|
+
* 图片链接
|
|
28
|
+
* 类型: string
|
|
29
|
+
*/
|
|
30
|
+
src: String,
|
|
31
|
+
/**
|
|
32
|
+
* 预览图片链接
|
|
33
|
+
* 类型: string
|
|
34
|
+
*/
|
|
35
|
+
previewSrc: String,
|
|
36
|
+
/**
|
|
37
|
+
* 是否显示为圆形
|
|
38
|
+
* 类型: boolean
|
|
39
|
+
* 默认值: false
|
|
40
|
+
*/
|
|
41
|
+
round: makeBooleanProp(false),
|
|
42
|
+
/**
|
|
43
|
+
* 填充模式
|
|
44
|
+
* 类型: string
|
|
45
|
+
* 可选值: 'scaleToFill' | 'aspectFit' | 'aspectFill' | 'widthFix' | 'heightFix' | 'top' | 'bottom' | 'center' | 'left' | 'right' | 'top left' | 'top right' | 'bottom left' | 'bottom right'
|
|
46
|
+
* 默认值: 'scaleToFill'
|
|
47
|
+
*/
|
|
48
|
+
mode: makeStringProp<ImageMode>('scaleToFill'),
|
|
49
|
+
/**
|
|
50
|
+
* 是否懒加载
|
|
51
|
+
* 类型: boolean
|
|
52
|
+
* 默认值: false
|
|
53
|
+
*/
|
|
54
|
+
lazyLoad: makeBooleanProp(false),
|
|
55
|
+
/**
|
|
56
|
+
* 宽度,默认单位为px
|
|
57
|
+
* 类型: string | number
|
|
58
|
+
*/
|
|
59
|
+
width: numericProp,
|
|
60
|
+
/**
|
|
61
|
+
* 高度,默认单位为px
|
|
62
|
+
* 类型: string | number
|
|
63
|
+
*/
|
|
64
|
+
height: numericProp,
|
|
65
|
+
/**
|
|
66
|
+
* 圆角大小,默认单位为px
|
|
67
|
+
* 类型: string | number
|
|
68
|
+
*/
|
|
69
|
+
radius: numericProp,
|
|
70
|
+
/**
|
|
71
|
+
* 是否允许预览
|
|
72
|
+
* 类型: boolean
|
|
73
|
+
* 默认值: false
|
|
74
|
+
*/
|
|
75
|
+
enablePreview: makeBooleanProp(false),
|
|
76
|
+
/**
|
|
77
|
+
* 开启长按图片显示识别小程序码菜单,仅在微信小程序平台有效
|
|
78
|
+
* 类型: boolean
|
|
79
|
+
* 默认值: false
|
|
80
|
+
*/
|
|
81
|
+
showMenuByLongpress: makeBooleanProp(false),
|
|
82
|
+
/**
|
|
83
|
+
* 是否展示加载中
|
|
84
|
+
* 类型: boolean
|
|
85
|
+
* 默认值: true
|
|
86
|
+
*/
|
|
87
|
+
showLoading: makeBooleanProp(true),
|
|
88
|
+
/**
|
|
89
|
+
* 是否展示错误
|
|
90
|
+
* 类型: boolean
|
|
91
|
+
* 默认值: true
|
|
92
|
+
*/
|
|
93
|
+
showError: makeBooleanProp(true)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type ImgProps = ExtractPropTypes<typeof imgProps>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="rootClass" @click="handleClick" :style="rootStyle">
|
|
3
|
+
<image
|
|
4
|
+
v-if="status !== 'error'"
|
|
5
|
+
:class="`wd-img__image ${customImage}`"
|
|
6
|
+
:src="src"
|
|
7
|
+
:mode="mode"
|
|
8
|
+
:show-menu-by-longpress="showMenuByLongpress"
|
|
9
|
+
:lazy-load="lazyLoad"
|
|
10
|
+
@load="handleLoad"
|
|
11
|
+
@error="handleError"
|
|
12
|
+
/>
|
|
13
|
+
<view v-if="status === 'loading' && showLoading" class="wd-img__loading">
|
|
14
|
+
<slot name="loading">
|
|
15
|
+
<wd-icon name="image" custom-class="wd-img__loading-icon" />
|
|
16
|
+
</slot>
|
|
17
|
+
</view>
|
|
18
|
+
<view v-if="status === 'error' && showError" class="wd-img__error">
|
|
19
|
+
<slot name="error">
|
|
20
|
+
<wd-icon name="image-failloading" custom-class="wd-img__error-icon" />
|
|
21
|
+
</slot>
|
|
22
|
+
</view>
|
|
23
|
+
</view>
|
|
24
|
+
</template>
|
|
25
|
+
<script lang="ts">
|
|
26
|
+
export default {
|
|
27
|
+
name: 'wd-img',
|
|
28
|
+
options: {
|
|
29
|
+
// #ifndef MP-TOUTIAO
|
|
30
|
+
virtualHost: true,
|
|
31
|
+
// #endif
|
|
32
|
+
addGlobalClass: true,
|
|
33
|
+
styleIsolation: 'shared'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<script lang="ts" setup>
|
|
39
|
+
import { computed, ref } from 'vue'
|
|
40
|
+
import { addUnit, isDef, objToStyle } from '../../common/util'
|
|
41
|
+
import { imgProps } from './types'
|
|
42
|
+
|
|
43
|
+
const props = defineProps(imgProps)
|
|
44
|
+
const emit = defineEmits<{
|
|
45
|
+
(e: 'error', event: Event): void
|
|
46
|
+
(e: 'click', event: MouseEvent): void
|
|
47
|
+
(e: 'load', event: Event): void
|
|
48
|
+
}>()
|
|
49
|
+
|
|
50
|
+
const rootStyle = computed(() => {
|
|
51
|
+
const style: Record<string, string | number> = {}
|
|
52
|
+
if (isDef(props.height)) {
|
|
53
|
+
style['height'] = addUnit(props.height)
|
|
54
|
+
}
|
|
55
|
+
if (isDef(props.width)) {
|
|
56
|
+
style['width'] = addUnit(props.width)
|
|
57
|
+
}
|
|
58
|
+
if (isDef(props.radius)) {
|
|
59
|
+
style['border-radius'] = addUnit(props.radius)
|
|
60
|
+
style['overflow'] = 'hidden'
|
|
61
|
+
}
|
|
62
|
+
return `${objToStyle(style)}${props.customStyle}`
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const rootClass = computed(() => {
|
|
66
|
+
return `wd-img ${props.round ? 'is-round' : ''} ${props.customClass}`
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const status = ref<'loading' | 'error' | 'success'>('loading')
|
|
70
|
+
|
|
71
|
+
function handleError(event: any) {
|
|
72
|
+
status.value = 'error'
|
|
73
|
+
emit('error', event)
|
|
74
|
+
}
|
|
75
|
+
function handleClick(event: MouseEvent) {
|
|
76
|
+
if (props.enablePreview && props.src && status.value == 'success') {
|
|
77
|
+
uni.previewImage({
|
|
78
|
+
urls: [props.previewSrc || props.src]
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
emit('click', event)
|
|
82
|
+
}
|
|
83
|
+
function handleLoad(event: any) {
|
|
84
|
+
status.value = 'success'
|
|
85
|
+
emit('load', event)
|
|
86
|
+
}
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<style lang="scss">
|
|
90
|
+
@use './index.scss';
|
|
91
|
+
</style>
|