@wot-ui/ui 1.0.0 → 2.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +134 -0
- package/attributes.json +1 -0
- package/changelog.md +63 -0
- package/common/AbortablePromise.ts +28 -0
- package/common/canvasHelper.ts +49 -0
- package/common/clickoutside.ts +25 -0
- package/common/event.ts +8 -0
- package/common/formatDate.ts +68 -0
- package/common/interceptor.ts +43 -0
- package/common/props.ts +53 -0
- package/common/util.ts +836 -0
- package/components/wd-action-sheet/index.scss +232 -0
- package/components/wd-action-sheet/types.ts +155 -0
- package/components/wd-action-sheet/wd-action-sheet.vue +176 -0
- package/components/wd-avatar/index.scss +150 -0
- package/components/wd-avatar/types.ts +98 -0
- package/components/wd-avatar/wd-avatar.vue +184 -0
- package/components/wd-avatar-group/index.scss +11 -0
- package/components/wd-avatar-group/types.ts +61 -0
- package/components/wd-avatar-group/wd-avatar-group.vue +115 -0
- package/components/wd-backtop/index.scss +67 -0
- package/components/wd-backtop/types.ts +66 -0
- package/components/wd-backtop/wd-backtop.vue +57 -0
- package/components/wd-badge/index.scss +116 -0
- package/components/wd-badge/types.ts +94 -0
- package/components/wd-badge/wd-badge.vue +78 -0
- package/components/wd-button/index.scss +436 -0
- package/components/wd-button/types.ts +204 -0
- package/components/wd-button/wd-button.vue +210 -0
- package/components/wd-calendar/index.scss +97 -0
- package/components/wd-calendar/types.ts +221 -0
- package/components/wd-calendar/wd-calendar.vue +339 -0
- package/components/wd-calendar-view/index.scss +41 -0
- package/components/wd-calendar-view/month/index.scss +144 -0
- package/components/wd-calendar-view/month/month.vue +389 -0
- package/components/wd-calendar-view/month/types.ts +70 -0
- package/components/wd-calendar-view/monthPanel/index.scss +84 -0
- package/components/wd-calendar-view/monthPanel/month-panel.vue +541 -0
- package/components/wd-calendar-view/monthPanel/types.ts +151 -0
- package/components/wd-calendar-view/types.ts +166 -0
- package/components/wd-calendar-view/utils.ts +318 -0
- package/components/wd-calendar-view/wd-calendar-view.vue +117 -0
- package/components/wd-calendar-view/year/index.scss +148 -0
- package/components/wd-calendar-view/year/types.ts +74 -0
- package/components/wd-calendar-view/year/year.vue +206 -0
- package/components/wd-calendar-view/yearPanel/index.scss +42 -0
- package/components/wd-calendar-view/yearPanel/types.ts +96 -0
- package/components/wd-calendar-view/yearPanel/year-panel.vue +249 -0
- package/components/wd-card/index.scss +104 -0
- package/components/wd-card/types.ts +47 -0
- package/components/wd-card/wd-card.vue +38 -0
- package/components/wd-cascader/index.scss +154 -0
- package/components/wd-cascader/types.ts +191 -0
- package/components/wd-cascader/wd-cascader.vue +589 -0
- package/components/wd-cell/index.scss +244 -0
- package/components/wd-cell/types.ts +205 -0
- package/components/wd-cell/wd-cell.vue +172 -0
- package/components/wd-cell-group/index.scss +53 -0
- package/components/wd-cell-group/types.ts +97 -0
- package/components/wd-cell-group/wd-cell-group.vue +48 -0
- package/components/wd-checkbox/index.scss +166 -0
- package/components/wd-checkbox/types.ts +118 -0
- package/components/wd-checkbox/wd-checkbox.vue +216 -0
- package/components/wd-checkbox-group/index.scss +5 -0
- package/components/wd-checkbox-group/types.ts +93 -0
- package/components/wd-checkbox-group/wd-checkbox-group.vue +148 -0
- package/components/wd-circle/index.scss +28 -0
- package/components/wd-circle/types.ts +54 -0
- package/components/wd-circle/wd-circle.vue +306 -0
- package/components/wd-col/index.scss +5 -0
- package/components/wd-col/types.ts +16 -0
- package/components/wd-col/wd-col.vue +83 -0
- package/components/wd-collapse/index.scss +71 -0
- package/components/wd-collapse/types.ts +68 -0
- package/components/wd-collapse/wd-collapse.vue +165 -0
- package/components/wd-collapse-item/index.scss +86 -0
- package/components/wd-collapse-item/types.ts +62 -0
- package/components/wd-collapse-item/wd-collapse-item.vue +184 -0
- package/components/wd-config-provider/index.scss +10 -0
- package/components/wd-config-provider/types.ts +2061 -0
- package/components/wd-config-provider/wd-config-provider.vue +61 -0
- package/components/wd-count-down/index.scss +16 -0
- package/components/wd-count-down/types.ts +58 -0
- package/components/wd-count-down/utils.ts +52 -0
- package/components/wd-count-down/wd-count-down.vue +62 -0
- package/components/wd-count-to/index.scss +25 -0
- package/components/wd-count-to/types.ts +121 -0
- package/components/wd-count-to/wd-count-to.vue +126 -0
- package/components/wd-curtain/index.scss +96 -0
- package/components/wd-curtain/types.ts +82 -0
- package/components/wd-curtain/wd-curtain.vue +172 -0
- package/components/wd-datetime-picker/index.scss +133 -0
- package/components/wd-datetime-picker/types.ts +198 -0
- package/components/wd-datetime-picker/wd-datetime-picker.vue +526 -0
- package/components/wd-datetime-picker-view/types.ts +171 -0
- package/components/wd-datetime-picker-view/util.ts +30 -0
- package/components/wd-datetime-picker-view/wd-datetime-picker-view.vue +402 -0
- package/components/wd-dialog/index.scss +281 -0
- package/components/wd-dialog/index.ts +168 -0
- package/components/wd-dialog/types.ts +452 -0
- package/components/wd-dialog/wd-dialog.vue +586 -0
- package/components/wd-divider/index.scss +122 -0
- package/components/wd-divider/types.ts +50 -0
- package/components/wd-divider/wd-divider.vue +54 -0
- package/components/wd-drop-menu/index.scss +90 -0
- package/components/wd-drop-menu/types.ts +38 -0
- package/components/wd-drop-menu/wd-drop-menu.vue +168 -0
- package/components/wd-drop-menu-item/index.scss +96 -0
- package/components/wd-drop-menu-item/types.ts +93 -0
- package/components/wd-drop-menu-item/wd-drop-menu-item.vue +205 -0
- package/components/wd-empty/index.scss +46 -0
- package/components/wd-empty/types.ts +37 -0
- package/components/wd-empty/wd-empty.vue +47 -0
- package/components/wd-fab/index.scss +124 -0
- package/components/wd-fab/types.ts +119 -0
- package/components/wd-fab/wd-fab.vue +322 -0
- package/components/wd-floating-panel/index.scss +73 -0
- package/components/wd-floating-panel/type.ts +32 -0
- package/components/wd-floating-panel/wd-floating-panel.vue +142 -0
- package/components/wd-form/adapters/zod.ts +56 -0
- package/components/wd-form/index.ts +2 -0
- package/components/wd-form/types.ts +133 -0
- package/components/wd-form/wd-form.vue +121 -0
- package/components/wd-form-item/index.scss +26 -0
- package/components/wd-form-item/types.ts +134 -0
- package/components/wd-form-item/wd-form-item.vue +182 -0
- package/components/wd-gap/index.scss +9 -0
- package/components/wd-gap/types.ts +26 -0
- package/components/wd-gap/wd-gap.vue +38 -0
- package/components/wd-grid/index.scss +11 -0
- package/components/wd-grid/types.ts +97 -0
- package/components/wd-grid/wd-grid.vue +48 -0
- package/components/wd-grid-item/index.scss +187 -0
- package/components/wd-grid-item/types.ts +98 -0
- package/components/wd-grid-item/wd-grid-item.vue +295 -0
- package/components/wd-icon/index.scss +46 -0
- package/components/wd-icon/types.ts +44 -0
- package/components/wd-icon/wd-icon.vue +66 -0
- package/components/wd-image-preview/index.scss +94 -0
- package/components/wd-image-preview/index.ts +95 -0
- package/components/wd-image-preview/types.ts +165 -0
- package/components/wd-image-preview/wd-image-preview.vue +233 -0
- package/components/wd-img/index.scss +82 -0
- package/components/wd-img/types.ts +96 -0
- package/components/wd-img/wd-img.vue +91 -0
- package/components/wd-img-cropper/index.scss +259 -0
- package/components/wd-img-cropper/types.ts +101 -0
- package/components/wd-img-cropper/wd-img-cropper.vue +653 -0
- package/components/wd-index-anchor/index.scss +34 -0
- package/components/wd-index-anchor/type.ts +9 -0
- package/components/wd-index-anchor/wd-index-anchor.vue +55 -0
- package/components/wd-index-bar/index.scss +68 -0
- package/components/wd-index-bar/type.ts +23 -0
- package/components/wd-index-bar/wd-index-bar.vue +157 -0
- package/components/wd-input/index.scss +129 -0
- package/components/wd-input/types.ts +165 -0
- package/components/wd-input/wd-input.vue +237 -0
- package/components/wd-input-number/index.scss +233 -0
- package/components/wd-input-number/types.ts +131 -0
- package/components/wd-input-number/wd-input-number.vue +473 -0
- package/components/wd-keyboard/constants.ts +81 -0
- package/components/wd-keyboard/index.scss +104 -0
- package/components/wd-keyboard/key/index.scss +103 -0
- package/components/wd-keyboard/key/index.vue +84 -0
- package/components/wd-keyboard/key/types.ts +44 -0
- package/components/wd-keyboard/types.ts +138 -0
- package/components/wd-keyboard/wd-keyboard.vue +236 -0
- package/components/wd-loading/index.scss +205 -0
- package/components/wd-loading/types.ts +61 -0
- package/components/wd-loading/wd-loading.vue +70 -0
- package/components/wd-loadmore/index.scss +62 -0
- package/components/wd-loadmore/types.ts +42 -0
- package/components/wd-loadmore/wd-loadmore.vue +68 -0
- package/components/wd-navbar/index.scss +96 -0
- package/components/wd-navbar/types.ts +74 -0
- package/components/wd-navbar/wd-navbar.vue +136 -0
- package/components/wd-navbar-capsule/index.scss +70 -0
- package/components/wd-navbar-capsule/types.ts +11 -0
- package/components/wd-navbar-capsule/wd-navbar-capsule.vue +48 -0
- package/components/wd-notice-bar/index.scss +94 -0
- package/components/wd-notice-bar/types.ts +97 -0
- package/components/wd-notice-bar/wd-notice-bar.vue +270 -0
- package/components/wd-notify/index.scss +114 -0
- package/components/wd-notify/index.ts +63 -0
- package/components/wd-notify/types.ts +130 -0
- package/components/wd-notify/wd-notify.vue +162 -0
- package/components/wd-overlay/index.scss +14 -0
- package/components/wd-overlay/types.ts +42 -0
- package/components/wd-overlay/wd-overlay.vue +55 -0
- package/components/wd-pagination/index.scss +71 -0
- package/components/wd-pagination/types.ts +69 -0
- package/components/wd-pagination/wd-pagination.vue +118 -0
- package/components/wd-password-input/index.scss +134 -0
- package/components/wd-password-input/types.ts +42 -0
- package/components/wd-password-input/wd-password-input.vue +51 -0
- package/components/wd-picker/index.scss +72 -0
- package/components/wd-picker/types.ts +141 -0
- package/components/wd-picker/wd-picker.vue +220 -0
- package/components/wd-picker-view/index.scss +93 -0
- package/components/wd-picker-view/types.ts +145 -0
- package/components/wd-picker-view/useSelection.ts +385 -0
- package/components/wd-picker-view/wd-picker-view.vue +227 -0
- package/components/wd-popover/index.scss +117 -0
- package/components/wd-popover/types.ts +106 -0
- package/components/wd-popover/wd-popover.vue +212 -0
- package/components/wd-popup/index.scss +89 -0
- package/components/wd-popup/types.ts +110 -0
- package/components/wd-popup/wd-popup.vue +174 -0
- package/components/wd-progress/index.scss +155 -0
- package/components/wd-progress/types.ts +94 -0
- package/components/wd-progress/wd-progress.vue +249 -0
- package/components/wd-radio/index.scss +189 -0
- package/components/wd-radio/types.ts +64 -0
- package/components/wd-radio/wd-radio.vue +164 -0
- package/components/wd-radio-group/index.scss +5 -0
- package/components/wd-radio-group/types.ts +70 -0
- package/components/wd-radio-group/wd-radio-group.vue +53 -0
- package/components/wd-rate/index.scss +57 -0
- package/components/wd-rate/types.ts +86 -0
- package/components/wd-rate/wd-rate.vue +168 -0
- package/components/wd-resize/index.scss +31 -0
- package/components/wd-resize/types.ts +14 -0
- package/components/wd-resize/wd-resize.vue +157 -0
- package/components/wd-root-portal/wd-root-portal.vue +77 -0
- package/components/wd-row/index.scss +6 -0
- package/components/wd-row/types.ts +36 -0
- package/components/wd-row/wd-row.vue +88 -0
- package/components/wd-search/index.scss +171 -0
- package/components/wd-search/types.ts +107 -0
- package/components/wd-search/wd-search.vue +198 -0
- package/components/wd-segmented/index.scss +155 -0
- package/components/wd-segmented/types.ts +81 -0
- package/components/wd-segmented/wd-segmented.vue +169 -0
- package/components/wd-select-picker/index.scss +72 -0
- package/components/wd-select-picker/types.ts +72 -0
- package/components/wd-select-picker/wd-select-picker.vue +371 -0
- package/components/wd-sidebar/index.scss +25 -0
- package/components/wd-sidebar/types.ts +34 -0
- package/components/wd-sidebar/wd-sidebar.vue +57 -0
- package/components/wd-sidebar-item/index.scss +91 -0
- package/components/wd-sidebar-item/types.ts +28 -0
- package/components/wd-sidebar-item/wd-sidebar-item.vue +118 -0
- package/components/wd-signature/index.scss +42 -0
- package/components/wd-signature/types.ts +295 -0
- package/components/wd-signature/wd-signature.vue +664 -0
- package/components/wd-skeleton/index.scss +112 -0
- package/components/wd-skeleton/types.ts +124 -0
- package/components/wd-skeleton/wd-skeleton.vue +110 -0
- package/components/wd-slide-verify/index.scss +112 -0
- package/components/wd-slide-verify/types.ts +98 -0
- package/components/wd-slide-verify/wd-slide-verify.vue +222 -0
- package/components/wd-slider/index.scss +485 -0
- package/components/wd-slider/types.ts +166 -0
- package/components/wd-slider/wd-slider.vue +529 -0
- package/components/wd-sort-button/index.scss +126 -0
- package/components/wd-sort-button/types.ts +68 -0
- package/components/wd-sort-button/wd-sort-button.vue +67 -0
- package/components/wd-step/index.scss +366 -0
- package/components/wd-step/types.ts +43 -0
- package/components/wd-step/wd-step.vue +181 -0
- package/components/wd-steps/index.scss +7 -0
- package/components/wd-steps/types.ts +50 -0
- package/components/wd-steps/wd-steps.vue +39 -0
- package/components/wd-sticky/index.scss +9 -0
- package/components/wd-sticky/types.ts +13 -0
- package/components/wd-sticky/wd-sticky.vue +192 -0
- package/components/wd-sticky-box/index.scss +6 -0
- package/components/wd-sticky-box/types.ts +20 -0
- package/components/wd-sticky-box/wd-sticky-box.vue +157 -0
- package/components/wd-swipe-action/index.scss +22 -0
- package/components/wd-swipe-action/types.ts +87 -0
- package/components/wd-swipe-action/wd-swipe-action.vue +320 -0
- package/components/wd-swiper/index.scss +69 -0
- package/components/wd-swiper/types.ts +275 -0
- package/components/wd-swiper/wd-swiper.vue +332 -0
- package/components/wd-swiper-nav/index.scss +179 -0
- package/components/wd-swiper-nav/types.ts +42 -0
- package/components/wd-swiper-nav/wd-swiper-nav.vue +42 -0
- package/components/wd-switch/index.scss +177 -0
- package/components/wd-switch/types.ts +93 -0
- package/components/wd-switch/wd-switch.vue +107 -0
- package/components/wd-tab/index.scss +16 -0
- package/components/wd-tab/types.ts +45 -0
- package/components/wd-tab/wd-tab.vue +99 -0
- package/components/wd-tabbar/index.scss +71 -0
- package/components/wd-tabbar/types.ts +79 -0
- package/components/wd-tabbar/wd-tabbar.vue +109 -0
- package/components/wd-tabbar-item/index.scss +50 -0
- package/components/wd-tabbar-item/types.ts +45 -0
- package/components/wd-tabbar-item/wd-tabbar-item.vue +101 -0
- package/components/wd-table/index.scss +128 -0
- package/components/wd-table/types.ts +160 -0
- package/components/wd-table/wd-table.vue +331 -0
- package/components/wd-table-column/index.scss +15 -0
- package/components/wd-table-column/types.ts +81 -0
- package/components/wd-table-column/wd-table-column.vue +198 -0
- package/components/wd-tabs/index.scss +332 -0
- package/components/wd-tabs/types.ts +155 -0
- package/components/wd-tabs/wd-tabs.vue +508 -0
- package/components/wd-tag/index.scss +325 -0
- package/components/wd-tag/types.ts +90 -0
- package/components/wd-tag/wd-tag.vue +158 -0
- package/components/wd-text/index.scss +52 -0
- package/components/wd-text/types.ts +107 -0
- package/components/wd-text/wd-text.vue +141 -0
- package/components/wd-textarea/index.scss +112 -0
- package/components/wd-textarea/types.ts +151 -0
- package/components/wd-textarea/wd-textarea.vue +212 -0
- package/components/wd-toast/index.scss +92 -0
- package/components/wd-toast/index.ts +97 -0
- package/components/wd-toast/types.ts +190 -0
- package/components/wd-toast/wd-toast.vue +158 -0
- package/components/wd-tooltip/index.scss +77 -0
- package/components/wd-tooltip/types.ts +105 -0
- package/components/wd-tooltip/wd-tooltip.vue +169 -0
- package/components/wd-tour/index.scss +106 -0
- package/components/wd-tour/types.ts +268 -0
- package/components/wd-tour/wd-tour.vue +518 -0
- package/components/wd-transition/index.scss +67 -0
- package/components/wd-transition/types.ts +106 -0
- package/components/wd-transition/wd-transition.vue +238 -0
- package/components/wd-upload/index.scss +204 -0
- package/components/wd-upload/types.ts +390 -0
- package/components/wd-upload/wd-upload.vue +565 -0
- package/components/wd-video-preview/index.scss +54 -0
- package/components/wd-video-preview/index.ts +64 -0
- package/components/wd-video-preview/types.ts +66 -0
- package/components/wd-video-preview/wd-video-preview.vue +141 -0
- package/components/wd-watermark/index.scss +21 -0
- package/components/wd-watermark/types.ts +130 -0
- package/components/wd-watermark/wd-watermark.vue +718 -0
- package/components/wot-ui/wot-ui.vue +5 -0
- package/composables/index.ts +16 -0
- package/composables/useCell.ts +34 -0
- package/composables/useChildren.ts +120 -0
- package/composables/useConfigProvider.ts +45 -0
- package/composables/useCountDown.ts +138 -0
- package/composables/useDeviceInfo.ts +136 -0
- package/composables/useLockScroll.ts +37 -0
- package/composables/useParent.ts +51 -0
- package/composables/usePopover.ts +212 -0
- package/composables/useQueue.ts +52 -0
- package/composables/useRaf.ts +37 -0
- package/composables/useTouch.ts +43 -0
- package/composables/useTranslate.ts +12 -0
- package/composables/useUpload.ts +366 -0
- package/global.d.ts +106 -0
- package/index.ts +6 -0
- package/locale/index.ts +32 -0
- package/locale/lang/ar-SA.ts +150 -0
- package/locale/lang/de-DE.ts +150 -0
- package/locale/lang/en-US.ts +150 -0
- package/locale/lang/es-ES.ts +150 -0
- package/locale/lang/fr-FR.ts +150 -0
- package/locale/lang/ja-JP.ts +150 -0
- package/locale/lang/ko-KR.ts +150 -0
- package/locale/lang/pt-PT.ts +150 -0
- package/locale/lang/ru-RU.ts +150 -0
- package/locale/lang/th-TH.ts +150 -0
- package/locale/lang/tr-TR.ts +155 -0
- package/locale/lang/ug-CN.ts +154 -0
- package/locale/lang/vi-VN.ts +89 -0
- package/locale/lang/zh-CN.ts +154 -0
- package/locale/lang/zh-HK.ts +78 -0
- package/locale/lang/zh-TW.ts +78 -0
- package/package.json +1 -11
- package/styles/iconfont/iconfont.scss +1243 -0
- package/styles/mixin/_config.scss +7 -0
- package/styles/mixin/_function.scss +44 -0
- package/styles/mixin/_mixin.scss +473 -0
- package/styles/theme/base/color.scss +210 -0
- package/styles/theme/base/font.scss +13 -0
- package/styles/theme/base/index.scss +8 -0
- package/styles/theme/base/insets.scss +32 -0
- package/styles/theme/base/number.scss +36 -0
- package/styles/theme/base/opacity.scss +9 -0
- package/styles/theme/base/radius.scss +13 -0
- package/styles/theme/base/stroke.scss +9 -0
- package/styles/theme/base/typography.scss +44 -0
- package/styles/theme/dark.scss +101 -0
- package/styles/theme/index.scss +16 -0
- package/styles/theme/light.scss +101 -0
- package/styles/variable.scss +472 -0
- package/tags.json +1 -0
- package/web-types.json +1 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { useCell } from './useCell'
|
|
2
|
+
export { useChildren, flattenVNodes, sortChildren } from './useChildren'
|
|
3
|
+
export { useCountDown } from './useCountDown'
|
|
4
|
+
export { useLockScroll } from './useLockScroll'
|
|
5
|
+
export { useParent } from './useParent'
|
|
6
|
+
export { usePopover } from './usePopover'
|
|
7
|
+
export { useQueue } from './useQueue'
|
|
8
|
+
export { useRaf } from './useRaf'
|
|
9
|
+
export { useTouch } from './useTouch'
|
|
10
|
+
export { useTranslate } from './useTranslate'
|
|
11
|
+
export { useUpload } from './useUpload'
|
|
12
|
+
export { useConfigProvider } from './useConfigProvider'
|
|
13
|
+
export { useToast } from '../components/wd-toast'
|
|
14
|
+
export { useDialog } from '../components/wd-dialog'
|
|
15
|
+
export { useImagePreview } from '../components/wd-image-preview'
|
|
16
|
+
export { useNotify, setNotifyDefaultOptions, resetNotifyDefaultOptions } from '../components/wd-notify'
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { computed } from 'vue'
|
|
2
|
+
import { useParent } from './useParent'
|
|
3
|
+
import { CELL_GROUP_KEY } from '../components/wd-cell-group/types'
|
|
4
|
+
import type { CellLayout, CellSize, CellValueAlign } from '../components/wd-cell/types'
|
|
5
|
+
|
|
6
|
+
export function useCell() {
|
|
7
|
+
const { parent: cellGroup, index } = useParent(CELL_GROUP_KEY)
|
|
8
|
+
|
|
9
|
+
const border = computed(() => {
|
|
10
|
+
return cellGroup?.value && cellGroup.value.props.border && index.value
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const center = computed(() => {
|
|
14
|
+
return cellGroup.value?.props.center
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const size = computed<CellSize | undefined>(() => {
|
|
18
|
+
return cellGroup.value?.props.size
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const titleWidth = computed(() => {
|
|
22
|
+
return cellGroup.value?.props.titleWidth
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const layout = computed<CellLayout | undefined>(() => {
|
|
26
|
+
return cellGroup.value?.props.layout || undefined
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const valueAlign = computed<CellValueAlign | undefined>(() => {
|
|
30
|
+
return cellGroup.value?.props.valueAlign || undefined
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return { border, center, size, titleWidth, layout, valueAlign }
|
|
34
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
function isVNode(value: any): value is VNode {
|
|
13
|
+
return value ? value.__v_isVNode === true : false
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function flattenVNodes(children: VNode) {
|
|
17
|
+
const result: VNode[] = []
|
|
18
|
+
|
|
19
|
+
const traverse = (children: VNode | VNodeNormalizedChildren) => {
|
|
20
|
+
const vNode = Array.isArray(children) ? children : [children]
|
|
21
|
+
vNode.forEach((child) => {
|
|
22
|
+
if (Array.isArray(child)) {
|
|
23
|
+
traverse(child)
|
|
24
|
+
} else if (isVNode(child) && child.component?.subTree) {
|
|
25
|
+
result.push(child)
|
|
26
|
+
traverse(child.component.subTree)
|
|
27
|
+
} else if (isVNode(child) && Array.isArray(child.children)) {
|
|
28
|
+
traverse(child.children)
|
|
29
|
+
} else if (isVNode(child)) {
|
|
30
|
+
result.push(child)
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
traverse(children)
|
|
36
|
+
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const findVNodeIndex = (vnodes: VNode[], vnode: VNode) => {
|
|
41
|
+
const index = vnodes.indexOf(vnode)
|
|
42
|
+
if (index === -1) {
|
|
43
|
+
return vnodes.findIndex((item) => vnode.key !== undefined && vnode.key !== null && item.type === vnode.type && item.key === vnode.key)
|
|
44
|
+
}
|
|
45
|
+
return index
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function sortChildren(
|
|
49
|
+
parent: ComponentInternalInstance,
|
|
50
|
+
publicChildren: ComponentPublicInstance[],
|
|
51
|
+
internalChildren: ComponentInternalInstance[]
|
|
52
|
+
) {
|
|
53
|
+
const vnodes = parent && parent.subTree && parent.subTree.children ? flattenVNodes(parent.subTree) : []
|
|
54
|
+
internalChildren.sort((a, b) => findVNodeIndex(vnodes, a.vnode) - findVNodeIndex(vnodes, b.vnode))
|
|
55
|
+
|
|
56
|
+
const orderedPublicChildren = internalChildren.map((item) => item.proxy!)
|
|
57
|
+
|
|
58
|
+
publicChildren.sort((a, b) => {
|
|
59
|
+
const getIndex = (comp: ComponentPublicInstance) => {
|
|
60
|
+
const uid = comp.$.uid
|
|
61
|
+
return orderedPublicChildren.findIndex((i) => i.$.uid === uid)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const indexA = getIndex(a)
|
|
65
|
+
const indexB = getIndex(b)
|
|
66
|
+
return indexA - indexB
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function useChildren<
|
|
71
|
+
// eslint-disable-next-line
|
|
72
|
+
Child extends ComponentPublicInstance = ComponentPublicInstance<{}, any>,
|
|
73
|
+
ProvideValue = never
|
|
74
|
+
>(key: InjectionKey<ProvideValue>) {
|
|
75
|
+
const publicChildren: Child[] = reactive([])
|
|
76
|
+
const internalChildren: ComponentInternalInstance[] = reactive([])
|
|
77
|
+
const parent = getCurrentInstance()!
|
|
78
|
+
|
|
79
|
+
const linkChildren = (value?: ProvideValue) => {
|
|
80
|
+
const link = (child: ComponentInternalInstance) => {
|
|
81
|
+
if (child.proxy) {
|
|
82
|
+
if (internalChildren.indexOf(child) === -1) {
|
|
83
|
+
// #ifdef MP-ALIPAY
|
|
84
|
+
internalChildren.unshift(child)
|
|
85
|
+
publicChildren.unshift(child.proxy as Child)
|
|
86
|
+
// #endif
|
|
87
|
+
// #ifndef MP-ALIPAY
|
|
88
|
+
internalChildren.push(child)
|
|
89
|
+
publicChildren.push(child.proxy as Child)
|
|
90
|
+
// #endif
|
|
91
|
+
sortChildren(parent, publicChildren, internalChildren)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const unlink = (child: ComponentInternalInstance) => {
|
|
97
|
+
const index = internalChildren.indexOf(child)
|
|
98
|
+
publicChildren.splice(index, 1)
|
|
99
|
+
internalChildren.splice(index, 1)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
provide(
|
|
103
|
+
key,
|
|
104
|
+
Object.assign(
|
|
105
|
+
{
|
|
106
|
+
link,
|
|
107
|
+
unlink,
|
|
108
|
+
children: publicChildren,
|
|
109
|
+
internalChildren
|
|
110
|
+
},
|
|
111
|
+
value
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
children: publicChildren,
|
|
118
|
+
linkChildren
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { computed, provide, unref, type Ref } from 'vue'
|
|
2
|
+
import { type ConfigProviderThemeVars } from '../components/wd-config-provider/types'
|
|
3
|
+
import { objToStyle } from '../common/util'
|
|
4
|
+
|
|
5
|
+
export const USE_CONFIG_PROVIDER_KEY = '__CONFIG_PROVIDER__'
|
|
6
|
+
|
|
7
|
+
export const kebabCase = (str: string): string => {
|
|
8
|
+
str = str.replace(str.charAt(0), str.charAt(0).toLocaleLowerCase())
|
|
9
|
+
return str
|
|
10
|
+
.replace(/([a-z])([A-Z])/g, (_, p1, p2) => p1 + '-' + p2.toLowerCase())
|
|
11
|
+
.replace(/([a-zA-Z])(\d)/g, '$1-$2')
|
|
12
|
+
.replace(/(\d)([a-zA-Z])/g, '$1-$2')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const mapThemeVarsToCSSVars = (themeVars: Record<string, string>) => {
|
|
16
|
+
if (!themeVars) return
|
|
17
|
+
const cssVars: Record<string, string> = {}
|
|
18
|
+
Object.keys(themeVars).forEach((key) => {
|
|
19
|
+
cssVars[`--wot-${kebabCase(key)}`] = themeVars[key]
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return cssVars
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function useConfigProvider({
|
|
26
|
+
themeVars,
|
|
27
|
+
theme
|
|
28
|
+
}: {
|
|
29
|
+
themeVars?: ConfigProviderThemeVars | Ref<ConfigProviderThemeVars>
|
|
30
|
+
theme?: string | Ref<string>
|
|
31
|
+
}) {
|
|
32
|
+
const themeStyle = computed(() => {
|
|
33
|
+
const styleObj = mapThemeVarsToCSSVars(unref(themeVars) || {})
|
|
34
|
+
return styleObj ? `${objToStyle(styleObj)}` : ''
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const themeValue = computed(() => {
|
|
38
|
+
return unref(theme) || 'light'
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
provide(USE_CONFIG_PROVIDER_KEY, {
|
|
42
|
+
themeStyle,
|
|
43
|
+
theme: themeValue
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -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,136 @@
|
|
|
1
|
+
import { ref, computed } from 'vue'
|
|
2
|
+
|
|
3
|
+
interface SafeArea {
|
|
4
|
+
left: number
|
|
5
|
+
right: number
|
|
6
|
+
top: number
|
|
7
|
+
bottom: number
|
|
8
|
+
width: number
|
|
9
|
+
height: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface CapsuleInfo {
|
|
13
|
+
width: number
|
|
14
|
+
height: number
|
|
15
|
+
left: number
|
|
16
|
+
right: number
|
|
17
|
+
top: number
|
|
18
|
+
bottom: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const safeArea = ref<SafeArea>({
|
|
22
|
+
left: 0,
|
|
23
|
+
right: 0,
|
|
24
|
+
top: 0,
|
|
25
|
+
bottom: 0,
|
|
26
|
+
width: 0,
|
|
27
|
+
height: 0
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const capsule = ref<CapsuleInfo>({
|
|
31
|
+
width: 0,
|
|
32
|
+
height: 0,
|
|
33
|
+
left: 0,
|
|
34
|
+
right: 0,
|
|
35
|
+
top: 0,
|
|
36
|
+
bottom: 0
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const statusBarHeight = ref<number>(0)
|
|
40
|
+
const screenWidth = ref<number>(0)
|
|
41
|
+
const screenHeight = ref<number>(0)
|
|
42
|
+
const windowWidth = ref<number>(0)
|
|
43
|
+
const windowHeight = ref<number>(0)
|
|
44
|
+
const initialized = ref<boolean>(false)
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 初始化设备信息
|
|
48
|
+
*/
|
|
49
|
+
function init() {
|
|
50
|
+
try {
|
|
51
|
+
// 获取系统信息
|
|
52
|
+
const systemInfo = uni.getSystemInfoSync()
|
|
53
|
+
// 更新安全区域信息
|
|
54
|
+
if (systemInfo.safeArea) {
|
|
55
|
+
safeArea.value = {
|
|
56
|
+
left: systemInfo.safeArea.left,
|
|
57
|
+
right: systemInfo.screenWidth - systemInfo.safeArea.right,
|
|
58
|
+
top: systemInfo.safeArea.top,
|
|
59
|
+
bottom: systemInfo.safeArea.bottom,
|
|
60
|
+
width: systemInfo.safeArea.width,
|
|
61
|
+
height: systemInfo.safeArea.height
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 更新状态栏高度
|
|
66
|
+
statusBarHeight.value = systemInfo.statusBarHeight || 0
|
|
67
|
+
|
|
68
|
+
// 更新屏幕尺寸
|
|
69
|
+
screenWidth.value = systemInfo.screenWidth
|
|
70
|
+
screenHeight.value = systemInfo.screenHeight
|
|
71
|
+
windowWidth.value = systemInfo.windowWidth
|
|
72
|
+
windowHeight.value = systemInfo.windowHeight
|
|
73
|
+
|
|
74
|
+
// 获取胶囊按钮信息
|
|
75
|
+
// #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO
|
|
76
|
+
const capsuleInfo = uni.getMenuButtonBoundingClientRect()
|
|
77
|
+
if (capsuleInfo) {
|
|
78
|
+
capsule.value = {
|
|
79
|
+
width: capsuleInfo.width,
|
|
80
|
+
height: capsuleInfo.height,
|
|
81
|
+
left: capsuleInfo.left,
|
|
82
|
+
right: systemInfo.screenWidth - capsuleInfo.right,
|
|
83
|
+
top: capsuleInfo.top,
|
|
84
|
+
bottom: capsuleInfo.bottom
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// #endif
|
|
88
|
+
|
|
89
|
+
initialized.value = true
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error('获取设备信息失败', error)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 更新设备信息
|
|
97
|
+
*/
|
|
98
|
+
function update() {
|
|
99
|
+
init()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function useDeviceInfo() {
|
|
103
|
+
// 确保至少初始化一次
|
|
104
|
+
if (!initialized.value) {
|
|
105
|
+
init()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 获取底部安全区域高度
|
|
109
|
+
const safeAreaBottomHeight = computed(() => screenHeight.value - safeArea.value.bottom)
|
|
110
|
+
|
|
111
|
+
// 获取顶部安全区域高度(包含状态栏)
|
|
112
|
+
const safeAreaTopHeight = computed(() => safeArea.value.top)
|
|
113
|
+
|
|
114
|
+
// 获取导航栏高度(不包含状态栏)
|
|
115
|
+
const navBarHeight = computed(() => capsule.value.height + (capsule.value.top - statusBarHeight.value) * 2)
|
|
116
|
+
|
|
117
|
+
// 获取导航栏整体高度(包含状态栏)
|
|
118
|
+
const navBarTotalHeight = computed(() => navBarHeight.value + statusBarHeight.value)
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
safeArea,
|
|
122
|
+
capsule,
|
|
123
|
+
statusBarHeight,
|
|
124
|
+
screenWidth,
|
|
125
|
+
screenHeight,
|
|
126
|
+
windowWidth,
|
|
127
|
+
windowHeight,
|
|
128
|
+
initialized,
|
|
129
|
+
safeAreaBottomHeight,
|
|
130
|
+
safeAreaTopHeight,
|
|
131
|
+
navBarHeight,
|
|
132
|
+
navBarTotalHeight,
|
|
133
|
+
init,
|
|
134
|
+
update
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { onBeforeUnmount, onDeactivated, ref, watch } from 'vue'
|
|
2
|
+
|
|
3
|
+
export 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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
shallowRef,
|
|
4
|
+
inject,
|
|
5
|
+
computed,
|
|
6
|
+
onUnmounted,
|
|
7
|
+
type InjectionKey,
|
|
8
|
+
getCurrentInstance,
|
|
9
|
+
type ComponentPublicInstance,
|
|
10
|
+
type ComponentInternalInstance,
|
|
11
|
+
onMounted,
|
|
12
|
+
type Ref
|
|
13
|
+
} from 'vue'
|
|
14
|
+
|
|
15
|
+
type ParentProvide<T> = T & {
|
|
16
|
+
link(child: ComponentInternalInstance): void
|
|
17
|
+
unlink(child: ComponentInternalInstance): void
|
|
18
|
+
children: ComponentPublicInstance[]
|
|
19
|
+
internalChildren: ComponentInternalInstance[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type UseParentResult<T> = {
|
|
23
|
+
parent: Ref<ParentProvide<T> | null>
|
|
24
|
+
index: Ref<number>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useParent<T>(key: InjectionKey<ParentProvide<T>>): UseParentResult<T> {
|
|
28
|
+
const result: UseParentResult<T> = {
|
|
29
|
+
parent: shallowRef<ParentProvide<T> | null>(null),
|
|
30
|
+
index: ref<number>(-1)
|
|
31
|
+
}
|
|
32
|
+
// #ifdef MP-TOUTIAO
|
|
33
|
+
onMounted(() => {
|
|
34
|
+
// #endif
|
|
35
|
+
result.parent.value = inject(key, null)
|
|
36
|
+
|
|
37
|
+
if (result.parent.value) {
|
|
38
|
+
const instance = getCurrentInstance()!
|
|
39
|
+
const { link, unlink, internalChildren } = result.parent.value
|
|
40
|
+
|
|
41
|
+
link(instance)
|
|
42
|
+
onUnmounted(() => unlink(instance))
|
|
43
|
+
|
|
44
|
+
result.index = computed(() => internalChildren.indexOf(instance))
|
|
45
|
+
}
|
|
46
|
+
// #ifdef MP-TOUTIAO
|
|
47
|
+
})
|
|
48
|
+
// #endif
|
|
49
|
+
|
|
50
|
+
return result
|
|
51
|
+
}
|