提交 eca0cc12 编写于 作者: D DCloud_LXH

fix(App): showToast

上级 f4330786
......@@ -66,21 +66,6 @@ export function warpPlusMethod(
}
}
export function callApiSync<T extends (...args: any) => any>(
api: T,
args: Parameters<T>[0],
resolve: Function,
reject: (errMsg?: string | undefined, errRes?: any) => void
) {
api(args)
.then(() => {
resolve()
})
.catch((errMsg: string) => {
reject(errMsg)
})
}
export function isTabBarPage(path = '') {
if (!(__uniConfig.tabBar && Array.isArray(__uniConfig.tabBar.list))) {
return false
......
import { extend } from '@vue/shared'
import { callApiSync } from '../../../../helpers/plus'
import {
defineAsyncApi,
ShowToastOptions,
......@@ -16,6 +15,9 @@ import {
API_HIDE_LOADING,
} from '@dcloudio/uni-api'
type Resolve = (res?: any) => void
type Reject = (errMsg?: string, errRes?: any) => void
type ToastType = 'loading' | 'toast' | ''
let toast: PlusNativeUIWaitingObj | null
......@@ -25,30 +27,18 @@ let timeout: number | null
export const showLoading = defineAsyncApi<API_TYPE_SHOW_LOADING>(
API_SHOW_LOADING,
(args, { resolve, reject }) => {
callApiSync<typeof showToast>(
showToast,
(args, callbacks) =>
_showToast(
extend({}, args, {
type: 'loading',
}),
resolve,
reject
)
},
callbacks
),
ShowLoadingProtocol,
ShowLoadingOptions
)
export const hideLoading = defineAsyncApi<API_TYPE_HIDE_LOADING>(
API_HIDE_LOADING,
(_, { resolve, reject }) => {
callApiSync<typeof hide>(hide, 'loading', resolve, reject)
}
)
export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>(
API_SHOW_TOAST,
(
const _showToast = (
{
title = '',
icon = 'success',
......@@ -60,9 +50,9 @@ export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>(
type = 'toast',
// @ts-ignore PlusNativeUIWaitingStyles
style,
},
{ resolve, reject }
) => {
}: UniApp.ShowToastOptions,
{ resolve, reject }: { resolve: Resolve; reject: Reject }
) => {
hide('')
toastType = type
if (['top', 'center', 'bottom'].includes(String(position))) {
......@@ -122,21 +112,30 @@ export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>(
hide('')
}, duration)
return resolve()
},
}
export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>(
API_SHOW_TOAST,
_showToast,
ShowToastProtocol,
ShowToastOptions
)
export const hideToast = defineAsyncApi<API_TYPE_HIDE_TOAST>(
API_HIDE_TOAST,
(_, { resolve, reject }) => {
callApiSync<typeof hide>(hide, 'toast', resolve, reject)
}
(_, callbacks) => hide('toast', callbacks)
)
export const hideLoading = defineAsyncApi<API_TYPE_HIDE_LOADING>(
API_HIDE_LOADING,
(_, callbacks) => hide('loading', callbacks)
)
export function hide(type: string = 'toast') {
function hide(
type: string = 'toast',
callbacks?: { resolve: Resolve; reject: Reject }
) {
if (type && type !== toastType) {
return
return callbacks?.reject()
}
if (timeout) {
clearTimeout(timeout)
......@@ -150,7 +149,5 @@ export function hide(type: string = 'toast') {
toast = null
isShowToast = false
toastType = ''
return {
errMsg: 'hide:ok',
}
return callbacks?.resolve()
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册