@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,13 @@
|
|
|
1
|
+
import { computed } from 'vue'
|
|
2
|
+
import { useParent } from './useParent'
|
|
3
|
+
import { CELL_GROUP_KEY } from '../wd-cell-group/types'
|
|
4
|
+
|
|
5
|
+
export function useCell() {
|
|
6
|
+
const { parent: cellGroup, index } = useParent(CELL_GROUP_KEY)
|
|
7
|
+
|
|
8
|
+
const border = computed(() => {
|
|
9
|
+
return cellGroup && cellGroup.props.border && index.value
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
return { border }
|
|
13
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
provide,
|
|
3
|
+
reactive,
|
|
4
|
+
getCurrentInstance,
|
|
5
|
+
type VNode,
|
|
6
|
+
type InjectionKey,
|
|
7
|
+
type VNodeNormalizedChildren,
|
|
8
|
+
type ComponentPublicInstance,
|
|
9
|
+
type ComponentInternalInstance,
|
|
10
|
+
} from 'vue'
|
|
11
|
+
|
|
12
|
+
// 小程序端不支持从vue导出的isVNode方法,参考uni-mp-vue的实现
|
|
13
|
+
function isVNode(value: any): value is VNode {
|
|
14
|
+
return value ? value.__v_isVNode === true : false
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function flattenVNodes(children: VNodeNormalizedChildren) {
|
|
18
|
+
const result: VNode[] = []
|
|
19
|
+
|
|
20
|
+
const traverse = (children: VNodeNormalizedChildren) => {
|
|
21
|
+
if (Array.isArray(children)) {
|
|
22
|
+
children.forEach((child) => {
|
|
23
|
+
if (isVNode(child)) {
|
|
24
|
+
result.push(child)
|
|
25
|
+
|
|
26
|
+
if (child.component?.subTree) {
|
|
27
|
+
result.push(child.component.subTree)
|
|
28
|
+
traverse(child.component.subTree.children)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (child.children) {
|
|
32
|
+
traverse(child.children)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
traverse(children)
|
|
40
|
+
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const findVNodeIndex = (vnodes: VNode[], vnode: VNode) => {
|
|
45
|
+
const index = vnodes.indexOf(vnode)
|
|
46
|
+
if (index === -1) {
|
|
47
|
+
return vnodes.findIndex(
|
|
48
|
+
(item) =>
|
|
49
|
+
vnode.key !== undefined &&
|
|
50
|
+
vnode.key !== null &&
|
|
51
|
+
item.type === vnode.type &&
|
|
52
|
+
item.key === vnode.key,
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
return index
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// sort children instances by vnodes order
|
|
59
|
+
export function sortChildren(
|
|
60
|
+
parent: ComponentInternalInstance,
|
|
61
|
+
publicChildren: ComponentPublicInstance[],
|
|
62
|
+
internalChildren: ComponentInternalInstance[],
|
|
63
|
+
) {
|
|
64
|
+
const vnodes =
|
|
65
|
+
parent && parent.subTree && parent.subTree.children
|
|
66
|
+
? flattenVNodes(parent.subTree.children)
|
|
67
|
+
: []
|
|
68
|
+
|
|
69
|
+
internalChildren.sort((a, b) => findVNodeIndex(vnodes, a.vnode) - findVNodeIndex(vnodes, b.vnode))
|
|
70
|
+
|
|
71
|
+
const orderedPublicChildren = internalChildren.map((item) => item.proxy!)
|
|
72
|
+
|
|
73
|
+
publicChildren.sort((a, b) => {
|
|
74
|
+
const indexA = orderedPublicChildren.indexOf(a)
|
|
75
|
+
const indexB = orderedPublicChildren.indexOf(b)
|
|
76
|
+
return indexA - indexB
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function useChildren<
|
|
81
|
+
// eslint-disable-next-line
|
|
82
|
+
Child extends ComponentPublicInstance = ComponentPublicInstance<{}, any>,
|
|
83
|
+
ProvideValue = never,
|
|
84
|
+
>(key: InjectionKey<ProvideValue>) {
|
|
85
|
+
const publicChildren: Child[] = reactive([])
|
|
86
|
+
const internalChildren: ComponentInternalInstance[] = reactive([])
|
|
87
|
+
const parent = getCurrentInstance()!
|
|
88
|
+
|
|
89
|
+
const linkChildren = (value?: ProvideValue) => {
|
|
90
|
+
const link = (child: ComponentInternalInstance) => {
|
|
91
|
+
if (child.proxy) {
|
|
92
|
+
internalChildren.push(child)
|
|
93
|
+
publicChildren.push(child.proxy as Child)
|
|
94
|
+
sortChildren(parent, publicChildren, internalChildren)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const unlink = (child: ComponentInternalInstance) => {
|
|
99
|
+
const index = internalChildren.indexOf(child)
|
|
100
|
+
publicChildren.splice(index, 1)
|
|
101
|
+
internalChildren.splice(index, 1)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
provide(
|
|
105
|
+
key,
|
|
106
|
+
Object.assign(
|
|
107
|
+
{
|
|
108
|
+
link,
|
|
109
|
+
unlink,
|
|
110
|
+
children: publicChildren,
|
|
111
|
+
internalChildren,
|
|
112
|
+
},
|
|
113
|
+
value,
|
|
114
|
+
),
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
children: publicChildren,
|
|
120
|
+
linkChildren,
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { ref, computed, onBeforeUnmount } from 'vue'
|
|
2
|
+
import { isDef } from '../common/util'
|
|
3
|
+
import { useRaf } from './useRaf'
|
|
4
|
+
|
|
5
|
+
// 定义倒计时时间的数据结构
|
|
6
|
+
export type CurrentTime = {
|
|
7
|
+
days: number
|
|
8
|
+
hours: number
|
|
9
|
+
total: number
|
|
10
|
+
minutes: number
|
|
11
|
+
seconds: number
|
|
12
|
+
milliseconds: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 定义倒计时的配置项
|
|
16
|
+
export type UseCountDownOptions = {
|
|
17
|
+
time: number // 倒计时总时间,单位为毫秒
|
|
18
|
+
millisecond?: boolean // 是否开启毫秒级倒计时,默认为 false
|
|
19
|
+
onChange?: (current: CurrentTime) => void // 倒计时每次变化时的回调函数
|
|
20
|
+
onFinish?: () => void // 倒计时结束时的回调函数
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 定义常量
|
|
24
|
+
const SECOND = 1000
|
|
25
|
+
const MINUTE = 60 * SECOND
|
|
26
|
+
const HOUR = 60 * MINUTE
|
|
27
|
+
const DAY = 24 * HOUR
|
|
28
|
+
|
|
29
|
+
// 将时间转换为倒计时数据结构
|
|
30
|
+
function parseTime(time: number): CurrentTime {
|
|
31
|
+
const days = Math.floor(time / DAY)
|
|
32
|
+
const hours = Math.floor((time % DAY) / HOUR)
|
|
33
|
+
const minutes = Math.floor((time % HOUR) / MINUTE)
|
|
34
|
+
const seconds = Math.floor((time % MINUTE) / SECOND)
|
|
35
|
+
const milliseconds = Math.floor(time % SECOND)
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
total: time,
|
|
39
|
+
days,
|
|
40
|
+
hours,
|
|
41
|
+
minutes,
|
|
42
|
+
seconds,
|
|
43
|
+
milliseconds,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 判断两个时间是否在同一秒内
|
|
48
|
+
function isSameSecond(time1: number, time2: number): boolean {
|
|
49
|
+
return Math.floor(time1 / 1000) === Math.floor(time2 / 1000)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 定义 useCountDown 函数
|
|
53
|
+
export function useCountDown(options: UseCountDownOptions) {
|
|
54
|
+
let endTime: number // 结束时间
|
|
55
|
+
let counting: boolean // 是否计时中
|
|
56
|
+
|
|
57
|
+
const { start: startRaf, cancel: cancelRaf } = useRaf(tick)
|
|
58
|
+
|
|
59
|
+
const remain = ref(options.time) // 剩余时间
|
|
60
|
+
const current = computed(() => parseTime(remain.value)) // 当前倒计时数据
|
|
61
|
+
|
|
62
|
+
// 暂停倒计时
|
|
63
|
+
const pause = () => {
|
|
64
|
+
counting = false
|
|
65
|
+
cancelRaf()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 获取当前剩余时间
|
|
69
|
+
const getCurrentRemain = () => Math.max(endTime - Date.now(), 0)
|
|
70
|
+
|
|
71
|
+
// 设置剩余时间
|
|
72
|
+
const setRemain = (value: number) => {
|
|
73
|
+
remain.value = value
|
|
74
|
+
isDef(options.onChange) && options.onChange(current.value)
|
|
75
|
+
if (value === 0) {
|
|
76
|
+
pause()
|
|
77
|
+
isDef(options.onFinish) && options.onFinish()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 每毫秒更新一次倒计时
|
|
82
|
+
const microTick = () => {
|
|
83
|
+
if (counting) {
|
|
84
|
+
setRemain(getCurrentRemain())
|
|
85
|
+
if (remain.value > 0) {
|
|
86
|
+
startRaf()
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 每秒更新一次倒计时
|
|
92
|
+
const macroTick = () => {
|
|
93
|
+
if (counting) {
|
|
94
|
+
const remainRemain = getCurrentRemain()
|
|
95
|
+
if (!isSameSecond(remainRemain, remain.value) || remainRemain === 0) {
|
|
96
|
+
setRemain(remainRemain)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (remain.value > 0) {
|
|
100
|
+
startRaf()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 根据配置项选择更新方式
|
|
106
|
+
function tick() {
|
|
107
|
+
if (options.millisecond) {
|
|
108
|
+
microTick()
|
|
109
|
+
} else {
|
|
110
|
+
macroTick()
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 开始倒计时
|
|
115
|
+
const start = () => {
|
|
116
|
+
if (!counting) {
|
|
117
|
+
endTime = Date.now() + remain.value
|
|
118
|
+
counting = true
|
|
119
|
+
startRaf()
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 重置倒计时
|
|
124
|
+
const reset = (totalTime: number = options.time) => {
|
|
125
|
+
pause()
|
|
126
|
+
remain.value = totalTime
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 在组件卸载前暂停倒计时
|
|
130
|
+
onBeforeUnmount(pause)
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
start,
|
|
134
|
+
pause,
|
|
135
|
+
reset,
|
|
136
|
+
current,
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { onBeforeUnmount, onDeactivated, ref, watch } from 'vue'
|
|
2
|
+
|
|
3
|
+
function useLockScroll(shouldLock: () => boolean) {
|
|
4
|
+
const scrollLockCount = ref(0)
|
|
5
|
+
|
|
6
|
+
const lock = () => {
|
|
7
|
+
if (scrollLockCount.value === 0) {
|
|
8
|
+
document.getElementsByTagName('body')[0].style.overflow = 'hidden'
|
|
9
|
+
}
|
|
10
|
+
scrollLockCount.value++
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const unlock = () => {
|
|
14
|
+
if (scrollLockCount.value > 0) {
|
|
15
|
+
scrollLockCount.value--
|
|
16
|
+
if (scrollLockCount.value === 0) {
|
|
17
|
+
document.getElementsByTagName('body')[0].style.overflow = ''
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const destroy = () => {
|
|
23
|
+
shouldLock() && unlock()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
watch(shouldLock, (value) => {
|
|
27
|
+
value ? lock() : unlock()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
onDeactivated(destroy)
|
|
31
|
+
onBeforeUnmount(destroy)
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
lock,
|
|
35
|
+
unlock,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default useLockScroll
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
inject,
|
|
4
|
+
computed,
|
|
5
|
+
onUnmounted,
|
|
6
|
+
type InjectionKey,
|
|
7
|
+
getCurrentInstance,
|
|
8
|
+
type ComponentPublicInstance,
|
|
9
|
+
type ComponentInternalInstance,
|
|
10
|
+
} from 'vue'
|
|
11
|
+
|
|
12
|
+
type ParentProvide<T> = T & {
|
|
13
|
+
link(child: ComponentInternalInstance): void
|
|
14
|
+
unlink(child: ComponentInternalInstance): void
|
|
15
|
+
children: ComponentPublicInstance[]
|
|
16
|
+
internalChildren: ComponentInternalInstance[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useParent<T>(key: InjectionKey<ParentProvide<T>>) {
|
|
20
|
+
const parent = inject(key, null)
|
|
21
|
+
|
|
22
|
+
if (parent) {
|
|
23
|
+
const instance = getCurrentInstance()!
|
|
24
|
+
const { link, unlink, internalChildren } = parent
|
|
25
|
+
|
|
26
|
+
link(instance)
|
|
27
|
+
onUnmounted(() => unlink(instance))
|
|
28
|
+
|
|
29
|
+
const index = computed(() => internalChildren.indexOf(instance))
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
parent,
|
|
33
|
+
index,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
parent: null,
|
|
39
|
+
index: ref(-1),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { getCurrentInstance, ref } from 'vue'
|
|
2
|
+
import { getRect } from '../common/util'
|
|
3
|
+
|
|
4
|
+
export function usePopover() {
|
|
5
|
+
const { proxy } = getCurrentInstance() as any
|
|
6
|
+
const popStyle = ref<string>('')
|
|
7
|
+
const arrowStyle = ref<string>('')
|
|
8
|
+
const showStyle = ref<string>('')
|
|
9
|
+
const arrowClass = ref<string>('')
|
|
10
|
+
const popWidth = ref<number>(0)
|
|
11
|
+
const popHeight = ref<number>(0)
|
|
12
|
+
const left = ref<number>(0)
|
|
13
|
+
const bottom = ref<number>(0)
|
|
14
|
+
const width = ref<number>(0)
|
|
15
|
+
const height = ref<number>(0)
|
|
16
|
+
const top = ref<number>(0)
|
|
17
|
+
|
|
18
|
+
function noop() {}
|
|
19
|
+
|
|
20
|
+
function init(
|
|
21
|
+
placement:
|
|
22
|
+
| 'top'
|
|
23
|
+
| 'top-start'
|
|
24
|
+
| 'top-end'
|
|
25
|
+
| 'bottom'
|
|
26
|
+
| 'bottom-start'
|
|
27
|
+
| 'bottom-end'
|
|
28
|
+
| 'left'
|
|
29
|
+
| 'left-start'
|
|
30
|
+
| 'left-end'
|
|
31
|
+
| 'right'
|
|
32
|
+
| 'right-start'
|
|
33
|
+
| 'right-end',
|
|
34
|
+
visibleArrow: boolean,
|
|
35
|
+
selector: string,
|
|
36
|
+
) {
|
|
37
|
+
// 初始化 class
|
|
38
|
+
if (visibleArrow) {
|
|
39
|
+
const arrowClassArr = [
|
|
40
|
+
`wd-${selector}__arrow`,
|
|
41
|
+
placement === 'bottom' || placement === 'bottom-start' || placement === 'bottom-end'
|
|
42
|
+
? `wd-${selector}__arrow-up`
|
|
43
|
+
: '',
|
|
44
|
+
placement === 'left' || placement === 'left-start' || placement === 'left-end'
|
|
45
|
+
? `wd-${selector}__arrow-right`
|
|
46
|
+
: '',
|
|
47
|
+
placement === 'right' || placement === 'right-start' || placement === 'right-end'
|
|
48
|
+
? `wd-${selector}__arrow-left`
|
|
49
|
+
: '',
|
|
50
|
+
placement === 'top' || placement === 'top-start' || placement === 'top-end'
|
|
51
|
+
? `wd-${selector}__arrow-down`
|
|
52
|
+
: '',
|
|
53
|
+
]
|
|
54
|
+
arrowClass.value = arrowClassArr.join(' ')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 初始化数据获取
|
|
58
|
+
getRect('#target', false, proxy).then((rect) => {
|
|
59
|
+
if (!rect) return
|
|
60
|
+
left.value = rect.left as number
|
|
61
|
+
bottom.value = rect.bottom as number
|
|
62
|
+
width.value = rect.width as number
|
|
63
|
+
height.value = rect.height as number
|
|
64
|
+
top.value = rect.top as number
|
|
65
|
+
})
|
|
66
|
+
// 用透明度可在初始化时获取到pop尺寸
|
|
67
|
+
getRect('#pos', false, proxy).then((rect) => {
|
|
68
|
+
if (!rect) return
|
|
69
|
+
popWidth.value = rect.width as number
|
|
70
|
+
popHeight.value = rect.height as number
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function control(
|
|
75
|
+
placement:
|
|
76
|
+
| 'top'
|
|
77
|
+
| 'top-start'
|
|
78
|
+
| 'top-end'
|
|
79
|
+
| 'bottom'
|
|
80
|
+
| 'bottom-start'
|
|
81
|
+
| 'bottom-end'
|
|
82
|
+
| 'left'
|
|
83
|
+
| 'left-start'
|
|
84
|
+
| 'left-end'
|
|
85
|
+
| 'right'
|
|
86
|
+
| 'right-start'
|
|
87
|
+
| 'right-end',
|
|
88
|
+
offset: number,
|
|
89
|
+
) {
|
|
90
|
+
// arrow size
|
|
91
|
+
const arrowSize = 9
|
|
92
|
+
// 上下位(纵轴)对应的距离左边的距离
|
|
93
|
+
const verticalX = width.value / 2
|
|
94
|
+
// 上下位(纵轴)对应的距离底部的距离
|
|
95
|
+
const verticalY = arrowSize + height.value + 5
|
|
96
|
+
// 左右位(横轴)对应的距离左边的距离
|
|
97
|
+
const horizontalX = width.value + arrowSize + 5
|
|
98
|
+
// 左右位(横轴)对应的距离底部的距离
|
|
99
|
+
const horizontalY = height.value / 2
|
|
100
|
+
|
|
101
|
+
const offsetX = (verticalX - 17 > 0 ? 0 : verticalX - 25) + offset
|
|
102
|
+
const offsetY = (horizontalY - 17 > 0 ? 0 : horizontalY - 25) + offset
|
|
103
|
+
|
|
104
|
+
const placements = new Map([
|
|
105
|
+
// 上
|
|
106
|
+
[
|
|
107
|
+
'top',
|
|
108
|
+
[
|
|
109
|
+
`left: ${verticalX}px; bottom: ${verticalY}px; transform: translateX(-50%);`,
|
|
110
|
+
'left: 50%;',
|
|
111
|
+
],
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
'top-start',
|
|
115
|
+
[
|
|
116
|
+
`left: ${offsetX}px; bottom: ${verticalY}px;`,
|
|
117
|
+
`left: ${(popWidth.value >= width.value ? width.value / 2 : popWidth.value - 25) - offsetX}px;`,
|
|
118
|
+
],
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
'top-end',
|
|
122
|
+
[
|
|
123
|
+
`right: ${offsetX}px; bottom: ${verticalY}px;`,
|
|
124
|
+
`right: ${(popWidth.value >= width.value ? width.value / 2 : popWidth.value - 25) - offsetX}px; transform: translateX(50%);`,
|
|
125
|
+
],
|
|
126
|
+
],
|
|
127
|
+
// 下
|
|
128
|
+
[
|
|
129
|
+
'bottom',
|
|
130
|
+
[`left: ${verticalX}px; top: ${verticalY}px; transform: translateX(-50%);`, 'left: 50%;'],
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
'bottom-start',
|
|
134
|
+
[
|
|
135
|
+
`left: ${offsetX}px; top: ${verticalY}px;`,
|
|
136
|
+
`left: ${(popWidth.value >= width.value ? width.value / 2 : popWidth.value - 25) - offsetX}px;`,
|
|
137
|
+
],
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
'bottom-end',
|
|
141
|
+
[
|
|
142
|
+
`right: ${offsetX}px; top: ${verticalY}px;`,
|
|
143
|
+
`right: ${(popWidth.value >= width.value ? width.value / 2 : popWidth.value - 25) - offsetX}px; transform: translateX(50%);`,
|
|
144
|
+
],
|
|
145
|
+
],
|
|
146
|
+
// 左
|
|
147
|
+
[
|
|
148
|
+
'left',
|
|
149
|
+
[
|
|
150
|
+
`right: ${horizontalX}px; top: ${horizontalY}px; transform: translateY(-50%);`,
|
|
151
|
+
'top: 50%',
|
|
152
|
+
],
|
|
153
|
+
],
|
|
154
|
+
[
|
|
155
|
+
'left-start',
|
|
156
|
+
[
|
|
157
|
+
`right: ${horizontalX}px; top: ${offsetY}px;`,
|
|
158
|
+
`top: ${(popHeight.value >= height.value ? height.value / 2 : popHeight.value - 20) - offsetY}px;`,
|
|
159
|
+
],
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
'left-end',
|
|
163
|
+
[
|
|
164
|
+
`right: ${horizontalX}px; bottom: ${offsetY}px;`,
|
|
165
|
+
`bottom: ${(popHeight.value >= height.value ? height.value / 2 : popHeight.value - 20) - offsetY}px; transform: translateY(50%);`,
|
|
166
|
+
],
|
|
167
|
+
],
|
|
168
|
+
// 右
|
|
169
|
+
[
|
|
170
|
+
'right',
|
|
171
|
+
[`left: ${horizontalX}px; top: ${horizontalY}px; transform: translateY(-50%);`, 'top: 50%'],
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
'right-start',
|
|
175
|
+
[
|
|
176
|
+
`left: ${horizontalX}px; top: ${offsetY}px;`,
|
|
177
|
+
`top: ${(popHeight.value >= height.value ? height.value / 2 : popHeight.value - 20) - offsetY}px;`,
|
|
178
|
+
],
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
'right-end',
|
|
182
|
+
[
|
|
183
|
+
`left: ${horizontalX}px; bottom: ${offsetY}px;`,
|
|
184
|
+
`bottom: ${(popHeight.value >= height.value ? height.value / 2 : popHeight.value - 20) - offsetY}px; transform: translateY(50%);`,
|
|
185
|
+
],
|
|
186
|
+
],
|
|
187
|
+
])
|
|
188
|
+
popStyle.value = placements.get(placement)![0]
|
|
189
|
+
arrowStyle.value = placements.get(placement)![1]
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return { popStyle, arrowStyle, showStyle, arrowClass, init, control, noop }
|
|
193
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Ref, provide, ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
export const queueKey = '__QUEUE_KEY__'
|
|
4
|
+
|
|
5
|
+
export interface Queue {
|
|
6
|
+
queue: Ref<any[]>
|
|
7
|
+
pushToQueue: (comp: any) => void
|
|
8
|
+
removeFromQueue: (comp: any) => void
|
|
9
|
+
closeOther: (comp: any) => void
|
|
10
|
+
closeOutside: () => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useQueue() {
|
|
14
|
+
const queue = ref<any[]>([])
|
|
15
|
+
|
|
16
|
+
function pushToQueue(comp: any) {
|
|
17
|
+
queue.value.push(comp)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function removeFromQueue(comp: any) {
|
|
21
|
+
queue.value = queue.value.filter((item) => {
|
|
22
|
+
return item.$.uid !== comp.$.uid
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function closeOther(comp: any) {
|
|
27
|
+
queue.value.forEach((item) => {
|
|
28
|
+
if (item.$.uid !== comp.$.uid) {
|
|
29
|
+
item.$.exposed.close()
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function closeOutside() {
|
|
35
|
+
queue.value.forEach((item) => {
|
|
36
|
+
item.$.exposed.close()
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
provide(queueKey, {
|
|
41
|
+
queue,
|
|
42
|
+
pushToQueue,
|
|
43
|
+
removeFromQueue,
|
|
44
|
+
closeOther,
|
|
45
|
+
closeOutside,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
closeOther,
|
|
50
|
+
closeOutside,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ref, onUnmounted } from 'vue'
|
|
2
|
+
import { isDef, isH5, isNumber } from '../common/util'
|
|
3
|
+
|
|
4
|
+
// 定义回调函数类型
|
|
5
|
+
type RafCallback = (time: number) => void
|
|
6
|
+
|
|
7
|
+
export function useRaf(callback: RafCallback) {
|
|
8
|
+
const requestRef = ref<number | null | ReturnType<typeof setTimeout>>(null)
|
|
9
|
+
|
|
10
|
+
// 启动动画帧
|
|
11
|
+
const start = () => {
|
|
12
|
+
const handle = (time: number) => {
|
|
13
|
+
callback(time)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (isH5) {
|
|
17
|
+
requestRef.value = requestAnimationFrame(handle)
|
|
18
|
+
} else {
|
|
19
|
+
requestRef.value = setTimeout(() => handle(Date.now()), 1000 / 30)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 取消动画帧
|
|
24
|
+
const cancel = () => {
|
|
25
|
+
if (isH5 && isNumber(requestRef.value)) {
|
|
26
|
+
cancelAnimationFrame(requestRef.value!)
|
|
27
|
+
} else if (isDef(requestRef.value)) {
|
|
28
|
+
clearTimeout(requestRef.value)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
onUnmounted(() => {
|
|
33
|
+
cancel()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return { start, cancel }
|
|
37
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
export function useTouch() {
|
|
4
|
+
const direction = ref<string>('')
|
|
5
|
+
const deltaX = ref<number>(0)
|
|
6
|
+
const deltaY = ref<number>(0)
|
|
7
|
+
const offsetX = ref<number>(0)
|
|
8
|
+
const offsetY = ref<number>(0)
|
|
9
|
+
const startX = ref<number>(0)
|
|
10
|
+
const startY = ref<number>(0)
|
|
11
|
+
|
|
12
|
+
function touchStart(event: any) {
|
|
13
|
+
const touch = event.touches[0]
|
|
14
|
+
direction.value = ''
|
|
15
|
+
deltaX.value = 0
|
|
16
|
+
deltaY.value = 0
|
|
17
|
+
offsetX.value = 0
|
|
18
|
+
offsetY.value = 0
|
|
19
|
+
startX.value = touch.clientX
|
|
20
|
+
startY.value = touch.clientY
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function touchMove(event: any) {
|
|
24
|
+
const touch = event.touches[0]
|
|
25
|
+
deltaX.value = touch.clientX - startX.value
|
|
26
|
+
deltaY.value = touch.clientY - startY.value
|
|
27
|
+
offsetX.value = Math.abs(deltaX.value)
|
|
28
|
+
offsetY.value = Math.abs(deltaY.value)
|
|
29
|
+
direction.value =
|
|
30
|
+
offsetX.value > offsetY.value ? 'horizontal' : offsetX.value < offsetY.value ? 'vertical' : ''
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
touchStart,
|
|
35
|
+
touchMove,
|
|
36
|
+
direction,
|
|
37
|
+
deltaX,
|
|
38
|
+
deltaY,
|
|
39
|
+
offsetX,
|
|
40
|
+
offsetY,
|
|
41
|
+
startX,
|
|
42
|
+
startY,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: weisheng
|
|
3
|
+
* @Date: 2024-01-25 23:06:48
|
|
4
|
+
* @LastEditTime: 2024-01-26 14:00:48
|
|
5
|
+
* @LastEditors: weisheng
|
|
6
|
+
* @Description:
|
|
7
|
+
* @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\composables\useTranslate.ts
|
|
8
|
+
* 记得注释
|
|
9
|
+
*/
|
|
10
|
+
import { camelCase, getPropByPath, isFunction } from '../common/util'
|
|
11
|
+
import Locale from '../../locale'
|
|
12
|
+
|
|
13
|
+
export const useTranslate = (name?: string) => {
|
|
14
|
+
const prefix = name ? camelCase(name) + '.' : ''
|
|
15
|
+
const translate = (key: string, ...args: unknown[]) => {
|
|
16
|
+
const currentMessages = Locale.messages()
|
|
17
|
+
const message = getPropByPath(currentMessages, prefix + key)
|
|
18
|
+
return isFunction(message) ? message(...args) : message
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return { translate }
|
|
22
|
+
}
|