@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,142 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :style="{ height: addUnit(height) }">
|
|
3
|
+
<view
|
|
4
|
+
:class="`wd-navbar ${customClass} ${fixed ? 'is-fixed' : ''} ${bordered ? 'is-border' : ''}`"
|
|
5
|
+
:style="rootStyle"
|
|
6
|
+
>
|
|
7
|
+
<view class="wd-navbar__content">
|
|
8
|
+
<view class="wd-navbar__capsule" v-if="$slots.capsule">
|
|
9
|
+
<slot name="capsule" />
|
|
10
|
+
</view>
|
|
11
|
+
|
|
12
|
+
<view
|
|
13
|
+
:class="`wd-navbar__left ${leftDisabled ? 'is-disabled' : ''}`"
|
|
14
|
+
:hover-class="leftDisabled || $slots.left ? '' : 'wd-navbar__left--hover'"
|
|
15
|
+
hover-stay-time="70"
|
|
16
|
+
@click="handleClickLeft"
|
|
17
|
+
v-else-if="!$slots.left"
|
|
18
|
+
>
|
|
19
|
+
<wd-icon v-if="leftArrow" name="arrow-left" custom-class="wd-navbar__arrow" />
|
|
20
|
+
<view v-if="leftText" class="wd-navbar__text">{{ leftText }}</view>
|
|
21
|
+
</view>
|
|
22
|
+
|
|
23
|
+
<view
|
|
24
|
+
v-else
|
|
25
|
+
:class="`wd-navbar__left ${leftDisabled ? 'is-disabled' : ''}`"
|
|
26
|
+
@click="handleClickLeft"
|
|
27
|
+
>
|
|
28
|
+
<slot name="left" />
|
|
29
|
+
</view>
|
|
30
|
+
|
|
31
|
+
<view class="wd-navbar__title">
|
|
32
|
+
<slot name="title" />
|
|
33
|
+
<block v-if="!$slots.title && title">{{ title }}</block>
|
|
34
|
+
</view>
|
|
35
|
+
<view
|
|
36
|
+
:class="`wd-navbar__right ${rightDisabled ? 'is-disabled' : ''}`"
|
|
37
|
+
@click="handleClickRight"
|
|
38
|
+
v-if="$slots.right || rightText"
|
|
39
|
+
:hover-class="rightDisabled ? '' : 'wd-navbar__right--hover'"
|
|
40
|
+
hover-stay-time="70"
|
|
41
|
+
>
|
|
42
|
+
<slot name="right" />
|
|
43
|
+
|
|
44
|
+
<view
|
|
45
|
+
v-if="!$slots.right && rightText"
|
|
46
|
+
class="wd-navbar__text"
|
|
47
|
+
hover-class="wd-navbar__text--hover"
|
|
48
|
+
hover-stay-time="70"
|
|
49
|
+
>
|
|
50
|
+
{{ rightText }}
|
|
51
|
+
</view>
|
|
52
|
+
</view>
|
|
53
|
+
</view>
|
|
54
|
+
</view>
|
|
55
|
+
</view>
|
|
56
|
+
</template>
|
|
57
|
+
<script lang="ts">
|
|
58
|
+
export default {
|
|
59
|
+
name: 'wd-navbar',
|
|
60
|
+
options: {
|
|
61
|
+
virtualHost: true,
|
|
62
|
+
addGlobalClass: true,
|
|
63
|
+
styleIsolation: 'shared',
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<script lang="ts" setup>
|
|
69
|
+
import {
|
|
70
|
+
type CSSProperties,
|
|
71
|
+
computed,
|
|
72
|
+
getCurrentInstance,
|
|
73
|
+
nextTick,
|
|
74
|
+
onMounted,
|
|
75
|
+
ref,
|
|
76
|
+
watch,
|
|
77
|
+
} from 'vue'
|
|
78
|
+
import { getRect, addUnit, isDef, objToStyle } from '../common/util'
|
|
79
|
+
import { navbarProps } from './types'
|
|
80
|
+
|
|
81
|
+
const props = defineProps(navbarProps)
|
|
82
|
+
const emit = defineEmits(['click-left', 'click-right'])
|
|
83
|
+
|
|
84
|
+
const height = ref<number | ''>('') // 占位高度
|
|
85
|
+
|
|
86
|
+
const { statusBarHeight } = uni.getSystemInfoSync()
|
|
87
|
+
|
|
88
|
+
watch(
|
|
89
|
+
[() => props.fixed, () => props.placeholder],
|
|
90
|
+
() => {
|
|
91
|
+
setPlaceholderHeight()
|
|
92
|
+
},
|
|
93
|
+
{ deep: true, immediate: false },
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
const rootStyle = computed(() => {
|
|
97
|
+
const style: CSSProperties = {}
|
|
98
|
+
if (props.fixed && isDef(props.zIndex)) {
|
|
99
|
+
style['z-index'] = props.zIndex
|
|
100
|
+
}
|
|
101
|
+
if (props.safeAreaInsetTop) {
|
|
102
|
+
style['padding-top'] = addUnit(statusBarHeight || 0)
|
|
103
|
+
}
|
|
104
|
+
return `${objToStyle(style)};${props.customStyle}`
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
onMounted(() => {
|
|
108
|
+
if (props.fixed && props.placeholder) {
|
|
109
|
+
nextTick(() => {
|
|
110
|
+
setPlaceholderHeight()
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
function handleClickLeft() {
|
|
116
|
+
if (!props.leftDisabled) {
|
|
117
|
+
emit('click-left')
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function handleClickRight() {
|
|
122
|
+
if (!props.rightDisabled) {
|
|
123
|
+
emit('click-right')
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const { proxy } = getCurrentInstance() as any
|
|
128
|
+
|
|
129
|
+
function setPlaceholderHeight() {
|
|
130
|
+
if (!props.fixed || !props.placeholder) {
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
getRect('.wd-navbar', false, proxy).then((res) => {
|
|
135
|
+
height.value = res.height as number
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
</script>
|
|
139
|
+
|
|
140
|
+
<style lang="scss">
|
|
141
|
+
@import './index';
|
|
142
|
+
</style>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
@import './../common/abstracts/_mixin';
|
|
2
|
+
@import './../common/abstracts/variable';
|
|
3
|
+
|
|
4
|
+
.wot-theme-dark {
|
|
5
|
+
@include b(navbar-capsule) {
|
|
6
|
+
&::before {
|
|
7
|
+
border: 2rpx solid $-dark-border-color;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&::after {
|
|
11
|
+
background: $-dark-border-color;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
:deep(.wd-navbar-capsule__icon) {
|
|
15
|
+
color: $-dark-color;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@include b(navbar-capsule) {
|
|
21
|
+
position: relative;
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
width: $-navbar-capsule-width;
|
|
27
|
+
height: $-navbar-capsule-height;
|
|
28
|
+
|
|
29
|
+
&::before {
|
|
30
|
+
position: absolute;
|
|
31
|
+
top: 0;
|
|
32
|
+
left: 0;
|
|
33
|
+
box-sizing: border-box;
|
|
34
|
+
width: 200%;
|
|
35
|
+
height: 200%;
|
|
36
|
+
content: '';
|
|
37
|
+
border: 2rpx solid $-navbar-capsule-border-color;
|
|
38
|
+
border-radius: calc($-navbar-capsule-border-radius * 2);
|
|
39
|
+
transform: scale(0.5);
|
|
40
|
+
transform-origin: 0 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&::after {
|
|
44
|
+
position: absolute;
|
|
45
|
+
top: 50%;
|
|
46
|
+
left: 50%;
|
|
47
|
+
display: block;
|
|
48
|
+
width: 1px;
|
|
49
|
+
height: 36rpx;
|
|
50
|
+
content: '';
|
|
51
|
+
background: $-navbar-capsule-border-color;
|
|
52
|
+
transform: translateY(-50%);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&:empty {
|
|
56
|
+
display: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@include edeep(icon) {
|
|
60
|
+
position: relative;
|
|
61
|
+
flex: 1;
|
|
62
|
+
font-size: $-navbar-capsule-icon-size;
|
|
63
|
+
color: $-navbar-desc-font-color;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="wd-navbar-capsule">
|
|
3
|
+
<wd-icon @click="handleBack" name="chevron-left" custom-class="wd-navbar-capsule__icon" />
|
|
4
|
+
<wd-icon @click="handleBackHome" name="home" custom-class="wd-navbar-capsule__icon" />
|
|
5
|
+
</view>
|
|
6
|
+
</template>
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
export default {
|
|
9
|
+
name: 'wd-navbar-capsule',
|
|
10
|
+
options: {
|
|
11
|
+
virtualHost: true,
|
|
12
|
+
addGlobalClass: true,
|
|
13
|
+
styleIsolation: 'shared',
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts" setup>
|
|
19
|
+
const emit = defineEmits(['back', 'back-home'])
|
|
20
|
+
|
|
21
|
+
function handleBack() {
|
|
22
|
+
emit('back')
|
|
23
|
+
}
|
|
24
|
+
function handleBackHome() {
|
|
25
|
+
emit('back-home')
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<style lang="scss">
|
|
30
|
+
@import './index';
|
|
31
|
+
</style>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
@import '../common/abstracts/variable';
|
|
2
|
+
@import '../common/abstracts/mixin';
|
|
3
|
+
|
|
4
|
+
@include b(notice-bar) {
|
|
5
|
+
position: relative;
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
padding: $-notice-bar-padding;
|
|
10
|
+
font-size: $-notice-bar-fs;
|
|
11
|
+
border-radius: $-notice-bar-border-radius;
|
|
12
|
+
@include when(warning) {
|
|
13
|
+
color: $-notice-bar-warning-color;
|
|
14
|
+
background: $-notice-bar-warning-bg;
|
|
15
|
+
}
|
|
16
|
+
@include when(info) {
|
|
17
|
+
color: $-notice-bar-info-color;
|
|
18
|
+
background: $-notice-bar-info-bg;
|
|
19
|
+
}
|
|
20
|
+
@include when(danger) {
|
|
21
|
+
color: $-notice-bar-danger-color;
|
|
22
|
+
background: $-notice-bar-danger-bg;
|
|
23
|
+
}
|
|
24
|
+
@include edeep(prefix) {
|
|
25
|
+
padding-right: 4px;
|
|
26
|
+
font-size: $-notice-bar-prefix-size;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@include edeep(suffix) {
|
|
30
|
+
position: absolute;
|
|
31
|
+
top: 0;
|
|
32
|
+
right: 0;
|
|
33
|
+
display: inline-block;
|
|
34
|
+
padding: 0;
|
|
35
|
+
font-size: $-notice-bar-close-size;
|
|
36
|
+
color: $-notice-bar-close-color;
|
|
37
|
+
text-align: center;
|
|
38
|
+
background-color: $-notice-bar-close-bg;
|
|
39
|
+
border-radius: 0px 8px 0px 4px;
|
|
40
|
+
}
|
|
41
|
+
@include e(wrap) {
|
|
42
|
+
position: relative;
|
|
43
|
+
flex: 1;
|
|
44
|
+
height: $-notice-bar-line-height;
|
|
45
|
+
overflow: hidden;
|
|
46
|
+
line-height: $-notice-bar-line-height;
|
|
47
|
+
}
|
|
48
|
+
@include e(content) {
|
|
49
|
+
position: absolute;
|
|
50
|
+
white-space: nowrap;
|
|
51
|
+
|
|
52
|
+
@include m(play) {
|
|
53
|
+
animation: notice-bar-play linear both;
|
|
54
|
+
}
|
|
55
|
+
@include m(play-infinite) {
|
|
56
|
+
animation: notice-bar-play-infinite linear infinite both;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
@include m(ellipse) {
|
|
60
|
+
.wd-notice-bar__content {
|
|
61
|
+
position: static;
|
|
62
|
+
@include lineEllipsis;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
@include m(wrap) {
|
|
66
|
+
.wd-notice-bar__wrap {
|
|
67
|
+
height: auto;
|
|
68
|
+
}
|
|
69
|
+
.wd-notice-bar__content {
|
|
70
|
+
position: static;
|
|
71
|
+
white-space: normal;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@keyframes notice-bar-play {
|
|
77
|
+
100% {
|
|
78
|
+
transform: translate3d(-100%, 0, 0);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@keyframes notice-bar-play-infinite {
|
|
83
|
+
100% {
|
|
84
|
+
transform: translate3d(-100%, 0, 0);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { PropType } from 'vue'
|
|
2
|
+
import { baseProps, makeBooleanProp, makeNumberProp, makeStringProp } from '../common/props'
|
|
3
|
+
|
|
4
|
+
export type NoticeBarType = 'warning' | 'info' | 'danger' | ''
|
|
5
|
+
export type NoticeBarScrollDirection = 'horizontal' | 'vertical'
|
|
6
|
+
|
|
7
|
+
export const noticeBarProps = {
|
|
8
|
+
...baseProps,
|
|
9
|
+
/**
|
|
10
|
+
* 设置通知栏文案
|
|
11
|
+
*/
|
|
12
|
+
text: {
|
|
13
|
+
type: [String, Array] as PropType<string | string[]>,
|
|
14
|
+
default: '',
|
|
15
|
+
},
|
|
16
|
+
/**
|
|
17
|
+
* 设置通知栏类型,可选值为:'warning' | 'info' | 'danger'
|
|
18
|
+
*/
|
|
19
|
+
type: makeStringProp<NoticeBarType>('warning'),
|
|
20
|
+
/**
|
|
21
|
+
* 是否可滚动
|
|
22
|
+
*/
|
|
23
|
+
scrollable: makeBooleanProp(true),
|
|
24
|
+
/**
|
|
25
|
+
* 滚动延迟时间(秒)
|
|
26
|
+
*/
|
|
27
|
+
delay: makeNumberProp(1),
|
|
28
|
+
/**
|
|
29
|
+
* 滚动速度(px/s)
|
|
30
|
+
*/
|
|
31
|
+
speed: makeNumberProp(50),
|
|
32
|
+
/**
|
|
33
|
+
* 是否可关闭
|
|
34
|
+
*/
|
|
35
|
+
closable: makeBooleanProp(false),
|
|
36
|
+
/**
|
|
37
|
+
* 是否换行显示
|
|
38
|
+
*/
|
|
39
|
+
wrapable: makeBooleanProp(false),
|
|
40
|
+
/**
|
|
41
|
+
* 设置左侧图标,使用 icon 章节中的图标名
|
|
42
|
+
*/
|
|
43
|
+
prefix: String,
|
|
44
|
+
/**
|
|
45
|
+
* 文字、图标颜色
|
|
46
|
+
*/
|
|
47
|
+
color: String,
|
|
48
|
+
/**
|
|
49
|
+
* 背景颜色
|
|
50
|
+
*/
|
|
51
|
+
backgroundColor: String,
|
|
52
|
+
/**
|
|
53
|
+
* 滚动方向
|
|
54
|
+
*/
|
|
55
|
+
direction: makeStringProp<NoticeBarScrollDirection>('horizontal'),
|
|
56
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view v-if="show" :class="`wd-notice-bar ${customClass} ${noticeBarClass}`" :style="rootStyle">
|
|
3
|
+
<wd-icon v-if="prefix" custom-class="wd-notice-bar__prefix" :name="prefix"></wd-icon>
|
|
4
|
+
<slot v-else name="prefix"></slot>
|
|
5
|
+
<view class="wd-notice-bar__wrap">
|
|
6
|
+
<view
|
|
7
|
+
class="wd-notice-bar__content"
|
|
8
|
+
:style="animation"
|
|
9
|
+
@transitionend="animationEnd"
|
|
10
|
+
@click="handleClick"
|
|
11
|
+
>
|
|
12
|
+
<template v-if="isVertical">
|
|
13
|
+
<view v-for="item in textArray" :key="item">{{ item }}</view>
|
|
14
|
+
<view v-if="textArray.length > 1">{{ textArray[0] }}</view>
|
|
15
|
+
</template>
|
|
16
|
+
<slot v-else>{{ currentText }}</slot>
|
|
17
|
+
</view>
|
|
18
|
+
</view>
|
|
19
|
+
<wd-icon
|
|
20
|
+
v-if="closable"
|
|
21
|
+
custom-class="wd-notice-bar__suffix"
|
|
22
|
+
name="close-bold"
|
|
23
|
+
@click="handleClose"
|
|
24
|
+
></wd-icon>
|
|
25
|
+
<slot v-else name="suffix"></slot>
|
|
26
|
+
</view>
|
|
27
|
+
</template>
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
export default {
|
|
30
|
+
name: 'wd-notice-bar',
|
|
31
|
+
options: {
|
|
32
|
+
virtualHost: true,
|
|
33
|
+
addGlobalClass: true,
|
|
34
|
+
styleIsolation: 'shared',
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<script lang="ts" setup>
|
|
40
|
+
import { ref, watch, nextTick, computed, getCurrentInstance, type CSSProperties } from 'vue'
|
|
41
|
+
import { getRect, isArray, isDef, objToStyle } from '../common/util'
|
|
42
|
+
import { noticeBarProps } from './types'
|
|
43
|
+
|
|
44
|
+
const $wrap = '.wd-notice-bar__wrap'
|
|
45
|
+
const $content = '.wd-notice-bar__content'
|
|
46
|
+
|
|
47
|
+
const props = defineProps(noticeBarProps)
|
|
48
|
+
const emit = defineEmits(['close', 'next', 'click'])
|
|
49
|
+
|
|
50
|
+
const wrapWidth = ref<number>(0)
|
|
51
|
+
const show = ref<boolean>(true)
|
|
52
|
+
const animation = ref<string>('')
|
|
53
|
+
const currentIndex = ref(0)
|
|
54
|
+
const textArray = computed(() => (Array.isArray(props.text) ? props.text : [props.text]))
|
|
55
|
+
const currentText = computed(() => textArray.value[currentIndex.value])
|
|
56
|
+
const verticalIndex = ref(0)
|
|
57
|
+
const isHorizontal = computed(() => props.direction === 'horizontal')
|
|
58
|
+
const isVertical = computed(() => props.direction === 'vertical')
|
|
59
|
+
|
|
60
|
+
const rootStyle = computed(() => {
|
|
61
|
+
const style: CSSProperties = {}
|
|
62
|
+
if (isDef(props.color)) {
|
|
63
|
+
style.color = props.color
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isDef(props.backgroundColor)) {
|
|
67
|
+
style.background = props.backgroundColor
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return `${objToStyle(style)};${props.customStyle}`
|
|
71
|
+
})
|
|
72
|
+
const noticeBarClass = computed(() => {
|
|
73
|
+
const { type, wrapable, scrollable } = props
|
|
74
|
+
|
|
75
|
+
const noticeBarClasses: string[] = []
|
|
76
|
+
type && noticeBarClasses.push(`is-${type}`)
|
|
77
|
+
|
|
78
|
+
if (isHorizontal.value) {
|
|
79
|
+
!wrapable && !scrollable && noticeBarClasses.push('wd-notice-bar--ellipse')
|
|
80
|
+
} else {
|
|
81
|
+
noticeBarClasses.push('wd-notice-bar--ellipse')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
wrapable && !scrollable && noticeBarClasses.push('wd-notice-bar--wrap')
|
|
85
|
+
return noticeBarClasses.join(' ')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const { proxy } = getCurrentInstance() as any
|
|
89
|
+
|
|
90
|
+
watch(
|
|
91
|
+
[() => props.text],
|
|
92
|
+
() => {
|
|
93
|
+
nextTick(() => scroll())
|
|
94
|
+
},
|
|
95
|
+
{ deep: true, immediate: true },
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
function handleClose() {
|
|
99
|
+
show.value = false
|
|
100
|
+
emit('close')
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function initAnimation({
|
|
104
|
+
duration,
|
|
105
|
+
delay,
|
|
106
|
+
translate,
|
|
107
|
+
}: {
|
|
108
|
+
duration: number
|
|
109
|
+
delay: number
|
|
110
|
+
translate: number
|
|
111
|
+
}) {
|
|
112
|
+
const style: CSSProperties = {
|
|
113
|
+
transitionProperty: 'all',
|
|
114
|
+
transitionDelay: `${delay}s`,
|
|
115
|
+
transitionDuration: `${duration}s`,
|
|
116
|
+
transform: `${props.direction === 'vertical' ? 'translateY' : 'translateX'}(${translate}px)`,
|
|
117
|
+
transitionTimingFunction: 'linear',
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return objToStyle(style)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function queryRect() {
|
|
124
|
+
return Promise.all([getRect($wrap, false, proxy), getRect($content, false, proxy)])
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function verticalAnimate(height: number) {
|
|
128
|
+
const translate = -(height / (textArray.value.length + 1)) * (currentIndex.value + 1)
|
|
129
|
+
animation.value = initAnimation({
|
|
130
|
+
duration: height / (textArray.value.length + 1) / props.speed,
|
|
131
|
+
delay: props.delay,
|
|
132
|
+
translate,
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function scroll() {
|
|
137
|
+
const [wrapRect, contentRect] = await queryRect()
|
|
138
|
+
if (!wrapRect.width || !contentRect.width || !contentRect.height) return
|
|
139
|
+
|
|
140
|
+
wrapWidth.value = wrapRect.width
|
|
141
|
+
|
|
142
|
+
if (isHorizontal.value) {
|
|
143
|
+
if (props.scrollable) {
|
|
144
|
+
animation.value = initAnimation({
|
|
145
|
+
duration: contentRect.width / props.speed,
|
|
146
|
+
delay: props.delay,
|
|
147
|
+
translate: -contentRect.width,
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
if (textArray.value.length > 1) {
|
|
152
|
+
verticalAnimate(contentRect.height)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function next() {
|
|
158
|
+
if (currentIndex.value >= textArray.value.length - 1) {
|
|
159
|
+
currentIndex.value = 0
|
|
160
|
+
} else {
|
|
161
|
+
currentIndex.value++
|
|
162
|
+
}
|
|
163
|
+
emit('next', currentIndex.value)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function animationEnd() {
|
|
167
|
+
if (isHorizontal.value) {
|
|
168
|
+
animation.value = initAnimation({
|
|
169
|
+
duration: 0,
|
|
170
|
+
delay: 0,
|
|
171
|
+
translate: wrapWidth.value + 1, // +1容错空间,防止露出来一丢丢
|
|
172
|
+
})
|
|
173
|
+
} else {
|
|
174
|
+
if (++verticalIndex.value >= textArray.value.length) {
|
|
175
|
+
verticalIndex.value = 0
|
|
176
|
+
animation.value = initAnimation({
|
|
177
|
+
duration: 0,
|
|
178
|
+
delay: 0,
|
|
179
|
+
translate: 0,
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const timer = setTimeout(() => {
|
|
185
|
+
next() // 更换下一条文本
|
|
186
|
+
|
|
187
|
+
nextTick(async () => {
|
|
188
|
+
// 因为文本会发生变化,所以每一次都需要查询
|
|
189
|
+
const [_, contentRect] = await queryRect()
|
|
190
|
+
if (!contentRect.width || !contentRect.height) return
|
|
191
|
+
|
|
192
|
+
if (isHorizontal.value) {
|
|
193
|
+
animation.value = initAnimation({
|
|
194
|
+
duration: (wrapWidth.value + contentRect.width) / props.speed,
|
|
195
|
+
delay: props.delay,
|
|
196
|
+
translate: -contentRect.width,
|
|
197
|
+
})
|
|
198
|
+
} else {
|
|
199
|
+
verticalAnimate(contentRect.height)
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
clearTimeout(timer)
|
|
204
|
+
}, 20)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function handleClick() {
|
|
208
|
+
const result = isArray(props.text)
|
|
209
|
+
? {
|
|
210
|
+
index: currentIndex.value,
|
|
211
|
+
text: props.text[currentIndex.value],
|
|
212
|
+
}
|
|
213
|
+
: {
|
|
214
|
+
index: 0,
|
|
215
|
+
text: props.text,
|
|
216
|
+
}
|
|
217
|
+
emit('click', result)
|
|
218
|
+
}
|
|
219
|
+
</script>
|
|
220
|
+
|
|
221
|
+
<style lang="scss" scoped>
|
|
222
|
+
@import './index.scss';
|
|
223
|
+
</style>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
@import '../common/abstracts/variable';
|
|
2
|
+
@import '../common/abstracts/mixin';
|
|
3
|
+
|
|
4
|
+
@include b(notify) {
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
padding: $-notify-padding;
|
|
10
|
+
font-size: $-notify-font-size;
|
|
11
|
+
line-height: $-notify-line-height;
|
|
12
|
+
color: $-notify-text-color;
|
|
13
|
+
text-align: center;
|
|
14
|
+
word-wrap: break-word;
|
|
15
|
+
|
|
16
|
+
// allow newline character
|
|
17
|
+
white-space: pre-wrap;
|
|
18
|
+
|
|
19
|
+
@include m(primary) {
|
|
20
|
+
background: $-notify-primary-background;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@include m(success) {
|
|
24
|
+
background: $-notify-success-background;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@include m(danger) {
|
|
28
|
+
background: $-notify-danger-background;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@include m(warning) {
|
|
32
|
+
background: $-notify-warning-background;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { provide, reactive } from 'vue'
|
|
2
|
+
import type { NotifyProps } from './types'
|
|
3
|
+
import { deepMerge, isString } from '../common/util'
|
|
4
|
+
|
|
5
|
+
let timer: ReturnType<typeof setTimeout>
|
|
6
|
+
let currentOptions = getDefaultOptions()
|
|
7
|
+
const notifyDefaultOptionKey = '__NOTIFY_OPTION__'
|
|
8
|
+
export const setNotifyDefaultOptions = (options: NotifyProps) => {
|
|
9
|
+
currentOptions = deepMerge(currentOptions, options) as NotifyProps
|
|
10
|
+
}
|
|
11
|
+
export const resetNotifyDefaultOptions = () => {
|
|
12
|
+
currentOptions = getDefaultOptions()
|
|
13
|
+
}
|
|
14
|
+
export const useNotify = (selector: string = '') => {
|
|
15
|
+
const notifyOption = reactive<NotifyProps>(currentOptions)
|
|
16
|
+
const showNotify = (option: NotifyProps | string) => {
|
|
17
|
+
const options = deepMerge(
|
|
18
|
+
currentOptions,
|
|
19
|
+
isString(option) ? { message: option } : option,
|
|
20
|
+
) as NotifyProps
|
|
21
|
+
|
|
22
|
+
Object.assign(notifyOption, options, { visible: true })
|
|
23
|
+
if (notifyOption.duration && notifyOption.duration > 0) {
|
|
24
|
+
timer && clearTimeout(timer)
|
|
25
|
+
timer = setTimeout(() => closeNotify(), options.duration)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const closeNotify = () => {
|
|
29
|
+
timer && clearTimeout(timer)
|
|
30
|
+
notifyOption.visible = false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// provide
|
|
34
|
+
provide(getNotifyOptionKey(selector), notifyOption)
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
showNotify,
|
|
38
|
+
closeNotify,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export const getNotifyOptionKey = (selector: string) => {
|
|
42
|
+
return selector ? `${notifyDefaultOptionKey}${selector}` : notifyDefaultOptionKey
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getDefaultOptions(): NotifyProps {
|
|
46
|
+
return {
|
|
47
|
+
type: 'danger',
|
|
48
|
+
color: undefined,
|
|
49
|
+
zIndex: 99,
|
|
50
|
+
message: '',
|
|
51
|
+
duration: 3000,
|
|
52
|
+
position: 'top',
|
|
53
|
+
safeHeight: undefined,
|
|
54
|
+
background: undefined,
|
|
55
|
+
onClick: undefined,
|
|
56
|
+
onClosed: undefined,
|
|
57
|
+
onOpened: undefined,
|
|
58
|
+
}
|
|
59
|
+
}
|