Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
4e660eec
U
uni-app
项目概览
MuGuiLin
/
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,发现更多精彩内容 >>
提交
4e660eec
编写于
4月 06, 2021
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update: 新增插屏广告API uni.createInterstitialAd
上级
2391124e
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
135 addition
and
4 deletion
+135
-4
lib/apis.js
lib/apis.js
+2
-1
lib/modules.json
lib/modules.json
+2
-1
src/platforms/app-plus/service/api/ad/interstitial-ad.js
src/platforms/app-plus/service/api/ad/interstitial-ad.js
+115
-0
src/platforms/app-plus/service/api/ad/rewarded-video-ad.js
src/platforms/app-plus/service/api/ad/rewarded-video-ad.js
+15
-2
src/platforms/app-plus/service/api/index.js
src/platforms/app-plus/service/api/index.js
+1
-0
未找到文件。
lib/apis.js
浏览文件 @
4e660eec
...
...
@@ -240,7 +240,8 @@ const third = [
const
ad
=
[
'
createRewardedVideoAd
'
,
'
createFullScreenVideoAd
'
'
createFullScreenVideoAd
'
,
'
createInterstitialAd
'
]
const
apis
=
[
...
...
lib/modules.json
浏览文件 @
4e660eec
...
...
@@ -223,6 +223,7 @@
"title"
:
"广告"
,
"apiList"
:
{
"uni.createRewardedVideoAd"
:
true
,
"uni.createFullScreenVideoAd"
:
true
"uni.createFullScreenVideoAd"
:
true
,
"uni.'createInterstitialAd'"
:
true
}
}]
src/platforms/app-plus/service/api/ad/interstitial-ad.js
0 → 100644
浏览文件 @
4e660eec
const
eventNames
=
[
'
load
'
,
'
close
'
,
'
error
'
,
'
adClicked
'
]
class
InterstitialAd
{
constructor
(
options
=
{})
{
const
_callbacks
=
this
.
_callbacks
=
{}
eventNames
.
forEach
(
item
=>
{
_callbacks
[
item
]
=
[]
const
name
=
item
[
0
].
toUpperCase
()
+
item
.
substr
(
1
)
this
[
`on
${
name
}
`
]
=
function
(
callback
)
{
_callbacks
[
item
].
push
(
callback
)
}
})
this
.
_isLoad
=
false
this
.
_isLoading
=
false
this
.
_adError
=
''
this
.
_loadPromiseResolve
=
null
this
.
_loadPromiseReject
=
null
const
ad
=
this
.
_ad
=
plus
.
ad
.
createInterstitialAd
(
options
)
ad
.
onLoad
((
e
)
=>
{
this
.
_isLoad
=
true
this
.
_isLoading
=
false
this
.
_dispatchEvent
(
'
load
'
,
{})
if
(
this
.
_loadPromiseResolve
!=
null
)
{
this
.
_loadPromiseResolve
()
this
.
_loadPromiseResolve
=
null
}
})
ad
.
onClose
((
e
)
=>
{
this
.
_isLoad
=
false
this
.
_isLoading
=
false
this
.
_dispatchEvent
(
'
close
'
,
{})
})
ad
.
onError
((
e
)
=>
{
this
.
_isLoading
=
false
const
{
code
,
message
}
=
e
const
data
=
{
code
:
code
,
errMsg
:
message
}
this
.
_adError
=
message
this
.
_dispatchEvent
(
'
error
'
,
data
)
if
(
this
.
_loadPromiseReject
!=
null
)
{
this
.
_loadPromiseReject
(
data
)
this
.
_loadPromiseReject
=
null
}
})
ad
.
onAdClicked
((
e
)
=>
{
this
.
_dispatchEvent
(
'
adClicked
'
,
{})
})
}
load
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
_loadPromiseResolve
=
resolve
this
.
_loadPromiseReject
=
reject
if
(
this
.
_isLoading
)
{
return
}
if
(
this
.
_isLoad
)
{
resolve
()
return
}
this
.
_loadAd
()
})
}
show
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
_isLoading
)
{
return
}
if
(
this
.
_isLoad
)
{
this
.
_ad
.
show
()
resolve
()
}
else
{
reject
(
new
Error
(
this
.
_adError
))
}
})
}
getProvider
()
{
return
this
.
_ad
.
getProvider
()
}
destroy
()
{
this
.
_ad
.
destroy
()
}
_loadAd
()
{
this
.
_isLoad
=
false
this
.
_isLoading
=
true
this
.
_ad
.
load
()
}
_dispatchEvent
(
name
,
data
)
{
this
.
_callbacks
[
name
].
forEach
(
callback
=>
{
if
(
typeof
callback
===
'
function
'
)
{
callback
(
data
||
{})
}
})
}
}
export
function
createInterstitialAd
(
options
)
{
return
new
InterstitialAd
(
options
)
}
src/platforms/app-plus/service/api/ad/rewarded-video-ad.js
浏览文件 @
4e660eec
...
...
@@ -24,6 +24,7 @@ class RewardedVideoAd {
this
.
_preload
=
options
.
preload
!==
undefined
?
options
.
preload
:
true
this
.
_isLoad
=
false
this
.
_isLoading
=
false
this
.
_adError
=
''
this
.
_loadPromiseResolve
=
null
this
.
_loadPromiseReject
=
null
...
...
@@ -32,6 +33,7 @@ class RewardedVideoAd {
const
rewardAd
=
this
.
_rewardAd
=
plus
.
ad
.
createRewardedVideoAd
(
options
)
rewardAd
.
onLoad
((
e
)
=>
{
this
.
_isLoad
=
true
this
.
_isLoading
=
false
this
.
_lastLoadTime
=
Date
.
now
()
this
.
_dispatchEvent
(
'
load
'
,
{})
...
...
@@ -41,6 +43,8 @@ class RewardedVideoAd {
}
})
rewardAd
.
onClose
((
e
)
=>
{
this
.
_isLoad
=
false
this
.
_isLoading
=
false
if
(
this
.
_preload
)
{
this
.
_loadAd
()
}
...
...
@@ -50,6 +54,7 @@ class RewardedVideoAd {
this
.
_dispatchEvent
(
'
verify
'
,
{
isValid
:
e
.
isValid
})
})
rewardAd
.
onError
((
e
)
=>
{
this
.
_isLoading
=
false
const
{
code
,
message
}
=
e
const
data
=
{
code
:
code
,
errMsg
:
message
}
this
.
_adError
=
message
...
...
@@ -78,18 +83,25 @@ class RewardedVideoAd {
load
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
_loadPromiseResolve
=
resolve
this
.
_loadPromiseReject
=
reject
if
(
this
.
_isLoading
)
{
return
}
if
(
this
.
_isLoad
)
{
resolve
()
return
}
this
.
_loadPromiseResolve
=
resolve
this
.
_loadPromiseReject
=
reject
this
.
_loadAd
()
})
}
show
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
_isLoading
)
{
return
}
const
provider
=
this
.
getProvider
()
if
(
provider
===
ProviderType
.
CSJ
&&
this
.
isExpired
)
{
this
.
_isLoad
=
false
...
...
@@ -118,6 +130,7 @@ class RewardedVideoAd {
_loadAd
()
{
this
.
_isLoad
=
false
this
.
_isLoading
=
true
this
.
_rewardAd
.
load
()
}
...
...
src/platforms/app-plus/service/api/index.js
浏览文件 @
4e660eec
...
...
@@ -81,3 +81,4 @@ export * from './ui/request-component-info'
export
*
from
'
./ad/ad
'
export
*
from
'
./ad/rewarded-video-ad
'
export
*
from
'
./ad/full-screen-video-ad
'
export
*
from
'
./ad/interstitial-ad
'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录