提交 c511dee9 编写于 作者: D DCloud_LXH

fix(app): uni.showLoading question/135551

上级 2616be88
...@@ -17,6 +17,7 @@ import { ...@@ -17,6 +17,7 @@ import {
type Resolve = (res?: any) => void type Resolve = (res?: any) => void
type Reject = (errMsg?: string, errRes?: any) => void type Reject = (errMsg?: string, errRes?: any) => void
type CallBacks = { resolve: Resolve; reject: Reject }
type ToastType = 'loading' | 'toast' | '' type ToastType = 'loading' | 'toast' | ''
...@@ -30,7 +31,7 @@ export const showLoading = defineAsyncApi<API_TYPE_SHOW_LOADING>( ...@@ -30,7 +31,7 @@ export const showLoading = defineAsyncApi<API_TYPE_SHOW_LOADING>(
(args, callbacks) => (args, callbacks) =>
_showToast( _showToast(
extend({}, args, { extend({}, args, {
type: 'loading', type: 'loading' as ToastType,
icon: 'loading' as UniApp.ShowToastOptions['icon'], icon: 'loading' as UniApp.ShowToastOptions['icon'],
}), }),
callbacks callbacks
...@@ -39,6 +40,11 @@ export const showLoading = defineAsyncApi<API_TYPE_SHOW_LOADING>( ...@@ -39,6 +40,11 @@ export const showLoading = defineAsyncApi<API_TYPE_SHOW_LOADING>(
ShowLoadingOptions ShowLoadingOptions
) )
interface _ShowToast extends UniApp.ShowToastOptions {
type?: ToastType
style?: PlusNativeUIWaitingStyles
}
const _showToast = ( const _showToast = (
{ {
title = '', title = '',
...@@ -47,12 +53,10 @@ const _showToast = ( ...@@ -47,12 +53,10 @@ const _showToast = (
duration = 1500, duration = 1500,
mask = false, mask = false,
position, position,
// @ts-ignore ToastType
type = 'toast', type = 'toast',
// @ts-ignore PlusNativeUIWaitingStyles
style, style,
}: UniApp.ShowToastOptions, }: _ShowToast,
{ resolve, reject }: { resolve: Resolve; reject: Reject } { resolve, reject }: CallBacks
) => { ) => {
hide('') hide('')
toastType = type toastType = type
...@@ -109,9 +113,10 @@ const _showToast = ( ...@@ -109,9 +113,10 @@ const _showToast = (
} }
} }
timeout = setTimeout(() => { if (toastType === 'toast')
hide('') timeout = setTimeout(() => {
}, duration) hide('')
}, duration)
return resolve() return resolve()
} }
export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>( export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>(
...@@ -131,10 +136,7 @@ export const hideLoading = defineAsyncApi<API_TYPE_HIDE_LOADING>( ...@@ -131,10 +136,7 @@ export const hideLoading = defineAsyncApi<API_TYPE_HIDE_LOADING>(
(_, callbacks) => hide('loading', callbacks) (_, callbacks) => hide('loading', callbacks)
) )
function hide( function hide(type: ToastType = 'toast', callbacks?: CallBacks) {
type: string = 'toast',
callbacks?: { resolve: Resolve; reject: Reject }
) {
if (type && type !== toastType) { if (type && type !== toastType) {
// 应该不需要失败回调,在页面后退时,会主动 hideToast 和 hideLoading,如果 reject 会出异常。 // 应该不需要失败回调,在页面后退时,会主动 hideToast 和 hideLoading,如果 reject 会出异常。
return callbacks && callbacks.resolve() return callbacks && callbacks.resolve()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册