Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
6455f8c0
U
uni-app
项目概览
小浣熊撸代码
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6455f8c0
编写于
6月 25, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(App): showToast
上级
35a3c076
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
172 addition
and
0 deletion
+172
-0
packages/uni-app-plus/src/helpers/plus.ts
packages/uni-app-plus/src/helpers/plus.ts
+15
-0
packages/uni-app-plus/src/service/api/index.ts
packages/uni-app-plus/src/service/api/index.ts
+1
-0
packages/uni-app-plus/src/service/api/ui/popup/showToast.ts
packages/uni-app-plus/src/service/api/ui/popup/showToast.ts
+156
-0
未找到文件。
packages/uni-app-plus/src/helpers/plus.ts
浏览文件 @
6455f8c0
...
...
@@ -63,3 +63,18 @@ export function warpPlusMethod(
)
}
}
export
async
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
)
})
}
packages/uni-app-plus/src/service/api/index.ts
浏览文件 @
6455f8c0
...
...
@@ -29,3 +29,4 @@ export * from './location/getLocation'
export
*
from
'
./ui/popup/showModal
'
export
*
from
'
./ui/popup/showActionSheet
'
export
*
from
'
./ui/popup/showToast
'
packages/uni-app-plus/src/service/api/ui/popup/showToast.ts
0 → 100644
浏览文件 @
6455f8c0
import
{
extend
}
from
'
@vue/shared
'
import
{
callApiSync
}
from
'
../../../../helpers/plus
'
import
{
defineAsyncApi
,
ShowToastOptions
,
ShowToastProtocol
,
ShowLoadingProtocol
,
ShowLoadingOptions
,
API_TYPE_SHOW_TOAST
,
API_TYPE_SHOW_LOADING
,
API_TYPE_HIDE_LOADING
,
API_TYPE_HIDE_TOAST
,
API_SHOW_TOAST
,
API_SHOW_LOADING
,
API_HIDE_TOAST
,
API_HIDE_LOADING
,
}
from
'
@dcloudio/uni-api
'
type
ToastType
=
'
loading
'
|
'
toast
'
|
''
let
toast
:
PlusNativeUIWaitingObj
|
null
let
isShowToast
:
boolean
=
false
let
toastType
:
ToastType
=
''
let
timeout
:
number
|
null
export
const
showLoading
=
defineAsyncApi
<
API_TYPE_SHOW_LOADING
>
(
API_SHOW_LOADING
,
(
args
,
{
resolve
,
reject
})
=>
{
callApiSync
<
typeof
showToast
>
(
showToast
,
extend
({},
args
,
{
type
:
'
loading
'
,
}),
resolve
,
reject
)
},
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
,
(
{
title
=
''
,
icon
=
'
success
'
,
image
=
''
,
duration
=
1500
,
mask
=
false
,
position
,
// @ts-ignore ToastType
type
=
'
toast
'
,
// @ts-ignore PlusNativeUIWaitingStyles
style
,
},
{
resolve
,
reject
}
)
=>
{
hide
(
''
)
toastType
=
type
if
([
'
top
'
,
'
center
'
,
'
bottom
'
].
includes
(
String
(
position
)))
{
// 仅可以关闭 richtext 类型,但 iOS 部分情况换行显示有问题
plus
.
nativeUI
.
toast
(
title
,
{
verticalAlign
:
position
,
})
isShowToast
=
true
}
else
{
if
(
icon
&&
!~
[
'
success
'
,
'
loading
'
,
'
error
'
,
'
none
'
].
indexOf
(
icon
))
{
icon
=
'
success
'
}
const
waitingOptions
:
PlusNativeUIWaitingStyles
=
{
modal
:
mask
,
back
:
'
transmit
'
,
padding
:
'
10px
'
,
size
:
'
16px
'
,
// 固定字体大小
}
if
(
!
image
&&
(
!
icon
||
icon
===
'
none
'
))
{
// 无图
// waitingOptions.width = '120px'
// waitingOptions.height = '40px'
waitingOptions
.
loading
=
{
display
:
'
none
'
,
}
}
else
{
waitingOptions
.
width
=
'
140px
'
waitingOptions
.
height
=
'
112px
'
}
if
(
image
)
{
waitingOptions
.
loading
=
{
display
:
'
block
'
,
height
:
'
55px
'
,
icon
:
image
,
interval
:
duration
,
}
}
else
{
if
([
'
success
'
,
'
error
'
].
indexOf
(
icon
)
!==
-
1
)
{
waitingOptions
.
loading
=
{
display
:
'
block
'
,
height
:
'
55px
'
,
icon
:
icon
===
'
success
'
?
'
__uniappsuccess.png
'
:
'
__uniapperror.png
'
,
interval
:
duration
,
}
}
}
try
{
toast
=
plus
.
nativeUI
.
showWaiting
(
title
,
extend
(
waitingOptions
,
style
))
}
catch
(
error
)
{
reject
(
`
${
error
}
`
)
}
}
timeout
=
setTimeout
(()
=>
{
hide
(
''
)
},
duration
)
return
resolve
()
},
ShowToastProtocol
,
ShowToastOptions
)
export
const
hideToast
=
defineAsyncApi
<
API_TYPE_HIDE_TOAST
>
(
API_HIDE_TOAST
,
(
_
,
{
resolve
,
reject
})
=>
{
callApiSync
<
typeof
hide
>
(
hide
,
'
toast
'
,
resolve
,
reject
)
}
)
export
function
hide
(
type
:
string
=
'
toast
'
)
{
if
(
type
&&
type
!==
toastType
)
{
return
}
if
(
timeout
)
{
clearTimeout
(
timeout
)
timeout
=
null
}
if
(
isShowToast
)
{
plus
.
nativeUI
.
closeToast
()
}
else
if
(
toast
&&
toast
.
close
)
{
toast
.
close
()
}
toast
=
null
isShowToast
=
false
toastType
=
''
return
{
errMsg
:
'
hide:ok
'
,
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录