@wot-ui/ui 1.0.0 → 2.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +134 -0
- package/attributes.json +1 -0
- package/changelog.md +53 -0
- package/common/AbortablePromise.ts +28 -0
- package/common/canvasHelper.ts +49 -0
- package/common/clickoutside.ts +25 -0
- package/common/event.ts +8 -0
- package/common/formatDate.ts +68 -0
- package/common/interceptor.ts +43 -0
- package/common/props.ts +53 -0
- package/common/util.ts +836 -0
- package/components/wd-action-sheet/index.scss +232 -0
- package/components/wd-action-sheet/types.ts +155 -0
- package/components/wd-action-sheet/wd-action-sheet.vue +176 -0
- package/components/wd-avatar/index.scss +150 -0
- package/components/wd-avatar/types.ts +98 -0
- package/components/wd-avatar/wd-avatar.vue +184 -0
- package/components/wd-avatar-group/index.scss +11 -0
- package/components/wd-avatar-group/types.ts +61 -0
- package/components/wd-avatar-group/wd-avatar-group.vue +115 -0
- package/components/wd-backtop/index.scss +67 -0
- package/components/wd-backtop/types.ts +66 -0
- package/components/wd-backtop/wd-backtop.vue +57 -0
- package/components/wd-badge/index.scss +116 -0
- package/components/wd-badge/types.ts +94 -0
- package/components/wd-badge/wd-badge.vue +78 -0
- package/components/wd-button/index.scss +436 -0
- package/components/wd-button/types.ts +204 -0
- package/components/wd-button/wd-button.vue +210 -0
- package/components/wd-calendar/index.scss +97 -0
- package/components/wd-calendar/types.ts +221 -0
- package/components/wd-calendar/wd-calendar.vue +339 -0
- package/components/wd-calendar-view/index.scss +41 -0
- package/components/wd-calendar-view/month/index.scss +144 -0
- package/components/wd-calendar-view/month/month.vue +389 -0
- package/components/wd-calendar-view/month/types.ts +70 -0
- package/components/wd-calendar-view/monthPanel/index.scss +84 -0
- package/components/wd-calendar-view/monthPanel/month-panel.vue +541 -0
- package/components/wd-calendar-view/monthPanel/types.ts +151 -0
- package/components/wd-calendar-view/types.ts +166 -0
- package/components/wd-calendar-view/utils.ts +318 -0
- package/components/wd-calendar-view/wd-calendar-view.vue +117 -0
- package/components/wd-calendar-view/year/index.scss +148 -0
- package/components/wd-calendar-view/year/types.ts +74 -0
- package/components/wd-calendar-view/year/year.vue +206 -0
- package/components/wd-calendar-view/yearPanel/index.scss +42 -0
- package/components/wd-calendar-view/yearPanel/types.ts +96 -0
- package/components/wd-calendar-view/yearPanel/year-panel.vue +249 -0
- package/components/wd-card/index.scss +104 -0
- package/components/wd-card/types.ts +47 -0
- package/components/wd-card/wd-card.vue +38 -0
- package/components/wd-cascader/index.scss +154 -0
- package/components/wd-cascader/types.ts +191 -0
- package/components/wd-cascader/wd-cascader.vue +589 -0
- package/components/wd-cell/index.scss +244 -0
- package/components/wd-cell/types.ts +205 -0
- package/components/wd-cell/wd-cell.vue +172 -0
- package/components/wd-cell-group/index.scss +53 -0
- package/components/wd-cell-group/types.ts +97 -0
- package/components/wd-cell-group/wd-cell-group.vue +48 -0
- package/components/wd-checkbox/index.scss +166 -0
- package/components/wd-checkbox/types.ts +118 -0
- package/components/wd-checkbox/wd-checkbox.vue +216 -0
- package/components/wd-checkbox-group/index.scss +5 -0
- package/components/wd-checkbox-group/types.ts +93 -0
- package/components/wd-checkbox-group/wd-checkbox-group.vue +148 -0
- package/components/wd-circle/index.scss +28 -0
- package/components/wd-circle/types.ts +54 -0
- package/components/wd-circle/wd-circle.vue +306 -0
- package/components/wd-col/index.scss +5 -0
- package/components/wd-col/types.ts +16 -0
- package/components/wd-col/wd-col.vue +83 -0
- package/components/wd-collapse/index.scss +71 -0
- package/components/wd-collapse/types.ts +68 -0
- package/components/wd-collapse/wd-collapse.vue +165 -0
- package/components/wd-collapse-item/index.scss +86 -0
- package/components/wd-collapse-item/types.ts +62 -0
- package/components/wd-collapse-item/wd-collapse-item.vue +184 -0
- package/components/wd-config-provider/index.scss +10 -0
- package/components/wd-config-provider/types.ts +2063 -0
- package/components/wd-config-provider/wd-config-provider.vue +61 -0
- package/components/wd-count-down/index.scss +16 -0
- package/components/wd-count-down/types.ts +58 -0
- package/components/wd-count-down/utils.ts +52 -0
- package/components/wd-count-down/wd-count-down.vue +62 -0
- package/components/wd-count-to/index.scss +25 -0
- package/components/wd-count-to/types.ts +121 -0
- package/components/wd-count-to/wd-count-to.vue +126 -0
- package/components/wd-curtain/index.scss +96 -0
- package/components/wd-curtain/types.ts +82 -0
- package/components/wd-curtain/wd-curtain.vue +172 -0
- package/components/wd-datetime-picker/index.scss +133 -0
- package/components/wd-datetime-picker/types.ts +198 -0
- package/components/wd-datetime-picker/wd-datetime-picker.vue +526 -0
- package/components/wd-datetime-picker-view/types.ts +171 -0
- package/components/wd-datetime-picker-view/util.ts +30 -0
- package/components/wd-datetime-picker-view/wd-datetime-picker-view.vue +402 -0
- package/components/wd-dialog/index.scss +281 -0
- package/components/wd-dialog/index.ts +168 -0
- package/components/wd-dialog/types.ts +452 -0
- package/components/wd-dialog/wd-dialog.vue +586 -0
- package/components/wd-divider/index.scss +122 -0
- package/components/wd-divider/types.ts +50 -0
- package/components/wd-divider/wd-divider.vue +54 -0
- package/components/wd-drop-menu/index.scss +90 -0
- package/components/wd-drop-menu/types.ts +38 -0
- package/components/wd-drop-menu/wd-drop-menu.vue +168 -0
- package/components/wd-drop-menu-item/index.scss +96 -0
- package/components/wd-drop-menu-item/types.ts +93 -0
- package/components/wd-drop-menu-item/wd-drop-menu-item.vue +205 -0
- package/components/wd-empty/index.scss +46 -0
- package/components/wd-empty/types.ts +37 -0
- package/components/wd-empty/wd-empty.vue +47 -0
- package/components/wd-fab/index.scss +124 -0
- package/components/wd-fab/types.ts +119 -0
- package/components/wd-fab/wd-fab.vue +322 -0
- package/components/wd-floating-panel/index.scss +73 -0
- package/components/wd-floating-panel/type.ts +32 -0
- package/components/wd-floating-panel/wd-floating-panel.vue +142 -0
- package/components/wd-form/adapters/zod.ts +56 -0
- package/components/wd-form/types.ts +147 -0
- package/components/wd-form/wd-form.vue +121 -0
- package/components/wd-form-item/index.scss +26 -0
- package/components/wd-form-item/types.ts +134 -0
- package/components/wd-form-item/wd-form-item.vue +182 -0
- package/components/wd-gap/index.scss +9 -0
- package/components/wd-gap/types.ts +26 -0
- package/components/wd-gap/wd-gap.vue +38 -0
- package/components/wd-grid/index.scss +11 -0
- package/components/wd-grid/types.ts +97 -0
- package/components/wd-grid/wd-grid.vue +48 -0
- package/components/wd-grid-item/index.scss +187 -0
- package/components/wd-grid-item/types.ts +98 -0
- package/components/wd-grid-item/wd-grid-item.vue +295 -0
- package/components/wd-icon/index.scss +46 -0
- package/components/wd-icon/types.ts +44 -0
- package/components/wd-icon/wd-icon.vue +66 -0
- package/components/wd-image-preview/index.scss +94 -0
- package/components/wd-image-preview/index.ts +95 -0
- package/components/wd-image-preview/types.ts +165 -0
- package/components/wd-image-preview/wd-image-preview.vue +233 -0
- package/components/wd-img/index.scss +82 -0
- package/components/wd-img/types.ts +96 -0
- package/components/wd-img/wd-img.vue +91 -0
- package/components/wd-img-cropper/index.scss +259 -0
- package/components/wd-img-cropper/types.ts +101 -0
- package/components/wd-img-cropper/wd-img-cropper.vue +653 -0
- package/components/wd-index-anchor/index.scss +34 -0
- package/components/wd-index-anchor/type.ts +9 -0
- package/components/wd-index-anchor/wd-index-anchor.vue +55 -0
- package/components/wd-index-bar/index.scss +68 -0
- package/components/wd-index-bar/type.ts +23 -0
- package/components/wd-index-bar/wd-index-bar.vue +157 -0
- package/components/wd-input/index.scss +129 -0
- package/components/wd-input/types.ts +165 -0
- package/components/wd-input/wd-input.vue +237 -0
- package/components/wd-input-number/index.scss +233 -0
- package/components/wd-input-number/types.ts +131 -0
- package/components/wd-input-number/wd-input-number.vue +473 -0
- package/components/wd-keyboard/constants.ts +81 -0
- package/components/wd-keyboard/index.scss +104 -0
- package/components/wd-keyboard/key/index.scss +103 -0
- package/components/wd-keyboard/key/index.vue +84 -0
- package/components/wd-keyboard/key/types.ts +44 -0
- package/components/wd-keyboard/types.ts +138 -0
- package/components/wd-keyboard/wd-keyboard.vue +236 -0
- package/components/wd-loading/index.scss +205 -0
- package/components/wd-loading/types.ts +61 -0
- package/components/wd-loading/wd-loading.vue +70 -0
- package/components/wd-loadmore/index.scss +62 -0
- package/components/wd-loadmore/types.ts +42 -0
- package/components/wd-loadmore/wd-loadmore.vue +68 -0
- package/components/wd-navbar/index.scss +96 -0
- package/components/wd-navbar/types.ts +74 -0
- package/components/wd-navbar/wd-navbar.vue +136 -0
- package/components/wd-navbar-capsule/index.scss +70 -0
- package/components/wd-navbar-capsule/types.ts +11 -0
- package/components/wd-navbar-capsule/wd-navbar-capsule.vue +48 -0
- package/components/wd-notice-bar/index.scss +94 -0
- package/components/wd-notice-bar/types.ts +97 -0
- package/components/wd-notice-bar/wd-notice-bar.vue +270 -0
- package/components/wd-notify/index.scss +114 -0
- package/components/wd-notify/index.ts +63 -0
- package/components/wd-notify/types.ts +130 -0
- package/components/wd-notify/wd-notify.vue +162 -0
- package/components/wd-overlay/index.scss +14 -0
- package/components/wd-overlay/types.ts +42 -0
- package/components/wd-overlay/wd-overlay.vue +55 -0
- package/components/wd-pagination/index.scss +71 -0
- package/components/wd-pagination/types.ts +69 -0
- package/components/wd-pagination/wd-pagination.vue +118 -0
- package/components/wd-password-input/index.scss +134 -0
- package/components/wd-password-input/types.ts +42 -0
- package/components/wd-password-input/wd-password-input.vue +51 -0
- package/components/wd-picker/index.scss +72 -0
- package/components/wd-picker/types.ts +141 -0
- package/components/wd-picker/wd-picker.vue +220 -0
- package/components/wd-picker-view/index.scss +93 -0
- package/components/wd-picker-view/types.ts +145 -0
- package/components/wd-picker-view/useSelection.ts +385 -0
- package/components/wd-picker-view/wd-picker-view.vue +227 -0
- package/components/wd-popover/index.scss +117 -0
- package/components/wd-popover/types.ts +106 -0
- package/components/wd-popover/wd-popover.vue +212 -0
- package/components/wd-popup/index.scss +89 -0
- package/components/wd-popup/types.ts +110 -0
- package/components/wd-popup/wd-popup.vue +174 -0
- package/components/wd-progress/index.scss +155 -0
- package/components/wd-progress/types.ts +94 -0
- package/components/wd-progress/wd-progress.vue +249 -0
- package/components/wd-radio/index.scss +189 -0
- package/components/wd-radio/types.ts +64 -0
- package/components/wd-radio/wd-radio.vue +164 -0
- package/components/wd-radio-group/index.scss +5 -0
- package/components/wd-radio-group/types.ts +70 -0
- package/components/wd-radio-group/wd-radio-group.vue +53 -0
- package/components/wd-rate/index.scss +57 -0
- package/components/wd-rate/types.ts +86 -0
- package/components/wd-rate/wd-rate.vue +168 -0
- package/components/wd-resize/index.scss +31 -0
- package/components/wd-resize/types.ts +14 -0
- package/components/wd-resize/wd-resize.vue +157 -0
- package/components/wd-root-portal/wd-root-portal.vue +77 -0
- package/components/wd-row/index.scss +6 -0
- package/components/wd-row/types.ts +36 -0
- package/components/wd-row/wd-row.vue +88 -0
- package/components/wd-search/index.scss +171 -0
- package/components/wd-search/types.ts +107 -0
- package/components/wd-search/wd-search.vue +198 -0
- package/components/wd-segmented/index.scss +155 -0
- package/components/wd-segmented/types.ts +81 -0
- package/components/wd-segmented/wd-segmented.vue +169 -0
- package/components/wd-select-picker/index.scss +72 -0
- package/components/wd-select-picker/types.ts +72 -0
- package/components/wd-select-picker/wd-select-picker.vue +371 -0
- package/components/wd-sidebar/index.scss +25 -0
- package/components/wd-sidebar/types.ts +34 -0
- package/components/wd-sidebar/wd-sidebar.vue +57 -0
- package/components/wd-sidebar-item/index.scss +91 -0
- package/components/wd-sidebar-item/types.ts +28 -0
- package/components/wd-sidebar-item/wd-sidebar-item.vue +118 -0
- package/components/wd-signature/index.scss +42 -0
- package/components/wd-signature/types.ts +295 -0
- package/components/wd-signature/wd-signature.vue +664 -0
- package/components/wd-skeleton/index.scss +112 -0
- package/components/wd-skeleton/types.ts +124 -0
- package/components/wd-skeleton/wd-skeleton.vue +110 -0
- package/components/wd-slide-verify/index.scss +112 -0
- package/components/wd-slide-verify/types.ts +98 -0
- package/components/wd-slide-verify/wd-slide-verify.vue +222 -0
- package/components/wd-slider/index.scss +485 -0
- package/components/wd-slider/types.ts +166 -0
- package/components/wd-slider/wd-slider.vue +529 -0
- package/components/wd-sort-button/index.scss +126 -0
- package/components/wd-sort-button/types.ts +68 -0
- package/components/wd-sort-button/wd-sort-button.vue +67 -0
- package/components/wd-step/index.scss +366 -0
- package/components/wd-step/types.ts +43 -0
- package/components/wd-step/wd-step.vue +181 -0
- package/components/wd-steps/index.scss +7 -0
- package/components/wd-steps/types.ts +50 -0
- package/components/wd-steps/wd-steps.vue +39 -0
- package/components/wd-sticky/index.scss +9 -0
- package/components/wd-sticky/types.ts +13 -0
- package/components/wd-sticky/wd-sticky.vue +192 -0
- package/components/wd-sticky-box/index.scss +6 -0
- package/components/wd-sticky-box/types.ts +20 -0
- package/components/wd-sticky-box/wd-sticky-box.vue +157 -0
- package/components/wd-swipe-action/index.scss +22 -0
- package/components/wd-swipe-action/types.ts +87 -0
- package/components/wd-swipe-action/wd-swipe-action.vue +320 -0
- package/components/wd-swiper/index.scss +69 -0
- package/components/wd-swiper/types.ts +275 -0
- package/components/wd-swiper/wd-swiper.vue +332 -0
- package/components/wd-swiper-nav/index.scss +179 -0
- package/components/wd-swiper-nav/types.ts +42 -0
- package/components/wd-swiper-nav/wd-swiper-nav.vue +42 -0
- package/components/wd-switch/index.scss +177 -0
- package/components/wd-switch/types.ts +93 -0
- package/components/wd-switch/wd-switch.vue +107 -0
- package/components/wd-tab/index.scss +16 -0
- package/components/wd-tab/types.ts +45 -0
- package/components/wd-tab/wd-tab.vue +99 -0
- package/components/wd-tabbar/index.scss +71 -0
- package/components/wd-tabbar/types.ts +79 -0
- package/components/wd-tabbar/wd-tabbar.vue +109 -0
- package/components/wd-tabbar-item/index.scss +50 -0
- package/components/wd-tabbar-item/types.ts +45 -0
- package/components/wd-tabbar-item/wd-tabbar-item.vue +101 -0
- package/components/wd-table/index.scss +128 -0
- package/components/wd-table/types.ts +160 -0
- package/components/wd-table/wd-table.vue +331 -0
- package/components/wd-table-column/index.scss +15 -0
- package/components/wd-table-column/types.ts +81 -0
- package/components/wd-table-column/wd-table-column.vue +198 -0
- package/components/wd-tabs/index.scss +332 -0
- package/components/wd-tabs/types.ts +155 -0
- package/components/wd-tabs/wd-tabs.vue +508 -0
- package/components/wd-tag/index.scss +325 -0
- package/components/wd-tag/types.ts +90 -0
- package/components/wd-tag/wd-tag.vue +158 -0
- package/components/wd-text/index.scss +52 -0
- package/components/wd-text/types.ts +107 -0
- package/components/wd-text/wd-text.vue +141 -0
- package/components/wd-textarea/index.scss +112 -0
- package/components/wd-textarea/types.ts +151 -0
- package/components/wd-textarea/wd-textarea.vue +212 -0
- package/components/wd-toast/index.scss +92 -0
- package/components/wd-toast/index.ts +97 -0
- package/components/wd-toast/types.ts +190 -0
- package/components/wd-toast/wd-toast.vue +158 -0
- package/components/wd-tooltip/index.scss +77 -0
- package/components/wd-tooltip/types.ts +105 -0
- package/components/wd-tooltip/wd-tooltip.vue +169 -0
- package/components/wd-tour/index.scss +106 -0
- package/components/wd-tour/types.ts +268 -0
- package/components/wd-tour/wd-tour.vue +518 -0
- package/components/wd-transition/index.scss +67 -0
- package/components/wd-transition/types.ts +106 -0
- package/components/wd-transition/wd-transition.vue +238 -0
- package/components/wd-upload/index.scss +204 -0
- package/components/wd-upload/types.ts +390 -0
- package/components/wd-upload/wd-upload.vue +565 -0
- package/components/wd-video-preview/index.scss +54 -0
- package/components/wd-video-preview/index.ts +64 -0
- package/components/wd-video-preview/types.ts +66 -0
- package/components/wd-video-preview/wd-video-preview.vue +141 -0
- package/components/wd-watermark/index.scss +21 -0
- package/components/wd-watermark/types.ts +130 -0
- package/components/wd-watermark/wd-watermark.vue +718 -0
- package/components/wot-ui/wot-ui.vue +5 -0
- package/composables/index.ts +12 -0
- package/composables/useCell.ts +34 -0
- package/composables/useChildren.ts +120 -0
- package/composables/useConfigProvider.ts +45 -0
- package/composables/useCountDown.ts +138 -0
- package/composables/useDeviceInfo.ts +136 -0
- package/composables/useLockScroll.ts +37 -0
- package/composables/useParent.ts +51 -0
- package/composables/usePopover.ts +212 -0
- package/composables/useQueue.ts +52 -0
- package/composables/useRaf.ts +37 -0
- package/composables/useTouch.ts +43 -0
- package/composables/useTranslate.ts +12 -0
- package/composables/useUpload.ts +366 -0
- package/global.d.ts +106 -0
- package/index.ts +11 -0
- package/locale/index.ts +32 -0
- package/locale/lang/ar-SA.ts +150 -0
- package/locale/lang/de-DE.ts +150 -0
- package/locale/lang/en-US.ts +150 -0
- package/locale/lang/es-ES.ts +150 -0
- package/locale/lang/fr-FR.ts +150 -0
- package/locale/lang/ja-JP.ts +150 -0
- package/locale/lang/ko-KR.ts +150 -0
- package/locale/lang/pt-PT.ts +150 -0
- package/locale/lang/ru-RU.ts +150 -0
- package/locale/lang/th-TH.ts +150 -0
- package/locale/lang/tr-TR.ts +155 -0
- package/locale/lang/ug-CN.ts +154 -0
- package/locale/lang/vi-VN.ts +89 -0
- package/locale/lang/zh-CN.ts +154 -0
- package/locale/lang/zh-HK.ts +78 -0
- package/locale/lang/zh-TW.ts +78 -0
- package/package.json +1 -11
- package/styles/iconfont/iconfont.scss +1243 -0
- package/styles/mixin/_config.scss +7 -0
- package/styles/mixin/_function.scss +44 -0
- package/styles/mixin/_mixin.scss +473 -0
- package/styles/theme/base/color.scss +210 -0
- package/styles/theme/base/font.scss +13 -0
- package/styles/theme/base/index.scss +8 -0
- package/styles/theme/base/insets.scss +32 -0
- package/styles/theme/base/number.scss +36 -0
- package/styles/theme/base/opacity.scss +9 -0
- package/styles/theme/base/radius.scss +13 -0
- package/styles/theme/base/stroke.scss +9 -0
- package/styles/theme/base/typography.scss +44 -0
- package/styles/theme/dark.scss +101 -0
- package/styles/theme/index.scss +16 -0
- package/styles/theme/light.scss +101 -0
- package/styles/variable.scss +472 -0
- package/tags.json +1 -0
- package/web-types.json +1 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { ComponentPublicInstance, ExtractPropTypes, PropType } from 'vue'
|
|
2
|
+
import { baseProps, makeArrayProp, makeBooleanProp, makeNumberProp, makeStringProp, type Numeric } from '../../common/props'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 选项对象
|
|
6
|
+
*/
|
|
7
|
+
export type PickerOption = {
|
|
8
|
+
/**
|
|
9
|
+
* 选项值
|
|
10
|
+
* 类型: string | number
|
|
11
|
+
*/
|
|
12
|
+
value?: Numeric
|
|
13
|
+
/**
|
|
14
|
+
* 选项显示文本
|
|
15
|
+
* 类型: string | number
|
|
16
|
+
*/
|
|
17
|
+
label?: Numeric
|
|
18
|
+
/**
|
|
19
|
+
* 是否禁用
|
|
20
|
+
* 类型: boolean
|
|
21
|
+
* 默认值: false
|
|
22
|
+
*/
|
|
23
|
+
disabled?: boolean
|
|
24
|
+
/**
|
|
25
|
+
* 子选项
|
|
26
|
+
* 类型: PickerOption[]
|
|
27
|
+
*/
|
|
28
|
+
children?: PickerOption[]
|
|
29
|
+
/**
|
|
30
|
+
* 允许额外的自定义属性
|
|
31
|
+
*/
|
|
32
|
+
[key: string]: any
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Use PickerOption instead
|
|
37
|
+
*/
|
|
38
|
+
export type ColumnItem = PickerOption
|
|
39
|
+
|
|
40
|
+
export const pickerViewProps = {
|
|
41
|
+
...baseProps,
|
|
42
|
+
/**
|
|
43
|
+
* 选项高度
|
|
44
|
+
* 类型: number
|
|
45
|
+
* 默认值: 44
|
|
46
|
+
*/
|
|
47
|
+
itemHeight: makeNumberProp(44),
|
|
48
|
+
/**
|
|
49
|
+
* 可见选项数量
|
|
50
|
+
* 类型: number
|
|
51
|
+
* 默认值: 6
|
|
52
|
+
*/
|
|
53
|
+
visibleItemCount: makeNumberProp(6),
|
|
54
|
+
/**
|
|
55
|
+
* 选项对象中,value对应的 key
|
|
56
|
+
* 类型: string
|
|
57
|
+
* 默认值: 'value'
|
|
58
|
+
*/
|
|
59
|
+
valueKey: makeStringProp('value'),
|
|
60
|
+
/**
|
|
61
|
+
* 选项对象中,展示的文本对应的 key
|
|
62
|
+
* 类型: string
|
|
63
|
+
* 默认值: 'label'
|
|
64
|
+
*/
|
|
65
|
+
labelKey: makeStringProp('label'),
|
|
66
|
+
/**
|
|
67
|
+
* 是否在手指松开时立即触发 picker-view 的 change 事件。若不开启则会在滚动动画结束后触发 change 事件
|
|
68
|
+
* 类型: boolean
|
|
69
|
+
* 默认值: false
|
|
70
|
+
*/
|
|
71
|
+
immediateChange: makeBooleanProp(false),
|
|
72
|
+
/**
|
|
73
|
+
* 是否开启级联模式
|
|
74
|
+
* 类型: boolean
|
|
75
|
+
* 默认值: false
|
|
76
|
+
*/
|
|
77
|
+
cascade: makeBooleanProp(false),
|
|
78
|
+
/**
|
|
79
|
+
* 选项对象中,children 对应的 key
|
|
80
|
+
* 类型: string
|
|
81
|
+
* 默认值: 'children'
|
|
82
|
+
*/
|
|
83
|
+
childrenKey: makeStringProp('children'),
|
|
84
|
+
/**
|
|
85
|
+
* 选中项
|
|
86
|
+
* 类型: (string | number)[]
|
|
87
|
+
* 默认值: []
|
|
88
|
+
*/
|
|
89
|
+
modelValue: makeArrayProp<Numeric>(),
|
|
90
|
+
/**
|
|
91
|
+
* 选择器数据,可以为字符串数组,也可以为对象数组,如果为二维数组,则为多列选择器
|
|
92
|
+
* 类型: Array<string | number | PickerOption | Array<string | number | PickerOption>>
|
|
93
|
+
* 默认值: []
|
|
94
|
+
*/
|
|
95
|
+
columns: makeArrayProp<PickerOption | Array<PickerOption>>()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type PickerViewExpose = {
|
|
99
|
+
/**
|
|
100
|
+
* 获取所有列选中项
|
|
101
|
+
* @returns {PickerOption[]} 选中项
|
|
102
|
+
*/
|
|
103
|
+
getSelectedOptions: () => PickerOption[]
|
|
104
|
+
/**
|
|
105
|
+
* 获取所有列的选中值
|
|
106
|
+
* @returns {Numeric[]} 选中值
|
|
107
|
+
*/
|
|
108
|
+
getSelectedValues: () => Numeric[]
|
|
109
|
+
/**
|
|
110
|
+
* 获取所有列数据
|
|
111
|
+
* @returns {PickerOption[][]} 所有列数据
|
|
112
|
+
*/
|
|
113
|
+
getColumnsData: () => PickerOption[][]
|
|
114
|
+
/**
|
|
115
|
+
* 获取指定列的数据
|
|
116
|
+
* @param {number} columnIndex 列索引
|
|
117
|
+
* @returns {PickerOption[]} 指定列数据
|
|
118
|
+
*/
|
|
119
|
+
getColumnData: (columnIndex: number) => PickerOption[]
|
|
120
|
+
/**
|
|
121
|
+
* 获取指定列的选中项下标
|
|
122
|
+
* @param {number} columnIndex 列索引
|
|
123
|
+
* @returns {number} 选中项下标
|
|
124
|
+
*/
|
|
125
|
+
getColumnIndex: (columnIndex: number) => number
|
|
126
|
+
/**
|
|
127
|
+
* 获取所有列选中项的 label
|
|
128
|
+
* @returns {string[]} label 数组
|
|
129
|
+
*/
|
|
130
|
+
getSelectedLabels: () => string[]
|
|
131
|
+
/**
|
|
132
|
+
* 获取所有列的选中下标
|
|
133
|
+
* @returns {number[]} 选中下标数组
|
|
134
|
+
*/
|
|
135
|
+
getSelectedIndex: () => number[]
|
|
136
|
+
/**
|
|
137
|
+
* 重置列数据
|
|
138
|
+
* @param {Array<string | number | PickerOption | Array<string | number | PickerOption>>} columns 新的列数据
|
|
139
|
+
*/
|
|
140
|
+
resetColumns: (columns: Array<string | number | PickerOption | Array<string | number | PickerOption>>) => void
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type PickerViewProps = ExtractPropTypes<typeof pickerViewProps>
|
|
144
|
+
|
|
145
|
+
export type PickerViewInstance = ComponentPublicInstance<PickerViewProps, PickerViewExpose>
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { computed, ref } from 'vue'
|
|
2
|
+
import { getType, isArray, isDef, range, isObj, deepClone } from '../../common/util'
|
|
3
|
+
import type { PickerOption } from './types'
|
|
4
|
+
import { type Numeric } from '../../common/props'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 格式化传入的列数据
|
|
8
|
+
* 列数据统一格式化为二维数组
|
|
9
|
+
* @param {Array<string | number | PickerOption | Array<string | number | PickerOption>>} array 列数据
|
|
10
|
+
* @param {string} valueKey value 对应的 key
|
|
11
|
+
* @param {string} labelKey label 对应的 key
|
|
12
|
+
* @returns {PickerOption[][]} 格式化后的二维数组
|
|
13
|
+
*/
|
|
14
|
+
function formatArray(
|
|
15
|
+
array: Array<string | number | PickerOption | Array<string | number | PickerOption>>,
|
|
16
|
+
valueKey: string,
|
|
17
|
+
labelKey: string
|
|
18
|
+
): PickerOption[][] {
|
|
19
|
+
let tempArray: Array<string | number | PickerOption | Array<string | number | PickerOption>> = isArray(array) ? array : [array]
|
|
20
|
+
// 判断数组第一层的数据类型,如果存在多种类型,则抛错
|
|
21
|
+
const firstLevelTypeList = new Set(array.map(getType))
|
|
22
|
+
/**
|
|
23
|
+
* 存在三种类型的合法数据
|
|
24
|
+
* 1.数组是一维元素,所有元素都是原始值
|
|
25
|
+
* 2.数组是一维元素,所有元素都是object
|
|
26
|
+
* 3.数组是二维元素,二维元素可以是任意内容
|
|
27
|
+
*/
|
|
28
|
+
if (firstLevelTypeList.size !== 1 && firstLevelTypeList.has('object')) {
|
|
29
|
+
// 原始值和引用类型不用混用
|
|
30
|
+
throw Error('The columns are correct')
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 简单处理,如果数组第一项不是数组则认为它是一个一维数组
|
|
34
|
+
* 所以需要把一维的转成二维,这样方便统一处理
|
|
35
|
+
*/
|
|
36
|
+
if (!isArray(array[0])) {
|
|
37
|
+
tempArray = [tempArray as Array<string | number | PickerOption>]
|
|
38
|
+
}
|
|
39
|
+
// 转化为二维数组后需要将每一项包装成PickerOption
|
|
40
|
+
const result: Array<Array<PickerOption>> = (tempArray as Array<Array<string | number | PickerOption>>).map((col) => {
|
|
41
|
+
return col.map((row) => {
|
|
42
|
+
// 非对象类型直接将值作为label和value
|
|
43
|
+
if (!isObj(row)) {
|
|
44
|
+
return {
|
|
45
|
+
[valueKey]: row,
|
|
46
|
+
[labelKey]: row
|
|
47
|
+
} as PickerOption
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 针对已经是object的,修补成{valueKey,labelKey}
|
|
51
|
+
* 如果没有labelKey,用valueKey代替
|
|
52
|
+
* 如果没有valueKey,用labelKey代替
|
|
53
|
+
* valueKey,labelKey都没有,直接抛错
|
|
54
|
+
*/
|
|
55
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
56
|
+
if (!row.hasOwnProperty(valueKey) && !row.hasOwnProperty(labelKey)) {
|
|
57
|
+
// eslint-disable-next-line prettier/prettier
|
|
58
|
+
throw Error('Can\'t find valueKey and labelKey in columns')
|
|
59
|
+
}
|
|
60
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
61
|
+
if (!row.hasOwnProperty(labelKey)) {
|
|
62
|
+
row[labelKey] = row[valueKey]
|
|
63
|
+
}
|
|
64
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
65
|
+
if (!row.hasOwnProperty(valueKey)) {
|
|
66
|
+
row[valueKey] = row[labelKey]
|
|
67
|
+
}
|
|
68
|
+
return row as PickerOption
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
return result
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 选择器数据处理 hooks
|
|
77
|
+
* 负责管理列数据、选中索引以及相关的数据处理逻辑
|
|
78
|
+
* @param {string} valueKey 选项对象中,value对应的 key
|
|
79
|
+
* @param {string} labelKey 选项对象中,展示的文本对应的 key
|
|
80
|
+
* @param {string} childrenKey 选项对象中,children对应的 key
|
|
81
|
+
* @param {boolean} cascade 是否启用级联模式
|
|
82
|
+
*/
|
|
83
|
+
export function useSelection(valueKey: string, labelKey: string, childrenKey: string = 'children', cascade: boolean = false) {
|
|
84
|
+
// 格式化后的列数据
|
|
85
|
+
const formatColumns = ref<PickerOption[][]>([])
|
|
86
|
+
// 每列选中的下标集合
|
|
87
|
+
const selectedIndex = ref<number[]>([])
|
|
88
|
+
/**
|
|
89
|
+
* 所有列选中项
|
|
90
|
+
*/
|
|
91
|
+
const selectedOptions = computed(() => {
|
|
92
|
+
return selectedIndex.value.map((row, col) => formatColumns.value[col][row])
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 获取所有列的选中值
|
|
97
|
+
* @returns {Numeric[]} 选中值
|
|
98
|
+
*/
|
|
99
|
+
const selectedValues = computed(() => {
|
|
100
|
+
const values = selectedIndex.value.map((row, col) => {
|
|
101
|
+
return formatColumns.value[col][row][valueKey] as Numeric
|
|
102
|
+
})
|
|
103
|
+
return values
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 获取所有列选中项的label,返回值为一个数组
|
|
108
|
+
* @returns {string[]} label数组
|
|
109
|
+
*/
|
|
110
|
+
const selectedLabels = computed(() => {
|
|
111
|
+
return selectedIndex.value.map((row, col) => String(formatColumns.value[col][row][labelKey] ?? ''))
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 根据传入的value,寻找对应的索引,并传递给原生选择器。
|
|
116
|
+
* 需要保证formatColumns先设置,之后会修改selectedIndex。
|
|
117
|
+
* @param {Numeric[]} value 选中值
|
|
118
|
+
*/
|
|
119
|
+
function selectWithValue(value: Numeric | Numeric[]) {
|
|
120
|
+
if (formatColumns.value.length === 0) {
|
|
121
|
+
selectedIndex.value = [] // 如果列为空,直接清空选中索引
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 标准化 value 为数组形式
|
|
126
|
+
let normalizedValue: Numeric[]
|
|
127
|
+
|
|
128
|
+
// 使其默认选中首项
|
|
129
|
+
if (!isDef(value) || (isArray(value) && value.length === 0)) {
|
|
130
|
+
normalizedValue = formatColumns.value.map((col) => {
|
|
131
|
+
return col[0][valueKey] as Numeric
|
|
132
|
+
})
|
|
133
|
+
} else {
|
|
134
|
+
normalizedValue = isArray(value) ? (value as Numeric[]) : [value as Numeric]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 1.单key转为Array<key>
|
|
139
|
+
* 2.根据formatColumns的长度截取Array<String>,保证下面的遍历不溢出
|
|
140
|
+
* 3.根据每列的key值找到选项中value为此key的下标并记录
|
|
141
|
+
*/
|
|
142
|
+
const slicedValue = normalizedValue.slice(0, formatColumns.value.length)
|
|
143
|
+
|
|
144
|
+
// 使用浅拷贝替代深拷贝,因为 selectedIndex 是简单数字数组
|
|
145
|
+
let selected: number[] = [...selectedIndex.value]
|
|
146
|
+
slicedValue.forEach((target, col) => {
|
|
147
|
+
let row = formatColumns.value[col].findIndex((row) => {
|
|
148
|
+
return row[valueKey]?.toString() === target.toString()
|
|
149
|
+
})
|
|
150
|
+
row = row === -1 ? 0 : row
|
|
151
|
+
selected = correctSelectedIndex(col, row, selected)
|
|
152
|
+
})
|
|
153
|
+
/** 根据formatColumns的长度去除selectWithIndex无用的部分。
|
|
154
|
+
* 始终保持value、selectWithIndex、formatColumns长度一致
|
|
155
|
+
*/
|
|
156
|
+
selectedIndex.value = selected.slice(0, slicedValue.length)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 修正选中项的值
|
|
161
|
+
* @param {number[]} value 当前picker选择器选中的值
|
|
162
|
+
* @returns {number[]} 修正后的选中值
|
|
163
|
+
*/
|
|
164
|
+
function correctSelected(value: number[]): number[] {
|
|
165
|
+
let selected = [...value]
|
|
166
|
+
value.forEach((row, col) => {
|
|
167
|
+
row = range(row, 0, formatColumns.value[col].length - 1)
|
|
168
|
+
selected = correctSelectedIndex(col, row, selected)
|
|
169
|
+
})
|
|
170
|
+
return selected
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 修正选中项指定列行的值
|
|
175
|
+
* @param {number} columnIndex 列下标
|
|
176
|
+
* @param {number} rowIndex 行下标
|
|
177
|
+
* @param {number[]} selected 选中值列表
|
|
178
|
+
* @returns {number[]} 修正后的选中值列表
|
|
179
|
+
*/
|
|
180
|
+
function correctSelectedIndex(columnIndex: number, rowIndex: number, selected: number[]): number[] {
|
|
181
|
+
const col = formatColumns.value[columnIndex]
|
|
182
|
+
if (!col || !col[rowIndex]) {
|
|
183
|
+
console.error(`[wd-picker-view] The value to select with Col:${columnIndex} Row:${rowIndex} is incorrect`)
|
|
184
|
+
// 返回原始 selected 而不是抛出错误,提供降级策略
|
|
185
|
+
return selected
|
|
186
|
+
}
|
|
187
|
+
const select: number[] = [...selected]
|
|
188
|
+
select[columnIndex] = rowIndex
|
|
189
|
+
|
|
190
|
+
// 被禁用的无法选中,选中距离它最近的未被禁用的
|
|
191
|
+
if (col[rowIndex].disabled) {
|
|
192
|
+
// 寻找向前最近的未被禁用的节点的索引
|
|
193
|
+
const prev = col
|
|
194
|
+
.slice(0, rowIndex)
|
|
195
|
+
.reverse()
|
|
196
|
+
.findIndex((s) => !s.disabled)
|
|
197
|
+
// 寻找向后最近的未被禁用的节点的索引
|
|
198
|
+
const next = col.slice(rowIndex + 1).findIndex((s) => !s.disabled)
|
|
199
|
+
|
|
200
|
+
if (prev !== -1) {
|
|
201
|
+
// 找到了向前的可选项
|
|
202
|
+
select[columnIndex] = rowIndex - 1 - prev
|
|
203
|
+
} else if (next !== -1) {
|
|
204
|
+
// 找到了向后的可选项
|
|
205
|
+
select[columnIndex] = rowIndex + 1 + next
|
|
206
|
+
} else {
|
|
207
|
+
// 所有选项都被禁用时,仍然选中当前行并给出警告
|
|
208
|
+
console.warn(`[wd-picker-view] All options in column ${columnIndex} are disabled, selecting disabled item at index ${rowIndex}`)
|
|
209
|
+
select[columnIndex] = rowIndex
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return select
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 获取选中项变化的列的下标
|
|
217
|
+
* @param {number[]} now 当前选中项值
|
|
218
|
+
* @param {number[]} origin 旧选中项值
|
|
219
|
+
* @returns {number} 变化的列下标,无变化返回 -1
|
|
220
|
+
*/
|
|
221
|
+
function getChangeColumnIndex(now: number[], origin: number[]): number {
|
|
222
|
+
if (!now || !origin) return -1
|
|
223
|
+
const index = now.findIndex((row, index) => row !== origin[index])
|
|
224
|
+
return index
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* 获取某一列的选中项下标
|
|
229
|
+
* @param {number} columnIndex 列的下标
|
|
230
|
+
* @returns {number} 下标
|
|
231
|
+
*/
|
|
232
|
+
function getColumnIndex(columnIndex: number): number {
|
|
233
|
+
return selectedIndex.value[columnIndex]
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 获取某一列的选项
|
|
238
|
+
* @param {number} columnIndex 列的下标
|
|
239
|
+
* @returns {PickerOption[]} 当前列的集合
|
|
240
|
+
*/
|
|
241
|
+
function getColumnData(columnIndex: number): PickerOption[] {
|
|
242
|
+
return formatColumns.value[columnIndex]
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 获取列数据
|
|
247
|
+
* @returns {PickerOption[][]} 列数据
|
|
248
|
+
*/
|
|
249
|
+
function getColumnsData(): PickerOption[][] {
|
|
250
|
+
return deepClone(formatColumns.value)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 从树形数据(带 children)构建多列数组
|
|
255
|
+
* @param {PickerOption[]} data 树形数据
|
|
256
|
+
* @param {Numeric[]} selectedValues 选中值数组
|
|
257
|
+
* @returns {PickerOption[][]} 多列数据
|
|
258
|
+
*/
|
|
259
|
+
function buildCascadeColumns(data: PickerOption[], selectedValues: Numeric[]): PickerOption[][] {
|
|
260
|
+
const result: PickerOption[][] = []
|
|
261
|
+
let currentLevel = data
|
|
262
|
+
|
|
263
|
+
// 第一列始终是根数据
|
|
264
|
+
if (currentLevel.length > 0) {
|
|
265
|
+
result.push(currentLevel)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// 根据选中值逐级构建后续列
|
|
269
|
+
for (let i = 0; i < selectedValues.length; i++) {
|
|
270
|
+
const value = selectedValues[i]
|
|
271
|
+
const selected = currentLevel.find((item) => item[valueKey]?.toString() === value.toString())
|
|
272
|
+
|
|
273
|
+
if (selected && selected[childrenKey] && (selected[childrenKey] as PickerOption[]).length > 0) {
|
|
274
|
+
currentLevel = selected[childrenKey] as PickerOption[]
|
|
275
|
+
result.push(currentLevel)
|
|
276
|
+
} else {
|
|
277
|
+
// 如果没有 children 或 children 为空,停止构建
|
|
278
|
+
break
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return result
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 更新级联模式下的列数据
|
|
287
|
+
* @param {PickerOption[]} rootData 根级数据
|
|
288
|
+
* @param {number} changedColumnIndex 变化的列索引
|
|
289
|
+
* @param {number[]} currentSelectedIndex 当前选中索引数组
|
|
290
|
+
*/
|
|
291
|
+
function updateCascadeColumns(rootData: PickerOption[], changedColumnIndex: number, currentSelectedIndex: number[]) {
|
|
292
|
+
// 从根级开始重新构建到变化列的数据
|
|
293
|
+
const newColumns: PickerOption[][] = [rootData]
|
|
294
|
+
let currentLevel = rootData
|
|
295
|
+
const newSelectedIndex: number[] = []
|
|
296
|
+
|
|
297
|
+
// 重新构建到变化列(包括变化列)
|
|
298
|
+
for (let i = 0; i <= changedColumnIndex && i < currentSelectedIndex.length; i++) {
|
|
299
|
+
const selectedIndex = currentSelectedIndex[i]
|
|
300
|
+
const selected = currentLevel[selectedIndex]
|
|
301
|
+
|
|
302
|
+
newSelectedIndex.push(selectedIndex)
|
|
303
|
+
|
|
304
|
+
if (selected && selected[childrenKey] && (selected[childrenKey] as PickerOption[]).length > 0) {
|
|
305
|
+
currentLevel = selected[childrenKey] as PickerOption[]
|
|
306
|
+
newColumns.push(currentLevel)
|
|
307
|
+
} else {
|
|
308
|
+
// 当前选中项没有子级,停止构建
|
|
309
|
+
break
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// 继续构建变化列之后的列,每次选中第一个可用项(非禁用)
|
|
314
|
+
while (currentLevel.length > 0) {
|
|
315
|
+
// 找到第一个非禁用项的索引
|
|
316
|
+
const firstEnabledIndex = currentLevel.findIndex((item) => !item.disabled)
|
|
317
|
+
|
|
318
|
+
// 如果所有项都被禁用,选中第一项
|
|
319
|
+
const nextIndex = firstEnabledIndex !== -1 ? firstEnabledIndex : 0
|
|
320
|
+
const selected = currentLevel[nextIndex]
|
|
321
|
+
|
|
322
|
+
if (selected && selected[childrenKey] && (selected[childrenKey] as PickerOption[]).length > 0) {
|
|
323
|
+
newSelectedIndex.push(nextIndex)
|
|
324
|
+
currentLevel = selected[childrenKey] as PickerOption[]
|
|
325
|
+
newColumns.push(currentLevel)
|
|
326
|
+
} else {
|
|
327
|
+
// 如果最后一个选中项有子级,需要添加其索引
|
|
328
|
+
if (newColumns.length > newSelectedIndex.length) {
|
|
329
|
+
newSelectedIndex.push(nextIndex)
|
|
330
|
+
}
|
|
331
|
+
// 没有更多子级了,停止构建
|
|
332
|
+
break
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// 更新 formatColumns 和 selectedIndex
|
|
337
|
+
formatColumns.value = newColumns
|
|
338
|
+
selectedIndex.value = newSelectedIndex
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* 用于重置列数据为指定列数据
|
|
343
|
+
* @param {(string | number | PickerOption | Array<string | number | PickerOption>)[]} columns 新列数据
|
|
344
|
+
*/
|
|
345
|
+
function resetColumns(columns: Array<string | number | PickerOption | Array<string | number | PickerOption>>) {
|
|
346
|
+
if (isArray(columns) && columns.length > 0) {
|
|
347
|
+
// 级联模式:判断是否为树形数据(检查第一项是否有 children)
|
|
348
|
+
if (cascade && isArray(columns) && columns.length > 0 && !isArray(columns[0])) {
|
|
349
|
+
const firstItem = columns[0] as PickerOption
|
|
350
|
+
// 如果是对象且包含 childrenKey,则认为是级联数据
|
|
351
|
+
if (isObj(firstItem) && childrenKey in firstItem) {
|
|
352
|
+
// 树形数据,需要根据当前选中值构建多列
|
|
353
|
+
const cascadeData = columns as PickerOption[]
|
|
354
|
+
// 初始化时,如果没有选中值,只显示第一列
|
|
355
|
+
formatColumns.value = [formatArray([cascadeData], valueKey, labelKey)[0]]
|
|
356
|
+
return
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// 非级联模式或普通二维数组:使用原有逻辑
|
|
361
|
+
formatColumns.value = formatArray(columns, valueKey, labelKey)
|
|
362
|
+
} else {
|
|
363
|
+
formatColumns.value = []
|
|
364
|
+
selectedIndex.value = []
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return {
|
|
369
|
+
formatColumns,
|
|
370
|
+
selectedIndex,
|
|
371
|
+
selectedOptions,
|
|
372
|
+
selectedValues,
|
|
373
|
+
selectedLabels,
|
|
374
|
+
selectWithValue,
|
|
375
|
+
correctSelected,
|
|
376
|
+
correctSelectedIndex,
|
|
377
|
+
getChangeColumnIndex,
|
|
378
|
+
getColumnIndex,
|
|
379
|
+
getColumnData,
|
|
380
|
+
getColumnsData,
|
|
381
|
+
resetColumns,
|
|
382
|
+
buildCascadeColumns,
|
|
383
|
+
updateCascadeColumns
|
|
384
|
+
}
|
|
385
|
+
}
|