Skip to content

Commit

Permalink
mip-ad 组件 ad-fd 类型新增按条件渲染广告功能 (#689)
Browse files Browse the repository at this point in the history
* mip-ad 组件添加 af-fd 广告类型

* 优化代码

* 优化代码

* 新增定向条件属性

* 新增定向条件属性

* 新增定向条件属性
  • Loading branch information
linyineng authored and Brunoon committed Aug 15, 2019
1 parent f06e3e4 commit 40338a3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
4 changes: 3 additions & 1 deletion components/mip-ad/example/mip-ad-fd.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
width="100"
height="30"
type="ad-fd"
data-id="143">
data-id="143"
data-dep="54,12"
data-dis="12100">
</mip-ad>
</div>
<script src="https://c.mipcdn.com/static/v2/mip.js"></script>
Expand Down
25 changes: 23 additions & 2 deletions components/mip-ad/mip-ad-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,36 @@ export default function render (el) {
el.classList.add('__customer_place')

if (window.CUSTOMER) {
loadSubScript(el)
setConditions(el)
} else {
window.require(['https://img.familydoctor.com.cn/component/common/scripts/gg_main.min'], function (CUSTOMER) {
window.CUSTOMER = CUSTOMER
loadSubScript(el)
setConditions(el)
})
}
}

/**
* 设置定向条件
*
* @param {HTMLElement} el 当前 mip-ad 组件的 DOM 元素
*/
function setConditions (el) {
let dep = el.getAttribute('data-dep')
let dis = el.getAttribute('data-dis')

if (dep) {
dep = dep.split(',')
window.CUSTOMER.setDep(...dep)
}

if (dis) {
window.CUSTOMER.setDis(dis)
}

loadSubScript(el)
}

/**
* 加载广告位 js
*
Expand Down
20 changes: 19 additions & 1 deletion components/mip-ad/mip-ad-fd.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ mip 广告组件 `<mip-ad>` 的一种类型:家庭医生在线提供的广告
width="100"
height="30"
type="ad-fd"
data-id="143">
data-id="143"
data-dep="54,12"
data-dis="12100">
</mip-ad>
```

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

**必选项**:是

**类型**:数字

### data-dep

**说明**:按科室编号投放。可分两种情况:示例1、投放到一级科室 data-dep="54";示例2、投放到一级科室和二级科室 data-dep="54,12"。

**必选项**:否

**类型**:数字

### data-dis

**说明**:按疾病编号投放。

**必选项**:否

**类型**:数字

0 comments on commit 40338a3

Please sign in to comment.