From d9cedce2194f8b77ea11e9defb1906cc152e651e Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Tue, 22 Jun 2021 18:19:03 +0800 Subject: [PATCH] chore: showToast add error type --- .../uni-api/src/protocols/ui/showToast.ts | 3 +- .../uni-h5/src/service/api/ui/popup/toast.tsx | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/uni-api/src/protocols/ui/showToast.ts b/packages/uni-api/src/protocols/ui/showToast.ts index c9155207e7..67ced465a4 100644 --- a/packages/uni-api/src/protocols/ui/showToast.ts +++ b/packages/uni-api/src/protocols/ui/showToast.ts @@ -3,11 +3,12 @@ import { elemInArray } from '../../helpers/protocol' export const API_SHOW_TOAST = 'showToast' export type API_TYPE_SHOW_TOAST = typeof uni.showToast -export type API_TYPE_SHOW_TOAST_ICON = 'success' | 'loading' | 'none' +export type API_TYPE_SHOW_TOAST_ICON = 'success' | 'loading' | 'none' | 'error' export const SHOW_TOAST_ICON: API_TYPE_SHOW_TOAST_ICON[] = [ 'success', 'loading', 'none', + 'error', ] export const ShowToastProtocol: ApiProtocol = { diff --git a/packages/uni-h5/src/service/api/ui/popup/toast.tsx b/packages/uni-h5/src/service/api/ui/popup/toast.tsx index 2b7370cdef..d4f4327a2f 100644 --- a/packages/uni-h5/src/service/api/ui/popup/toast.tsx +++ b/packages/uni-h5/src/service/api/ui/popup/toast.tsx @@ -12,6 +12,7 @@ import { onEventPrevent, createSvgIconVNode, ICON_PATH_SUCCESS_NO_CIRCLE, + ICON_PATH_WARN, } from '@dcloudio/uni-core' import { initI18nShowToastMsgsOnce, @@ -94,16 +95,27 @@ export default /*#__PURE__*/ defineComponent({ }) function useToastIcon(props: ToastProps) { - const Icon = computed(() => - props.icon === 'success' ? ( - createVNode(createSvgIconVNode(ICON_PATH_SUCCESS_NO_CIRCLE, '#fff', 38), { - class: ToastIconClassName, - }) - ) : props.icon === 'loading' ? ( - // @ts-ignore - - ) : null - ) + const Icon = computed(() => { + switch (props.icon) { + case 'success': + return createVNode( + createSvgIconVNode(ICON_PATH_SUCCESS_NO_CIRCLE, '#fff', 38), + { + class: ToastIconClassName, + } + ) + case 'error': + return createVNode(createSvgIconVNode(ICON_PATH_WARN, '#fff', 38), { + class: ToastIconClassName, + }) + case 'loading': + // @ts-ignore + return + + default: + return null + } + }) return { Icon, -- GitLab