oxy-uni-ui 2.1.2 → 2.1.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/attributes.json +1 -1
- package/components/common/AbortablePromise.ts +4 -0
- package/components/common/abstracts/variable.scss +172 -66
- package/components/common/base64.ts +6 -0
- package/components/common/clickoutside.ts +5 -0
- package/components/common/interceptor.ts +9 -0
- package/components/common/path.ts +4 -0
- package/components/common/props.ts +23 -0
- package/components/common/util.ts +18 -1
- package/components/composables/index.ts +2 -0
- package/components/composables/useCell.ts +8 -1
- package/components/composables/useChildren.ts +27 -1
- package/components/composables/useCountDown.ts +10 -1
- package/components/composables/useDynamicVirtualScroll.ts +9 -0
- package/components/composables/useGlobalLoading.ts +6 -0
- package/components/composables/useGlobalMessage.ts +6 -0
- package/components/composables/useGlobalToast.ts +6 -0
- package/components/composables/useLockScroll.ts +9 -0
- package/components/composables/useParent.ts +65 -14
- package/components/composables/usePopover.ts +9 -0
- package/components/composables/useQueue.ts +8 -0
- package/components/composables/useRaf.ts +10 -0
- package/components/composables/useSharedState.ts +284 -0
- package/components/composables/useTouch.ts +8 -0
- package/components/composables/useTranslate.ts +9 -0
- package/components/composables/useUpload.ts +83 -11
- package/components/composables/useVirtualScroll.ts +7 -0
- package/components/composables/useWindowResize.ts +9 -0
- package/components/oxy-action-sheet/index.scss +5 -5
- package/components/oxy-action-sheet/oxy-action-sheet.vue +11 -0
- package/components/oxy-backtop/index.scss +2 -2
- package/components/oxy-backtop/oxy-backtop.vue +2 -0
- package/components/oxy-badge/oxy-badge.vue +2 -0
- package/components/oxy-badge/types.ts +3 -0
- package/components/oxy-button/index.scss +13 -13
- package/components/oxy-button/oxy-button.vue +11 -0
- package/components/oxy-button/types.ts +3 -3
- package/components/oxy-calendar/index.scss +17 -17
- package/components/oxy-calendar/oxy-calendar.vue +31 -0
- package/components/oxy-calendar/types.ts +3 -0
- package/components/oxy-calendar-view/month/month.vue +2 -0
- package/components/oxy-calendar-view/monthPanel/month-panel.vue +3 -1
- package/components/oxy-calendar-view/monthPanel/types.ts +10 -7
- package/components/oxy-calendar-view/oxy-calendar-view.vue +2 -0
- package/components/oxy-calendar-view/types.ts +3 -1
- package/components/oxy-calendar-view/year/types.ts +33 -1
- package/components/oxy-calendar-view/year/year.vue +2 -0
- package/components/oxy-calendar-view/yearPanel/year-panel.vue +2 -0
- package/components/oxy-card/index.scss +1 -1
- package/components/oxy-card/oxy-card.vue +2 -0
- package/components/oxy-cell/index.scss +3 -1
- package/components/oxy-cell/oxy-cell.vue +6 -4
- package/components/oxy-cell-group/oxy-cell-group.vue +2 -0
- package/components/oxy-checkbox/index.scss +7 -7
- package/components/oxy-checkbox/oxy-checkbox.vue +22 -16
- package/components/oxy-checkbox/types.ts +9 -0
- package/components/oxy-checkbox-group/index.scss +1 -1
- package/components/oxy-checkbox-group/oxy-checkbox-group.vue +2 -0
- package/components/oxy-circle/oxy-circle.vue +2 -0
- package/components/oxy-col/oxy-col.vue +3 -1
- package/components/oxy-col-picker/index.scss +3 -3
- package/components/oxy-col-picker/oxy-col-picker.vue +17 -1
- package/components/oxy-col-picker/types.ts +3 -0
- package/components/oxy-collapse/index.scss +2 -2
- package/components/oxy-collapse/oxy-collapse.vue +9 -0
- package/components/oxy-collapse-item/oxy-collapse-item.vue +4 -2
- package/components/oxy-config-provider/oxy-config-provider.vue +18 -0
- package/components/oxy-config-provider/types.ts +18 -0
- package/components/oxy-corner/index.scss +50 -32
- package/components/oxy-corner/oxy-corner.vue +2 -0
- package/components/oxy-count-down/oxy-count-down.vue +2 -0
- package/components/oxy-count-to/oxy-count-to.vue +12 -1
- package/components/oxy-count-to/types.ts +14 -4
- package/components/oxy-curtain/index.scss +10 -9
- package/components/oxy-curtain/oxy-curtain.vue +2 -0
- package/components/oxy-date-strip/oxy-date-strip.vue +22 -1
- package/components/oxy-date-strip-item/index.scss +4 -4
- package/components/oxy-date-strip-item/oxy-date-strip-item.vue +2 -0
- package/components/oxy-datetime-picker/index.scss +3 -3
- package/components/oxy-datetime-picker/oxy-datetime-picker.vue +11 -1
- package/components/oxy-datetime-picker-view/oxy-datetime-picker-view.vue +2 -0
- package/components/oxy-divider/oxy-divider.vue +2 -0
- package/components/oxy-drop-menu/index.scss +2 -2
- package/components/oxy-drop-menu/oxy-drop-menu.vue +3 -0
- package/components/oxy-drop-menu-item/index.scss +1 -1
- package/components/oxy-drop-menu-item/oxy-drop-menu-item.vue +17 -9
- package/components/oxy-echarts/oxy-echarts.vue +4 -2
- package/components/oxy-fab/index.scss +1 -1
- package/components/oxy-fab/oxy-fab.vue +27 -0
- package/components/oxy-file-list/index.scss +9 -9
- package/components/oxy-file-list/oxy-file-list.vue +29 -17
- package/components/oxy-floating-panel/oxy-floating-panel.vue +34 -10
- package/components/oxy-footer/index.scss +7 -0
- package/components/oxy-footer/oxy-footer.vue +4 -2
- package/components/oxy-footer/types.ts +9 -6
- package/components/oxy-form/oxy-form.vue +13 -1
- package/components/oxy-form-item/oxy-form-item.vue +5 -3
- package/components/oxy-gap/oxy-gap.vue +2 -0
- package/components/oxy-global-loading/oxy-global-loading.vue +18 -5
- package/components/oxy-global-message/oxy-global-message.vue +30 -17
- package/components/oxy-global-toast/oxy-global-toast.vue +18 -5
- package/components/oxy-grid/oxy-grid.vue +6 -0
- package/components/oxy-grid-item/index.scss +1 -1
- package/components/oxy-grid-item/oxy-grid-item.vue +22 -20
- package/components/oxy-guidance/index.scss +9 -9
- package/components/oxy-guidance/oxy-guidance.vue +22 -16
- package/components/oxy-icon/oxy-icon.vue +2 -0
- package/components/oxy-icon/types.ts +3 -0
- package/components/oxy-image-preview/index.scss +75 -0
- package/components/oxy-image-preview/index.ts +56 -0
- package/components/oxy-image-preview/oxy-image-preview.vue +221 -0
- package/components/oxy-image-preview/types.ts +164 -0
- package/components/oxy-img/oxy-img.vue +2 -0
- package/components/oxy-img-cropper/index.scss +2 -2
- package/components/oxy-img-cropper/oxy-img-cropper.vue +6 -0
- package/components/oxy-img-lazy/oxy-img-lazy.vue +9 -0
- package/components/oxy-index-anchor/index.scss +1 -1
- package/components/oxy-index-anchor/oxy-index-anchor.vue +2 -2
- package/components/oxy-index-bar/index.scss +1 -1
- package/components/oxy-index-bar/oxy-index-bar.vue +18 -0
- package/components/oxy-input/index.scss +2 -1
- package/components/oxy-input/oxy-input.vue +18 -4
- package/components/oxy-input/types.ts +6 -0
- package/components/oxy-input-number/index.scss +3 -1
- package/components/oxy-input-number/oxy-input-number.vue +2 -0
- package/components/oxy-keyboard/index.scss +3 -3
- package/components/oxy-keyboard/key/index.vue +2 -0
- package/components/oxy-keyboard/oxy-keyboard.vue +11 -2
- package/components/oxy-link/index.scss +8 -4
- package/components/oxy-link/oxy-link.vue +9 -3
- package/components/oxy-link/types.ts +2 -2
- package/components/oxy-list/oxy-list.vue +2 -0
- package/components/oxy-list/types.ts +7 -0
- package/components/oxy-loading/oxy-loading.vue +6 -0
- package/components/oxy-loadmore/index.scss +1 -1
- package/components/oxy-loadmore/oxy-loadmore.vue +2 -0
- package/components/oxy-long-press-menu/index.scss +1 -1
- package/components/oxy-long-press-menu/oxy-long-press-menu.vue +42 -13
- package/components/oxy-message-box/index.scss +223 -36
- package/components/oxy-message-box/index.ts +49 -23
- package/components/oxy-message-box/oxy-message-box.vue +181 -56
- package/components/oxy-message-box/types.ts +60 -2
- package/components/oxy-navbar/index.scss +1 -1
- package/components/oxy-navbar/oxy-navbar.vue +9 -6
- package/components/oxy-navbar-capsule/oxy-navbar-capsule.vue +2 -0
- package/components/oxy-notice-bar/index.scss +1 -1
- package/components/oxy-notice-bar/oxy-notice-bar.vue +29 -0
- package/components/oxy-notify/index.ts +16 -12
- package/components/oxy-notify/oxy-notify.vue +11 -4
- package/components/oxy-overlay/oxy-overlay.vue +34 -2
- package/components/oxy-pagination/oxy-pagination.vue +2 -0
- package/components/oxy-password-input/oxy-password-input.vue +2 -0
- package/components/oxy-picker/index.scss +7 -7
- package/components/oxy-picker/oxy-picker.vue +11 -0
- package/components/oxy-picker-view/index.scss +1 -1
- package/components/oxy-picker-view/oxy-picker-view.vue +2 -0
- package/components/oxy-popover/index.scss +2 -2
- package/components/oxy-popover/oxy-popover.vue +4 -1
- package/components/oxy-popup/oxy-popup.vue +8 -0
- package/components/oxy-progress/index.scss +2 -2
- package/components/oxy-progress/oxy-progress.vue +7 -0
- package/components/oxy-qrcode/draw.ts +15 -1
- package/components/oxy-qrcode/oxy-qrcode.vue +10 -3
- package/components/oxy-radio/index.scss +8 -8
- package/components/oxy-radio/oxy-radio.vue +13 -11
- package/components/oxy-radio-group/index.scss +1 -1
- package/components/oxy-radio-group/oxy-radio-group.vue +2 -0
- package/components/oxy-rate/oxy-rate.vue +5 -0
- package/components/oxy-rate/types.ts +2 -2
- package/components/oxy-resize/oxy-resize.vue +12 -0
- package/components/oxy-rich-text/index.scss +9 -9
- package/components/oxy-rich-text/oxy-rich-text.vue +6 -0
- package/components/oxy-rich-text/types.ts +15 -0
- package/components/oxy-root-portal/oxy-root-portal.vue +23 -15
- package/components/oxy-row/oxy-row.vue +2 -0
- package/components/oxy-search/index.scss +3 -3
- package/components/oxy-search/oxy-search.vue +19 -0
- package/components/oxy-segmented/index.scss +4 -4
- package/components/oxy-segmented/oxy-segmented.vue +2 -0
- package/components/oxy-select/index.scss +25 -25
- package/components/oxy-select/oxy-select.vue +27 -0
- package/components/oxy-select/types.ts +3 -0
- package/components/oxy-select-picker/index.scss +5 -5
- package/components/oxy-select-picker/oxy-select-picker.vue +7 -0
- package/components/oxy-sidebar/oxy-sidebar.vue +2 -0
- package/components/oxy-sidebar-item/index.scss +3 -3
- package/components/oxy-sidebar-item/oxy-sidebar-item.vue +17 -31
- package/components/oxy-signature/oxy-signature.vue +17 -0
- package/components/oxy-skeleton/oxy-skeleton.vue +7 -1
- package/components/oxy-slide-verify/index.scss +95 -0
- package/components/oxy-slide-verify/oxy-slide-verify.vue +244 -0
- package/components/oxy-slide-verify/types.ts +98 -0
- package/components/oxy-slider/oxy-slider.vue +3 -0
- package/components/oxy-sort-button/index.scss +10 -8
- package/components/oxy-sort-button/oxy-sort-button.vue +6 -0
- package/components/oxy-splitter/index.scss +9 -0
- package/components/oxy-splitter/oxy-splitter.vue +23 -2
- package/components/oxy-splitter-panel/index.scss +7 -5
- package/components/oxy-splitter-panel/oxy-splitter-panel.vue +93 -89
- package/components/oxy-status-tip/index.scss +3 -3
- package/components/oxy-status-tip/oxy-status-tip.vue +2 -0
- package/components/oxy-step/index.scss +4 -4
- package/components/oxy-step/oxy-step.vue +15 -13
- package/components/oxy-steps/oxy-steps.vue +2 -0
- package/components/oxy-sticky/oxy-sticky.vue +5 -3
- package/components/oxy-stream-render/oxy-stream-render.vue +29 -0
- package/components/oxy-swipe-action/oxy-swipe-action.vue +8 -0
- package/components/oxy-swiper/oxy-swiper.vue +6 -0
- package/components/oxy-swiper-nav/index.scss +4 -4
- package/components/oxy-switch/index.scss +6 -3
- package/components/oxy-switch/oxy-switch.vue +10 -0
- package/components/oxy-tab/index.scss +1 -7
- package/components/oxy-tab/oxy-tab.vue +12 -10
- package/components/oxy-tabbar/oxy-tabbar.vue +5 -0
- package/components/oxy-tabbar-item/oxy-tabbar-item.vue +11 -9
- package/components/oxy-table/index.scss +1 -1
- package/components/oxy-table/oxy-table.vue +8 -0
- package/components/oxy-table/types.ts +3 -0
- package/components/oxy-table-col/oxy-table-col.vue +21 -19
- package/components/oxy-tabs/index.scss +11 -11
- package/components/oxy-tabs/oxy-tabs.vue +17 -0
- package/components/oxy-tag/index.scss +24 -5
- package/components/oxy-tag/oxy-tag.vue +17 -2
- package/components/oxy-tag/types.ts +7 -0
- package/components/oxy-text/oxy-text.vue +12 -1
- package/components/oxy-textarea/index.scss +3 -2
- package/components/oxy-textarea/oxy-textarea.vue +10 -4
- package/components/oxy-toast/index.ts +21 -20
- package/components/oxy-toast/oxy-toast.vue +30 -5
- package/components/oxy-toast/types.ts +20 -9
- package/components/oxy-tooltip/index.scss +1 -1
- package/components/oxy-tooltip/oxy-tooltip.vue +2 -0
- package/components/oxy-transition/index.scss +3 -1
- package/components/oxy-transition/oxy-transition.vue +14 -0
- package/components/oxy-tree/index.scss +3 -3
- package/components/oxy-tree/oxy-tree.vue +28 -5
- package/components/oxy-tree/types.ts +57 -1
- package/components/oxy-upload/index.scss +9 -9
- package/components/oxy-upload/oxy-upload.vue +5 -3
- package/components/oxy-verification-code/oxy-verification-code.vue +24 -0
- package/components/oxy-video-preview/index.scss +12 -7
- package/components/oxy-video-preview/index.ts +64 -0
- package/components/oxy-video-preview/oxy-video-preview.vue +102 -31
- package/components/oxy-video-preview/types.ts +54 -8
- package/components/oxy-virtual-scroll/index.scss +1 -1
- package/components/oxy-virtual-scroll/oxy-virtual-scroll.vue +2 -0
- package/components/oxy-voice-player/index.scss +64 -64
- package/components/oxy-voice-player/oxy-voice-player.vue +38 -10
- package/components/oxy-waterfall/oxy-waterfall.vue +13 -0
- package/components/oxy-waterfall/types.ts +7 -0
- package/components/oxy-waterfall-item/oxy-waterfall-item.vue +9 -0
- package/components/oxy-watermark/oxy-watermark.vue +2 -0
- package/global.d.ts +2 -0
- package/index.ts +2 -0
- package/locale/lang/en-US.ts +51 -2
- package/locale/lang/zh-CN.ts +51 -2
- package/package.json +2 -2
- package/styles/all.scss +125 -0
- package/tags.json +1 -1
- package/vite-plugins/vite-plugin-host-class.ts +166 -0
- package/web-types.json +1 -1
|
@@ -9,31 +9,54 @@ export const truthProp = {
|
|
|
9
9
|
default: true as const
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* 创建必填 prop 定义。
|
|
14
|
+
* @param type prop 类型
|
|
15
|
+
*/
|
|
12
16
|
export const makeRequiredProp = <T>(type: T) => ({
|
|
13
17
|
type,
|
|
14
18
|
required: true as const
|
|
15
19
|
})
|
|
16
20
|
|
|
21
|
+
/**
|
|
22
|
+
* 创建数组类型 prop 定义,默认值为空数组 `[]`。
|
|
23
|
+
*/
|
|
17
24
|
export const makeArrayProp = <T>() => ({
|
|
18
25
|
type: Array as PropType<T[]>,
|
|
19
26
|
default: () => []
|
|
20
27
|
})
|
|
21
28
|
|
|
29
|
+
/**
|
|
30
|
+
* 创建布尔类型 prop 定义。
|
|
31
|
+
* @param defaultVal 默认值
|
|
32
|
+
*/
|
|
22
33
|
export const makeBooleanProp = <T>(defaultVal: T) => ({
|
|
23
34
|
type: Boolean,
|
|
24
35
|
default: defaultVal
|
|
25
36
|
})
|
|
26
37
|
|
|
38
|
+
/**
|
|
39
|
+
* 创建数字类型 prop 定义。
|
|
40
|
+
* @param defaultVal 默认值
|
|
41
|
+
*/
|
|
27
42
|
export const makeNumberProp = <T>(defaultVal: T) => ({
|
|
28
43
|
type: Number,
|
|
29
44
|
default: defaultVal
|
|
30
45
|
})
|
|
31
46
|
|
|
47
|
+
/**
|
|
48
|
+
* 创建 Numeric(支持 Number 和 String)类型 prop 定义。
|
|
49
|
+
* @param defaultVal 默认值
|
|
50
|
+
*/
|
|
32
51
|
export const makeNumericProp = <T>(defaultVal: T) => ({
|
|
33
52
|
type: numericProp,
|
|
34
53
|
default: defaultVal
|
|
35
54
|
})
|
|
36
55
|
|
|
56
|
+
/**
|
|
57
|
+
* 创建字符串类型 prop 定义。
|
|
58
|
+
* @param defaultVal 默认值
|
|
59
|
+
*/
|
|
37
60
|
export const makeStringProp = <T>(defaultVal: T) => ({
|
|
38
61
|
type: String as unknown as PropType<T>,
|
|
39
62
|
default: defaultVal
|
|
@@ -687,6 +687,12 @@ export function isEmptyObj(obj: unknown): boolean {
|
|
|
687
687
|
return !hasFields(obj)
|
|
688
688
|
}
|
|
689
689
|
|
|
690
|
+
/**
|
|
691
|
+
* 借由 requestAnimationFrame 实现定时 Promise,用于等待下一帧渲染完成。
|
|
692
|
+
* 小程序端降级为 `setInterval`(约 33fps)。
|
|
693
|
+
*
|
|
694
|
+
* @param cb 定时回调
|
|
695
|
+
*/
|
|
690
696
|
export const requestAnimationFrame = (cb = () => {}) => {
|
|
691
697
|
return new AbortablePromise((resolve) => {
|
|
692
698
|
const timer = setInterval(() => {
|
|
@@ -827,6 +833,16 @@ type DebounceOptions = {
|
|
|
827
833
|
trailing?: boolean // 是否在延迟时间结束时调用函数
|
|
828
834
|
}
|
|
829
835
|
|
|
836
|
+
/**
|
|
837
|
+
* 防抖函数。
|
|
838
|
+
*
|
|
839
|
+
* 在连续触发中只执行最后一次或第一次(leading),
|
|
840
|
+
* 默认在延迟结束后执行(trailing=true)。
|
|
841
|
+
*
|
|
842
|
+
* @param func 要防抖的函数
|
|
843
|
+
* @param wait 等待时间(毫秒)
|
|
844
|
+
* @param options leading 是否在开始时调用,trailing 是否在结束时调用
|
|
845
|
+
*/
|
|
830
846
|
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number, options: DebounceOptions = {}): T {
|
|
831
847
|
let timeoutId: ReturnType<typeof setTimeout> | null = null
|
|
832
848
|
let lastArgs: any[] | undefined
|
|
@@ -996,7 +1012,8 @@ export function isExcelUrl(url: string): boolean {
|
|
|
996
1012
|
}
|
|
997
1013
|
|
|
998
1014
|
/**
|
|
999
|
-
* 判断环境是否是H5
|
|
1015
|
+
* 判断环境是否是 H5。
|
|
1016
|
+
* 通过条件编译 `#ifdef H5` 在编译时静态确定。
|
|
1000
1017
|
*/
|
|
1001
1018
|
export const isH5 = (() => {
|
|
1002
1019
|
let isH5 = false
|
|
@@ -11,3 +11,5 @@ export { useTranslate } from './useTranslate'
|
|
|
11
11
|
export { useUpload } from './useUpload'
|
|
12
12
|
export { useVirtualScroll } from './useVirtualScroll'
|
|
13
13
|
export { useWindowResize } from './useWindowResize'
|
|
14
|
+
export { useImagePreview } from '../oxy-image-preview'
|
|
15
|
+
export { createSharedState } from './useSharedState'
|
|
@@ -2,11 +2,18 @@ import { computed } from 'vue'
|
|
|
2
2
|
import { useParent } from './useParent'
|
|
3
3
|
import { CELL_GROUP_KEY } from '../oxy-cell-group/types'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* 获取 Cell Group 上下文,用于判断当前 cell 是否需要显示底部边框。
|
|
7
|
+
*
|
|
8
|
+
* 仅在父组件为 `oxy-cell-group` 且当前 cell 不是第一个子节点时返回 `border: true`。
|
|
9
|
+
*
|
|
10
|
+
* @returns `{ border }` 是否显示 cell 间分割线
|
|
11
|
+
*/
|
|
5
12
|
export function useCell() {
|
|
6
13
|
const { parent: cellGroup, index } = useParent(CELL_GROUP_KEY)
|
|
7
14
|
|
|
8
15
|
const border = computed(() => {
|
|
9
|
-
return cellGroup && cellGroup.props.border && index.value
|
|
16
|
+
return cellGroup.value && cellGroup.value.props.border && index.value
|
|
10
17
|
})
|
|
11
18
|
|
|
12
19
|
return { border }
|
|
@@ -14,6 +14,15 @@ function isVNode(value: any): value is VNode {
|
|
|
14
14
|
return value ? value.__v_isVNode === true : false
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* 展平 VNode 树,递归收集所有合法的 VNode 节点。
|
|
19
|
+
*
|
|
20
|
+
* 用于在父组件中获取所有子 VNode,以便按 DOM 顺序排序 children。
|
|
21
|
+
* 小程序端不支持 `isVNode`,因此内部提供了自定义实现。
|
|
22
|
+
*
|
|
23
|
+
* @param children 父组件的 VNode children
|
|
24
|
+
* @returns 展平后的 VNode 数组
|
|
25
|
+
*/
|
|
17
26
|
export function flattenVNodes(children: VNodeNormalizedChildren) {
|
|
18
27
|
const result: VNode[] = []
|
|
19
28
|
|
|
@@ -49,7 +58,13 @@ const findVNodeIndex = (vnodes: VNode[], vnode: VNode) => {
|
|
|
49
58
|
return index
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
/**
|
|
62
|
+
* 按 VNodes 在 DOM 中的顺序排序子组件实例。
|
|
63
|
+
*
|
|
64
|
+
* @param parent 父组件内部实例
|
|
65
|
+
* @param publicChildren 子组件公开实例数组
|
|
66
|
+
* @param internalChildren 子组件内部实例数组
|
|
67
|
+
*/
|
|
53
68
|
export function sortChildren(
|
|
54
69
|
parent: ComponentInternalInstance,
|
|
55
70
|
publicChildren: ComponentPublicInstance[],
|
|
@@ -68,6 +83,17 @@ export function sortChildren(
|
|
|
68
83
|
})
|
|
69
84
|
}
|
|
70
85
|
|
|
86
|
+
/**
|
|
87
|
+
* 为父组件提供子组件管理能力,常用于父子联动场景。
|
|
88
|
+
*
|
|
89
|
+
* 父组件调用此 Hook 后,可通过 `provide` 向子组件注入上下文,
|
|
90
|
+
* 子组件通过 `useParent` 获取父组件共享的状态和自己的索引。
|
|
91
|
+
*
|
|
92
|
+
* 典型场景:tabs/tab、radio-group/radio、collapse/collapse-item。
|
|
93
|
+
*
|
|
94
|
+
* @param key 用于 provide/inject 的 InjectionKey
|
|
95
|
+
* @returns `{ children, linkChildren }`——children 为响应式子组件公开实例数组,linkChildren 用于向子组件注入上下文。
|
|
96
|
+
*/
|
|
71
97
|
export function useChildren<
|
|
72
98
|
// eslint-disable-next-line
|
|
73
99
|
Child extends ComponentPublicInstance = ComponentPublicInstance<{}, any>,
|
|
@@ -49,7 +49,16 @@ function isSameSecond(time1: number, time2: number): boolean {
|
|
|
49
49
|
return Math.floor(time1 / 1000) === Math.floor(time2 / 1000)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* 倒计时 Hook。
|
|
54
|
+
*
|
|
55
|
+
* 提供毫秒级和秒级倒计时能力,基于 `useRaf` 实现帧同步。
|
|
56
|
+
* 支持开始、暂停、重置,以及结束回调和变化回调。
|
|
57
|
+
* 组件卸载时自动暂停。
|
|
58
|
+
*
|
|
59
|
+
* @param options 倒计时配置
|
|
60
|
+
* @returns `{ start, pause, reset, current }`
|
|
61
|
+
*/
|
|
53
62
|
export function useCountDown(options: UseCountDownOptions) {
|
|
54
63
|
let endTime: number // 结束时间
|
|
55
64
|
let counting: boolean // 是否计时中
|
|
@@ -13,6 +13,15 @@ export interface UseDynamicVirtualScrollOptions<T extends DynamicVirtualScrollIt
|
|
|
13
13
|
buffer?: number
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* 不定高虚拟滚动 Hook。
|
|
18
|
+
*
|
|
19
|
+
* 通过二分查找计算当前可视区域内的数据项,适用于列表项高度不固定的场景。
|
|
20
|
+
* 数据源的每个元素需要包含 `top`(累加偏移量)和 `height` 字段。
|
|
21
|
+
*
|
|
22
|
+
* @param options 配置项
|
|
23
|
+
* @returns `{ visibleData, getTargetIndex }` 可视数据列表和根据 scrollTop 查找索引的方法
|
|
24
|
+
*/
|
|
16
25
|
export function useDynamicVirtualScroll<T extends DynamicVirtualScrollItem>(options: UseDynamicVirtualScrollOptions<T>) {
|
|
17
26
|
const { data, scrollTop, viewportHeight, buffer = 0 } = options
|
|
18
27
|
|
|
@@ -12,6 +12,12 @@ interface GlobalLoading {
|
|
|
12
12
|
const defaultOptions: ToastOptions = {
|
|
13
13
|
show: false
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* 全局 Loading 状态管理(Pinia Store)。
|
|
17
|
+
*
|
|
18
|
+
* 通过 Pinia 跨页面共享 loading 状态,
|
|
19
|
+
* 在路由切换时自动记录当前页面并显示全屏加载遮罩。
|
|
20
|
+
*/
|
|
15
21
|
export const useGlobalLoading = defineStore('global-loading', {
|
|
16
22
|
state: (): GlobalLoading => ({
|
|
17
23
|
loadingOptions: defaultOptions,
|
|
@@ -13,6 +13,12 @@ interface GlobalMessage {
|
|
|
13
13
|
currentPage: string
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* 全局 Message 弹窗状态管理(Pinia Store)。
|
|
18
|
+
*
|
|
19
|
+
* 通过 Pinia 跨页面管理 message-box 的显示/隐藏,
|
|
20
|
+
* 支持 alert、confirm、prompt 三种模式。
|
|
21
|
+
*/
|
|
16
22
|
export const useGlobalMessage = defineStore('global-message', {
|
|
17
23
|
state: (): GlobalMessage => ({
|
|
18
24
|
messageOptions: null,
|
|
@@ -13,6 +13,12 @@ const defaultOptions: ToastOptions = {
|
|
|
13
13
|
duration: 2000,
|
|
14
14
|
show: false
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* 全局 Toast 状态管理(Pinia Store)。
|
|
18
|
+
*
|
|
19
|
+
* 通过 Pinia 跨页面管理 toast 的显示/隐藏,
|
|
20
|
+
* 提供 show、success、error、info、warning 等快捷方法。
|
|
21
|
+
*/
|
|
16
22
|
export const useGlobalToast = defineStore('global-toast', {
|
|
17
23
|
state: (): GlobalToast => ({
|
|
18
24
|
toastOptions: defaultOptions,
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { onBeforeUnmount, onDeactivated, ref, watch } from 'vue'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* 锁定页面滚动。
|
|
5
|
+
*
|
|
6
|
+
* 当 `shouldLock` 返回 true 时将 body 的 overflow 设为 hidden,
|
|
7
|
+
* 支持嵌套调用(通过计数器管理)。仅 H5 环境有效。
|
|
8
|
+
*
|
|
9
|
+
* @param shouldLock 返回布尔值的响应式函数,用于判断是否需要锁定滚动
|
|
10
|
+
* @returns `{ lock, unlock }` 手动锁定/解锁方法
|
|
11
|
+
*/
|
|
3
12
|
export function useLockScroll(shouldLock: () => boolean) {
|
|
4
13
|
const scrollLockCount = ref(0)
|
|
5
14
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ref,
|
|
3
2
|
inject,
|
|
4
3
|
computed,
|
|
4
|
+
onMounted,
|
|
5
5
|
onUnmounted,
|
|
6
|
+
shallowRef,
|
|
6
7
|
type InjectionKey,
|
|
7
8
|
getCurrentInstance,
|
|
8
9
|
type ComponentPublicInstance,
|
|
@@ -16,26 +17,76 @@ type ParentProvide<T> = T & {
|
|
|
16
17
|
internalChildren: ComponentInternalInstance[]
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
function findParentProvide<T>(instance: ComponentInternalInstance, key: InjectionKey<ParentProvide<T>>): ParentProvide<T> | null {
|
|
21
|
+
let parent: ComponentInternalInstance | null = instance.parent
|
|
22
|
+
const provideKey = key as unknown as PropertyKey
|
|
23
|
+
|
|
24
|
+
while (parent) {
|
|
25
|
+
const provides = (parent as any).provides as Record<PropertyKey, unknown> | undefined
|
|
26
|
+
if (provides && provideKey in provides) {
|
|
27
|
+
return provides[provideKey] as ParentProvide<T>
|
|
28
|
+
}
|
|
29
|
+
parent = parent.parent
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 获取父组件提供的上下文数据。
|
|
37
|
+
*
|
|
38
|
+
* 子组件通过传入父组件 `provide` 的 InjectionKey,可以获取父组件共享的状态和子组件在同类兄弟中的索引。
|
|
39
|
+
* 常用于父子联动组件(如 tabs/tab、radio-group/radio、collapse/collapse-item)。
|
|
40
|
+
*
|
|
41
|
+
* 抖音小程序端存在父子初始化时序差异:
|
|
42
|
+
* - 非抖音端保持 setup 阶段同步注入。
|
|
43
|
+
* - 抖音端在 mounted 阶段延迟回查并完成 link。
|
|
44
|
+
*
|
|
45
|
+
* @param key 父组件 provide 时使用的 InjectionKey
|
|
46
|
+
* @returns `{ parent, index }`,parent 为父组件提供的上下文 Ref,index 为当前子组件在兄弟节点中的顺序索引。
|
|
47
|
+
*/
|
|
19
48
|
export function useParent<T>(key: InjectionKey<ParentProvide<T>>) {
|
|
20
|
-
const
|
|
49
|
+
const instance = getCurrentInstance()!
|
|
21
50
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const { link, unlink, internalChildren } = parent
|
|
51
|
+
const parent = shallowRef<ParentProvide<T> | null>(null)
|
|
52
|
+
const linkedParent = shallowRef<ParentProvide<T> | null>(null)
|
|
25
53
|
|
|
26
|
-
|
|
27
|
-
|
|
54
|
+
const tryLinkParent = () => {
|
|
55
|
+
if (!parent.value || linkedParent.value) return false
|
|
28
56
|
|
|
29
|
-
|
|
57
|
+
parent.value.link(instance)
|
|
58
|
+
linkedParent.value = parent.value
|
|
59
|
+
return true
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 非抖音端保持原有 setup 同步 link 行为。
|
|
63
|
+
// #ifndef MP-TOUTIAO
|
|
64
|
+
parent.value = inject(key, null)
|
|
65
|
+
tryLinkParent()
|
|
66
|
+
// #endif
|
|
67
|
+
|
|
68
|
+
// 抖音端延迟到 mounted,规避 setup 阶段父子注入时序问题。
|
|
69
|
+
// #ifdef MP-TOUTIAO
|
|
70
|
+
onMounted(() => {
|
|
71
|
+
parent.value = findParentProvide(instance, key)
|
|
72
|
+
tryLinkParent()
|
|
73
|
+
})
|
|
74
|
+
// #endif
|
|
30
75
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
76
|
+
onUnmounted(() => {
|
|
77
|
+
if (linkedParent.value) {
|
|
78
|
+
linkedParent.value.unlink(instance)
|
|
79
|
+
linkedParent.value = null
|
|
34
80
|
}
|
|
35
|
-
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const index = computed(() => {
|
|
84
|
+
if (!parent.value) return -1
|
|
85
|
+
return parent.value.internalChildren.indexOf(instance)
|
|
86
|
+
})
|
|
36
87
|
|
|
37
88
|
return {
|
|
38
|
-
parent
|
|
39
|
-
index
|
|
89
|
+
parent,
|
|
90
|
+
index
|
|
40
91
|
}
|
|
41
92
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { getCurrentInstance, ref } from 'vue'
|
|
2
2
|
import { getRect, isObj, unitConvert } from '../common/util'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Popover/Tooltip 定位计算 Hook。
|
|
6
|
+
*
|
|
7
|
+
* 计算弹出层相对于目标元素的位置和箭头方向,
|
|
8
|
+
* 支持 12 种 placement(top/bottom/left/right 及其 start/end 变体)。
|
|
9
|
+
*
|
|
10
|
+
* @param visibleArrow 是否显示箭头
|
|
11
|
+
* @returns `{ popStyle, arrowStyle, arrowClass, init, control }` 定位样式和初始化/控制方法
|
|
12
|
+
*/
|
|
4
13
|
export function usePopover(visibleArrow = true) {
|
|
5
14
|
const { proxy } = getCurrentInstance() as any
|
|
6
15
|
const popStyle = ref<string>('')
|
|
@@ -10,6 +10,14 @@ export interface Queue {
|
|
|
10
10
|
closeOutside: () => void
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 组件队列管理 Hook,用于管理同类型弹出组件的互斥展示。
|
|
15
|
+
*
|
|
16
|
+
* 父组件通过 `provide` 注入队列上下文,子组件通过 `inject` 获取,
|
|
17
|
+
* 在打开时关闭其他同类组件,实现唯一展示(如 swipe-action、popup 等)。
|
|
18
|
+
*
|
|
19
|
+
* @returns `{ closeOther, closeOutside }` 关闭其他组件和全部关闭的方法
|
|
20
|
+
*/
|
|
13
21
|
export function useQueue() {
|
|
14
22
|
const queue = ref<any[]>([])
|
|
15
23
|
|
|
@@ -4,6 +4,16 @@ import { isDef, isH5, isNumber } from '../common/util'
|
|
|
4
4
|
// 定义回调函数类型
|
|
5
5
|
type RafCallback = (time: number) => void
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* 跨平台 requestAnimationFrame 封装。
|
|
9
|
+
*
|
|
10
|
+
* H5 环境使用原生 `requestAnimationFrame`,
|
|
11
|
+
* 小程序端使用 `setTimeout` 降级(约 33fps)。
|
|
12
|
+
* 组件卸载时自动取消未完成的动画帧。
|
|
13
|
+
*
|
|
14
|
+
* @param callback 每帧回调,接收当前时间戳
|
|
15
|
+
* @returns `{ start, cancel }` 启动和取消动画帧的方法
|
|
16
|
+
*/
|
|
7
17
|
export function useRaf(callback: RafCallback) {
|
|
8
18
|
const requestRef = ref<number | null | ReturnType<typeof setTimeout>>(null)
|
|
9
19
|
|