Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
be99d88e
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
be99d88e
编写于
7月 28, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' of
https://github.com/dcloudio/uni-app
into dev
上级
6601533e
fcdac4b8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
166 addition
and
33 deletion
+166
-33
packages/webpack-uni-pages-loader/lib/platforms/h5.js
packages/webpack-uni-pages-loader/lib/platforms/h5.js
+5
-2
src/platforms/h5/view/components/ad/index.vue
src/platforms/h5/view/components/ad/index.vue
+161
-31
未找到文件。
packages/webpack-uni-pages-loader/lib/platforms/h5.js
浏览文件 @
be99d88e
...
...
@@ -12,7 +12,9 @@ const {
const
{
addPageUsingComponents
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/pages
'
)
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/pages
'
)
const
compilerVersion
=
require
(
'
@dcloudio/webpack-uni-pages-loader/package.json
'
)[
'
uni-app
'
].
compilerVersion
const
PLATFORMS
=
getPlatforms
()
...
...
@@ -400,7 +402,8 @@ module.exports = function (pagesJson, manifestJson, loader) {
import Vue from 'vue'
global['____
${
h5
.
appid
}
____'] = true;
delete global['____
${
h5
.
appid
}
____'];
global.__uniConfig =
${
JSON
.
stringify
(
pagesJson
)}
;
global.__uniConfig =
${
JSON
.
stringify
(
pagesJson
)}
;
global.__uniConfig.compilerVersion = '
${
compilerVersion
}
';
global.__uniConfig.router =
${
JSON
.
stringify
(
h5
.
router
)}
;
global.__uniConfig.publicPath =
${
JSON
.
stringify
(
h5
.
publicPath
)}
;
global.__uniConfig['async'] =
${
JSON
.
stringify
(
h5
.
async
)}
;
...
...
src/platforms/h5/view/components/ad/index.vue
浏览文件 @
be99d88e
...
...
@@ -6,7 +6,7 @@
<div
ref=
"container"
class=
"uni-ad-container"
@
click=
"onhandle"
@
click=
"
_
onhandle"
/>
</uni-ad>
</
template
>
...
...
@@ -36,14 +36,20 @@ class AdConfig {
return
this
.
_adConfig
}
get
isExpired
()
{
if
(
this
.
_adConfig
==
null
)
{
return
true
}
return
(
Math
.
abs
(
Date
.
now
()
-
this
.
_adConfig
.
last
)
>
this
.
CACHE_TIME
)
}
_init
()
{
var
config
=
this
.
_getConfig
()
if
(
config
===
null
||
!
config
.
last
)
{
return
}
var
td
=
Math
.
abs
(
Date
.
now
()
-
config
.
last
)
if
(
td
<
this
.
CACHE_TIME
)
{
if
(
!
this
.
isExpired
)
{
this
.
_adConfig
=
config
.
data
}
}
...
...
@@ -51,6 +57,9 @@ class AdConfig {
get
(
adpid
,
success
,
fail
)
{
if
(
this
.
_adConfig
!=
null
)
{
this
.
_doCallback
(
adpid
,
success
,
fail
)
if
(
this
.
isExpired
)
{
this
.
_loadAdConfig
(
adpid
)
}
return
}
...
...
@@ -65,8 +74,8 @@ class AdConfig {
_doCallback
(
adpid
,
success
,
fail
)
{
var
data
=
this
.
_adConfig
if
(
data
.
adpids
[
adpid
])
{
success
(
data
.
adpids
[
adpid
])
if
(
data
[
adpid
])
{
success
(
data
[
adpid
])
}
else
{
fail
(
this
.
ERROR_INVALID_ADPID
)
}
...
...
@@ -76,15 +85,15 @@ class AdConfig {
if
(
this
.
_isLoading
===
true
)
{
return
}
this
.
_isLoading
=
true
uni
.
request
({
url
:
this
.
URL
,
method
:
'
GET
'
,
timeout
:
3
000
,
timeout
:
5
000
,
data
:
{
adpid
:
adpid
d
:
location
.
hostname
,
a
:
adpid
},
dataType
:
'
json
'
,
success
:
(
res
)
=>
{
...
...
@@ -100,14 +109,14 @@ class AdConfig {
})
}
else
{
this
.
_callbacks
.
forEach
((
i
)
=>
{
i
.
fail
(
rd
.
message
)
i
.
fail
(
{
errCode
:
rd
.
ret
,
errMsg
:
rd
.
msg
}
)
})
}
this
.
_callbacks
=
[]
},
fail
:
(
err
)
=>
{
this
.
_callbacks
.
forEach
((
i
)
=>
{
i
.
fail
(
err
.
errMsg
)
i
.
fail
(
err
)
})
this
.
_callbacks
=
[]
},
...
...
@@ -136,7 +145,7 @@ class AdConfig {
}
}
Object
.
assign
(
AdConfig
.
prototype
,
{
URL
:
'
//
stream.dcloud.net.cn/dcloud/H5Config
'
,
URL
:
'
//
qy5y9ee9ch8r87pg72w5.dcloud.net.cn/hcs
'
,
KEY
:
'
uni_app_ad_config
'
,
CACHE_TIME
:
1000
*
60
*
10
,
ERROR_INVALID_ADPID
:
{
...
...
@@ -144,9 +153,89 @@ Object.assign(AdConfig.prototype, {
}
})
class
AdReport
{
static
get
instance
()
{
if
(
this
.
_instance
==
null
)
{
this
.
_instance
=
new
AdReport
()
this
.
_instance
.
_init
()
}
return
this
.
_instance
}
constructor
()
{
this
.
_instance
=
null
this
.
_adConfig
=
null
this
.
_guid
=
null
}
_init
()
{
var
config
=
this
.
_getConfig
()
if
(
config
!==
null
&&
config
.
guid
)
{
this
.
_guid
=
config
.
guid
return
}
this
.
_guid
=
this
.
_newGUID
()
this
.
_setConfig
(
this
.
_guid
)
}
get
(
data
)
{
this
.
_process
(
Object
.
assign
(
data
,
{
d
:
location
.
hostname
,
i
:
this
.
_guid
}))
}
_process
(
data
)
{
uni
.
request
({
url
:
this
.
URL
,
method
:
'
GET
'
,
data
:
data
,
dataType
:
'
json
'
,
success
:
()
=>
{
}
})
}
_newGUID
()
{
let
guid
=
''
const
format
=
'
xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx
'
for
(
let
i
=
0
;
i
<
format
.
length
;
i
++
)
{
if
(
format
[
i
]
===
'
x
'
)
{
guid
+=
(
Math
.
random
()
*
16
|
0
).
toString
(
16
)
}
else
{
guid
+=
format
[
i
]
}
}
return
guid
.
toUpperCase
()
}
_getConfig
()
{
if
(
!
navigator
.
cookieEnabled
||
!
window
.
localStorage
)
{
return
null
}
var
data
=
localStorage
.
getItem
(
this
.
KEY
)
return
data
?
JSON
.
parse
(
data
)
:
null
}
_setConfig
(
guid
)
{
if
(
!
navigator
.
cookieEnabled
||
!
window
.
localStorage
)
{
return
null
}
localStorage
.
setItem
(
this
.
KEY
,
JSON
.
stringify
({
last
:
Date
.
now
(),
guid
:
guid
}))
}
}
Object
.
assign
(
AdReport
.
prototype
,
{
URL
:
'
//hp66hwpyev7yx2hfughh.dcloud.net.cn/ahl
'
,
KEY
:
'
uni_app_ad_guid
'
})
const
adProvider
=
{
hx
:
'
hx
'
,
ky
:
'
ky
'
hx
:
'
zswx_
hx
'
,
ky
:
'
zswx_
ky
'
}
const
CHECK_RENDER_DELAY
=
1000
...
...
@@ -175,21 +264,35 @@ export default {
this
.
_checkTimer
=
null
this
.
_checkTimerCount
=
0
this
.
_loadData
()
AdReport
.
instance
.
get
({
h
:
__uniConfig
.
compilerVersion
,
a
:
this
.
adpid
,
at
:
30
})
},
beforeDestroy
()
{
this
.
_clearCheckTimer
()
this
.
$refs
.
container
.
innerHTML
=
''
},
methods
:
{
onhandle
(
e
)
{
console
.
log
(
'
onhandle
'
)
_onhandle
(
e
)
{
this
.
_report
(
41
)
},
_reset
()
{
this
.
_pl
=
[]
this
.
_pd
=
{}
this
.
_pi
=
0
this
.
_clearCheckTimer
()
this
.
$refs
.
container
.
innerHTML
=
''
},
_loadData
(
adpid
)
{
this
.
_reset
()
AdConfig
.
instance
.
get
(
adpid
||
this
.
adpid
,
(
data
)
=>
{
this
.
_pd
=
data
this
.
_pl
=
data
.
psp
.
split
(
'
,
'
)
this
.
_renderAd
()
},
(
err
)
=>
{
this
.
$trigger
(
'
error
'
,
{},
{
message
:
err
}
)
this
.
$trigger
(
'
error
'
,
{},
err
)
})
},
_renderAd
()
{
...
...
@@ -208,12 +311,29 @@ export default {
break
}
},
_renderNext
()
{
if
(
this
.
_pi
>=
this
.
_pl
.
length
-
1
)
{
return
}
this
.
_pi
++
this
.
_renderAd
()
},
_renderHX
(
data
)
{
if
(
document
.
querySelector
(
'
#
'
+
adProvider
.
hx
))
{
this
.
_renderNext
()
return
}
var
ad
=
document
.
createElement
(
'
script
'
)
ad
.
src
=
data
.
src
||
data
.
url
var
adView
=
document
.
createElement
(
'
div
'
)
adView
.
setAttribute
(
'
id
'
,
adProvider
.
hx
)
adView
.
appendChild
(
ad
)
this
.
$refs
.
container
.
innerHTML
=
''
this
.
$refs
.
container
.
append
(
ad
)
this
.
$refs
.
container
.
append
(
ad
View
)
this
.
_startCheckTimer
()
},
...
...
@@ -226,31 +346,25 @@ export default {
this
.
_startCheckTimer
()
},
_renderNext
()
{
if
(
this
.
_pi
>=
this
.
_pl
.
length
-
1
)
{
return
}
this
.
_pi
++
this
.
_renderAd
()
},
_checkRender
()
{
var
hasContent
=
(
this
.
$refs
.
container
.
clientHeight
>
40
)
var
hasContent
=
(
this
.
$refs
.
container
.
children
.
length
>
0
&&
this
.
$refs
.
container
.
clientHeight
>
40
)
if
(
hasContent
)
{
this
.
_report
(
40
)
}
return
hasContent
},
_startCheckTimer
()
{
this
.
_clearCheckTimer
()
this
.
_checkTimer
=
setInterval
(()
=>
{
if
(
this
.
_checkRender
())
{
this
.
_checkTimerCount
++
if
(
this
.
_checkTimerCount
>=
CHECK_RENDER_RETRY
)
{
this
.
_clearCheckTimer
()
this
.
_renderNext
()
return
}
this
.
_checkTimerCount
++
if
(
this
.
_checkTimerCount
>=
CHECK_RENDER_RETRY
)
{
if
(
this
.
_checkRender
())
{
this
.
_clearCheckTimer
()
this
.
_renderNext
()
}
},
CHECK_RENDER_DELAY
)
},
...
...
@@ -260,6 +374,22 @@ export default {
window
.
clearInterval
(
this
.
_checkTimer
)
this
.
_checkTimer
=
null
}
},
_report
(
type
)
{
var
taskId
=
''
if
(
this
.
_pl
.
length
>
0
&&
this
.
_pi
<
this
.
_pl
.
length
)
{
var
data
=
this
.
_pd
[
this
.
_pl
[
this
.
_pi
]]
if
(
data
)
{
taskId
=
data
.
task_id
}
}
AdReport
.
instance
.
get
({
h
:
__uniConfig
.
compilerVersion
,
a
:
this
.
adpid
,
t
:
taskId
,
at
:
type
})
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录