@tplc/wot 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/common/AbortablePromise.ts +36 -0
- package/components/common/abstracts/_config.scss +7 -0
- package/components/common/abstracts/_function.scss +76 -0
- package/components/common/abstracts/_mixin.scss +339 -0
- package/components/common/abstracts/variable.scss +1346 -0
- package/components/common/base64.ts +30 -0
- package/components/common/canvasHelper.ts +49 -0
- package/components/common/clickoutside.ts +34 -0
- package/components/common/dayjs.ts +157 -0
- package/components/common/event.ts +8 -0
- package/components/common/props.ts +51 -0
- package/components/common/util.ts +751 -0
- package/components/composables/useCell.ts +13 -0
- package/components/composables/useChildren.ts +122 -0
- package/components/composables/useCountDown.ts +138 -0
- package/components/composables/useLockScroll.ts +39 -0
- package/components/composables/useParent.ts +41 -0
- package/components/composables/usePopover.ts +193 -0
- package/components/composables/useQueue.ts +52 -0
- package/components/composables/useRaf.ts +37 -0
- package/components/composables/useTouch.ts +44 -0
- package/components/composables/useTranslate.ts +22 -0
- package/components/wd-action-sheet/index.scss +204 -0
- package/components/wd-action-sheet/types.ts +128 -0
- package/components/wd-action-sheet/wd-action-sheet.vue +174 -0
- package/components/wd-backtop/index.scss +25 -0
- package/components/wd-backtop/types.ts +37 -0
- package/components/wd-backtop/wd-backtop.vue +48 -0
- package/components/wd-badge/index.scss +59 -0
- package/components/wd-badge/types.ts +53 -0
- package/components/wd-badge/wd-badge.vue +69 -0
- package/components/wd-button/index.scss +340 -0
- package/components/wd-button/types.ts +112 -0
- package/components/wd-button/wd-button.vue +176 -0
- package/components/wd-calendar/index.scss +244 -0
- package/components/wd-calendar/types.ts +235 -0
- package/components/wd-calendar/wd-calendar.vue +456 -0
- package/components/wd-calendar-view/index.scss +9 -0
- package/components/wd-calendar-view/month/index.scss +151 -0
- package/components/wd-calendar-view/month/month.vue +391 -0
- package/components/wd-calendar-view/month/types.ts +19 -0
- package/components/wd-calendar-view/monthPanel/index.scss +89 -0
- package/components/wd-calendar-view/monthPanel/month-panel.vue +388 -0
- package/components/wd-calendar-view/monthPanel/types.ts +48 -0
- package/components/wd-calendar-view/types.ts +134 -0
- package/components/wd-calendar-view/utils.ts +451 -0
- package/components/wd-calendar-view/wd-calendar-view.vue +111 -0
- package/components/wd-calendar-view/year/index.scss +148 -0
- package/components/wd-calendar-view/year/types.ts +19 -0
- package/components/wd-calendar-view/year/year.vue +220 -0
- package/components/wd-calendar-view/yearPanel/index.scss +24 -0
- package/components/wd-calendar-view/yearPanel/types.ts +38 -0
- package/components/wd-calendar-view/yearPanel/year-panel.vue +140 -0
- package/components/wd-card/index.scss +70 -0
- package/components/wd-card/types.ts +30 -0
- package/components/wd-card/wd-card.vue +40 -0
- package/components/wd-cell/index.scss +189 -0
- package/components/wd-cell/types.ts +96 -0
- package/components/wd-cell/wd-cell.vue +135 -0
- package/components/wd-cell-group/index.scss +55 -0
- package/components/wd-cell-group/types.ts +41 -0
- package/components/wd-cell-group/wd-cell-group.vue +45 -0
- package/components/wd-checkbox/index.scss +285 -0
- package/components/wd-checkbox/types.ts +68 -0
- package/components/wd-checkbox/wd-checkbox.vue +185 -0
- package/components/wd-checkbox-group/index.scss +20 -0
- package/components/wd-checkbox-group/types.ts +59 -0
- package/components/wd-checkbox-group/wd-checkbox-group.vue +103 -0
- package/components/wd-circle/index.scss +18 -0
- package/components/wd-circle/types.ts +54 -0
- package/components/wd-circle/wd-circle.vue +318 -0
- package/components/wd-col/index.scss +19 -0
- package/components/wd-col/types.ts +15 -0
- package/components/wd-col/wd-col.vue +91 -0
- package/components/wd-col-picker/index.scss +241 -0
- package/components/wd-col-picker/types.ts +170 -0
- package/components/wd-col-picker/wd-col-picker.vue +550 -0
- package/components/wd-collapse/index.scss +55 -0
- package/components/wd-collapse/types.ts +63 -0
- package/components/wd-collapse/wd-collapse.vue +160 -0
- package/components/wd-collapse-item/index.scss +79 -0
- package/components/wd-collapse-item/types.ts +36 -0
- package/components/wd-collapse-item/wd-collapse-item.vue +182 -0
- package/components/wd-config-provider/types.ts +1023 -0
- package/components/wd-config-provider/wd-config-provider.vue +82 -0
- package/components/wd-count-down/index.scss +14 -0
- package/components/wd-count-down/types.ts +41 -0
- package/components/wd-count-down/utils.ts +52 -0
- package/components/wd-count-down/wd-count-down.vue +60 -0
- package/components/wd-count-to/index.scss +6 -0
- package/components/wd-count-to/types.ts +110 -0
- package/components/wd-count-to/wd-count-to.vue +134 -0
- package/components/wd-curtain/index.scss +80 -0
- package/components/wd-curtain/types.ts +45 -0
- package/components/wd-curtain/wd-curtain.vue +174 -0
- package/components/wd-datetime-picker/index.scss +243 -0
- package/components/wd-datetime-picker/types.ts +225 -0
- package/components/wd-datetime-picker/wd-datetime-picker.vue +827 -0
- package/components/wd-datetime-picker-view/index.scss +0 -0
- package/components/wd-datetime-picker-view/types.ts +137 -0
- package/components/wd-datetime-picker-view/wd-datetime-picker-view.vue +514 -0
- package/components/wd-divider/index.scss +32 -0
- package/components/wd-divider/types.ts +12 -0
- package/components/wd-divider/wd-divider.vue +29 -0
- package/components/wd-drop-menu/index.scss +89 -0
- package/components/wd-drop-menu/types.ts +38 -0
- package/components/wd-drop-menu/wd-drop-menu.vue +128 -0
- package/components/wd-drop-menu-item/index.scss +66 -0
- package/components/wd-drop-menu-item/types.ts +78 -0
- package/components/wd-drop-menu-item/wd-drop-menu-item.vue +230 -0
- package/components/wd-fab/index.scss +115 -0
- package/components/wd-fab/types.ts +61 -0
- package/components/wd-fab/wd-fab.vue +257 -0
- package/components/wd-form/index.scss +10 -0
- package/components/wd-form/types.ts +93 -0
- package/components/wd-form/wd-form.vue +185 -0
- package/components/wd-form-item/index.scss +17 -0
- package/components/wd-form-item/types.ts +22 -0
- package/components/wd-form-item/wd-form-item.vue +65 -0
- package/components/wd-gap/index.scss +9 -0
- package/components/wd-gap/types.ts +23 -0
- package/components/wd-gap/wd-gap.vue +39 -0
- package/components/wd-grid/index.scss +9 -0
- package/components/wd-grid/types.ts +54 -0
- package/components/wd-grid/wd-grid.vue +107 -0
- package/components/wd-grid-item/index.scss +137 -0
- package/components/wd-grid-item/types.ts +74 -0
- package/components/wd-grid-item/wd-grid-item.vue +181 -0
- package/components/wd-icon/index.scss +1222 -0
- package/components/wd-icon/types.ts +21 -0
- package/components/wd-icon/wd-icon.vue +53 -0
- package/components/wd-icon/wd-icons.ttf +0 -0
- package/components/wd-img/index.scss +19 -0
- package/components/wd-img/types.ts +53 -0
- package/components/wd-img/wd-img.vue +76 -0
- package/components/wd-img-cropper/index.scss +227 -0
- package/components/wd-img-cropper/types.ts +87 -0
- package/components/wd-img-cropper/wd-img-cropper.vue +659 -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 +57 -0
- package/components/wd-index-bar/index.scss +39 -0
- package/components/wd-index-bar/type.ts +28 -0
- package/components/wd-index-bar/wd-index-bar.vue +158 -0
- package/components/wd-input/index.scss +326 -0
- package/components/wd-input/types.ts +182 -0
- package/components/wd-input/wd-input.vue +327 -0
- package/components/wd-input-number/index.scss +132 -0
- package/components/wd-input-number/types.ts +78 -0
- package/components/wd-input-number/wd-input-number.vue +221 -0
- package/components/wd-loading/index.scss +34 -0
- package/components/wd-loading/types.ts +31 -0
- package/components/wd-loading/wd-loading.vue +90 -0
- package/components/wd-loadmore/index.scss +39 -0
- package/components/wd-loadmore/types.ts +24 -0
- package/components/wd-loadmore/wd-loadmore.vue +53 -0
- package/components/wd-message-box/index.scss +121 -0
- package/components/wd-message-box/index.ts +95 -0
- package/components/wd-message-box/types.ts +116 -0
- package/components/wd-message-box/wd-message-box.vue +326 -0
- package/components/wd-navbar/index.scss +103 -0
- package/components/wd-navbar/types.ts +52 -0
- package/components/wd-navbar/wd-navbar.vue +142 -0
- package/components/wd-navbar-capsule/index.scss +65 -0
- package/components/wd-navbar-capsule/types.ts +0 -0
- package/components/wd-navbar-capsule/wd-navbar-capsule.vue +31 -0
- package/components/wd-notice-bar/index.scss +86 -0
- package/components/wd-notice-bar/types.ts +56 -0
- package/components/wd-notice-bar/wd-notice-bar.vue +223 -0
- package/components/wd-notify/index.scss +34 -0
- package/components/wd-notify/index.ts +59 -0
- package/components/wd-notify/types.ts +62 -0
- package/components/wd-notify/wd-notify.vue +83 -0
- package/components/wd-number-keyboard/index.scss +78 -0
- package/components/wd-number-keyboard/key/index.scss +79 -0
- package/components/wd-number-keyboard/key/index.vue +76 -0
- package/components/wd-number-keyboard/key/types.ts +11 -0
- package/components/wd-number-keyboard/types.ts +79 -0
- package/components/wd-number-keyboard/wd-number-keyboard.vue +173 -0
- package/components/wd-overlay/index.scss +17 -0
- package/components/wd-overlay/types.ts +25 -0
- package/components/wd-overlay/wd-overlay.vue +46 -0
- package/components/wd-pagination/index.scss +57 -0
- package/components/wd-pagination/types.ts +41 -0
- package/components/wd-pagination/wd-pagination.vue +121 -0
- package/components/wd-password-input/index.scss +123 -0
- package/components/wd-password-input/types.ts +48 -0
- package/components/wd-password-input/wd-password-input.vue +58 -0
- package/components/wd-picker/index.scss +216 -0
- package/components/wd-picker/types.ts +186 -0
- package/components/wd-picker/wd-picker.vue +409 -0
- package/components/wd-picker-view/index.scss +91 -0
- package/components/wd-picker-view/types.ts +162 -0
- package/components/wd-picker-view/wd-picker-view.vue +361 -0
- package/components/wd-popover/index.scss +123 -0
- package/components/wd-popover/types.ts +69 -0
- package/components/wd-popover/wd-popover.vue +216 -0
- package/components/wd-popup/index.scss +112 -0
- package/components/wd-popup/types.ts +68 -0
- package/components/wd-popup/wd-popup.vue +227 -0
- package/components/wd-progress/index.scss +62 -0
- package/components/wd-progress/types.ts +40 -0
- package/components/wd-progress/wd-progress.vue +201 -0
- package/components/wd-radio/index.scss +300 -0
- package/components/wd-radio/types.ts +42 -0
- package/components/wd-radio/wd-radio.vue +136 -0
- package/components/wd-radio-group/index.scss +23 -0
- package/components/wd-radio-group/types.ts +36 -0
- package/components/wd-radio-group/wd-radio-group.vue +54 -0
- package/components/wd-rate/index.scss +24 -0
- package/components/wd-rate/types.ts +91 -0
- package/components/wd-rate/wd-rate.vue +131 -0
- package/components/wd-resize/index.scss +26 -0
- package/components/wd-resize/types.ts +6 -0
- package/components/wd-resize/wd-resize.vue +155 -0
- package/components/wd-row/index.scss +10 -0
- package/components/wd-row/types.ts +16 -0
- package/components/wd-row/wd-row.vue +63 -0
- package/components/wd-search/index.scss +148 -0
- package/components/wd-search/types.ts +83 -0
- package/components/wd-search/wd-search.vue +237 -0
- package/components/wd-segmented/index.scss +97 -0
- package/components/wd-segmented/types.ts +68 -0
- package/components/wd-segmented/wd-segmented.vue +143 -0
- package/components/wd-select-picker/index.scss +177 -0
- package/components/wd-select-picker/types.ts +116 -0
- package/components/wd-select-picker/wd-select-picker.vue +486 -0
- package/components/wd-sidebar/index.scss +25 -0
- package/components/wd-sidebar/types.ts +28 -0
- package/components/wd-sidebar/wd-sidebar.vue +41 -0
- package/components/wd-sidebar-item/index.scss +93 -0
- package/components/wd-sidebar-item/types.ts +31 -0
- package/components/wd-sidebar-item/wd-sidebar-item.vue +114 -0
- package/components/wd-skeleton/index.scss +101 -0
- package/components/wd-skeleton/index.ts +1 -0
- package/components/wd-skeleton/types.ts +69 -0
- package/components/wd-skeleton/wd-skeleton.vue +135 -0
- package/components/wd-slider/index.scss +91 -0
- package/components/wd-slider/types.ts +104 -0
- package/components/wd-slider/wd-slider.vue +377 -0
- package/components/wd-sort-button/index.scss +86 -0
- package/components/wd-sort-button/types.ts +43 -0
- package/components/wd-sort-button/wd-sort-button.vue +76 -0
- package/components/wd-status-tip/index.scss +37 -0
- package/components/wd-status-tip/types.ts +59 -0
- package/components/wd-status-tip/wd-status-tip.vue +94 -0
- package/components/wd-step/index.scss +236 -0
- package/components/wd-step/types.ts +33 -0
- package/components/wd-step/wd-step.vue +151 -0
- package/components/wd-steps/index.scss +10 -0
- package/components/wd-steps/types.ts +59 -0
- package/components/wd-steps/wd-steps.vue +37 -0
- package/components/wd-sticky/index.scss +9 -0
- package/components/wd-sticky/types.ts +13 -0
- package/components/wd-sticky/wd-sticky.vue +190 -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 +154 -0
- package/components/wd-swipe-action/index.scss +22 -0
- package/components/wd-swipe-action/types.ts +43 -0
- package/components/wd-swipe-action/wd-swipe-action.vue +307 -0
- package/components/wd-swiper/index.scss +23 -0
- package/components/wd-swiper/types.ts +189 -0
- package/components/wd-swiper/wd-swiper.vue +202 -0
- package/components/wd-swiper-nav/index.scss +153 -0
- package/components/wd-swiper-nav/types.ts +42 -0
- package/components/wd-swiper-nav/wd-swiper-nav.vue +37 -0
- package/components/wd-switch/index.scss +58 -0
- package/components/wd-switch/types.ts +56 -0
- package/components/wd-switch/wd-switch.vue +83 -0
- package/components/wd-tab/index.scss +8 -0
- package/components/wd-tab/types.ts +20 -0
- package/components/wd-tab/wd-tab.vue +100 -0
- package/components/wd-tabbar/index.scss +57 -0
- package/components/wd-tabbar/types.ts +88 -0
- package/components/wd-tabbar/wd-tabbar.vue +104 -0
- package/components/wd-tabbar-item/index.scss +52 -0
- package/components/wd-tabbar-item/types.ts +51 -0
- package/components/wd-tabbar-item/wd-tabbar-item.vue +101 -0
- package/components/wd-table/index.scss +132 -0
- package/components/wd-table/types.ts +69 -0
- package/components/wd-table/wd-table.vue +255 -0
- package/components/wd-table-col/index.scss +44 -0
- package/components/wd-table-col/types.ts +54 -0
- package/components/wd-table-col/wd-table-col.vue +149 -0
- package/components/wd-tabs/index.scss +280 -0
- package/components/wd-tabs/types.ts +71 -0
- package/components/wd-tabs/wd-tabs.vue +528 -0
- package/components/wd-tag/index.scss +115 -0
- package/components/wd-tag/types.ts +81 -0
- package/components/wd-tag/wd-tag.vue +154 -0
- package/components/wd-text/index.scss +34 -0
- package/components/wd-text/types.ts +98 -0
- package/components/wd-text/wd-text.vue +138 -0
- package/components/wd-textarea/index.scss +343 -0
- package/components/wd-textarea/types.ts +298 -0
- package/components/wd-textarea/wd-textarea.vue +303 -0
- package/components/wd-toast/index.scss +66 -0
- package/components/wd-toast/index.ts +109 -0
- package/components/wd-toast/types.ts +76 -0
- package/components/wd-toast/wd-toast.vue +212 -0
- package/components/wd-tooltip/index.scss +61 -0
- package/components/wd-tooltip/types.ts +102 -0
- package/components/wd-tooltip/wd-tooltip.vue +167 -0
- package/components/wd-transition/index.scss +91 -0
- package/components/wd-transition/types.ts +89 -0
- package/components/wd-transition/wd-transition.vue +221 -0
- package/components/wd-upload/index.scss +173 -0
- package/components/wd-upload/types.ts +378 -0
- package/components/wd-upload/utils.ts +152 -0
- package/components/wd-upload/wd-upload.vue +737 -0
- package/components/wd-video-preview/index.scss +34 -0
- package/components/wd-video-preview/types.ts +32 -0
- package/components/wd-video-preview/wd-video-preview.vue +76 -0
- package/components/wd-watermark/index.scss +18 -0
- package/components/wd-watermark/types.ts +82 -0
- package/components/wd-watermark/wd-watermark.vue +592 -0
- package/components/wot-design-uni/wot-design-uni.vue +14 -0
- package/global.d.ts +108 -0
- package/index.ts +30 -0
- package/locale/index.ts +41 -0
- package/locale/lang/en-US.ts +128 -0
- package/locale/lang/th-TH.ts +127 -0
- package/locale/lang/vi-VN.ts +89 -0
- package/locale/lang/zh-CN.ts +127 -0
- package/locale/lang/zh-HK.ts +84 -0
- package/locale/lang/zh-TW.ts +84 -0
- package/package.json +20 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
@import '../common/abstracts/variable';
|
|
2
|
+
@import '../common/abstracts/mixin';
|
|
3
|
+
|
|
4
|
+
.wot-theme-dark {
|
|
5
|
+
@include b(fab) {
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@include b(fab) {
|
|
10
|
+
position: fixed;
|
|
11
|
+
z-index: 99;
|
|
12
|
+
|
|
13
|
+
@include edeep(trigger) {
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
width: $-fab-trigger-width !important;
|
|
16
|
+
min-width: auto !important;
|
|
17
|
+
height: $-fab-trigger-height !important;
|
|
18
|
+
border-radius: calc($-fab-trigger-height / 2) !important;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
:deep() {
|
|
22
|
+
@include e(actions) {
|
|
23
|
+
position: absolute;
|
|
24
|
+
z-index: 0;
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
padding: $-fab-actions-padding 0;
|
|
29
|
+
|
|
30
|
+
@include m(left, right) {
|
|
31
|
+
top: 0;
|
|
32
|
+
height: 100%;
|
|
33
|
+
padding: 0 $-fab-actions-padding;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@include m(left) {
|
|
37
|
+
right: 100%;
|
|
38
|
+
flex-direction: row-reverse;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@include m(right) {
|
|
42
|
+
left: 100%;
|
|
43
|
+
flex-direction: row;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@include m(top, bottom) {
|
|
47
|
+
left: 0;
|
|
48
|
+
width: 100%;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@include m(top) {
|
|
52
|
+
bottom: 100%;
|
|
53
|
+
flex-direction: column-reverse;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@include m(bottom) {
|
|
57
|
+
top: 100%;
|
|
58
|
+
flex-direction: column;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 动画
|
|
63
|
+
@include e(transition-enter-active, transition-leave-active) {
|
|
64
|
+
transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@include e(transition-enter) {
|
|
68
|
+
@include m(top) {
|
|
69
|
+
opacity: 0;
|
|
70
|
+
transform: translateY(40px);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@include m(bottom) {
|
|
74
|
+
opacity: 0;
|
|
75
|
+
transform: translateY(-40px);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@include m(left) {
|
|
79
|
+
opacity: 0;
|
|
80
|
+
transform: translateX(40px);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@include m(right) {
|
|
84
|
+
opacity: 0;
|
|
85
|
+
transform: translateX(-40px);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@include e(transition-leave-to) {
|
|
90
|
+
@include m(top) {
|
|
91
|
+
opacity: 0;
|
|
92
|
+
transform: translateY(40px);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@include m(bottom) {
|
|
96
|
+
opacity: 0;
|
|
97
|
+
transform: translateY(-40px);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@include m(left) {
|
|
101
|
+
opacity: 0;
|
|
102
|
+
transform: translateX(40px);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@include m(right) {
|
|
106
|
+
opacity: 0;
|
|
107
|
+
transform: translateX(-40px);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@include edeep(icon) {
|
|
113
|
+
font-size: $-fab-icon-fs;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ComponentPublicInstance, ExtractPropTypes, PropType } from 'vue'
|
|
2
|
+
import { baseProps, makeBooleanProp, makeNumberProp, makeStringProp } from '../common/props'
|
|
3
|
+
|
|
4
|
+
export type FabType = 'primary' | 'success' | 'info' | 'warning' | 'error' | 'default'
|
|
5
|
+
export type FabPosition = 'left-top' | 'right-top' | 'left-bottom' | 'right-bottom'
|
|
6
|
+
export type FabDirection = 'top' | 'right' | 'bottom' | 'left'
|
|
7
|
+
export type FabGap = Partial<Record<FabDirection, number>>
|
|
8
|
+
export const fabProps = {
|
|
9
|
+
...baseProps,
|
|
10
|
+
/**
|
|
11
|
+
* 是否激活
|
|
12
|
+
*/
|
|
13
|
+
active: makeBooleanProp(false),
|
|
14
|
+
/**
|
|
15
|
+
* 类型,可选值为 default primary info success warning error
|
|
16
|
+
*/
|
|
17
|
+
type: makeStringProp<FabType>('primary'),
|
|
18
|
+
/**
|
|
19
|
+
* 悬浮按钮位置,可选值为 left-top right-top left-bottom right-bottom
|
|
20
|
+
*/
|
|
21
|
+
position: makeStringProp<FabPosition>('right-bottom'),
|
|
22
|
+
/**
|
|
23
|
+
* 悬浮按钮菜单弹出方向,可选值为 top bottom left right
|
|
24
|
+
*/
|
|
25
|
+
direction: makeStringProp<FabDirection>('top'),
|
|
26
|
+
/**
|
|
27
|
+
* 是否禁用
|
|
28
|
+
*/
|
|
29
|
+
disabled: makeBooleanProp(false),
|
|
30
|
+
/**
|
|
31
|
+
* 悬浮按钮未展开时的图标
|
|
32
|
+
*/
|
|
33
|
+
inactiveIcon: makeStringProp('add'),
|
|
34
|
+
/**
|
|
35
|
+
* 悬浮按钮展开时的图标
|
|
36
|
+
*/
|
|
37
|
+
activeIcon: makeStringProp('close'),
|
|
38
|
+
/**
|
|
39
|
+
* 自定义悬浮按钮层级
|
|
40
|
+
*/
|
|
41
|
+
zIndex: makeNumberProp(99),
|
|
42
|
+
/**
|
|
43
|
+
* 是否可拖动
|
|
44
|
+
*/
|
|
45
|
+
draggable: makeBooleanProp(false),
|
|
46
|
+
gap: {
|
|
47
|
+
type: Object as PropType<FabGap>,
|
|
48
|
+
default: () => ({}),
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type FabProps = ExtractPropTypes<typeof fabProps>
|
|
53
|
+
|
|
54
|
+
export type FabExpose = {
|
|
55
|
+
// 展开菜单
|
|
56
|
+
open: () => void
|
|
57
|
+
// 收起菜单
|
|
58
|
+
close: () => void
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type FabInstance = ComponentPublicInstance<FabProps, FabExpose>
|
|
@@ -0,0 +1,257 @@
|
|
|
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
|
+
<wd-button
|
|
12
|
+
@click="handleClick"
|
|
13
|
+
custom-class="wd-fab__trigger"
|
|
14
|
+
round
|
|
15
|
+
:type="type"
|
|
16
|
+
:disabled="disabled"
|
|
17
|
+
>
|
|
18
|
+
<wd-icon custom-class="wd-fab__icon" :name="isActive ? activeIcon : inactiveIcon"></wd-icon>
|
|
19
|
+
</wd-button>
|
|
20
|
+
</view>
|
|
21
|
+
<wd-transition
|
|
22
|
+
:enter-class="`wd-fab__transition-enter--${fabDirection}`"
|
|
23
|
+
enter-active-class="wd-fab__transition-enter-active"
|
|
24
|
+
:leave-to-class="`wd-fab__transition-leave-to--${fabDirection}`"
|
|
25
|
+
leave-active-class="wd-fab__transition-leave-active"
|
|
26
|
+
:custom-class="`wd-fab__actions wd-fab__actions--${fabDirection}`"
|
|
27
|
+
:show="isActive"
|
|
28
|
+
:duration="300"
|
|
29
|
+
name=""
|
|
30
|
+
>
|
|
31
|
+
<slot></slot>
|
|
32
|
+
</wd-transition>
|
|
33
|
+
</view>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script lang="ts">
|
|
37
|
+
export default {
|
|
38
|
+
name: 'wd-fab',
|
|
39
|
+
options: {
|
|
40
|
+
virtualHost: true,
|
|
41
|
+
addGlobalClass: true,
|
|
42
|
+
styleIsolation: 'shared',
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<script lang="ts" setup>
|
|
48
|
+
import {
|
|
49
|
+
type CSSProperties,
|
|
50
|
+
computed,
|
|
51
|
+
ref,
|
|
52
|
+
watch,
|
|
53
|
+
inject,
|
|
54
|
+
getCurrentInstance,
|
|
55
|
+
onBeforeUnmount,
|
|
56
|
+
onMounted,
|
|
57
|
+
nextTick,
|
|
58
|
+
} from 'vue'
|
|
59
|
+
import { getRect, isDef, isH5, objToStyle } from '../common/util'
|
|
60
|
+
import { type Queue, queueKey } from '../composables/useQueue'
|
|
61
|
+
import { closeOther, pushToQueue, removeFromQueue } from '../common/clickoutside'
|
|
62
|
+
import { fabProps, type FabExpose } from './types'
|
|
63
|
+
import { reactive } from 'vue'
|
|
64
|
+
|
|
65
|
+
const props = defineProps(fabProps)
|
|
66
|
+
const emit = defineEmits(['update:active'])
|
|
67
|
+
const inited = ref<boolean>(false) // 是否初始化完成
|
|
68
|
+
const isActive = ref<boolean>(false) // 是否激活状态
|
|
69
|
+
const queue = inject<Queue | null>(queueKey, null)
|
|
70
|
+
const { proxy } = getCurrentInstance() as any
|
|
71
|
+
|
|
72
|
+
watch(
|
|
73
|
+
() => props.active,
|
|
74
|
+
(newValue) => {
|
|
75
|
+
isActive.value = newValue
|
|
76
|
+
},
|
|
77
|
+
{ immediate: true, deep: true },
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
watch(
|
|
81
|
+
() => isActive.value,
|
|
82
|
+
(newValue) => {
|
|
83
|
+
if (newValue) {
|
|
84
|
+
if (queue && queue.closeOther) {
|
|
85
|
+
queue.closeOther(proxy)
|
|
86
|
+
} else {
|
|
87
|
+
closeOther(proxy)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
const fabDirection = ref(props.direction)
|
|
94
|
+
|
|
95
|
+
watch(
|
|
96
|
+
() => props.direction,
|
|
97
|
+
(direction) => (fabDirection.value = direction),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
watch(
|
|
101
|
+
() => props.position,
|
|
102
|
+
() => initPosition(),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
const top = ref<number>(0)
|
|
106
|
+
const left = ref<number>(0)
|
|
107
|
+
const screen = reactive({ width: 0, height: 0 })
|
|
108
|
+
const fabSize = ref<number>(56)
|
|
109
|
+
const bounding = reactive({
|
|
110
|
+
minTop: 0,
|
|
111
|
+
minLeft: 0,
|
|
112
|
+
maxTop: 0,
|
|
113
|
+
maxLeft: 0,
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
async function getBounding() {
|
|
117
|
+
const sysInfo = uni.getSystemInfoSync()
|
|
118
|
+
try {
|
|
119
|
+
const trigerInfo = await getRect('#trigger', false, proxy)
|
|
120
|
+
fabSize.value = trigerInfo.width || 56
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.log(error)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const { top = 16, left = 16, right = 16, bottom = 16 } = props.gap
|
|
126
|
+
screen.width = sysInfo.windowWidth
|
|
127
|
+
screen.height = isH5 ? sysInfo.windowTop + sysInfo.windowHeight : sysInfo.windowHeight
|
|
128
|
+
bounding.minTop = isH5 ? sysInfo.windowTop + top : top
|
|
129
|
+
bounding.minLeft = left
|
|
130
|
+
bounding.maxLeft = screen.width - fabSize.value - right
|
|
131
|
+
bounding.maxTop = screen.height - fabSize.value - bottom
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function initPosition() {
|
|
135
|
+
const pos = props.position
|
|
136
|
+
const { minLeft, minTop, maxLeft, maxTop } = bounding
|
|
137
|
+
if (pos === 'left-top') {
|
|
138
|
+
top.value = minTop
|
|
139
|
+
left.value = minLeft
|
|
140
|
+
} else if (pos === 'right-top') {
|
|
141
|
+
top.value = minTop
|
|
142
|
+
left.value = maxLeft
|
|
143
|
+
} else if (pos === 'left-bottom') {
|
|
144
|
+
top.value = maxTop
|
|
145
|
+
left.value = minLeft
|
|
146
|
+
} else if (pos === 'right-bottom') {
|
|
147
|
+
top.value = maxTop
|
|
148
|
+
left.value = maxLeft
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 按下时坐标相对于元素的偏移量
|
|
153
|
+
const touchOffset = reactive({ x: 0, y: 0 })
|
|
154
|
+
const attractTransition = ref<boolean>(false)
|
|
155
|
+
function handleTouchStart(e: TouchEvent) {
|
|
156
|
+
if (props.draggable === false) return
|
|
157
|
+
|
|
158
|
+
const touch = e.touches[0]
|
|
159
|
+
touchOffset.x = touch.clientX - left.value
|
|
160
|
+
touchOffset.y = touch.clientY - top.value
|
|
161
|
+
attractTransition.value = false
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function handleTouchMove(e: TouchEvent) {
|
|
165
|
+
if (props.draggable === false) return
|
|
166
|
+
|
|
167
|
+
const touch = e.touches[0]
|
|
168
|
+
const { minLeft, minTop, maxLeft, maxTop } = bounding
|
|
169
|
+
let x = touch.clientX - touchOffset.x
|
|
170
|
+
let y = touch.clientY - touchOffset.y
|
|
171
|
+
|
|
172
|
+
if (x < minLeft) x = minLeft
|
|
173
|
+
else if (x > maxLeft) x = maxLeft
|
|
174
|
+
|
|
175
|
+
if (y < minTop) y = minTop
|
|
176
|
+
else if (y > maxTop) y = maxTop
|
|
177
|
+
|
|
178
|
+
top.value = y
|
|
179
|
+
left.value = x
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function handleTouchEnd() {
|
|
183
|
+
if (props.draggable === false) return
|
|
184
|
+
|
|
185
|
+
const screenCenterX = screen.width / 2
|
|
186
|
+
const fabCenterX = left.value + fabSize.value / 2
|
|
187
|
+
attractTransition.value = true
|
|
188
|
+
if (fabCenterX < screenCenterX) {
|
|
189
|
+
left.value = bounding.minLeft
|
|
190
|
+
fabDirection.value = 'right'
|
|
191
|
+
} else {
|
|
192
|
+
left.value = bounding.maxLeft
|
|
193
|
+
fabDirection.value = 'left'
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const rootStyle = computed(() => {
|
|
198
|
+
const style: CSSProperties = {
|
|
199
|
+
top: top.value + 'px',
|
|
200
|
+
left: left.value + 'px',
|
|
201
|
+
transition: attractTransition.value ? 'all ease 0.3s' : 'none',
|
|
202
|
+
}
|
|
203
|
+
if (isDef(props.zIndex)) {
|
|
204
|
+
style['z-index'] = props.zIndex
|
|
205
|
+
}
|
|
206
|
+
return `${objToStyle(style)};${props.customStyle}`
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
onMounted(() => {
|
|
210
|
+
if (queue && queue.pushToQueue) {
|
|
211
|
+
queue.pushToQueue(proxy)
|
|
212
|
+
} else {
|
|
213
|
+
pushToQueue(proxy)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
nextTick(async () => {
|
|
217
|
+
await getBounding()
|
|
218
|
+
initPosition()
|
|
219
|
+
inited.value = true
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
onBeforeUnmount(() => {
|
|
224
|
+
if (queue && queue.removeFromQueue) {
|
|
225
|
+
queue.removeFromQueue(proxy)
|
|
226
|
+
} else {
|
|
227
|
+
removeFromQueue(proxy)
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
function handleClick() {
|
|
232
|
+
if (props.disabled) {
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
isActive.value = !isActive.value
|
|
236
|
+
emit('update:active', isActive.value)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function open() {
|
|
240
|
+
isActive.value = true
|
|
241
|
+
emit('update:active', true)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function close() {
|
|
245
|
+
isActive.value = false
|
|
246
|
+
emit('update:active', false)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
defineExpose<FabExpose>({
|
|
250
|
+
open,
|
|
251
|
+
close,
|
|
252
|
+
})
|
|
253
|
+
</script>
|
|
254
|
+
|
|
255
|
+
<style lang="scss" scoped>
|
|
256
|
+
@import './index';
|
|
257
|
+
</style>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: weisheng
|
|
3
|
+
* @Date: 2023-12-14 11:21:58
|
|
4
|
+
* @LastEditTime: 2024-03-18 12:50:41
|
|
5
|
+
* @LastEditors: weisheng
|
|
6
|
+
* @Description:
|
|
7
|
+
* @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-form\types.ts
|
|
8
|
+
* 记得注释
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
type ComponentPublicInstance,
|
|
12
|
+
type ExtractPropTypes,
|
|
13
|
+
type InjectionKey,
|
|
14
|
+
type PropType,
|
|
15
|
+
} from 'vue'
|
|
16
|
+
import { baseProps, makeBooleanProp, makeRequiredProp } from '../common/props'
|
|
17
|
+
|
|
18
|
+
export type FormProvide = {
|
|
19
|
+
props: {
|
|
20
|
+
model: Record<string, any>
|
|
21
|
+
rules?: FormRules
|
|
22
|
+
border?: boolean
|
|
23
|
+
}
|
|
24
|
+
errorMessages?: Record<string, string>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const FORM_KEY: InjectionKey<FormProvide> = Symbol('wd-form')
|
|
28
|
+
|
|
29
|
+
export type FormRules = {
|
|
30
|
+
[key: string]: FormItemRule[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ErrorMessage = {
|
|
34
|
+
prop: string
|
|
35
|
+
message: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface FormItemRule {
|
|
39
|
+
[key: string]: any
|
|
40
|
+
required: boolean
|
|
41
|
+
message: string
|
|
42
|
+
pattern?: RegExp
|
|
43
|
+
validator?: (
|
|
44
|
+
value: any,
|
|
45
|
+
rule: FormItemRuleWithoutValidator,
|
|
46
|
+
) => boolean | Promise<string> | Promise<boolean> | Promise<void> | Promise<unknown>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type FormItemRuleWithoutValidator = Omit<FormItemRule, 'validator'>
|
|
50
|
+
|
|
51
|
+
export const formProps = {
|
|
52
|
+
...baseProps,
|
|
53
|
+
/**
|
|
54
|
+
* 表单数据对象
|
|
55
|
+
*/
|
|
56
|
+
model: makeRequiredProp(Object as PropType<Record<string, any>>),
|
|
57
|
+
/**
|
|
58
|
+
* 表单验证规则
|
|
59
|
+
*/
|
|
60
|
+
rules: {
|
|
61
|
+
type: Object as PropType<FormRules>,
|
|
62
|
+
default: () => ({}),
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* 是否在输入时重置表单校验信息
|
|
66
|
+
*/
|
|
67
|
+
resetOnChange: makeBooleanProp(true),
|
|
68
|
+
/**
|
|
69
|
+
* 错误提示类型
|
|
70
|
+
*/
|
|
71
|
+
errorType: {
|
|
72
|
+
type: String as PropType<'toast' | 'message' | 'none'>,
|
|
73
|
+
default: 'message',
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
export type FormProps = ExtractPropTypes<typeof formProps>
|
|
77
|
+
|
|
78
|
+
export type FormExpose = {
|
|
79
|
+
/**
|
|
80
|
+
* 表单校验
|
|
81
|
+
* @param prop 指定校验字段
|
|
82
|
+
*/
|
|
83
|
+
validate: (prop?: string) => Promise<{
|
|
84
|
+
valid: boolean
|
|
85
|
+
errors: ErrorMessage[]
|
|
86
|
+
}>
|
|
87
|
+
/**
|
|
88
|
+
* 重置表单项的验证提示
|
|
89
|
+
*/
|
|
90
|
+
reset: () => void
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type FormInstance = ComponentPublicInstance<FormProps, FormExpose>
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="`wd-form ${customClass}`" :style="customStyle">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
<wd-toast v-if="props.errorType === 'toast'" selector="wd-form-toast" />
|
|
5
|
+
</view>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
export default {
|
|
10
|
+
name: 'wd-form',
|
|
11
|
+
options: {
|
|
12
|
+
addGlobalClass: true,
|
|
13
|
+
virtualHost: true,
|
|
14
|
+
styleIsolation: 'shared',
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts" setup>
|
|
20
|
+
import { reactive, watch } from 'vue'
|
|
21
|
+
import { deepClone, getPropByPath, isDef, isPromise } from '../common/util'
|
|
22
|
+
import { useChildren } from '../composables/useChildren'
|
|
23
|
+
import { useToast } from '../wd-toast'
|
|
24
|
+
import { type FormRules, FORM_KEY, type ErrorMessage, formProps, type FormExpose } from './types'
|
|
25
|
+
|
|
26
|
+
const toast = useToast('wd-form-toast')
|
|
27
|
+
const props = defineProps(formProps)
|
|
28
|
+
|
|
29
|
+
const { children, linkChildren } = useChildren(FORM_KEY)
|
|
30
|
+
const errorMessages = reactive<Record<string, string>>({})
|
|
31
|
+
|
|
32
|
+
linkChildren({ props, errorMessages })
|
|
33
|
+
|
|
34
|
+
watch(
|
|
35
|
+
() => props.model,
|
|
36
|
+
() => {
|
|
37
|
+
if (props.resetOnChange) {
|
|
38
|
+
clearMessage()
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{ immediate: true, deep: true },
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 表单校验
|
|
46
|
+
* @param prop 指定校验字段
|
|
47
|
+
*/
|
|
48
|
+
async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorMessage[] }> {
|
|
49
|
+
const errors: ErrorMessage[] = []
|
|
50
|
+
let valid: boolean = true
|
|
51
|
+
const promises: Promise<void>[] = []
|
|
52
|
+
const formRules: FormRules = getMergeRules()
|
|
53
|
+
const rulesToValidate: FormRules = prop ? { [prop]: formRules[prop] } : formRules
|
|
54
|
+
for (const prop in rulesToValidate) {
|
|
55
|
+
const rules = rulesToValidate[prop]
|
|
56
|
+
const value = getPropByPath(props.model, prop)
|
|
57
|
+
if (rules && rules.length > 0) {
|
|
58
|
+
for (const rule of rules) {
|
|
59
|
+
if (rule.required && (!isDef(value) || value === '')) {
|
|
60
|
+
errors.push({
|
|
61
|
+
prop,
|
|
62
|
+
message: rule.message,
|
|
63
|
+
})
|
|
64
|
+
valid = false
|
|
65
|
+
break
|
|
66
|
+
}
|
|
67
|
+
if (rule.pattern && !rule.pattern.test(value)) {
|
|
68
|
+
errors.push({
|
|
69
|
+
prop,
|
|
70
|
+
message: rule.message,
|
|
71
|
+
})
|
|
72
|
+
valid = false
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
const { validator, ...ruleWithoutValidator } = rule
|
|
76
|
+
if (validator) {
|
|
77
|
+
const result = validator(value, ruleWithoutValidator)
|
|
78
|
+
if (isPromise(result)) {
|
|
79
|
+
promises.push(
|
|
80
|
+
result
|
|
81
|
+
.then((res: any) => {
|
|
82
|
+
if (typeof res === 'string') {
|
|
83
|
+
errors.push({
|
|
84
|
+
prop,
|
|
85
|
+
message: res,
|
|
86
|
+
})
|
|
87
|
+
valid = false
|
|
88
|
+
} else if (typeof res === 'boolean' && !res) {
|
|
89
|
+
errors.push({
|
|
90
|
+
prop,
|
|
91
|
+
message: rule.message,
|
|
92
|
+
})
|
|
93
|
+
valid = false
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch((error) => {
|
|
97
|
+
errors.push({
|
|
98
|
+
prop,
|
|
99
|
+
message: error || rule.message,
|
|
100
|
+
})
|
|
101
|
+
valid = false
|
|
102
|
+
}),
|
|
103
|
+
)
|
|
104
|
+
} else {
|
|
105
|
+
if (!result) {
|
|
106
|
+
errors.push({
|
|
107
|
+
prop,
|
|
108
|
+
message: rule.message,
|
|
109
|
+
})
|
|
110
|
+
valid = false
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
await Promise.all(promises)
|
|
119
|
+
|
|
120
|
+
errors.forEach((error) => {
|
|
121
|
+
showMessage(error)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
if (valid) {
|
|
125
|
+
if (prop) {
|
|
126
|
+
clearMessage(prop)
|
|
127
|
+
} else {
|
|
128
|
+
clearMessage()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
valid,
|
|
134
|
+
errors,
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 合并子组件的rules到父组件的rules
|
|
139
|
+
function getMergeRules() {
|
|
140
|
+
const mergedRules: FormRules = deepClone(props.rules)
|
|
141
|
+
children.forEach((item) => {
|
|
142
|
+
if (isDef(item.prop) && isDef(item.rules) && item.rules.length) {
|
|
143
|
+
if (mergedRules[item.prop]) {
|
|
144
|
+
mergedRules[item.prop] = [...mergedRules[item.prop], ...item.rules]
|
|
145
|
+
} else {
|
|
146
|
+
mergedRules[item.prop] = item.rules
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
return mergedRules
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function showMessage(errorMsg: ErrorMessage) {
|
|
154
|
+
if (!errorMsg.message) return
|
|
155
|
+
|
|
156
|
+
if (props.errorType === 'toast') {
|
|
157
|
+
toast.show(errorMsg.message)
|
|
158
|
+
} else if (props.errorType === 'message') {
|
|
159
|
+
errorMessages[errorMsg.prop] = errorMsg.message
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function clearMessage(prop?: string) {
|
|
164
|
+
if (prop) {
|
|
165
|
+
errorMessages[prop] = ''
|
|
166
|
+
} else {
|
|
167
|
+
Object.keys(errorMessages).forEach((key) => {
|
|
168
|
+
errorMessages[key] = ''
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 重置表单项的验证提示
|
|
175
|
+
*/
|
|
176
|
+
function reset() {
|
|
177
|
+
clearMessage()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
defineExpose<FormExpose>({ validate, reset })
|
|
181
|
+
</script>
|
|
182
|
+
|
|
183
|
+
<style lang="scss" scoped>
|
|
184
|
+
@import './index.scss';
|
|
185
|
+
</style>
|