Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
20岁爱吃必胜客
uni-app
提交
6fc31ea6
U
uni-app
项目概览
20岁爱吃必胜客
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
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,发现更多精彩内容 >>
提交
6fc31ea6
编写于
4月 24, 2022
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
eslint: ad-component
上级
d651121d
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
231 addition
and
224 deletion
+231
-224
.eslintignore
.eslintignore
+4
-0
packages/uni-cli-shared/components/ad-interactive.vue
packages/uni-cli-shared/components/ad-interactive.vue
+113
-114
packages/uni-cli-shared/components/ad.mixin.js
packages/uni-cli-shared/components/ad.mixin.js
+80
-83
packages/uni-cli-shared/components/ad.mixin.mp.js
packages/uni-cli-shared/components/ad.mixin.mp.js
+13
-13
packages/uni-cli-shared/components/uniad.vue
packages/uni-cli-shared/components/uniad.vue
+16
-9
packages/webpack-uni-pages-loader/lib/platforms/mp-weixin/app.json.uniad.js
...ni-pages-loader/lib/platforms/mp-weixin/app.json.uniad.js
+5
-5
未找到文件。
.eslintignore
浏览文件 @
6fc31ea6
...
...
@@ -36,3 +36,7 @@ node_modules
automator.js
uni.automator.js
uni-polyfill.js
packages/uni-cli-shared/components/ad-full-screen-video.vue
packages/uni-cli-shared/components/ad-interactive.vue
packages/uni-cli-shared/components/ad-interstitial.vue
packages/uni-cli-shared/components/ad-rewarded-video.vue
packages/uni-cli-shared/components/ad-interactive.vue
浏览文件 @
6fc31ea6
<
template
>
<view
@
click=
"onclick"
>
<slot
:options=
"options"
:data=
"adData"
/>
<slot
:options=
"options"
:data=
"adData"
/>
</view>
</
template
>
<
script
>
const
AD_URL
=
'
https://wxac1.dcloud.net.cn/tuiaApplet/acs
'
const
AD_REPORT_URL
=
'
https://wxac1.dcloud.net.cn/tuiaApplet/acs
'
const
WEBVIEW_PATH
=
'
/uni_modules/uni-ad-interactive/pages/uni-ad-interactive/uni-ad-interactive
'
const
AD_URL
=
'
https://wxac1.dcloud.net.cn/tuiaApplet/acs
'
const
AD_REPORT_URL
=
'
https://wxac1.dcloud.net.cn/tuiaApplet/acs
'
const
WEBVIEW_PATH
=
'
/uni_modules/uni-ad-interactive/pages/uni-ad-interactive/uni-ad-interactive
'
const
events
=
{
const
events
=
{
load
:
'
load
'
,
close
:
'
close
'
,
error
:
'
error
'
}
}
const
OpenTypes
=
{
const
OpenTypes
=
{
Interactive
:
'
interactive
'
}
}
export
default
{
export
default
{
name
:
'
AdInteractive
'
,
props
:
{
options
:
{
...
...
@@ -37,26 +40,26 @@
default
:
WEBVIEW_PATH
}
},
data
()
{
data
()
{
return
{
adData
:
{}
}
},
created
()
{
created
()
{
this
.
_uniAdPlugin
=
null
this
.
_interactiveUrl
=
null
if
(
this
.
openType
==
OpenTypes
.
Interactive
)
{
if
(
this
.
openType
=
==
OpenTypes
.
Interactive
)
{
this
.
getAdData
()
}
},
methods
:
{
show
()
{
if
(
this
.
_uniAdPlugin
==
null
)
{
show
()
{
if
(
this
.
_uniAdPlugin
=
==
null
)
{
this
.
_uniAdPlugin
=
this
.
selectComponent
(
'
.uni-ad-plugin
'
)
}
this
.
_uniAdPlugin
.
show
()
},
getAdData
()
{
getAdData
()
{
if
(
!
this
.
adpid
)
{
this
.
$emit
(
events
.
error
,
{
code
:
-
5002
,
...
...
@@ -84,11 +87,11 @@
return
}
const
responseData
=
res
.
data
;
if
(
responseData
.
ret
==
0
)
{
const
responseData
=
res
.
data
if
(
responseData
.
ret
=
==
0
)
{
this
.
_interactiveUrl
=
responseData
.
data
.
adp_url
this
.
adData
.
imgUrl
=
responseData
.
data
.
icon_url
this
.
adData
.
openUrl
=
this
.
openUrl
+
"
?url=
"
+
encodeURIComponent
(
this
.
_interactiveUrl
)
this
.
adData
.
openUrl
=
this
.
openUrl
+
'
?url=
'
+
encodeURIComponent
(
this
.
_interactiveUrl
)
this
.
$emit
(
events
.
load
,
{})
}
else
{
this
.
$emit
(
events
.
error
,
{
...
...
@@ -105,8 +108,8 @@
}
})
},
onclick
()
{
if
(
this
.
openType
!
=
OpenTypes
.
Interactive
||
!
this
.
_interactiveUrl
)
{
onclick
()
{
if
(
this
.
openType
!=
=
OpenTypes
.
Interactive
||
!
this
.
_interactiveUrl
)
{
return
}
...
...
@@ -116,7 +119,7 @@
this
.
_report
()
},
_report
()
{
_report
()
{
uni
.
request
({
url
:
AD_REPORT_URL
,
data
:
{
...
...
@@ -124,15 +127,11 @@
t
:
'
10019
'
},
timeout
:
5000
,
dataType
:
'
json
'
,
success
:
(
res
)
=>
{
},
fail
:
(
err
)
=>
{
}
dataType
:
'
json
'
})
}
}
}
}
</
script
>
<
style
>
...
...
packages/uni-cli-shared/components/ad.mixin.js
浏览文件 @
6fc31ea6
const
ADType
=
{
RewardedVideo
:
"
RewardedVideo
"
,
FullScreenVideo
:
"
FullScreenVideo
"
,
Interstitial
:
"
Interstitial
"
RewardedVideo
:
'
RewardedVideo
'
,
FullScreenVideo
:
'
FullScreenVideo
'
,
Interstitial
:
'
Interstitial
'
}
const
EventType
=
{
...
...
@@ -19,8 +19,7 @@ const ProviderType = {
const
RETRY_COUNT
=
1
class
AdBase
{
constructor
(
adInstance
,
options
=
{},
interstitial
)
{
constructor
(
adInstance
,
options
=
{},
interstitial
)
{
this
.
_isLoad
=
false
this
.
_isLoading
=
false
this
.
_isPlaying
=
false
...
...
@@ -80,23 +79,23 @@ class AdBase {
})
}
get
isExpired
()
{
get
isExpired
()
{
return
(
this
.
_lastLoadTime
!==
0
&&
(
Math
.
abs
(
Date
.
now
()
-
this
.
_lastLoadTime
)
>
EXPIRED_TIME
))
}
get
isLoad
()
{
get
isLoad
()
{
return
this
.
_isLoad
}
get
isLoading
()
{
get
isLoading
()
{
return
this
.
_isLoading
}
getProvider
()
{
getProvider
()
{
return
this
.
_ad
.
getProvider
()
}
load
(
onload
,
onerror
)
{
load
(
onload
,
onerror
)
{
this
.
_loadCallback
=
onload
this
.
_errorCallback
=
onerror
...
...
@@ -119,7 +118,7 @@ class AdBase {
this
.
_loadAd
()
}
show
(
onclose
,
onshow
)
{
show
(
onclose
,
onshow
)
{
this
.
_closeCallback
=
onclose
if
(
this
.
_isLoading
||
this
.
_isPlaying
||
!
this
.
_isLoad
)
{
...
...
@@ -155,13 +154,13 @@ class AdBase {
}
}
onLoad
(
e
)
{
onLoad
(
e
)
{
if
(
this
.
_loadCallback
!=
null
)
{
this
.
_loadCallback
()
}
}
onClose
(
e
)
{
onClose
(
e
)
{
if
(
this
.
_closeCallback
!=
null
)
{
this
.
_closeCallback
({
isEnded
:
e
.
isEnded
...
...
@@ -169,17 +168,17 @@ class AdBase {
}
}
onError
(
e
)
{
onError
(
e
)
{
if
(
this
.
_errorCallback
!=
null
)
{
this
.
_errorCallback
(
e
)
}
}
destroy
()
{
destroy
()
{
this
.
_ad
.
destroy
()
}
_loadAd
()
{
_loadAd
()
{
this
.
_isLoad
=
false
this
.
_isLoading
=
true
this
.
_lastError
=
null
...
...
@@ -188,31 +187,30 @@ class AdBase {
}
class
RewardedVideo
extends
AdBase
{
constructor
(
options
=
{})
{
constructor
(
options
=
{})
{
super
(
plus
.
ad
.
createRewardedVideoAd
(
options
),
options
)
}
}
class
FullScreenVideo
extends
AdBase
{
constructor
(
options
=
{})
{
constructor
(
options
=
{})
{
super
(
plus
.
ad
.
createFullScreenVideoAd
(
options
),
options
)
}
}
class
Interstitial
extends
AdBase
{
constructor
(
options
=
{},
interstitial
)
{
constructor
(
options
=
{},
interstitial
)
{
super
(
plus
.
ad
.
createInterstitialAd
(
options
),
options
,
interstitial
)
}
}
class
AdHelper
{
constructor
(
adType
)
{
constructor
(
adType
)
{
this
.
_ads
=
{}
this
.
_adType
=
adType
}
load
(
options
,
onload
,
onerror
)
{
load
(
options
,
onload
,
onerror
)
{
if
(
!
options
.
adpid
||
this
.
isBusy
(
options
.
adpid
))
{
return
}
...
...
@@ -220,8 +218,8 @@ class AdHelper {
this
.
get
(
options
).
load
(
onload
,
onerror
)
}
show
(
options
,
onload
,
onerror
,
onclose
,
onshow
)
{
le
t
ad
=
this
.
get
(
options
)
show
(
options
,
onload
,
onerror
,
onclose
,
onshow
)
{
cons
t
ad
=
this
.
get
(
options
)
if
(
ad
.
isLoad
)
{
ad
.
show
((
e
)
=>
{
...
...
@@ -244,8 +242,8 @@ class AdHelper {
}
// 底价预载逻辑
loadWaterfall
(
options
,
onload
,
onfail
,
index
=
0
)
{
le
t
{
loadWaterfall
(
options
,
onload
,
onfail
,
index
=
0
)
{
cons
t
{
adpid
,
urlCallback
}
=
options
...
...
@@ -253,28 +251,28 @@ class AdHelper {
return
}
le
t
options2
=
{
cons
t
options2
=
{
adpid
:
adpid
[
index
],
urlCallback
,
retry
:
false
}
;
}
this
.
load
(
options2
,
(
res
)
=>
{
onload
(
options2
)
;
onload
(
options2
)
},
(
err
)
=>
{
index
++
;
index
++
if
(
index
>=
adpid
.
length
)
{
onfail
(
err
)
;
onfail
(
err
)
}
else
{
console
.
log
(
'
loadWaterfall::index=
'
+
index
)
;
this
.
loadWaterfall
(
options
,
onload
,
onfail
,
index
)
;
console
.
log
(
'
loadWaterfall::index=
'
+
index
)
this
.
loadWaterfall
(
options
,
onload
,
onfail
,
index
)
}
})
;
})
}
// 底价逻辑,失败后下一个,无重试机制
showWaterfall
(
options
,
onload
,
onfail
,
onclose
,
onshow
,
index
=
0
)
{
le
t
{
showWaterfall
(
options
,
onload
,
onfail
,
onclose
,
onshow
,
index
=
0
)
{
cons
t
{
adpid
,
urlCallback
}
=
options
...
...
@@ -282,70 +280,69 @@ class AdHelper {
return
}
le
t
options2
=
{
cons
t
options2
=
{
adpid
:
adpid
[
index
],
urlCallback
,
retry
:
false
}
;
}
this
.
show
(
options2
,
()
=>
{
onload
()
;
onload
()
},
(
err
)
=>
{
index
++
;
index
++
if
(
index
>=
adpid
.
length
)
{
onfail
(
err
)
;
onfail
(
err
)
}
else
{
this
.
showWaterfall
(
options
,
onload
,
onfail
,
onclose
,
onshow
,
index
)
;
this
.
showWaterfall
(
options
,
onload
,
onfail
,
onclose
,
onshow
,
index
)
}
},
(
res
)
=>
{
onclose
(
res
)
;
onclose
(
res
)
},
()
=>
{
onshow
()
;
})
;
onshow
()
})
}
// 预载底价瀑布流
preloadWaterfall
(
options
,
index
=
0
,
step
=
1
)
{
preloadWaterfall
(
options
,
index
=
0
,
step
=
1
)
{
if
(
step
===
1
)
{
this
.
loadWaterfall
(
options
,
(
res
)
=>
{
console
.
log
(
"
preloadWaterfall.success::
"
,
res
);
console
.
log
(
'
preloadWaterfall.success::
'
,
res
)
},
(
err
)
=>
{
console
.
log
(
"
loadWaterfall.fail
"
,
err
);
console
.
log
(
'
loadWaterfall.fail
'
,
err
)
})
return
;
return
}
le
t
{
cons
t
{
adpid
,
urlCallback
}
=
options
let
ads
=
[];
for
(
let
i
=
0
;
i
<
step
;
i
++
)
{
if
(
index
<
adpid
.
length
)
{
le
t
options2
=
{
cons
t
options2
=
{
adpid
:
adpid
[
index
],
urlCallback
}
;
}
this
.
loadWaterfall
(
options2
,
(
res
)
=>
{
console
.
log
(
"
preloadWaterfall.success::
"
,
res
);
console
.
log
(
'
preloadWaterfall.success::
'
,
res
)
},
(
err
)
=>
{
console
.
log
(
"
loadWaterfall.fail
"
,
err
);
this
.
preloadWaterfall
(
options
,
index
,
step
)
;
console
.
log
(
'
loadWaterfall.fail
'
,
err
)
this
.
preloadWaterfall
(
options
,
index
,
step
)
})
index
++
;
index
++
}
else
{
break
;
break
}
}
}
isBusy
(
adpid
)
{
isBusy
(
adpid
)
{
return
(
this
.
_ads
[
adpid
]
&&
this
.
_ads
[
adpid
].
isLoading
)
}
get
(
options
)
{
get
(
options
)
{
const
{
adpid
,
adpid
}
=
options
if
(
!
this
.
_ads
[
adpid
])
{
...
...
@@ -355,18 +352,18 @@ class AdHelper {
return
this
.
_ads
[
adpid
]
}
remove
(
adpid
)
{
remove
(
adpid
)
{
if
(
this
.
_ads
[
adpid
])
{
this
.
_ads
[
adpid
].
destroy
()
delete
this
.
_ads
[
adpid
]
}
}
_createInstance
(
options
)
{
_createInstance
(
options
)
{
const
adType
=
options
.
adType
||
this
.
_adType
delete
options
.
adType
let
ad
=
null
;
let
ad
=
null
if
(
adType
===
ADType
.
RewardedVideo
)
{
ad
=
new
RewardedVideo
(
options
)
}
else
if
(
adType
===
ADType
.
FullScreenVideo
)
{
...
...
@@ -410,25 +407,25 @@ export default {
}
}
},
data
()
{
data
()
{
return
{
loading
:
false
,
errorMessage
:
null
}
},
watch
:
{
adpid
(
newValue
,
oldValue
)
{
adpid
(
newValue
,
oldValue
)
{
this
.
_removeInstance
(
oldValue
)
if
(
this
.
preload
)
{
this
.
_loadAd
()
}
},
// 服务器回调透传参数,仅在创建广告实例时可传递参数,如果发生变化需要重新创建广告实例
urlCallback
()
{
urlCallback
()
{
this
.
_removeInstance
()
}
},
created
()
{
created
()
{
this
.
_adHelper
=
new
AdHelper
(
this
.
adType
)
setTimeout
(()
=>
{
...
...
@@ -438,9 +435,9 @@ export default {
},
100
)
},
methods
:
{
load
()
{
load
()
{
this
.
_startLoading
()
const
invoke
=
this
.
_isWaterfall
()
?
"
loadWaterfall
"
:
"
load
"
const
invoke
=
this
.
_isWaterfall
()
?
'
loadWaterfall
'
:
'
load
'
this
.
_adHelper
[
invoke
](
this
.
_getAdOptions
(),
()
=>
{
this
.
_onLoad
()
},
(
err
)
=>
{
...
...
@@ -448,9 +445,9 @@ export default {
})
},
show
()
{
show
()
{
this
.
_startLoading
()
const
invoke
=
this
.
_isWaterfall
()
?
"
showWaterfall
"
:
"
show
"
const
invoke
=
this
.
_isWaterfall
()
?
'
showWaterfall
'
:
'
show
'
this
.
_adHelper
[
invoke
](
this
.
_getAdOptions
(),
()
=>
{
this
.
_onLoad
()
},
(
err
)
=>
{
...
...
@@ -467,30 +464,30 @@ export default {
})
},
_loadAd
()
{
_loadAd
()
{
if
(
this
.
_canCreateAd
())
{
this
.
load
()
}
},
_onclick
()
{
_onclick
()
{
if
(
!
this
.
disabled
)
{
this
.
show
()
}
},
_getAdOptions
()
{
_getAdOptions
()
{
return
{
adpid
:
this
.
adpid
,
urlCallback
:
this
.
urlCallback
}
},
_isWaterfall
()
{
_isWaterfall
()
{
return
(
Array
.
isArray
(
this
.
adpid
)
&&
this
.
adpid
.
length
>
0
)
},
_canCreateAd
()
{
_canCreateAd
()
{
let
result
=
false
if
(
Array
.
isArray
(
this
.
adpid
)
&&
this
.
adpid
.
length
>
0
)
{
result
=
true
...
...
@@ -502,8 +499,8 @@ export default {
return
result
},
_removeInstance
(
adpid
)
{
le
t
id
=
adpid
||
this
.
adpid
_removeInstance
(
adpid
)
{
cons
t
id
=
adpid
||
this
.
adpid
if
(
Array
.
isArray
(
id
))
{
id
.
forEach
((
item
)
=>
{
this
.
_adHelper
.
remove
(
item
)
...
...
@@ -513,23 +510,23 @@ export default {
}
},
_startLoading
()
{
_startLoading
()
{
this
.
loading
=
true
this
.
errorMessage
=
null
},
_onLoad
(
err
)
{
_onLoad
(
)
{
this
.
loading
=
false
this
.
_dispatchEvent
(
EventType
.
Load
,
{})
},
_onLoadFail
(
err
)
{
_onLoadFail
(
err
)
{
this
.
loading
=
false
this
.
errorMessage
=
JSON
.
stringify
(
err
)
this
.
_dispatchEvent
(
EventType
.
Error
,
err
)
},
_dispatchEvent
(
type
,
data
)
{
_dispatchEvent
(
type
,
data
)
{
this
.
$emit
(
type
,
{
detail
:
data
})
...
...
packages/uni-cli-shared/components/ad.mixin.mp.js
浏览文件 @
6fc31ea6
...
...
@@ -29,56 +29,56 @@ export default {
default
:
false
}
},
data
()
{
data
()
{
return
{
loading
:
false
,
errorMessage
:
null
}
},
created
()
{
created
()
{
this
.
_ad
=
null
setTimeout
(()
=>
{
if
(
this
.
preload
&&
this
.
_canCreateAd
())
{
this
.
load
()
;
this
.
load
()
}
},
100
)
},
methods
:
{
load
()
{
load
()
{
this
.
errorMessage
=
null
},
show
()
{
show
()
{
this
.
errorMessage
=
null
this
.
_ad
=
this
.
selectComponent
(
'
.uni-ad
'
)
;
this
.
_ad
.
show
()
;
this
.
_ad
=
this
.
selectComponent
(
'
.uni-ad
'
)
this
.
_ad
.
show
()
},
_onclick
()
{
_onclick
()
{
this
.
show
()
},
_startLoading
()
{
_startLoading
()
{
this
.
loading
=
true
this
.
errorMessage
=
null
},
_onmpload
(
e
)
{
_onmpload
(
e
)
{
this
.
loading
=
false
this
.
_dispatchEvent
(
EventType
.
Load
,
{})
},
_onmpclose
(
e
)
{
_onmpclose
(
e
)
{
this
.
_dispatchEvent
(
EventType
.
Close
,
e
.
detail
)
},
_onmperror
(
e
)
{
_onmperror
(
e
)
{
this
.
loading
=
false
this
.
errorMessage
=
JSON
.
stringify
(
e
.
detail
)
this
.
_dispatchEvent
(
EventType
.
Error
,
e
.
detail
)
},
_dispatchEvent
(
type
,
data
)
{
_dispatchEvent
(
type
,
data
)
{
this
.
$emit
(
type
,
{
detail
:
data
})
...
...
packages/uni-cli-shared/components/uniad.vue
浏览文件 @
6fc31ea6
<
template
>
<view
@
click=
"onclick"
>
<uni-ad-plugin
class=
"uni-ad-plugin"
:adpid=
"adpid"
:unit-id=
"unitId"
@
load=
"_onmpload"
@
close=
"_onmpclose"
@
error=
"_onmperror"
></uni-ad-plugin>
<uni-ad-plugin
class=
"uni-ad-plugin"
:adpid=
"adpid"
:unit-id=
"unitId"
@
load=
"_onmpload"
@
close=
"_onmpclose"
@
error=
"_onmperror"
/>
</view>
</
template
>
<
script
>
import
adMixin
from
"
./ad.mixin.mp.js
"
export
default
{
import
adMixin
from
'
./ad.mixin.mp.js
'
export
default
{
name
:
'
UniAd
'
,
mixins
:
[
adMixin
],
props
:
{
},
methods
:
{
}
}
}
</
script
>
packages/webpack-uni-pages-loader/lib/platforms/mp-weixin/app.json.uniad.js
浏览文件 @
6fc31ea6
module
.
exports
=
function
(
appJson
)
{
module
.
exports
=
function
(
appJson
)
{
if
(
!
appJson
.
plugins
)
{
appJson
.
plugins
=
{}
}
if
(
!
appJson
.
plugins
[
'
uni-ad
'
])
{
appJson
.
plugins
[
'
uni-ad
'
]
=
{
"
version
"
:
"
1.0.2
"
,
"
provider
"
:
"
wx999bf02c8e05dfc9
"
version
:
'
1.0.2
'
,
provider
:
'
wx999bf02c8e05dfc9
'
}
}
if
(
!
appJson
.
plugins
[
'
coral-adv
'
])
{
appJson
.
plugins
[
'
coral-adv
'
]
=
{
"
version
"
:
"
1.0.7
"
,
"
provider
"
:
"
wx0e203209e27b1e66
"
version
:
'
1.0.7
'
,
provider
:
'
wx0e203209e27b1e66
'
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录