Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
良好的行为成为习惯
uni-app
提交
96e1d5db
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,发现更多精彩内容 >>
提交
96e1d5db
编写于
1月 11, 2021
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update: 优化vue页面ad组件缓存策略
上级
ca832a5c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
89 addition
and
46 deletion
+89
-46
src/platforms/app-plus/service/api/ad/ad.js
src/platforms/app-plus/service/api/ad/ad.js
+49
-0
src/platforms/app-plus/service/api/index.js
src/platforms/app-plus/service/api/index.js
+1
-0
src/platforms/app-plus/view/components/ad/index.vue
src/platforms/app-plus/view/components/ad/index.vue
+39
-46
未找到文件。
src/platforms/app-plus/service/api/ad/ad.js
0 → 100644
浏览文件 @
96e1d5db
function
operateAdView
(
pageId
,
id
,
type
,
data
)
{
UniServiceJSBridge
.
publishHandler
(
id
,
{
type
,
data
},
pageId
)
}
UniServiceJSBridge
.
subscribe
(
'
onAdMethodCallback
'
,
({
callbackId
,
data
},
pageId
)
=>
{
const
{
adpid
,
width
,
count
}
=
data
getAdData
(
adpid
,
width
,
count
,
(
res
)
=>
{
operateAdView
(
pageId
,
callbackId
,
'
success
'
,
res
)
},
(
err
)
=>
{
operateAdView
(
pageId
,
callbackId
,
'
fail
'
,
err
)
})
})
const
_adDataCache
=
{}
function
getAdData
(
adpid
,
width
,
count
,
onsuccess
,
onerror
)
{
const
key
=
adpid
+
'
-
'
+
width
const
adDataList
=
_adDataCache
[
key
]
if
(
adDataList
&&
adDataList
.
length
>
0
)
{
onsuccess
(
adDataList
.
splice
(
0
,
1
)[
0
])
return
}
plus
.
ad
.
getAds
(
{
adpid
,
count
,
width
},
(
res
)
=>
{
const
list
=
res
.
ads
onsuccess
(
list
.
splice
(
0
,
1
)[
0
])
_adDataCache
[
key
]
=
adDataList
?
adDataList
.
concat
(
list
)
:
list
},
(
err
)
=>
{
onerror
({
errCode
:
err
.
code
,
errMsg
:
err
.
message
})
}
)
}
src/platforms/app-plus/service/api/index.js
浏览文件 @
96e1d5db
...
...
@@ -76,5 +76,6 @@ export * from './ui/tab-bar'
export
*
from
'
./ui/request-component-info
'
export
*
from
'
./ad/ad
'
export
*
from
'
./ad/rewarded-video-ad
'
export
*
from
'
./ad/full-screen-video-ad
'
src/platforms/app-plus/view/components/ad/index.vue
浏览文件 @
96e1d5db
...
...
@@ -15,39 +15,6 @@ import {
}
from
'
uni-mixins
'
import
native
from
'
../../mixins/native
'
const
_adDataCache
=
{}
function
getAdData
(
adpid
,
adWidth
,
onsuccess
,
onerror
)
{
const
key
=
adpid
+
'
-
'
+
adWidth
const
adDataList
=
_adDataCache
[
key
]
if
(
adDataList
&&
adDataList
.
length
>
0
)
{
onsuccess
(
adDataList
.
splice
(
0
,
1
)[
0
])
return
}
plus
.
ad
.
getAds
(
{
adpid
:
adpid
,
count
:
10
,
width
:
adWidth
},
(
res
)
=>
{
const
list
=
res
.
ads
onsuccess
(
list
.
splice
(
0
,
1
)[
0
])
_adDataCache
[
key
]
=
adDataList
?
adDataList
.
concat
(
list
)
:
list
},
(
err
)
=>
{
onerror
({
errCode
:
err
.
code
,
errMsg
:
err
.
message
})
}
)
}
const
methods
=
[
'
draw
'
]
const
attrs
=
[
'
adpid
'
,
'
data
'
...
...
@@ -64,6 +31,10 @@ export default {
data
:
{
type
:
Object
,
default
:
null
},
dataCount
:
{
type
:
Number
,
default
:
5
}
},
data
()
{
...
...
@@ -98,8 +69,9 @@ export default {
}
},
mounted
()
{
this
.
_adId
=
'
AdView-
'
+
this
.
_newGUID
()
const
adStyle
=
Object
.
assign
({
id
:
'
AdView
'
+
Date
.
now
()
id
:
this
.
_adId
},
this
.
position
)
const
adView
=
this
.
adView
=
plus
.
ad
.
createAdView
(
adStyle
)
adView
.
interceptTouchEvent
(
false
)
...
...
@@ -139,6 +111,10 @@ export default {
adView
.
setAdClickedListener
((
data
)
=>
{
this
.
$trigger
(
'
adclicked
'
,
{},
data
)
})
this
.
_callbackId
=
this
.
$page
.
id
+
this
.
_adId
UniViewJSBridge
.
subscribe
(
this
.
_callbackId
,
this
.
_handleAdData
.
bind
(
this
))
this
.
_request
()
},
beforeDestroy
()
{
...
...
@@ -146,12 +122,17 @@ export default {
delete
this
.
adView
},
methods
:
{
_handle
Subscribe
({
_handle
AdData
({
type
,
data
=
{}
})
{
if
(
methods
.
includes
(
type
))
{
this
.
adView
&&
this
.
adView
[
type
](
data
)
switch
(
type
)
{
case
'
success
'
:
this
.
_fillData
(
data
)
break
case
'
fail
'
:
this
.
$trigger
(
'
error
'
,
{},
data
)
break
}
},
_request
()
{
...
...
@@ -166,22 +147,34 @@ export default {
}
},
_loadData
(
adpid
)
{
getAdData
(
adpid
||
this
.
adpid
,
this
.
position
.
width
,
(
data
)
=>
{
this
.
_fillData
(
data
)
},
(
err
)
=>
{
this
.
$trigger
(
'
error
'
,
{},
err
)
})
const
data
=
{
adpid
:
adpid
||
this
.
adpid
,
width
:
this
.
position
.
width
,
count
:
this
.
dataCount
}
UniViewJSBridge
.
publishHandler
(
'
onAdMethodCallback
'
,
{
callbackId
:
this
.
_callbackId
,
data
},
this
.
$page
.
id
)
},
_fillData
(
data
)
{
this
.
adView
.
renderingBind
(
data
)
// const height = plus.ad.measureAdHeight(this.position.width.replace('px', ''), data)
// this.$refs.container.style.height = height + 'px'
this
.
$trigger
(
'
load
'
,
{},
{})
},
_updateView
()
{
window
.
dispatchEvent
(
new
CustomEvent
(
'
updateview
'
))
},
_newGUID
()
{
let
guid
=
''
const
format
=
'
xxxxxxxx-xxxx
'
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
()
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录