diff --git a/packages/uni-api/src/protocols/ui/showToast.ts b/packages/uni-api/src/protocols/ui/showToast.ts index c9155207e7c49dc433782cb56d358787b9fc689d..67ced465a4a3cc985ebaac1ab610c100eb9a4520 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 2b7370cdefd6a3b1956579e8cc33243742c39f0c..d4f4327a2fae147f2b857977304b00a2262431e2 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,