Skip to content

Commit 40338a3

Browse files
linyinengBrunoon
authored andcommitted
mip-ad 组件 ad-fd 类型新增按条件渲染广告功能 (#689)
* mip-ad 组件添加 af-fd 广告类型 * 优化代码 * 优化代码 * 新增定向条件属性 * 新增定向条件属性 * 新增定向条件属性
1 parent f06e3e4 commit 40338a3

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

components/mip-ad/example/mip-ad-fd.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
width="100"
1818
height="30"
1919
type="ad-fd"
20-
data-id="143">
20+
data-id="143"
21+
data-dep="54,12"
22+
data-dis="12100">
2123
</mip-ad>
2224
</div>
2325
<script src="https://c.mipcdn.com/static/v2/mip.js"></script>

components/mip-ad/mip-ad-fd.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,36 @@ export default function render (el) {
1212
el.classList.add('__customer_place')
1313

1414
if (window.CUSTOMER) {
15-
loadSubScript(el)
15+
setConditions(el)
1616
} else {
1717
window.require(['https://img.familydoctor.com.cn/component/common/scripts/gg_main.min'], function (CUSTOMER) {
1818
window.CUSTOMER = CUSTOMER
19-
loadSubScript(el)
19+
setConditions(el)
2020
})
2121
}
2222
}
2323

24+
/**
25+
* 设置定向条件
26+
*
27+
* @param {HTMLElement} el 当前 mip-ad 组件的 DOM 元素
28+
*/
29+
function setConditions (el) {
30+
let dep = el.getAttribute('data-dep')
31+
let dis = el.getAttribute('data-dis')
32+
33+
if (dep) {
34+
dep = dep.split(',')
35+
window.CUSTOMER.setDep(...dep)
36+
}
37+
38+
if (dis) {
39+
window.CUSTOMER.setDis(dis)
40+
}
41+
42+
loadSubScript(el)
43+
}
44+
2445
/**
2546
* 加载广告位 js
2647
*

components/mip-ad/mip-ad-fd.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ mip 广告组件 `<mip-ad>` 的一种类型:家庭医生在线提供的广告
1919
width="100"
2020
height="30"
2121
type="ad-fd"
22-
data-id="143">
22+
data-id="143"
23+
data-dep="54,12"
24+
data-dis="12100">
2325
</mip-ad>
2426
```
2527

@@ -41,4 +43,20 @@ mip 广告组件 `<mip-ad>` 的一种类型:家庭医生在线提供的广告
4143

4244
**必选项**:是
4345

46+
**类型**:数字
47+
48+
### data-dep
49+
50+
**说明**:按科室编号投放。可分两种情况:示例1、投放到一级科室 data-dep="54";示例2、投放到一级科室和二级科室 data-dep="54,12"。
51+
52+
**必选项**:否
53+
54+
**类型**:数字
55+
56+
### data-dis
57+
58+
**说明**:按疾病编号投放。
59+
60+
**必选项**:否
61+
4462
**类型**:数字

0 commit comments

Comments
 (0)