Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzj-java
uni-app
提交
588a40b9
U
uni-app
项目概览
wzj-java
/
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,发现更多精彩内容 >>
提交
588a40b9
编写于
4月 28, 2021
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update: 新增互动广告API
上级
f46bdab5
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
245 addition
and
3 deletion
+245
-3
lib/apis.js
lib/apis.js
+2
-1
lib/modules.json
lib/modules.json
+2
-1
src/platforms/app-plus/service/api/ad/ad-base.js
src/platforms/app-plus/service/api/ad/ad-base.js
+2
-0
src/platforms/app-plus/service/api/ad/interactive-ad.js
src/platforms/app-plus/service/api/ad/interactive-ad.js
+237
-0
src/platforms/app-plus/service/api/ad/interstitial-ad.js
src/platforms/app-plus/service/api/ad/interstitial-ad.js
+1
-1
src/platforms/app-plus/service/api/index.js
src/platforms/app-plus/service/api/index.js
+1
-0
未找到文件。
lib/apis.js
浏览文件 @
588a40b9
...
...
@@ -242,7 +242,8 @@ const third = [
const
ad
=
[
'
createRewardedVideoAd
'
,
'
createFullScreenVideoAd
'
,
'
createInterstitialAd
'
'
createInterstitialAd
'
,
'
createInteractiveAd
'
]
const
apis
=
[
...
...
lib/modules.json
浏览文件 @
588a40b9
...
...
@@ -225,6 +225,7 @@
"apiList"
:
{
"uni.createRewardedVideoAd"
:
true
,
"uni.createFullScreenVideoAd"
:
true
,
"uni.'createInterstitialAd'"
:
true
"uni.'createInterstitialAd'"
:
true
,
"uni.'createInteractiveAd'"
:
true
}
}]
src/platforms/app-plus/service/api/ad/ad-base.js
浏览文件 @
588a40b9
...
...
@@ -152,5 +152,7 @@ class AdBase {
}
export
{
eventTypes
,
eventNames
,
AdBase
}
src/platforms/app-plus/service/api/ad/interactive-ad.js
0 → 100644
浏览文件 @
588a40b9
import
{
requireNativePlugin
}
from
'
../../bridge
'
import
{
eventTypes
,
eventNames
}
from
'
./ad-base.js
'
const
sdkCache
=
{}
const
sdkQueue
=
{}
function
initSDK
(
options
)
{
const
provider
=
options
.
provider
if
(
typeof
sdkCache
[
provider
]
===
'
object
'
)
{
options
.
success
(
sdkCache
[
provider
])
return
}
if
(
!
sdkQueue
[
provider
])
{
sdkQueue
[
provider
]
=
[]
}
sdkQueue
[
provider
].
push
(
options
)
if
(
sdkCache
[
provider
]
===
true
)
{
return
}
sdkCache
[
provider
]
=
true
const
plugin
=
requireNativePlugin
(
provider
)
if
(
!
plugin
||
!
plugin
.
initSDK
)
{
sdkQueue
[
provider
].
forEach
((
item
)
=>
{
item
.
fail
({
code
:
-
1
,
message
:
'
provider [
'
+
provider
+
'
] invalid
'
})
})
sdkQueue
[
provider
].
length
=
0
sdkCache
[
provider
]
=
false
return
}
options
.
__plugin
=
plugin
plugin
.
initSDK
((
res
)
=>
{
const
isSuccess
=
(
res
.
code
===
1
||
res
.
code
===
'
1
'
)
if
(
isSuccess
)
{
sdkCache
[
provider
]
=
plugin
}
else
{
sdkCache
[
provider
]
=
false
}
sdkQueue
[
provider
].
forEach
((
item
)
=>
{
if
(
isSuccess
)
{
item
.
success
(
item
.
__plugin
)
}
else
{
item
.
fail
(
res
)
}
})
sdkQueue
[
provider
].
length
=
0
})
}
class
InteractiveAd
{
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
.
_ad
=
null
this
.
_adError
=
''
this
.
_adpid
=
options
.
adpid
this
.
_provider
=
options
.
provider
this
.
_isLoaded
=
false
this
.
_isLoading
=
false
this
.
_loadPromiseResolve
=
null
this
.
_loadPromiseReject
=
null
this
.
_showPromiseResolve
=
null
this
.
_showPromiseReject
=
null
setTimeout
(()
=>
{
this
.
_init
()
})
}
_init
()
{
this
.
_adError
=
''
initSDK
({
provider
:
this
.
_provider
,
success
:
(
res
)
=>
{
this
.
_ad
=
res
this
.
_loadAd
()
},
fail
:
(
err
)
=>
{
this
.
_adError
=
err
this
.
_dispatchEvent
(
eventTypes
.
error
,
err
)
}
})
}
getProvider
()
{
return
this
.
_provider
}
load
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
_loadPromiseResolve
=
resolve
this
.
_loadPromiseReject
=
reject
if
(
this
.
_isLoading
)
{
return
}
if
(
this
.
_adError
)
{
this
.
_init
()
return
}
if
(
this
.
_isLoaded
)
{
resolve
()
}
else
{
this
.
_loadAd
()
}
})
}
show
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
_showPromiseResolve
=
resolve
this
.
_showPromiseReject
=
reject
if
(
this
.
_isLoading
)
{
return
}
if
(
this
.
_adError
)
{
this
.
_init
()
return
}
if
(
this
.
_isLoaded
)
{
this
.
_showAd
()
resolve
()
}
else
{
this
.
_loadAd
()
}
})
}
destroy
()
{
if
(
this
.
_ad
!==
null
&&
this
.
_ad
.
destroy
)
{
this
.
_ad
.
destroy
({
adpid
:
this
.
_adpid
})
}
}
_loadAd
()
{
if
(
this
.
_ad
!==
null
)
{
if
(
this
.
_isLoading
===
true
)
{
return
}
this
.
_isLoading
=
true
this
.
_ad
.
loadData
({
adpid
:
this
.
_adpid
},
(
res
)
=>
{
this
.
_isLoaded
=
true
this
.
_isLoading
=
false
this
.
_dispatchEvent
(
eventTypes
.
load
,
res
)
if
(
this
.
_loadPromiseResolve
!=
null
)
{
this
.
_loadPromiseResolve
()
this
.
_loadPromiseResolve
=
null
}
if
(
this
.
_showPromiseResolve
!=
null
)
{
this
.
_showPromiseResolve
()
this
.
_showPromiseResolve
=
null
this
.
_showAd
()
}
},
(
err
)
=>
{
this
.
_isLoading
=
false
this
.
_dispatchEvent
(
eventTypes
.
error
,
err
)
if
(
this
.
_showPromiseReject
!=
null
)
{
this
.
_showPromiseReject
(
this
.
_createError
(
err
))
this
.
_showPromiseReject
=
null
}
})
}
}
_showAd
()
{
if
(
this
.
_ad
!==
null
&&
this
.
_isLoaded
===
true
)
{
this
.
_ad
.
show
({
adpid
:
this
.
_adpid
},
(
res
)
=>
{
this
.
_isLoaded
=
false
},
(
err
)
=>
{
this
.
_isLoaded
=
false
this
.
_dispatchEvent
(
eventTypes
.
error
,
err
)
if
(
this
.
_showPromiseReject
!=
null
)
{
this
.
_showPromiseReject
(
this
.
_createError
(
err
))
this
.
_showPromiseReject
=
null
}
})
}
}
_createError
(
err
)
{
const
error
=
new
Error
(
JSON
.
stringify
(
err
))
error
.
code
=
err
.
code
error
.
errMsg
=
err
.
message
return
error
}
_dispatchEvent
(
name
,
data
)
{
this
.
_callbacks
[
name
].
forEach
(
callback
=>
{
if
(
typeof
callback
===
'
function
'
)
{
callback
(
data
||
{})
}
})
}
}
export
function
createInteractiveAd
(
options
)
{
if
(
!
options
.
provider
)
{
return
new
Error
(
'
provider invalid
'
)
}
if
(
!
options
.
adpid
)
{
return
new
Error
(
'
adpid invalid
'
)
}
return
new
InteractiveAd
(
options
)
}
src/platforms/app-plus/service/api/ad/interstitial-ad.js
浏览文件 @
588a40b9
...
...
@@ -6,7 +6,7 @@ class InterstitialAd extends AdBase {
constructor
(
options
=
{})
{
super
(
plus
.
ad
.
createInterstitialAd
(
options
),
options
)
this
.
loa
d
()
this
.
_loadA
d
()
}
}
...
...
src/platforms/app-plus/service/api/index.js
浏览文件 @
588a40b9
...
...
@@ -82,3 +82,4 @@ export * from './ad/ad'
export
*
from
'
./ad/rewarded-video-ad
'
export
*
from
'
./ad/full-screen-video-ad
'
export
*
from
'
./ad/interstitial-ad
'
export
*
from
'
./ad/interactive-ad
'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录