From 5f85117a0f68096633dc78dce50b2d322d5934df Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Mon, 26 Apr 2021 19:03:58 +0800 Subject: [PATCH] fix(h5): 1. UniServiceJSBridge.on tree sharkable in showToast 2. fix checkbox disabled status --- .../src/components/checkbox/index.tsx | 5 ++++- packages/uni-h5/dist/uni-h5.esm.js | 17 ++++++++++------- .../src/service/api/ui/popup/showToast.ts | 12 +++++++----- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/uni-components/src/components/checkbox/index.tsx b/packages/uni-components/src/components/checkbox/index.tsx index 384d4ad22..55ea9b969 100644 --- a/packages/uni-components/src/components/checkbox/index.tsx +++ b/packages/uni-components/src/components/checkbox/index.tsx @@ -84,7 +84,10 @@ export default /*#__PURE__*/ defineComponent({ return (
-
+
{checkboxChecked.value ? createSvgIconVNode(ICON_PATH_SUCCESS_NO_CIRCLE, color, 16) : ''} diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index 4c4557218..116f3b9a4 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -5419,8 +5419,10 @@ var index$9 = /* @__PURE__ */ defineComponent({ }, [createVNode("div", { class: "uni-checkbox-wrapper" }, [createVNode("div", { - class: "uni-checkbox-input" - }, [checkboxChecked.value ? createSvgIconVNode(ICON_PATH_SUCCESS_NO_CIRCLE, color, 16) : ""]), slots.default && slots.default()])], 8, ["disabled", "onClick"]); + class: ["uni-checkbox-input", { + "uni-checkbox-input-disabled": disabled + }] + }, [checkboxChecked.value ? createSvgIconVNode(ICON_PATH_SUCCESS_NO_CIRCLE, color, 16) : ""], 2), slots.default && slots.default()])], 8, ["disabled", "onClick"]); }; } }); @@ -13250,6 +13252,9 @@ function useToastIcon(props2) { let showToastState; let showType = ""; let timeoutId; +const onHidePopupOnce = once(() => { + UniServiceJSBridge.on("onHidePopup", () => hidePopup("onHidePopup")); +}); function createToast(args) { if (!showToastState) { showToastState = reactive(args); @@ -13273,6 +13278,7 @@ function createToast(args) { timeoutId && clearTimeout(timeoutId); } }); + onHidePopupOnce(); } const showToast = defineAsyncApi(API_SHOW_TOAST, (args, {resolve, reject}) => { createToast(args); @@ -13298,7 +13304,7 @@ const hideLoading = defineAsyncApi(API_HIDE_LOADING, (args, {resolve, reject}) = hidePopup("onHideLoading"); resolve(); }); -const hidePopup = (type) => { +function hidePopup(type) { const {t: t2} = useI18n(); if (!showType) { return; @@ -13316,10 +13322,7 @@ const hidePopup = (type) => { setTimeout(() => { showToastState.visible = false; }, 10); -}; -setTimeout(() => { - UniServiceJSBridge.on("onHidePopup", () => hidePopup("onHidePopup")); -}, 0); +} const loadFontFace = defineAsyncApi(API_LOAD_FONT_FACE, ({family, source, desc}, {resolve, reject}) => { addFont(family, source, desc).then(() => { resolve(); diff --git a/packages/uni-h5/src/service/api/ui/popup/showToast.ts b/packages/uni-h5/src/service/api/ui/popup/showToast.ts index d67cd95c0..395a87415 100644 --- a/packages/uni-h5/src/service/api/ui/popup/showToast.ts +++ b/packages/uni-h5/src/service/api/ui/popup/showToast.ts @@ -24,11 +24,15 @@ import type { API_TYPE_HIDE_LOADING, API_TYPE_SHOW_TOAST, } from '@dcloudio/uni-api' +import { once } from '@dcloudio/uni-shared' //#endregion let showToastState: ToastProps let showType: 'onShowToast' | 'onShowLoading' | '' = '' let timeoutId: number +const onHidePopupOnce = once(() => { + UniServiceJSBridge.on('onHidePopup', () => hidePopup('onHidePopup')) +}) function createToast(args: ToastProps) { if (!showToastState) { @@ -56,6 +60,8 @@ function createToast(args: ToastProps) { timeoutId && clearTimeout(timeoutId) } }) + + onHidePopupOnce() } export const showToast = defineAsyncApi( @@ -103,7 +109,7 @@ export const hideLoading = defineAsyncApi( } ) -const hidePopup = (type: 'onHideToast' | 'onHideLoading' | 'onHidePopup') => { +function hidePopup(type: 'onHideToast' | 'onHideLoading' | 'onHidePopup') { const { t } = useI18n() if (!showType) { return @@ -123,7 +129,3 @@ const hidePopup = (type: 'onHideToast' | 'onHideLoading' | 'onHidePopup') => { showToastState.visible = false }, 10) } - -setTimeout(() => { - UniServiceJSBridge.on('onHidePopup', () => hidePopup('onHidePopup')) -}, 0) -- GitLab