@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,664 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="wd-signature">
|
|
3
|
+
<view class="wd-signature__content">
|
|
4
|
+
<!-- #ifdef MP-WEIXIN -->
|
|
5
|
+
<canvas
|
|
6
|
+
class="wd-signature__content-canvas"
|
|
7
|
+
:style="canvasStyle"
|
|
8
|
+
:width="canvasState.canvasWidth"
|
|
9
|
+
:height="canvasState.canvasHeight"
|
|
10
|
+
:canvas-id="canvasId"
|
|
11
|
+
:id="canvasId"
|
|
12
|
+
:disable-scroll="disableScroll"
|
|
13
|
+
@touchstart="startDrawing"
|
|
14
|
+
@touchend="stopDrawing"
|
|
15
|
+
@touchmove="draw"
|
|
16
|
+
type="2d"
|
|
17
|
+
/>
|
|
18
|
+
<!-- #endif -->
|
|
19
|
+
<!-- #ifndef MP-WEIXIN -->
|
|
20
|
+
<canvas
|
|
21
|
+
class="wd-signature__content-canvas"
|
|
22
|
+
:canvas-id="canvasId"
|
|
23
|
+
:style="canvasStyle"
|
|
24
|
+
:width="canvasState.canvasWidth"
|
|
25
|
+
:height="canvasState.canvasHeight"
|
|
26
|
+
:id="canvasId"
|
|
27
|
+
:disable-scroll="disableScroll"
|
|
28
|
+
@touchstart="startDrawing"
|
|
29
|
+
@touchend="stopDrawing"
|
|
30
|
+
@touchmove="draw"
|
|
31
|
+
/>
|
|
32
|
+
<!-- #endif -->
|
|
33
|
+
</view>
|
|
34
|
+
<view class="wd-signature__footer">
|
|
35
|
+
<slot
|
|
36
|
+
name="footer"
|
|
37
|
+
:clear="clear"
|
|
38
|
+
:confirm="confirmSignature"
|
|
39
|
+
:current-step="currentStep"
|
|
40
|
+
:revoke="revoke"
|
|
41
|
+
:restore="restore"
|
|
42
|
+
:can-undo="lines.length > 0"
|
|
43
|
+
:can-redo="redoLines.length > 0"
|
|
44
|
+
:history-list="lines"
|
|
45
|
+
>
|
|
46
|
+
<block v-if="enableHistory">
|
|
47
|
+
<wd-button custom-class="wd-signature__button" size="small" plain @click="revoke" :disabled="lines.length <= 0">
|
|
48
|
+
{{ revokeText || translate('revokeText') }}
|
|
49
|
+
</wd-button>
|
|
50
|
+
<wd-button custom-class="wd-signature__button" size="small" plain @click="restore" :disabled="redoLines.length <= 0">
|
|
51
|
+
{{ restoreText || translate('restoreText') }}
|
|
52
|
+
</wd-button>
|
|
53
|
+
</block>
|
|
54
|
+
<wd-button custom-class="wd-signature__button" size="small" plain @click="clear">{{ clearText || translate('clearText') }}</wd-button>
|
|
55
|
+
<wd-button custom-class="wd-signature__button" size="small" @click="confirmSignature">
|
|
56
|
+
{{ confirmText || translate('confirmText') }}
|
|
57
|
+
</wd-button>
|
|
58
|
+
</slot>
|
|
59
|
+
</view>
|
|
60
|
+
</view>
|
|
61
|
+
</template>
|
|
62
|
+
<script lang="ts">
|
|
63
|
+
export default {
|
|
64
|
+
name: 'wd-signature',
|
|
65
|
+
options: {
|
|
66
|
+
addGlobalClass: true,
|
|
67
|
+
// #ifndef MP-TOUTIAO
|
|
68
|
+
virtualHost: true,
|
|
69
|
+
// #endif
|
|
70
|
+
styleIsolation: 'shared'
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
</script>
|
|
74
|
+
<script lang="ts" setup>
|
|
75
|
+
import { computed, getCurrentInstance, onBeforeMount, onMounted, reactive, ref, watch, type CSSProperties } from 'vue'
|
|
76
|
+
import { addUnit, getRect, getSystemInfo, isDef, objToStyle, uuid } from '../../common/util'
|
|
77
|
+
import { signatureProps, type SignatureExpose, type SignatureResult, type Point, type Line } from './types'
|
|
78
|
+
import { useTranslate } from '../../composables/useTranslate'
|
|
79
|
+
// #ifdef MP-WEIXIN
|
|
80
|
+
import { canvas2dAdapter } from '../../common/canvasHelper'
|
|
81
|
+
// #endif
|
|
82
|
+
|
|
83
|
+
const props = defineProps(signatureProps)
|
|
84
|
+
const emit = defineEmits(['start', 'end', 'signing', 'confirm', 'clear'])
|
|
85
|
+
const { translate } = useTranslate('signature')
|
|
86
|
+
const { proxy } = getCurrentInstance() as any
|
|
87
|
+
const canvasId = ref<string>(`signature${uuid()}`) // canvas 组件的唯一标识符
|
|
88
|
+
let canvas: any = null // canvas 对象,微信小程序生成图片必须传入
|
|
89
|
+
const drawing = ref<boolean>(false) // 是否正在绘制
|
|
90
|
+
const pixelRatio = ref<number>(1) // 像素比
|
|
91
|
+
|
|
92
|
+
const canvasState = reactive({
|
|
93
|
+
canvasWidth: 0,
|
|
94
|
+
canvasHeight: 0,
|
|
95
|
+
ctx: null as UniApp.CanvasContext | null // canvas 上下文
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 判断颜色是否为透明色
|
|
100
|
+
* @param {string} color 颜色值(支持 rgba/hsla/hex/transparent)
|
|
101
|
+
* @returns {boolean} 是否为透明
|
|
102
|
+
*/
|
|
103
|
+
function isTransparentColor(color: string | undefined): boolean {
|
|
104
|
+
if (!color) return true
|
|
105
|
+
const transparentKeywords = ['transparent', '#0000', '#00000000']
|
|
106
|
+
|
|
107
|
+
// 标准透明关键字
|
|
108
|
+
if (transparentKeywords.includes(color.toLowerCase())) {
|
|
109
|
+
return true
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 匹配 rgba(r, g, b, a)
|
|
113
|
+
const rgbaMatch = color.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*(\d*\.?\d+))?\)$/i)
|
|
114
|
+
if (rgbaMatch) {
|
|
115
|
+
const alpha = rgbaMatch[4] ? parseFloat(rgbaMatch[4]) : 1
|
|
116
|
+
return alpha === 0
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 匹配 hsla(h, s, l, a)
|
|
120
|
+
const hslaMatch = color.match(/^hsla?\(\s*(\d+)(?:deg)?\s*,\s*(\d+)%\s*,\s*(\d+)%(?:\s*,\s*(\d*\.?\d+))?\)$/i)
|
|
121
|
+
if (hslaMatch) {
|
|
122
|
+
const alpha = hslaMatch[4] ? parseFloat(hslaMatch[4]) : 1
|
|
123
|
+
return alpha === 0
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 匹配 #RRGGBBAA 或 #RGBA
|
|
127
|
+
const hexMatch = color.match(/^#([0-9a-f]{8}|[0-9a-f]{4})$/i)
|
|
128
|
+
if (hexMatch) {
|
|
129
|
+
const hex = hexMatch[1]
|
|
130
|
+
const alphaHex = hex.length === 8 ? hex.slice(6, 8) : hex.slice(3, 4).repeat(2)
|
|
131
|
+
const alpha = parseInt(alphaHex, 16)
|
|
132
|
+
return alpha === 0
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return false
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
watch(
|
|
139
|
+
() => props.penColor,
|
|
140
|
+
() => {
|
|
141
|
+
setLine()
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
watch(
|
|
146
|
+
() => props.lineWidth,
|
|
147
|
+
() => {
|
|
148
|
+
setLine()
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
const canvasStyle = computed(() => {
|
|
153
|
+
const style: CSSProperties = {}
|
|
154
|
+
if (isDef(props.width)) {
|
|
155
|
+
style.width = addUnit(props.width)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (isDef(props.height)) {
|
|
159
|
+
style.height = addUnit(props.height)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return `${objToStyle(style)}`
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const disableScroll = computed(() => props.disableScroll)
|
|
166
|
+
const enableHistory = computed(() => props.enableHistory)
|
|
167
|
+
|
|
168
|
+
const lines = ref<Line[]>([]) // 保存所有线条
|
|
169
|
+
const redoLines = ref<Line[]>([]) // 保存撤销的线条
|
|
170
|
+
const currentLine = ref<Line>() // 当前正在绘制的线
|
|
171
|
+
const currentStep = ref(0) // 当前步骤
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 计算笔画宽度 (压感模式)
|
|
175
|
+
* @param {number} speed 当前绘制速度
|
|
176
|
+
* @returns {number} 转换后的笔触宽度
|
|
177
|
+
*/
|
|
178
|
+
function calculateLineWidth(speed: number): number {
|
|
179
|
+
if (!props.pressure) return props.lineWidth
|
|
180
|
+
|
|
181
|
+
const minSpeed = props.minSpeed || 1.5
|
|
182
|
+
const limitedSpeed = Math.min(minSpeed * 10, Math.max(minSpeed, speed))
|
|
183
|
+
const addWidth = ((props.maxWidth - props.minWidth) * (limitedSpeed - minSpeed)) / minSpeed
|
|
184
|
+
const lineWidth = Math.max(props.maxWidth - addWidth, props.minWidth)
|
|
185
|
+
return Math.min(lineWidth, props.maxWidth)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 获取默认笔画宽度
|
|
190
|
+
*/
|
|
191
|
+
const getDefaultLineWidth = () => {
|
|
192
|
+
if (props.pressure) {
|
|
193
|
+
// 在压感模式下,使用最大和最小宽度的平均值作为默认值
|
|
194
|
+
return (props.maxWidth + props.minWidth) / 2
|
|
195
|
+
}
|
|
196
|
+
return props.lineWidth
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 触摸开始绘制
|
|
201
|
+
* @param event 触摸事件
|
|
202
|
+
*/
|
|
203
|
+
const startDrawing = (e: any) => {
|
|
204
|
+
e.preventDefault()
|
|
205
|
+
drawing.value = true
|
|
206
|
+
setLine()
|
|
207
|
+
emit('start', e)
|
|
208
|
+
|
|
209
|
+
// 创建新线条,同时保存当前的所有绘制参数
|
|
210
|
+
const { x, y } = e.touches[0]
|
|
211
|
+
currentLine.value = {
|
|
212
|
+
points: [
|
|
213
|
+
{
|
|
214
|
+
x,
|
|
215
|
+
y,
|
|
216
|
+
t: Date.now() // 使用 t 记录时间戳,用于速度计算
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
color: props.penColor,
|
|
220
|
+
width: getDefaultLineWidth(),
|
|
221
|
+
backgroundColor: props.backgroundColor,
|
|
222
|
+
isPressure: props.pressure // 添加笔锋模式标记
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// 清空重做记录
|
|
226
|
+
redoLines.value = []
|
|
227
|
+
draw(e)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 结束绘制
|
|
232
|
+
* @param {TouchEvent} e 触摸事件
|
|
233
|
+
*/
|
|
234
|
+
const stopDrawing = (e: TouchEvent) => {
|
|
235
|
+
e.preventDefault()
|
|
236
|
+
drawing.value = false
|
|
237
|
+
if (currentLine.value) {
|
|
238
|
+
// 保存完整的线条信息,包括所有点的参数
|
|
239
|
+
lines.value.push({
|
|
240
|
+
...currentLine.value,
|
|
241
|
+
points: currentLine.value.points.map((point) => ({
|
|
242
|
+
...point,
|
|
243
|
+
t: point.t,
|
|
244
|
+
speed: point.speed,
|
|
245
|
+
distance: point.distance,
|
|
246
|
+
lineWidth: point.lineWidth,
|
|
247
|
+
lastX1: point.lastX1,
|
|
248
|
+
lastY1: point.lastY1,
|
|
249
|
+
lastX2: point.lastX2,
|
|
250
|
+
lastY2: point.lastY2,
|
|
251
|
+
isFirstPoint: point.isFirstPoint
|
|
252
|
+
}))
|
|
253
|
+
})
|
|
254
|
+
currentStep.value = lines.value.length
|
|
255
|
+
}
|
|
256
|
+
currentLine.value = undefined
|
|
257
|
+
const { ctx } = canvasState
|
|
258
|
+
if (ctx) ctx.beginPath()
|
|
259
|
+
emit('end', e)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* 初始化 canvas
|
|
264
|
+
* @param forceUpdate 是否强制更新
|
|
265
|
+
*/
|
|
266
|
+
const initCanvas = (forceUpdate: boolean = false) => {
|
|
267
|
+
// 如果不是强制更新,且已经初始化过 canvas,则不再重复初始化
|
|
268
|
+
if (!forceUpdate && canvasState.canvasHeight && canvasState.canvasWidth) {
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
getContext().then(() => {
|
|
272
|
+
const { ctx } = canvasState
|
|
273
|
+
if (ctx && isDef(props.backgroundColor)) {
|
|
274
|
+
ctx.setFillStyle(props.backgroundColor)
|
|
275
|
+
ctx.fillRect(0, 0, canvasState.canvasWidth, canvasState.canvasHeight)
|
|
276
|
+
ctx.draw()
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* 清除画布内容,清空历史记录
|
|
283
|
+
*/
|
|
284
|
+
const clear = () => {
|
|
285
|
+
lines.value = []
|
|
286
|
+
redoLines.value = []
|
|
287
|
+
currentStep.value = 0
|
|
288
|
+
clearCanvas()
|
|
289
|
+
emit('clear')
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* 确认签名并导出图片
|
|
294
|
+
*/
|
|
295
|
+
const confirmSignature = () => {
|
|
296
|
+
canvasToImage()
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
//canvas划线
|
|
300
|
+
const draw = (e: any) => {
|
|
301
|
+
e.preventDefault()
|
|
302
|
+
const { ctx } = canvasState
|
|
303
|
+
|
|
304
|
+
if (!drawing.value || props.disabled || !ctx) return
|
|
305
|
+
const { x, y } = e.touches[0]
|
|
306
|
+
|
|
307
|
+
const point: Point = {
|
|
308
|
+
x,
|
|
309
|
+
y,
|
|
310
|
+
t: Date.now()
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (currentLine.value) {
|
|
314
|
+
const points = currentLine.value.points
|
|
315
|
+
const prePoint = points[points.length - 1]
|
|
316
|
+
|
|
317
|
+
if (prePoint.t === point.t || (prePoint.x === x && prePoint.y === y)) {
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// 计算点的速度和距离
|
|
322
|
+
point.distance = Math.sqrt(Math.pow(point.x - prePoint.x, 2) + Math.pow(point.y - prePoint.y, 2))
|
|
323
|
+
point.speed = point.distance / (point.t - prePoint.t || 0.1)
|
|
324
|
+
|
|
325
|
+
if (props.pressure) {
|
|
326
|
+
point.lineWidth = calculateLineWidth(point.speed)
|
|
327
|
+
// 处理线宽变化率限制
|
|
328
|
+
if (points.length >= 2) {
|
|
329
|
+
const prePoint2 = points[points.length - 2]
|
|
330
|
+
if (prePoint2.lineWidth && prePoint.lineWidth) {
|
|
331
|
+
const rate = (point.lineWidth - prePoint.lineWidth) / prePoint.lineWidth
|
|
332
|
+
const maxRate = 0.2 // 最大变化率20%
|
|
333
|
+
if (Math.abs(rate) > maxRate) {
|
|
334
|
+
const per = rate > 0 ? maxRate : -maxRate
|
|
335
|
+
point.lineWidth = prePoint.lineWidth * (1 + per)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
points.push(point)
|
|
342
|
+
|
|
343
|
+
// 非笔锋模式直接使用线段连接
|
|
344
|
+
if (!props.pressure) {
|
|
345
|
+
ctx.beginPath()
|
|
346
|
+
ctx.moveTo(prePoint.x, prePoint.y)
|
|
347
|
+
ctx.lineTo(point.x, point.y)
|
|
348
|
+
ctx.stroke()
|
|
349
|
+
ctx.draw(true)
|
|
350
|
+
} else if (points.length >= 2) {
|
|
351
|
+
// 笔锋模式使用贝塞尔曲线
|
|
352
|
+
drawSmoothLine(prePoint, point)
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
emit('signing', e)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* 重绘整个画布 (用于撤销/恢复或修改背景色时)
|
|
361
|
+
*/
|
|
362
|
+
const redrawCanvas = () => {
|
|
363
|
+
const { ctx } = canvasState
|
|
364
|
+
if (!ctx) return
|
|
365
|
+
|
|
366
|
+
// 清除画布并设置背景
|
|
367
|
+
if (!isTransparentColor(props.backgroundColor)) {
|
|
368
|
+
ctx.setFillStyle(props.backgroundColor as string)
|
|
369
|
+
ctx.fillRect(0, 0, canvasState.canvasWidth, canvasState.canvasHeight)
|
|
370
|
+
} else {
|
|
371
|
+
ctx.clearRect(0, 0, canvasState.canvasWidth, canvasState.canvasHeight)
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// 如果没有线条,只需要清空画布
|
|
375
|
+
if (lines.value.length === 0) {
|
|
376
|
+
ctx.draw()
|
|
377
|
+
return
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// 递归重绘所有存储的线条
|
|
381
|
+
lines.value.forEach((line) => {
|
|
382
|
+
if (!line.points.length) return
|
|
383
|
+
|
|
384
|
+
ctx.setStrokeStyle(line.color)
|
|
385
|
+
ctx.setLineJoin('round')
|
|
386
|
+
ctx.setLineCap('round')
|
|
387
|
+
|
|
388
|
+
if (line.isPressure && props.pressure) {
|
|
389
|
+
// 笔锋模式的重绘
|
|
390
|
+
line.points.forEach((point, index) => {
|
|
391
|
+
if (index === 0) return
|
|
392
|
+
const prePoint = line.points[index - 1]
|
|
393
|
+
const dis_x = point.x - prePoint.x
|
|
394
|
+
const dis_y = point.y - prePoint.y
|
|
395
|
+
const distance = Math.sqrt(dis_x * dis_x + dis_y * dis_y)
|
|
396
|
+
|
|
397
|
+
if (distance <= 2) {
|
|
398
|
+
point.lastX1 = point.lastX2 = prePoint.x + dis_x * 0.5
|
|
399
|
+
point.lastY1 = point.lastY2 = prePoint.y + dis_y * 0.5
|
|
400
|
+
} else {
|
|
401
|
+
const speed = point.speed || 0
|
|
402
|
+
const minSpeed = props.minSpeed || 1.5
|
|
403
|
+
const speedFactor = Math.max(0.1, Math.min(0.9, speed / (minSpeed * 10)))
|
|
404
|
+
|
|
405
|
+
point.lastX1 = prePoint.x + dis_x * (0.2 + speedFactor * 0.3)
|
|
406
|
+
point.lastY1 = prePoint.y + dis_y * (0.2 + speedFactor * 0.3)
|
|
407
|
+
point.lastX2 = prePoint.x + dis_x * (0.8 - speedFactor * 0.3)
|
|
408
|
+
point.lastY2 = prePoint.y + dis_y * (0.8 - speedFactor * 0.3)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const lineWidth = point.lineWidth || line.width
|
|
412
|
+
if (typeof prePoint.lastX1 === 'number') {
|
|
413
|
+
ctx.setLineWidth(lineWidth)
|
|
414
|
+
ctx.beginPath()
|
|
415
|
+
ctx.moveTo(prePoint.lastX2!, prePoint.lastY2!)
|
|
416
|
+
ctx.quadraticCurveTo(prePoint.x, prePoint.y, point.lastX1, point.lastY1)
|
|
417
|
+
ctx.stroke()
|
|
418
|
+
|
|
419
|
+
if (!prePoint.isFirstPoint) {
|
|
420
|
+
ctx.beginPath()
|
|
421
|
+
ctx.moveTo(prePoint.lastX1!, prePoint.lastY1!)
|
|
422
|
+
ctx.quadraticCurveTo(prePoint.x, prePoint.y, prePoint.lastX2!, prePoint.lastY2!)
|
|
423
|
+
ctx.stroke()
|
|
424
|
+
}
|
|
425
|
+
} else {
|
|
426
|
+
point.isFirstPoint = true
|
|
427
|
+
}
|
|
428
|
+
})
|
|
429
|
+
} else {
|
|
430
|
+
// 非笔锋模式的重绘
|
|
431
|
+
ctx.setLineWidth(line.width)
|
|
432
|
+
line.points.forEach((point, index) => {
|
|
433
|
+
if (index === 0) return
|
|
434
|
+
const prePoint = line.points[index - 1]
|
|
435
|
+
ctx.beginPath()
|
|
436
|
+
ctx.moveTo(prePoint.x, prePoint.y)
|
|
437
|
+
ctx.lineTo(point.x, point.y)
|
|
438
|
+
ctx.stroke()
|
|
439
|
+
})
|
|
440
|
+
}
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
// 所有线条绘制完成后,一次性更新画布
|
|
444
|
+
ctx.draw()
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* 撤销上一笔记录
|
|
449
|
+
*/
|
|
450
|
+
const revoke = () => {
|
|
451
|
+
if (!lines.value.length) return
|
|
452
|
+
const step = Math.min(props.step, lines.value.length)
|
|
453
|
+
const removedLines = lines.value.splice(lines.value.length - step)
|
|
454
|
+
redoLines.value.push(...removedLines)
|
|
455
|
+
currentStep.value = Math.max(0, currentStep.value - step)
|
|
456
|
+
redrawCanvas()
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* 恢复上一笔记录
|
|
461
|
+
*/
|
|
462
|
+
const restore = () => {
|
|
463
|
+
if (!redoLines.value.length) return
|
|
464
|
+
const step = Math.min(props.step, redoLines.value.length)
|
|
465
|
+
const restoredLines = redoLines.value.splice(redoLines.value.length - step)
|
|
466
|
+
lines.value.push(...restoredLines)
|
|
467
|
+
currentStep.value = Math.min(lines.value.length, currentStep.value + step)
|
|
468
|
+
redrawCanvas()
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* 绘制平滑线条 (贝塞尔曲线)
|
|
473
|
+
* @param {Point} prePoint 前一个点
|
|
474
|
+
* @param {Point} point 当前点
|
|
475
|
+
*/
|
|
476
|
+
function drawSmoothLine(prePoint: Point, point: Point) {
|
|
477
|
+
const { ctx } = canvasState
|
|
478
|
+
if (!ctx) return
|
|
479
|
+
|
|
480
|
+
// 计算两点间距离
|
|
481
|
+
const dis_x = point.x - prePoint.x
|
|
482
|
+
const dis_y = point.y - prePoint.y
|
|
483
|
+
const distance = Math.sqrt(dis_x * dis_x + dis_y * dis_y)
|
|
484
|
+
|
|
485
|
+
if (distance <= 2) {
|
|
486
|
+
// 对于非常近的点,直接使用中点
|
|
487
|
+
point.lastX1 = point.lastX2 = prePoint.x + dis_x * 0.5
|
|
488
|
+
point.lastY1 = point.lastY2 = prePoint.y + dis_y * 0.5
|
|
489
|
+
} else {
|
|
490
|
+
// 根据点的速度计算控制点的偏移程度
|
|
491
|
+
const speed = point.speed || 0
|
|
492
|
+
const minSpeed = props.minSpeed || 1.5
|
|
493
|
+
const speedFactor = Math.max(0.1, Math.min(0.9, speed / (minSpeed * 10)))
|
|
494
|
+
|
|
495
|
+
// 计算控制点
|
|
496
|
+
point.lastX1 = prePoint.x + dis_x * (0.2 + speedFactor * 0.3)
|
|
497
|
+
point.lastY1 = prePoint.y + dis_y * (0.2 + speedFactor * 0.3)
|
|
498
|
+
point.lastX2 = prePoint.x + dis_x * (0.8 - speedFactor * 0.3)
|
|
499
|
+
point.lastY2 = prePoint.y + dis_y * (0.8 - speedFactor * 0.3)
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// 计算线宽
|
|
503
|
+
const lineWidth = point.lineWidth || props.lineWidth
|
|
504
|
+
|
|
505
|
+
// 绘制贝塞尔曲线
|
|
506
|
+
if (typeof prePoint.lastX1 === 'number') {
|
|
507
|
+
// 设置线宽
|
|
508
|
+
ctx.setLineWidth(lineWidth)
|
|
509
|
+
// 绘制第一段曲线
|
|
510
|
+
ctx.beginPath()
|
|
511
|
+
ctx.moveTo(prePoint.lastX2!, prePoint.lastY2!)
|
|
512
|
+
ctx.quadraticCurveTo(prePoint.x, prePoint.y, point.lastX1, point.lastY1)
|
|
513
|
+
ctx.stroke()
|
|
514
|
+
|
|
515
|
+
if (!prePoint.isFirstPoint) {
|
|
516
|
+
// 绘制连接段曲线
|
|
517
|
+
ctx.beginPath()
|
|
518
|
+
ctx.moveTo(prePoint.lastX1!, prePoint.lastY1!)
|
|
519
|
+
ctx.quadraticCurveTo(prePoint.x, prePoint.y, prePoint.lastX2!, prePoint.lastY2!)
|
|
520
|
+
ctx.stroke()
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// 批量更新绘制内容
|
|
524
|
+
ctx.draw(true)
|
|
525
|
+
} else {
|
|
526
|
+
point.isFirstPoint = true
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
onMounted(() => {
|
|
531
|
+
initCanvas()
|
|
532
|
+
})
|
|
533
|
+
|
|
534
|
+
onBeforeMount(() => {
|
|
535
|
+
// #ifdef MP
|
|
536
|
+
pixelRatio.value = getSystemInfo().pixelRatio
|
|
537
|
+
// #endif
|
|
538
|
+
})
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* 获取canvas上下文
|
|
542
|
+
*/
|
|
543
|
+
function getContext() {
|
|
544
|
+
return new Promise<UniApp.CanvasContext>((resolve) => {
|
|
545
|
+
const { ctx } = canvasState
|
|
546
|
+
|
|
547
|
+
if (ctx) {
|
|
548
|
+
return resolve(ctx)
|
|
549
|
+
}
|
|
550
|
+
// #ifndef MP-WEIXIN
|
|
551
|
+
getRect(`#${canvasId.value}`, false, proxy).then((canvasRect) => {
|
|
552
|
+
setcanvasState(canvasRect.width!, canvasRect.height!)
|
|
553
|
+
canvasState.ctx = uni.createCanvasContext(canvasId.value, proxy)
|
|
554
|
+
if (canvasState.ctx) {
|
|
555
|
+
canvasState.ctx.scale(pixelRatio.value, pixelRatio.value)
|
|
556
|
+
}
|
|
557
|
+
resolve(canvasState.ctx)
|
|
558
|
+
})
|
|
559
|
+
// #endif
|
|
560
|
+
// #ifdef MP-WEIXIN
|
|
561
|
+
|
|
562
|
+
getRect(`#${canvasId.value}`, false, proxy, true).then((canvasRect: any) => {
|
|
563
|
+
if (canvasRect && canvasRect.node && canvasRect.width && canvasRect.height) {
|
|
564
|
+
const canvasInstance = canvasRect.node
|
|
565
|
+
canvasState.ctx = canvas2dAdapter(canvasInstance.getContext('2d') as CanvasRenderingContext2D)
|
|
566
|
+
canvasInstance.width = canvasRect.width * pixelRatio.value
|
|
567
|
+
canvasInstance.height = canvasRect.height * pixelRatio.value
|
|
568
|
+
canvasState.ctx.scale(pixelRatio.value, pixelRatio.value)
|
|
569
|
+
canvas = canvasInstance
|
|
570
|
+
setcanvasState(canvasRect.width, canvasRect.height)
|
|
571
|
+
resolve(canvasState.ctx)
|
|
572
|
+
}
|
|
573
|
+
})
|
|
574
|
+
// #endif
|
|
575
|
+
})
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* 设置 canvasState
|
|
580
|
+
*/
|
|
581
|
+
function setcanvasState(width: number, height: number) {
|
|
582
|
+
canvasState.canvasHeight = height * pixelRatio.value
|
|
583
|
+
canvasState.canvasWidth = width * pixelRatio.value
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/* 设置线段 */
|
|
587
|
+
function setLine() {
|
|
588
|
+
const { ctx } = canvasState
|
|
589
|
+
if (ctx) {
|
|
590
|
+
ctx.setLineWidth(getDefaultLineWidth()) // 使用新的默认宽度
|
|
591
|
+
ctx.setStrokeStyle(props.penColor)
|
|
592
|
+
ctx.setLineJoin('round')
|
|
593
|
+
ctx.setLineCap('round')
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* canvas 绘制图片输出成文件类型
|
|
599
|
+
*/
|
|
600
|
+
function canvasToImage() {
|
|
601
|
+
const { fileType, quality, exportScale } = props
|
|
602
|
+
const { canvasWidth, canvasHeight } = canvasState
|
|
603
|
+
uni.canvasToTempFilePath(
|
|
604
|
+
{
|
|
605
|
+
width: canvasWidth,
|
|
606
|
+
height: canvasHeight,
|
|
607
|
+
destWidth: canvasWidth * exportScale,
|
|
608
|
+
destHeight: canvasHeight * exportScale,
|
|
609
|
+
fileType,
|
|
610
|
+
quality,
|
|
611
|
+
canvasId: canvasId.value,
|
|
612
|
+
canvas: canvas,
|
|
613
|
+
success: (res) => {
|
|
614
|
+
const result: SignatureResult = {
|
|
615
|
+
tempFilePath: res.tempFilePath,
|
|
616
|
+
width: (canvasWidth * exportScale) / pixelRatio.value,
|
|
617
|
+
height: (canvasHeight * exportScale) / pixelRatio.value,
|
|
618
|
+
success: true
|
|
619
|
+
}
|
|
620
|
+
// #ifdef MP-DINGTALK
|
|
621
|
+
result.tempFilePath = (res as any).filePath
|
|
622
|
+
// #endif
|
|
623
|
+
emit('confirm', result)
|
|
624
|
+
},
|
|
625
|
+
fail: () => {
|
|
626
|
+
const result: SignatureResult = {
|
|
627
|
+
tempFilePath: '',
|
|
628
|
+
width: (canvasWidth * exportScale) / pixelRatio.value,
|
|
629
|
+
height: (canvasHeight * exportScale) / pixelRatio.value,
|
|
630
|
+
success: false
|
|
631
|
+
}
|
|
632
|
+
emit('confirm', result)
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
proxy
|
|
636
|
+
)
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* 清空画布
|
|
641
|
+
*/
|
|
642
|
+
function clearCanvas() {
|
|
643
|
+
const { canvasWidth, canvasHeight, ctx } = canvasState
|
|
644
|
+
if (ctx) {
|
|
645
|
+
ctx.clearRect(0, 0, canvasWidth, canvasHeight)
|
|
646
|
+
if (!isTransparentColor(props.backgroundColor)) {
|
|
647
|
+
ctx.setFillStyle(props.backgroundColor as string)
|
|
648
|
+
ctx.fillRect(0, 0, canvasWidth, canvasHeight)
|
|
649
|
+
}
|
|
650
|
+
ctx.draw()
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
defineExpose<SignatureExpose>({
|
|
655
|
+
init: initCanvas,
|
|
656
|
+
clear,
|
|
657
|
+
confirm: confirmSignature,
|
|
658
|
+
restore,
|
|
659
|
+
revoke
|
|
660
|
+
})
|
|
661
|
+
</script>
|
|
662
|
+
<style lang="scss">
|
|
663
|
+
@use './index.scss';
|
|
664
|
+
</style>
|