提交 6b462945 编写于 作者: fxy060608's avatar fxy060608

fix(h5): add effectScope

上级 7eafee5c
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue"; import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, isArray, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared"; import { isString, extend, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, isArray, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { I18N_JSON_DELIMITERS, once, passive, initCustomDataset, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, ON_ERROR, callOptions, ON_LAUNCH, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, UniLifecycleHooks, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared"; import { I18N_JSON_DELIMITERS, once, passive, initCustomDataset, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, ON_ERROR, callOptions, ON_LAUNCH, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, UniLifecycleHooks, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n"; import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
...@@ -7219,9 +7219,9 @@ function text(Quill) { ...@@ -7219,9 +7219,9 @@ function text(Quill) {
} }
]; ];
const result = {}; const result = {};
text2.forEach(({ name, scope }) => { text2.forEach(({ name, scope: scope2 }) => {
result[`formats/${name}`] = new Attributor.Style(name, hyphenate(name), { result[`formats/${name}`] = new Attributor.Style(name, hyphenate(name), {
scope scope: scope2
}); });
}); });
return result; return result;
...@@ -17706,7 +17706,7 @@ var modal = /* @__PURE__ */ defineComponent({ ...@@ -17706,7 +17706,7 @@ var modal = /* @__PURE__ */ defineComponent({
} }
}); });
let showModalState; let showModalState;
const onHidePopupOnce$2 = /* @__PURE__ */ once(() => { const onHidePopupOnce$1 = /* @__PURE__ */ once(() => {
UniServiceJSBridge.on("onHidePopup", () => showModalState.visible = false); UniServiceJSBridge.on("onHidePopup", () => showModalState.visible = false);
}); });
let currentShowModalResolve; let currentShowModalResolve;
...@@ -17717,7 +17717,7 @@ function onModalClose(type) { ...@@ -17717,7 +17717,7 @@ function onModalClose(type) {
}); });
} }
const showModal = /* @__PURE__ */ defineAsyncApi(API_SHOW_MODAL, (args, { resolve }) => { const showModal = /* @__PURE__ */ defineAsyncApi(API_SHOW_MODAL, (args, { resolve }) => {
onHidePopupOnce$2(); onHidePopupOnce$1();
currentShowModalResolve = resolve; currentShowModalResolve = resolve;
if (!showModalState) { if (!showModalState) {
showModalState = reactive(args); showModalState = reactive(args);
...@@ -17823,27 +17823,29 @@ function useToastIcon(props2) { ...@@ -17823,27 +17823,29 @@ function useToastIcon(props2) {
let showToastState; let showToastState;
let showType = ""; let showType = "";
let timeoutId; let timeoutId;
const onHidePopupOnce$1 = /* @__PURE__ */ once(() => { const scope = effectScope();
UniServiceJSBridge.on("onHidePopup", () => hidePopup("onHidePopup")); function watchVisible() {
}); scope.run(() => {
const watchVisibleOnce = /* @__PURE__ */ once(() => { watch([() => showToastState.visible, () => showToastState.duration], ([visible, duration]) => {
watch([() => showToastState.visible, () => showToastState.duration], ([visible, duration]) => { if (visible) {
if (visible) { timeoutId && clearTimeout(timeoutId);
timeoutId && clearTimeout(timeoutId); if (showType === "onShowLoading")
if (showType === "onShowLoading") return;
return; timeoutId = setTimeout(() => {
timeoutId = setTimeout(() => { hidePopup("onHideToast");
hidePopup("onHideToast"); }, duration);
}, duration); } else {
} else { timeoutId && clearTimeout(timeoutId);
timeoutId && clearTimeout(timeoutId); }
} });
}); });
}); }
function createToast(args) { function createToast(args) {
if (!showToastState) { if (!showToastState) {
showToastState = reactive(extend(args, { visible: false })); showToastState = reactive(extend(args, { visible: false }));
nextTick(() => { nextTick(() => {
watchVisible();
UniServiceJSBridge.on("onHidePopup", () => hidePopup("onHidePopup"));
createRootApp(Toast, showToastState, () => { createRootApp(Toast, showToastState, () => {
}).mount(ensureRoot("u-a-t")); }).mount(ensureRoot("u-a-t"));
}); });
...@@ -17853,8 +17855,6 @@ function createToast(args) { ...@@ -17853,8 +17855,6 @@ function createToast(args) {
setTimeout(() => { setTimeout(() => {
showToastState.visible = true; showToastState.visible = true;
}, 10); }, 10);
watchVisibleOnce();
onHidePopupOnce$1();
} }
const showToast = /* @__PURE__ */ defineAsyncApi(API_SHOW_TOAST, (args, { resolve, reject }) => { const showToast = /* @__PURE__ */ defineAsyncApi(API_SHOW_TOAST, (args, { resolve, reject }) => {
createToast(args); createToast(args);
......
//#region Functions //#region Functions
import { reactive, nextTick, watch } from 'vue' import { reactive, nextTick, watch, effectScope } from 'vue'
import { extend } from '@vue/shared' import { extend } from '@vue/shared'
import { import {
defineAsyncApi, defineAsyncApi,
...@@ -24,38 +24,39 @@ import type { ...@@ -24,38 +24,39 @@ import type {
API_TYPE_HIDE_LOADING, API_TYPE_HIDE_LOADING,
API_TYPE_SHOW_TOAST, API_TYPE_SHOW_TOAST,
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
import { once } from '@dcloudio/uni-shared'
//#endregion //#endregion
let showToastState: ToastProps let showToastState: ToastProps
let showType: 'onShowToast' | 'onShowLoading' | '' = '' let showType: 'onShowToast' | 'onShowLoading' | '' = ''
let timeoutId: number let timeoutId: number
const onHidePopupOnce = /*#__PURE__*/ once(() => {
UniServiceJSBridge.on('onHidePopup', () => hidePopup('onHidePopup'))
})
const watchVisibleOnce = /*#__PURE__*/ once(() => { const scope = effectScope()
watch( function watchVisible() {
[() => showToastState.visible, () => showToastState.duration], scope.run(() => {
([visible, duration]) => { watch(
if (visible) { [() => showToastState.visible, () => showToastState.duration],
timeoutId && clearTimeout(timeoutId) ([visible, duration]) => {
if (showType === 'onShowLoading') return if (visible) {
timeoutId = setTimeout(() => { timeoutId && clearTimeout(timeoutId)
hidePopup('onHideToast') if (showType === 'onShowLoading') return
}, duration) timeoutId = setTimeout(() => {
} else { hidePopup('onHideToast')
timeoutId && clearTimeout(timeoutId) }, duration)
} else {
timeoutId && clearTimeout(timeoutId)
}
} }
} )
) })
}) }
function createToast(args: ToastProps) { function createToast(args: ToastProps) {
if (!showToastState) { if (!showToastState) {
showToastState = reactive(extend(args, { visible: false })) showToastState = reactive(extend(args, { visible: false }))
// 异步执行,避免干扰 getCurrentInstance // 异步执行,避免干扰 getCurrentInstance
nextTick(() => { nextTick(() => {
watchVisible()
UniServiceJSBridge.on('onHidePopup', () => hidePopup('onHidePopup'))
createRootApp(Toast, showToastState, () => {}).mount(ensureRoot('u-a-t')) createRootApp(Toast, showToastState, () => {}).mount(ensureRoot('u-a-t'))
}) })
} else { } else {
...@@ -66,10 +67,6 @@ function createToast(args: ToastProps) { ...@@ -66,10 +67,6 @@ function createToast(args: ToastProps) {
// 延迟一下 show 可解决窗口打开前调用 showToast 在 onHidePopup 之后触发 // 延迟一下 show 可解决窗口打开前调用 showToast 在 onHidePopup 之后触发
showToastState.visible = true showToastState.visible = true
}, 10) }, 10)
watchVisibleOnce()
onHidePopupOnce()
} }
export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>( export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册