ant-design-vue/site/components/CarbonAds.vue

125 lines
2.8 KiB
Vue
Raw Normal View History

2019-01-17 03:59:21 +00:00
<script>
2019-01-26 08:04:32 +00:00
import axios from 'axios';
2019-01-17 03:59:21 +00:00
const carbonUrls = {
2019-08-12 12:38:09 +00:00
'vuecomponent.github.io':
'//cdn.carbonads.com/carbon.js?serve=CK7DL2JW&placement=vuecomponentgithubio',
'tangjinzhou.gitee.io':
'//cdn.carbonads.com/carbon.js?serve=CK7DL2JN&placement=tangjinzhougiteeio',
'ant-design-vue.gitee.io':
'//cdn.carbonads.com/carbon.js?serve=CK7DL2JN&placement=antdesignvuegiteeio',
2019-02-16 09:16:59 +00:00
'vue.ant.design': '//cdn.carbonads.com/carbon.js?serve=CK7DL2JW&placement=vueantdesign',
2019-01-17 03:59:21 +00:00
};
2019-08-12 12:38:09 +00:00
const carbonUrl =
carbonUrls[location.host] ||
'//cdn.carbonads.com/carbon.js?serve=CK7DL2JW&placement=vueantdesign';
2019-01-17 03:59:21 +00:00
export default {
2019-02-16 06:32:46 +00:00
props: {
isMobile: Boolean,
},
2019-01-17 03:59:21 +00:00
watch: {
$route(e, t) {
2019-01-26 08:04:32 +00:00
let adId = '#carbonads';
2019-02-16 06:32:46 +00:00
// if(isGitee) {
// adId = '#cf';
// }
2019-08-12 12:38:09 +00:00
if (e.path !== t.path && this.$el.querySelector(adId)) {
this.$el.innerHTML = '';
2019-01-17 03:59:21 +00:00
this.load();
}
2019-01-18 02:18:57 +00:00
this.adInterval && clearInterval(this.adInterval);
2019-08-12 12:38:09 +00:00
this.adInterval = setInterval(() => {
if (!this.$el.querySelector(adId)) {
this.$el.innerHTML = '';
2019-01-18 02:18:57 +00:00
this.load();
}
2019-01-19 09:54:15 +00:00
}, 20000);
2019-01-17 03:59:21 +00:00
},
},
2019-02-01 09:23:00 +00:00
mounted() {
this.load();
},
2019-01-17 03:59:21 +00:00
methods: {
load() {
2019-02-16 06:32:46 +00:00
// if(isGitee) {
// axios.get('https://api.codefund.app/properties/162/funder.html?template=horizontal')
// .then(function (response) {
// document.getElementById("codefund-ads").innerHTML = response.data;
// });
2019-08-12 12:38:09 +00:00
// } else
if (carbonUrl) {
const e = document.createElement('script');
e.id = '_carbonads_js';
2019-01-17 03:59:21 +00:00
e.src = carbonUrl;
this.$el.appendChild(e);
}
},
},
2019-08-12 12:38:09 +00:00
render() {
return <div id="carbon-ads" class={this.isMobile ? 'carbon-mobile' : ''} />;
2019-01-17 03:59:21 +00:00
},
};
</script>
2019-02-16 06:32:46 +00:00
<style lang="less">
2019-08-12 12:38:09 +00:00
#carbon-ads {
width: 280px;
float: right;
position: relative;
right: 0;
bottom: 0;
2019-03-18 09:09:41 +00:00
padding: 0;
2019-02-16 06:32:46 +00:00
overflow: hidden;
2019-01-26 08:04:32 +00:00
z-index: 9;
2019-01-17 03:59:21 +00:00
background-color: #fff;
2019-08-12 12:38:09 +00:00
border-radius: 3px;
2019-01-17 03:59:21 +00:00
font-size: 13px;
2019-02-16 06:32:46 +00:00
background: #f5f5f5;
2019-08-12 12:38:09 +00:00
font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
2019-01-17 03:59:21 +00:00
}
2019-03-18 09:09:41 +00:00
#carbonads {
overflow: hidden;
}
2019-01-17 03:59:21 +00:00
#carbon-ads a {
display: inline-block;
color: #7f8c8d;
font-weight: normal;
}
#carbon-ads span {
color: #7f8c8d;
}
#carbon-ads img {
2019-03-18 09:09:41 +00:00
float: left;
2019-08-04 13:14:08 +00:00
padding-right: 10px;
2019-01-17 03:59:21 +00:00
}
#carbon-ads .carbon-img,
#carbon-ads .carbon-text {
display: block;
font-weight: normal;
color: #34495e;
}
#carbon-ads .carbon-text {
2019-03-18 09:09:41 +00:00
padding-top: 6px;
2019-01-17 03:59:21 +00:00
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 4;
overflow: hidden;
}
#carbon-ads .carbon-poweredby {
2019-08-12 12:38:09 +00:00
color: #aaa;
font-weight: normal;
line-height: 1.2;
2019-02-16 06:32:46 +00:00
margin-top: 6px;
}
#carbon-ads.carbon-mobile {
width: 100%;
position: relative;
right: 0;
bottom: 0;
padding: 0;
2019-08-04 13:14:08 +00:00
margin-bottom: 15px;
2019-02-16 06:32:46 +00:00
.carbon-img {
float: left;
margin-right: 10px;
}
2019-01-17 03:59:21 +00:00
}
</style>