Skip to content

Commit 29b6ca3

Browse files
committed
feat: add carbon ads
1 parent 000f8e9 commit 29b6ca3

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ yarn-error.log*
1919
*.njsproj
2020
*.sln
2121
*.sw*
22+
package-lock.json

src/components/Menu/SideMenu.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
:mode="mode"
1414
@select="onSelect"
1515
style="padding: 16px 0px;"></s-menu>
16+
<!-- 广告代码 真实项目中请移除 -->
17+
<ads v-if="!collapsed"/>
1618
</a-layout-sider>
1719

1820
</template>
@@ -21,10 +23,11 @@
2123
import Logo from '@/components/tools/Logo'
2224
import SMenu from './index'
2325
import { mixin, mixinDevice } from '@/utils/mixin'
26+
import Ads from '@/components/Other/CarbonAds'
2427
2528
export default {
2629
name: 'SideMenu',
27-
components: { Logo, SMenu },
30+
components: { Logo, SMenu, Ads },
2831
mixins: [mixin, mixinDevice],
2932
props: {
3033
mode: {

src/components/Other/CarbonAds.vue

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<script>
2+
const carbonUrl = '//cdn.carbonads.com/carbon.js?serve=CK7DL2JW&placement=antdvcom'
3+
export default {
4+
props: {
5+
isMobile: Boolean
6+
},
7+
watch: {
8+
$route (e, t) {
9+
const adId = '#carbonads'
10+
// if(isGitee) {
11+
// adId = '#cf';
12+
// }
13+
if (e.path !== t.path && this.$el.querySelector(adId)) {
14+
this.$el.innerHTML = ''
15+
this.load()
16+
}
17+
this.adInterval && clearInterval(this.adInterval)
18+
this.adInterval = setInterval(() => {
19+
if (!this.$el.querySelector(adId)) {
20+
this.$el.innerHTML = ''
21+
this.load()
22+
}
23+
}, 20000)
24+
}
25+
},
26+
mounted () {
27+
this.load()
28+
},
29+
methods: {
30+
load () {
31+
// if(isGitee) {
32+
// axios.get('https://api.codefund.app/properties/162/funder.html?template=horizontal')
33+
// .then(function (response) {
34+
// document.getElementById("codefund-ads").innerHTML = response.data;
35+
// });
36+
// } else
37+
if (carbonUrl) {
38+
const e = document.createElement('script')
39+
e.id = '_carbonads_js'
40+
e.src = carbonUrl
41+
this.$el.appendChild(e)
42+
}
43+
}
44+
},
45+
render () {
46+
return <div id="carbon-ads" class={this.isMobile ? 'carbon-mobile' : ''} />
47+
}
48+
}
49+
</script>
50+
<style lang="less">
51+
#carbon-ads {
52+
width: 256px;
53+
/* float: right; */
54+
margin-top: 75px;
55+
position: fixed;
56+
left: 0;
57+
bottom: 0;
58+
padding: 0;
59+
overflow: hidden;
60+
z-index: 9;
61+
background-color: #fff;
62+
/* border-radius: 3px; */
63+
font-size: 13px;
64+
background: #f5f5f5;
65+
font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
66+
}
67+
#carbonads {
68+
overflow: hidden;
69+
}
70+
#carbon-ads a {
71+
display: inline-block;
72+
color: #7f8c8d;
73+
font-weight: normal;
74+
}
75+
#carbon-ads span {
76+
color: #7f8c8d;
77+
}
78+
#carbon-ads img {
79+
float: left;
80+
padding-right: 10px;
81+
}
82+
#carbon-ads .carbon-img,
83+
#carbon-ads .carbon-text {
84+
display: block;
85+
font-weight: normal;
86+
color: #34495e;
87+
}
88+
#carbon-ads .carbon-text {
89+
padding-top: 6px;
90+
display: -webkit-box;
91+
-webkit-box-orient: vertical;
92+
-webkit-line-clamp: 4;
93+
overflow: hidden;
94+
}
95+
#carbon-ads .carbon-poweredby {
96+
color: #aaa;
97+
font-weight: normal;
98+
line-height: 1.2;
99+
margin-top: 6px;
100+
}
101+
#carbon-ads.carbon-mobile {
102+
width: 100%;
103+
position: relative;
104+
right: 0;
105+
bottom: 0;
106+
padding: 0;
107+
margin-bottom: 15px;
108+
margin-top: 5px;
109+
.carbon-img {
110+
float: left;
111+
margin-right: 10px;
112+
}
113+
}
114+
</style>

0 commit comments

Comments
 (0)