diff --git a/packages/shims-vue-runtime.d.ts b/packages/shims-vue-runtime.d.ts index bb2ec096eccc0b76b62adae78378baec2703c450..b649aadb8ca3bd8d46f11a51ad3eaaf791650349 100644 --- a/packages/shims-vue-runtime.d.ts +++ b/packages/shims-vue-runtime.d.ts @@ -15,6 +15,7 @@ declare module '@vue/runtime-core' { __isUnload: boolean __isVisible: boolean __isActive?: boolean // tabBar + __isPage: boolean } export const callSyncHook: ( diff --git a/packages/uni-components/src/components/label/index.tsx b/packages/uni-components/src/components/label/index.tsx index 3934a9ba5b58c6205681aa5335cebfcc3b5b7cb3..c38667710b0434a2ea56071b35885c8d9d87d4f1 100644 --- a/packages/uni-components/src/components/label/index.tsx +++ b/packages/uni-components/src/components/label/index.tsx @@ -1,5 +1,6 @@ import { defineComponent, provide, getCurrentInstance, computed } from 'vue' import { PolySymbol } from '@dcloudio/uni-core' +import { withWebEvent } from '@dcloudio/uni-components' export const uniLabelKey = PolySymbol(__DEV__ ? 'uniLabel' : 'ul') const props = { @@ -14,8 +15,7 @@ export default /*#__PURE__*/ defineComponent({ props, setup(props, { emit, slots }) { const instance = getCurrentInstance()! - const vm = instance.proxy! - const pageId = vm.$root!.$page.id + const pageId = instance.root.proxy!.$page.id const handlers = useProvideLabel() @@ -23,7 +23,7 @@ export default /*#__PURE__*/ defineComponent({ () => props.for || (slots.default && slots.default.length) ) - const _onClick = ($event: Event) => { + const _onClick = withWebEvent(($event: Event) => { const EventTarget = $event.target as HTMLElement let stopPropagation = /^uni-(checkbox|radio|switch)-/.test( EventTarget.className @@ -52,7 +52,7 @@ export default /*#__PURE__*/ defineComponent({ handler($event, true) }) } - } + }) return () => ( diff --git a/packages/uni-components/src/helpers/useEvent.ts b/packages/uni-components/src/helpers/useEvent.ts index bf4c5d00ece4fde28378b9f8eea0a3dc8fc5ee7a..347f23f0bfc3542231cd24e7819d0e6d3da8a5a0 100644 --- a/packages/uni-components/src/helpers/useEvent.ts +++ b/packages/uni-components/src/helpers/useEvent.ts @@ -4,6 +4,10 @@ import { normalizeTarget } from '@dcloudio/uni-shared' type EventDetail = Record export type CustomEventTrigger = ReturnType +export function withWebEvent(fn: Function) { + return ((fn as any).__wwe = true), fn +} + export function useCustomEvent( ref: Ref, emit: SetupContext['emit'] diff --git a/packages/uni-components/src/helpers/useListeners.ts b/packages/uni-components/src/helpers/useListeners.ts index cab4a2b8ef456008a70c22d613693dc8351d5334..74f7ce873926c832ea1b5f2441bebbba7f15d0a2 100644 --- a/packages/uni-components/src/helpers/useListeners.ts +++ b/packages/uni-components/src/helpers/useListeners.ts @@ -1,7 +1,7 @@ import { isPlainObject } from '@vue/shared' import { watch, onUnmounted, getCurrentInstance } from 'vue' -export function /*#__PURE__*/ useListeners( +export function useListeners( props: { id: string }, listeners: Record ) { @@ -26,8 +26,7 @@ function _addListeners( watch?: boolean ) { const instance = getCurrentInstance()! - const vm = instance.proxy! - const pageId = vm.$root!.$page.id + const pageId = instance.root.proxy!.$page.id if (watch && !id) { // id被置空 @@ -61,8 +60,7 @@ function _removeListeners( watch?: boolean ) { const instance = getCurrentInstance()! - const vm = instance.proxy! - const pageId = vm.$root!.$page.id + const pageId = instance.root.proxy!.$page.id if (watch && !id) { // id之前不存在 diff --git a/packages/uni-components/src/helpers/useScopedAttrs.ts b/packages/uni-components/src/helpers/useScopedAttrs.ts index 61b7fc27c52a61298410624acb7624e565cfcdf7..e84e0eacc6c61eb97b3cd955e7e256a42ef5680d 100644 --- a/packages/uni-components/src/helpers/useScopedAttrs.ts +++ b/packages/uni-components/src/helpers/useScopedAttrs.ts @@ -14,16 +14,13 @@ export function useScopedAttrs() { }) onMounted(() => { - let vm = (getCurrentInstance() as ComponentInternalInstance).proxy - while (vm) { - const $options = vm.$options - const scopeId = $options.__scopeId + let instance = getCurrentInstance() + while (instance) { + const scopeId = (instance.type as any).__scopeId if (scopeId) { - const attrs: Record = {} - attrs[scopeId] = '' - state.attrs = attrs + state.attrs[scopeId] = '' } - vm = vm.$parent + instance = instance.__isPage ? null : instance.parent } }) diff --git a/packages/uni-components/src/helpers/useSubscribe.ts b/packages/uni-components/src/helpers/useSubscribe.ts index 7c070d4d10b3314a11e9cbb11a0565ce4ac6b018..ad5a9b0ae9705fafd3fdca4fa183fd5eef01a285 100644 --- a/packages/uni-components/src/helpers/useSubscribe.ts +++ b/packages/uni-components/src/helpers/useSubscribe.ts @@ -45,7 +45,8 @@ export function useSubscribe( ) { const instance = getCurrentInstance()! const vm = instance.proxy! - const pageId = name ? 0 : vm.$root!.$page.id + // 不能直接使用instance.proxy.$root,此时可能获取到的是exposed + const pageId = name ? 0 : instance.root.proxy!.$page.id onMounted(() => { addSubscribe(name || normalizeEvent(pageId, vm)!, callback) if (!name) { diff --git a/packages/uni-components/src/index.ts b/packages/uni-components/src/index.ts index 994cb20dbf62cb898df2b985b353ab7c29afe169..c6c3276970a4d077ad208f9aca982c3e57e2bfb7 100644 --- a/packages/uni-components/src/index.ts +++ b/packages/uni-components/src/index.ts @@ -1,4 +1,4 @@ export * from './components' export { useOn, useSubscribe } from './helpers/useSubscribe' -export { useCustomEvent } from './helpers/useEvent' +export { withWebEvent, useCustomEvent } from './helpers/useEvent' export { useUserAction } from './helpers/useUserAction' diff --git a/packages/uni-core/src/view/plugin/componentInstance.ts b/packages/uni-core/src/view/plugin/componentInstance.ts index 20df9f4fb5652fe6661773eeee9f4b0a20325809..74d15619e32f11154167e7250a7038e1a5f3a5c3 100644 --- a/packages/uni-core/src/view/plugin/componentInstance.ts +++ b/packages/uni-core/src/view/plugin/componentInstance.ts @@ -1,26 +1,20 @@ import { ComponentPublicInstance } from 'vue' +import { extend } from '@vue/shared' import { normalizeTarget } from '@dcloudio/uni-shared' import { getWindowOffset } from '../../helpers' -// TODO 临时跳过内置组件事件处理 -const TempSkipComponents = ['UNI-CHECKBOX', 'UNI-LABEL'] const isClickEvent = (val: Event): val is MouseEvent => val.type === 'click' const isMouseEvent = (val: Event): val is MouseEvent => val.type.indexOf('mouse') === 0 // normalizeNativeEvent export function $nne(this: ComponentPublicInstance, evt: Event) { - // TODO 目前内置组件底层实现,也会进入以下处理逻辑,可能会有影响 + // 目前内置组件底层实现,当需要访问原始event时,请使用withWebEvent包裹 + // 用法参考:uni-h5/src/framework/components/page/page-refresh/index.ts const { currentTarget } = evt if (!(evt instanceof Event) || !(currentTarget instanceof HTMLElement)) { return evt } - const { tagName } = currentTarget - if ( - tagName.indexOf('UNI-') !== 0 || - tagName === 'UNI-PAGE-WRAPPER' || - TempSkipComponents.indexOf(tagName) !== -1 - ) { - // TODO 下拉刷新事件返回原始event,目前硬编码,后续换其他方案解决 + if (currentTarget.tagName.indexOf('UNI-') !== 0) { return evt } @@ -42,29 +36,34 @@ export function $nne(this: ComponentPublicInstance, evt: Event) { function createNativeEvent(evt: Event) { const { type, timeStamp, currentTarget } = evt const target = normalizeTarget(currentTarget as HTMLElement) - return { + const event = { type, timeStamp, target, detail: {}, currentTarget: target, - preventDefault() { - if (__DEV__) { - console.warn( - 'preventDefault is only supported in h5, use `.prevent` instead.' - ) - } - return evt.preventDefault() - }, - stopPropagation() { - if (__DEV__) { - console.warn( - 'stopPropagation is only supported in h5, use `.stop` instead.' - ) - } - return evt.stopPropagation() - }, } + if (__PLATFORM__ === 'h5') { + extend(event, { + preventDefault() { + if (__DEV__) { + console.warn( + 'preventDefault is only supported in h5, use `.prevent` instead.' + ) + } + return evt.preventDefault() + }, + stopPropagation() { + if (__DEV__) { + console.warn( + 'stopPropagation is only supported in h5, use `.stop` instead.' + ) + } + return evt.stopPropagation() + }, + }) + } + return event } function normalizeClickEvent( diff --git a/packages/uni-h5-vue/dist/vue.runtime.esm.js b/packages/uni-h5-vue/dist/vue.runtime.esm.js index edcc810e7f453e2fa29f96c3e38a0a51d3c0f158..9abcb2ee0295062f0f75fe34ec1fbdbb4013e6e9 100644 --- a/packages/uni-h5-vue/dist/vue.runtime.esm.js +++ b/packages/uni-h5-vue/dist/vue.runtime.esm.js @@ -8403,7 +8403,19 @@ function createInvoker(initialValue, instance) { // fixed by xxxxxx const proxy = instance && instance.proxy; const normalizeNativeEvent = proxy && proxy.$nne; - callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [normalizeNativeEvent ? normalizeNativeEvent(e) : e]); + if (normalizeNativeEvent && isArray(invoker.value)) { + const fns = invoker.value; + for (let i = 0; i < fns.length; i++) { + const fn = fns[i]; + callWithAsyncErrorHandling(fn, instance, 5 /* NATIVE_EVENT_HANDLER */, [!fn.__wwe ? normalizeNativeEvent(e) : e]); + } + return; + } + callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [ + normalizeNativeEvent && !invoker.value.__wwe + ? normalizeNativeEvent(e) + : e + ]); } }; invoker.value = initialValue; @@ -8448,7 +8460,7 @@ const forcePatchProp = (_, key) => key === 'value'; const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => { // @ts-expect-error fixed by xxxxxx if (__UNI_FEATURE_WXS__ && key.indexOf('change:') === 0) { - patchWxs(el, key, nextValue, parentComponent); + return patchWxs(el, key, nextValue, parentComponent); } switch (key) { // special diff --git a/packages/uni-h5-vue/lib/vue.runtime.esm.js b/packages/uni-h5-vue/lib/vue.runtime.esm.js index 3b31283c3a18cf4a8f0000487bd9d70d78c7db8a..77e477d9031b84a6b837a10bf2d85909dd3dea08 100644 --- a/packages/uni-h5-vue/lib/vue.runtime.esm.js +++ b/packages/uni-h5-vue/lib/vue.runtime.esm.js @@ -8403,7 +8403,19 @@ function createInvoker(initialValue, instance) { // fixed by xxxxxx const proxy = instance && instance.proxy; const normalizeNativeEvent = proxy && proxy.$nne; - callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [normalizeNativeEvent ? normalizeNativeEvent(e) : e]); + if (normalizeNativeEvent && isArray(invoker.value)) { + const fns = invoker.value; + for (let i = 0; i < fns.length; i++) { + const fn = fns[i]; + callWithAsyncErrorHandling(fn, instance, 5 /* NATIVE_EVENT_HANDLER */, [!fn.__wwe ? normalizeNativeEvent(e) : e]); + } + return; + } + callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [ + normalizeNativeEvent && !invoker.value.__wwe + ? normalizeNativeEvent(e) + : e + ]); } }; invoker.value = initialValue; @@ -8448,7 +8460,7 @@ const forcePatchProp = (_, key) => key === 'value'; const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => { // @ts-expect-error fixed by xxxxxx if (__UNI_FEATURE_WXS__ && key.indexOf('change:') === 0) { - patchWxs(el, key, nextValue, parentComponent); + return patchWxs(el, key, nextValue, parentComponent); } switch (key) { // special diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index df72717c0aef49b85c0684997b6d5c61da003235..fb53df60de56bba7c7260c4b16b7e9f253880a23 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -678,7 +678,7 @@ var safeAreaInsets = { onChange, offChange }; -var D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out = safeAreaInsets; +var out = safeAreaInsets; const onEventPrevent = /* @__PURE__ */ withModifiers(() => { }, ["prevent"]); const onEventStop = /* @__PURE__ */ withModifiers(() => { @@ -690,10 +690,10 @@ function getWindowOffset() { const left = parseInt(style2.getPropertyValue("--window-left")); const right = parseInt(style2.getPropertyValue("--window-right")); return { - top: top ? top + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top : 0, - bottom: bottom ? bottom + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom : 0, - left: left ? left + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left : 0, - right: right ? right + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right : 0 + top: top ? top + out.top : 0, + bottom: bottom ? bottom + out.bottom : 0, + left: left ? left + out.left : 0, + right: right ? right + out.right : 0 }; } const style = document.documentElement.style; @@ -857,7 +857,6 @@ function getRealRoute(fromRoute, toRoute) { fromRouteArray.splice(fromRouteArray.length - i2 - 1, i2 + 1); return "/" + fromRouteArray.concat(toRouteArray).join("/"); } -const TempSkipComponents = ["UNI-CHECKBOX", "UNI-LABEL"]; const isClickEvent = (val) => val.type === "click"; const isMouseEvent = (val) => val.type.indexOf("mouse") === 0; function $nne(evt) { @@ -865,8 +864,7 @@ function $nne(evt) { if (!(evt instanceof Event) || !(currentTarget instanceof HTMLElement)) { return evt; } - const {tagName} = currentTarget; - if (tagName.indexOf("UNI-") !== 0 || tagName === "UNI-PAGE-WRAPPER" || TempSkipComponents.indexOf(tagName) !== -1) { + if (currentTarget.tagName.indexOf("UNI-") !== 0) { return evt; } const res = createNativeEvent(evt); @@ -884,25 +882,30 @@ function $nne(evt) { function createNativeEvent(evt) { const {type, timeStamp, currentTarget} = evt; const target = normalizeTarget(currentTarget); - return { + const event2 = { type, timeStamp, target, detail: {}, - currentTarget: target, - preventDefault() { - if (process.env.NODE_ENV !== "production") { - console.warn("preventDefault is only supported in h5, use `.prevent` instead."); - } - return evt.preventDefault(); - }, - stopPropagation() { - if (process.env.NODE_ENV !== "production") { - console.warn("stopPropagation is only supported in h5, use `.stop` instead."); - } - return evt.stopPropagation(); - } + currentTarget: target }; + { + extend(event2, { + preventDefault() { + if (process.env.NODE_ENV !== "production") { + console.warn("preventDefault is only supported in h5, use `.prevent` instead."); + } + return evt.preventDefault(); + }, + stopPropagation() { + if (process.env.NODE_ENV !== "production") { + console.warn("stopPropagation is only supported in h5, use `.stop` instead."); + } + return evt.stopPropagation(); + } + }); + } + return event2; } function normalizeClickEvent(evt, mouseEvt) { const {x, y} = mouseEvt; @@ -1329,7 +1332,7 @@ function normalizePageMeta(pageMeta) { let offset = rpx2px(refreshOptions.offset); const {type} = navigationBar; if (type !== "transparent" && type !== "none") { - offset += NAVBAR_HEIGHT + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top; + offset += NAVBAR_HEIGHT + out.top; } refreshOptions.offset = offset; refreshOptions.height = rpx2px(refreshOptions.height); @@ -3803,6 +3806,7 @@ function setupPage(comp) { return setupComponent(comp, { init: initPage, setup(instance2) { + instance2.__isPage = true; instance2.root = instance2; const route = usePageRoute(); if (route.meta.isTabBar) { @@ -5031,8 +5035,7 @@ function useListeners(props2, listeners2) { } function _addListeners(id2, listeners2, watch2) { const instance2 = getCurrentInstance(); - const vm = instance2.proxy; - const pageId = vm.$root.$page.id; + const pageId = instance2.root.proxy.$page.id; if (watch2 && !id2) { return; } @@ -5055,8 +5058,7 @@ function _addListeners(id2, listeners2, watch2) { } function _removeListeners(id2, listeners2, watch2) { const instance2 = getCurrentInstance(); - const vm = instance2.proxy; - const pageId = vm.$root.$page.id; + const pageId = instance2.root.proxy.$page.id; if (watch2 && !id2) { return; } @@ -5077,6 +5079,9 @@ function _removeListeners(id2, listeners2, watch2) { } }); } +function withWebEvent(fn) { + return fn.__wwe = true, fn; +} function useCustomEvent(ref2, emit2) { return (name, evt, detail) => { emit2(name, normalizeCustomEvent(name, evt, ref2.value, detail || {})); @@ -5167,11 +5172,10 @@ var index$b = /* @__PURE__ */ defineComponent({ slots }) { const instance2 = getCurrentInstance(); - const vm = instance2.proxy; - const pageId = vm.$root.$page.id; + const pageId = instance2.root.proxy.$page.id; const handlers = useProvideLabel(); const pointer = computed(() => props2.for || slots.default && slots.default.length); - const _onClick = ($event) => { + const _onClick = withWebEvent(($event) => { const EventTarget = $event.target; let stopPropagation = /^uni-(checkbox|radio|switch)-/.test(EventTarget.className); if (!stopPropagation) { @@ -5190,7 +5194,7 @@ var index$b = /* @__PURE__ */ defineComponent({ handler($event, true); }); } - }; + }); return () => createVNode("uni-label", { class: { "uni-label-pointer": pointer @@ -6512,16 +6516,13 @@ function useScopedAttrs() { attrs: {} }); onMounted(() => { - let vm = getCurrentInstance().proxy; - while (vm) { - const $options = vm.$options; - const scopeId = $options.__scopeId; + let instance2 = getCurrentInstance(); + while (instance2) { + const scopeId = instance2.type.__scopeId; if (scopeId) { - const attrs2 = {}; - attrs2[scopeId] = ""; - state.attrs = attrs2; + state.attrs[scopeId] = ""; } - vm = vm.$parent; + instance2 = instance2.__isPage ? null : instance2.parent; } }); return { @@ -10320,7 +10321,7 @@ function removeSubscribe(name) { function useSubscribe(callback, name) { const instance2 = getCurrentInstance(); const vm = instance2.proxy; - const pageId = name ? 0 : vm.$root.$page.id; + const pageId = name ? 0 : instance2.root.proxy.$page.id; onMounted(() => { addSubscribe(name || normalizeEvent(pageId, vm), callback); if (!name) { @@ -11428,7 +11429,7 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => { const windowWidth = getWindowWidth(screenWidth); let windowHeight = window.innerHeight; const language = navigator.language; - const statusBarHeight = D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top; + const statusBarHeight = out.top; let osname; let osversion; let model; @@ -11541,12 +11542,12 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => { const system = `${osname} ${osversion}`; const platform = osname.toLocaleLowerCase(); const safeArea = { - left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left, - right: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right, - top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top, - bottom: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom, - width: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right, - height: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom + left: out.left, + right: windowWidth - out.right, + top: out.top, + bottom: windowHeight - out.bottom, + width: windowWidth - out.left - out.right, + height: windowHeight - out.top - out.bottom }; const {top: windowTop, bottom: windowBottom} = getWindowOffset(); windowHeight -= windowTop; @@ -11566,10 +11567,10 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => { model, safeArea, safeAreaInsets: { - top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top, - right: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right, - bottom: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom, - left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left + top: out.top, + right: out.right, + bottom: out.bottom, + left: out.left } }; }); @@ -14392,7 +14393,7 @@ function usePageRefresh(refreshRef) { refreshControllerElemStyle.clip = "rect(" + (45 - y) + "px,45px,45px,-5px)"; refreshControllerElemStyle.transform = "translate3d(-50%, " + y + "px, 0)"; } - function onTouchstartPassive(ev) { + const onTouchstartPassive = withWebEvent((ev) => { const touch = ev.changedTouches[0]; touchId = touch.identifier; startY = touch.pageY; @@ -14401,8 +14402,8 @@ function usePageRefresh(refreshRef) { } else { canRefresh = true; } - } - function onTouchmove(ev) { + }); + const onTouchmove = withWebEvent((ev) => { if (!canRefresh) { return; } @@ -14436,8 +14437,8 @@ function usePageRefresh(refreshRef) { addClass(); } pulling(deltaY); - } - function onTouchend(ev) { + }); + const onTouchend = withWebEvent((ev) => { if (!processDeltaY(ev, touchId, startY)) { return; } @@ -14458,7 +14459,7 @@ function usePageRefresh(refreshRef) { addClass(); refreshing(); } - } + }); function aborting(callback) { if (!refreshControllerElem) { return; @@ -14575,4 +14576,4 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { ]); } _sfc_main.render = _sfc_render; -export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$d as Audio, index$d as Button, _sfc_main$c as Canvas, index$a as Checkbox, index$c as CheckboxGroup, index$9 as Editor, index$e as Form, index$8 as Icon, index$7 as Image, Input, index$b as Label, LayoutComponent, _sfc_main$b as MovableView, _sfc_main$a as Navigator, index as PageComponent, index$6 as Progress, _sfc_main$9 as Radio, _sfc_main$8 as RadioGroup, ResizeSensor, _sfc_main$7 as RichText, _sfc_main$6 as ScrollView, _sfc_main$5 as Slider, _sfc_main$4 as SwiperItem, _sfc_main$3 as Switch, index$5 as Text, index$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$2 as Video, index$3 as View, index$1 as WebView, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, chooseFile, chooseImage, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createInnerAudioContext, createIntersectionObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLocation, getNetworkType, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getVideoInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, hideToast, loadFontFace, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, onAccelerometerChange, onCompassChange, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, openDocument, pageScrollTo, index$f as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeStorage, removeStorageSync, removeTabBarBadge, request, sendSocketMessage, setNavigationBarColor, setNavigationBarTitle, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setupApp, setupPage, showLoading, showModal, showNavigationBarLoading, showTabBar, showTabBarRedDot, showToast, startAccelerometer, startCompass, startPullDownRefresh, stopAccelerometer, stopCompass, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useCustomEvent, useOn, useSubscribe, useUserAction, vibrateLong, vibrateShort}; +export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$d as Audio, index$d as Button, _sfc_main$c as Canvas, index$a as Checkbox, index$c as CheckboxGroup, index$9 as Editor, index$e as Form, index$8 as Icon, index$7 as Image, Input, index$b as Label, LayoutComponent, _sfc_main$b as MovableView, _sfc_main$a as Navigator, index as PageComponent, index$6 as Progress, _sfc_main$9 as Radio, _sfc_main$8 as RadioGroup, ResizeSensor, _sfc_main$7 as RichText, _sfc_main$6 as ScrollView, _sfc_main$5 as Slider, _sfc_main$4 as SwiperItem, _sfc_main$3 as Switch, index$5 as Text, index$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$2 as Video, index$3 as View, index$1 as WebView, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, chooseFile, chooseImage, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createInnerAudioContext, createIntersectionObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLocation, getNetworkType, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getVideoInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, hideToast, loadFontFace, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, onAccelerometerChange, onCompassChange, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, openDocument, pageScrollTo, index$f as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeStorage, removeStorageSync, removeTabBarBadge, request, sendSocketMessage, setNavigationBarColor, setNavigationBarTitle, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setupApp, setupPage, showLoading, showModal, showNavigationBarLoading, showTabBar, showTabBarRedDot, showToast, startAccelerometer, startCompass, startPullDownRefresh, stopAccelerometer, stopCompass, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useCustomEvent, useOn, useSubscribe, useUserAction, vibrateLong, vibrateShort, withWebEvent}; diff --git a/packages/uni-h5/src/framework/components/page/page-refresh/index.ts b/packages/uni-h5/src/framework/components/page/page-refresh/index.ts index d890692f5290e83fb79a016945759f457eb35939..e5c108acc2b14897b10f14c0f9af38266ff06135 100644 --- a/packages/uni-h5/src/framework/components/page/page-refresh/index.ts +++ b/packages/uni-h5/src/framework/components/page/page-refresh/index.ts @@ -4,7 +4,7 @@ import { API_START_PULL_DOWN_REFRESH, API_STOP_PULL_DOWN_REFRESH, } from '@dcloudio/uni-api' -import { useSubscribe } from '@dcloudio/uni-components' +import { useSubscribe, withWebEvent } from '@dcloudio/uni-components' import { usePageMeta } from '../../../setup/provide' function processDeltaY( @@ -117,7 +117,7 @@ export function usePageRefresh(refreshRef: Ref) { refreshControllerElemStyle.transform = 'translate3d(-50%, ' + y + 'px, 0)' } - function onTouchstartPassive(ev: TouchEvent) { + const onTouchstartPassive = withWebEvent((ev: TouchEvent) => { const touch = ev.changedTouches[0] touchId = touch.identifier startY = touch.pageY @@ -126,9 +126,9 @@ export function usePageRefresh(refreshRef: Ref) { } else { canRefresh = true } - } + }) - function onTouchmove(ev: TouchEvent) { + const onTouchmove = withWebEvent((ev: TouchEvent) => { if (!canRefresh) { return } @@ -171,9 +171,9 @@ export function usePageRefresh(refreshRef: Ref) { } pulling(deltaY!) - } + }) - function onTouchend(ev: TouchEvent) { + const onTouchend = withWebEvent((ev: TouchEvent) => { if (!processDeltaY(ev, touchId, startY)) { return } @@ -194,7 +194,7 @@ export function usePageRefresh(refreshRef: Ref) { addClass() refreshing() } - } + }) function aborting(callback: Function) { if (!refreshControllerElem) { diff --git a/packages/uni-h5/src/framework/setup/index.ts b/packages/uni-h5/src/framework/setup/index.ts index c1bef1b2d044107800e9b976480ca10b21085fb6..ffd2ab4d3353aad6f56db783fd3fc79acf0e55e5 100644 --- a/packages/uni-h5/src/framework/setup/index.ts +++ b/packages/uni-h5/src/framework/setup/index.ts @@ -53,6 +53,7 @@ export function setupPage(comp: any) { return setupComponent(comp, { init: initPage, setup(instance) { + instance.__isPage = true // 标记当前组件是页面 instance.root = instance // 组件root指向页面 const route = usePageRoute() if (route.meta.isTabBar) {