Browse Source

feat 广告位对接

pull/3/head
Wangwei 2 years ago
parent
commit
f749e99fb7
  1. 3
      package.json
  2. 87
      src/components/banner.vue
  3. 6
      src/router.js
  4. 151
      src/utils/advertisementSDK.js
  5. 19
      src/views/studypath/finebi.vue
  6. 21
      src/views/studypath/finereportStudyPath2023.vue
  7. 19
      src/views/studypath/jiandaoyun.vue
  8. 3
      src/views/video/indexVideo.vue

3
package.json

@ -54,7 +54,8 @@
"parser": "babel-eslint" "parser": "babel-eslint"
}, },
"rules": { "rules": {
"no-undef": "off" "no-undef": "off",
"no-unused-vars": "off"
} }
}, },
"browserslist": [ "browserslist": [

87
src/components/banner.vue

@ -4,8 +4,7 @@
<div class="left-nav"> <div class="left-nav">
<ul class="left-wrapper"> <ul class="left-wrapper">
<li v-for="(item, i) in menuList.slice(0, 6)" :key="i"> <li v-for="(item, i) in menuList.slice(0, 6)" :key="i">
<router-link @mouseenter="gethot(item.id)" class="c1a flex-3 flex-1" :to="'/video?class1='+item.id" <router-link @mouseenter="gethot(item.id)" class="c1a flex-3 flex-1" :to="'/video?class1=' + item.id" target="_blank">
target="_blank">
<span>{{ item.it618_classname }}</span> <span>{{ item.it618_classname }}</span>
<i class="arrow el-icon-arrow-right"></i> <i class="arrow el-icon-arrow-right"></i>
</router-link> </router-link>
@ -39,13 +38,11 @@
</li> </li>
</ul> </ul>
</div> </div>
</div> </div>
</div> </div>
</li> </li>
<li> <li>
<!-- <a href="/video?class1=37&class2=0" class="c1a flex-3 flex-1"> <!-- <a href="/video?class1=37&class2=0" class="c1a flex-3 flex-1">
<span>FineDataLink</span> <span>FineDataLink</span>
<i class="arrow el-icon-arrow-right"></i> <i class="arrow el-icon-arrow-right"></i>
@ -69,28 +66,16 @@
</router-link> </router-link>
</div> </div>
</ul> </ul>
</div> </div>
</div> </div>
</li> </li>
</ul> </ul>
</div> </div>
<div class="right-box flex-3"> <div class="right-box flex-3">
<div class="ad"> <div class="ad">
<a :href="cover.click_url" target="_blank"> <div id="AD-1d4b2f969fcd43a99205e88c53b05d8d"></div>
<!-- <img :src="cover.imgurl" width="1000" height="420"> -->
<el-image :src="cover.img_url" style=" width: 1000px; height: 375px; position: static">
<template #error>
<div style="width: 800px; height: 100%;" class="flex-5">
<i class="el-icon-loading f24 colb3c"></i>
</div>
</template>
</el-image>
</a>
</div> </div>
<div class="menu"> <div class="menu">
<ul> <ul>
<a href="https://bbs.fanruan.com/course/report/standard?sqtjBI" target="_blank"> <a href="https://bbs.fanruan.com/course/report/standard?sqtjBI" target="_blank">
<li> <li>
@ -121,16 +106,11 @@
<i class="arrow el-icon-arrow-right"></i> <i class="arrow el-icon-arrow-right"></i>
</a> </a>
</ul> </ul>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="mbg ad-m dn"> <div class="mbg ad-m dn">
<a :href="cover.click_url" target="_blank"> <a :href="cover.click_url" target="_blank">
<el-image :src="cover.img_url" style=" width: 100%; position: static"> <el-image :src="cover.img_url" style=" width: 100%; position: static">
@ -142,13 +122,12 @@
</el-image> </el-image>
</a> </a>
</div> </div>
</template> </template>
<script> <script>
import { getCategories } from "@/api/video"; import { getCategories } from "@/api/video";
import { getcateHot, getCover } from "@/api/index"; import { getcateHot } from "@/api/index";
import { toRefs, reactive } from 'vue'; import { toRefs, reactive } from "vue";
export default { export default {
setup() { setup() {
const state = reactive({ const state = reactive({
@ -166,13 +145,17 @@
}; };
fetchMenuList(); fetchMenuList();
const fetchgetCover = async () => { // banner cid广
const res = await getCover(); // const fetchgetCover = async () => {
if (res.code === 200) { // const res = await getCover();
state.cover = res.data[0]; // if (res.code === 200) {
} // state.cover = res.data[0];
}; // }
fetchgetCover(); // };
// fetchgetCover();
// banner 广
window.fineAd.getAdvertisement({ adId: "1d4b2f969fcd43a99205e88c53b05d8d" });
const fetchgetcateHot = async (class1) => { const fetchgetcateHot = async (class1) => {
const res = await getcateHot(class1); const res = await getcateHot(class1);
@ -182,11 +165,9 @@
state.menuList.forEach((item, index) => { state.menuList.forEach((item, index) => {
if (item.id === class1) { if (item.id === class1) {
state.menuList[index]['hotdata'] = res.data; state.menuList[index]["hotdata"] = res.data;
} }
}); });
} }
}; };
@ -194,13 +175,12 @@
// //
state.menuList.forEach((item, index) => { state.menuList.forEach((item, index) => {
if (item.id === class1) { if (item.id === class1) {
if (!state.menuList[index]['hotdata']) { if (!state.menuList[index]["hotdata"]) {
fetchgetcateHot(class1); fetchgetcateHot(class1);
} }
} }
}); });
} };
return { return {
...toRefs(state), ...toRefs(state),
@ -212,7 +192,7 @@
<style lang="scss" scoped> <style lang="scss" scoped>
.mbg { .mbg {
background: #F3F8FF; background: #f3f8ff;
padding: 34px 0 0; padding: 34px 0 0;
} }
@ -252,8 +232,8 @@
} }
.left-nav .left-wrapper > li:hover { .left-nav .left-wrapper > li:hover {
color: #0082FC; color: #0082fc;
background: #EEF3FA; background: #eef3fa;
} }
.left-nav .left-wrapper li:hover .child-nav { .left-nav .left-wrapper li:hover .child-nav {
@ -261,7 +241,7 @@
} }
.nav .right-box { .nav .right-box {
background-color: #EEF3FA; background-color: #eef3fa;
border: none; border: none;
width: 1000px; width: 1000px;
@ -273,7 +253,6 @@
width: 200px; width: 200px;
position: relative; position: relative;
ul { ul {
width: 216px; width: 216px;
height: 100%; height: 100%;
@ -288,10 +267,9 @@
height: 25%; height: 25%;
padding: 0 16px; padding: 0 16px;
background-color: rgb(0, 0, 0, 0.19); background-color: rgb(0, 0, 0, 0.19);
transition: all .3s; transition: all 0.3s;
position: relative; position: relative;
h5 { h5 {
font-size: 16px; font-size: 16px;
padding-bottom: 2px; padding-bottom: 2px;
@ -302,7 +280,7 @@
} }
i { i {
transition: all .3s; transition: all 0.3s;
opacity: 0; opacity: 0;
margin-left: 0; margin-left: 0;
} }
@ -314,7 +292,6 @@
opacity: 1; opacity: 1;
margin-left: 26px; margin-left: 26px;
} }
} }
&::after { &::after {
@ -328,7 +305,6 @@
} }
} }
} }
} }
.child-nav { .child-nav {
@ -354,7 +330,7 @@
width: 320px; width: 320px;
height: 100%; height: 100%;
padding-top: 20px; padding-top: 20px;
background-color: #EEF3FA; background-color: #eef3fa;
padding: 20px 10px 0 10px; padding: 20px 10px 0 10px;
.amore { .amore {
@ -365,8 +341,8 @@
.mra { .mra {
padding: 20px 0 20px 32px; padding: 20px 0 20px 32px;
border-top: 1px solid #CEDDF2; border-top: 1px solid #ceddf2;
color: #0082FC; color: #0082fc;
font-size: 14px; font-size: 14px;
span { span {
@ -376,12 +352,11 @@
} }
&:after { &:after {
content: ' '; content: " ";
width: 42%; width: 42%;
} }
} }
.child-wrapper .child-item { .child-wrapper .child-item {
width: 42%; width: 42%;
border-radius: 20px; border-radius: 20px;
@ -396,7 +371,6 @@
text-align: center; text-align: center;
padding: 4px 0; padding: 4px 0;
font-size: 14px; font-size: 14px;
} }
} }
@ -409,9 +383,9 @@
} }
.left-wrapper .hot { .left-wrapper .hot {
border-left: 1px solid #CEDDF2; border-left: 1px solid #ceddf2;
width: 240px; width: 240px;
background-color: #EEF3FA; background-color: #eef3fa;
padding: 24px; padding: 24px;
h2 { h2 {
@ -451,6 +425,5 @@
margin: 0 auto; margin: 0 auto;
display: block; display: block;
} }
} }
</style> </style>

6
src/router.js

@ -2,7 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router';
import Layout from '@/layout/index.vue'; import Layout from '@/layout/index.vue';
import store from '@/store'; import store from '@/store';
import { refreshToken } from '@/api/auth'; import { refreshToken } from '@/api/auth';
// import '@/utils/fineClubSDK'; import '@/utils/advertisementSDK';
import { getUid, getExpiresTime } from '@/utils/cookie'; import { getUid, getExpiresTime } from '@/utils/cookie';
import { delUrlParams } from '@/utils/urlQuery'; import { delUrlParams } from '@/utils/urlQuery';
@ -350,6 +350,10 @@ const router = createRouter({
}, },
}); });
// 接入广告配置
let getAdEnv = process.env.VUE_APP_ENV == 'dist' ? false : true;
window.fineAd.config({debug:getAdEnv,dev:getAdEnv});
// 通过导航守卫 判断并刷新token // 通过导航守卫 判断并刷新token
let accessToken = store.getters.get_token; let accessToken = store.getters.get_token;
let expires = getExpiresTime(); let expires = getExpiresTime();

151
src/utils/advertisementSDK.js

@ -0,0 +1,151 @@
/**
* 广告调用SDK
* 2023-04-11 by Wangwei
*/
import axios from "axios";
const fineAd = (window.fineAd = window.fineAd || {});
fineAd.options = fineAd.options || {};
/**
* 初始化SDK配置
* @param debug
* @param dev
* @param adApiUrl
*/
const config = ({ debug = false, dev = false, adApiUrl }) => {
fineAd.options = {
...fineAd.options,
debug,
dev,
adApiUrl: dev ? 'https://testjdy.fanruan.com/fcoin' : 'https://home.fanruan.com/fcoin',
};
if(debug){
console.log('adApiUrl', fineAd.config.adApiUrl);
}
};
/**
* 获取并展示指定广告id的广告位
* @param adId 广告位id
* @param adId2 如果adId没有匹配到则显示第二个广告位
* @param top 顶边距
* @param bottom 底边距
*/
const getAdvertisement = async ({adId, adId2, top, bottom}) => {
const { debug, dev } = fineAd.options;
const dataPath = dev ? 'test' : 'prod';
await axios.get("https://shequ-oss.obs.cn-east-2.myhuaweicloud.com/digit/ad/data/" + dataPath + "/advertisement.json?v=" + Date.now())
.then(function (res) {
var isAdId = false;
res.data.forEach((item) => {
if(item.adId === adId){
isAdId = true;
let getSize = splitPicSize(item.picSize);
if(debug){
console.group("advertisement " + adId);
console.log('item',item);
console.log('picSize',getSize);
console.log('top',top);
console.log('bottom',bottom);
console.groupEnd();
}
let adDomId = document.getElementById('AD-' + adId);
adDomId.innerHTML='';
window.fineAd.adMargin({ adId:adId, top:top });
// 无链接图片广告
if(!item.adLink && item.type===1){
adDomId.innerHTML+=`<img width="${getSize.w}" height="${getSize.h}" src="${item.picUrl}">`;
}
// 有链接图片广告
if(item.adLink && item.type===1){
adDomId.innerHTML+=`<a onClick="window.fineAd.advertisementHits('${adId}');" href="${item.adLink}" target="_blank"><img width="${getSize.w}" height="${getSize.h}" src="${item.picUrl}"></a>`;
}
// 有链接文本广告
if(item.adLink && item.type===2){
adDomId.innerHTML+=`<a onClick="window.fineAd.advertisementHits('${adId}');" href="${item.adLink}" target="_blank">${item.adText}</a>`;
}
window.fineAd.adMargin({ adId:adId, bottom:bottom });
}
});
// 找第二个广告位
if(adId2 && !isAdId){
res.data.forEach((item) => {
if(item.adId === adId2){
console.log('isAdId',isAdId);
let getSize = splitPicSize(item.picSize);
if(debug){
console.group("advertisement " + adId2);
console.log('item',item);
console.log('picSize',getSize);
console.log('top',top);
console.log('bottom',bottom);
console.groupEnd();
}
let adDomId = document.getElementById('AD-' + adId2);
adDomId.innerHTML='';
window.fineAd.adMargin({ adId:adId2, top:top });
// 有链接图片广告
if(item.adLink && item.type===1){
adDomId.innerHTML=`<a onClick="window.fineAd.advertisementHits('${adId2}');" href="${item.adLink}" target="_blank"><img width="${getSize.w}" height="${getSize.h}" src="${item.picUrl}"></a>`;
}
// 有链接文本广告
if(item.adLink && item.type===2){
adDomId.innerHTML=`<a onClick="window.fineAd.advertisementHits('${adId2}');" href="${item.adLink}" target="_blank">${item.adText}</a>`;
}
window.fineAd.adMargin({ adId:adId2, bottom:bottom });
}
});
}
})
.catch(function (error) {
console.log('ad error',error);
});
};
/**
* 广告边距
* @param top 顶边距
* @param bottom 底边距
*/
const adMargin = ({ adId, top = 0, bottom = 0 }) => {
let adDomId = document.getElementById('AD-' + adId);
if(top > 0){
adDomId.innerHTML+=`<div style="height:${top}px;"></div>`;
}else if(bottom > 0){
adDomId.innerHTML+=`<div style="height:${bottom}px;"></div>`;
}
}
/**
* 拆分广告位尺寸
* @param adSize 广告位尺寸
* @return Array[w,h] 宽和高
*/
const splitPicSize = (adSize) =>{
let {w,h} = {w:'',h:''};
if(adSize){
let {[0]:w,[1]:h} = adSize.replace(/\s/g,"").split('*');
return {w,h};
}else{
return {w,h};
}
}
/**
* 广告位埋点
* @param adId 广告位id
*/
const advertisementHits = (adId) =>{
const { adApiUrl } = fineAd.options;
axios.get(adApiUrl + "/api/advertisement/hits/" + adId);
}
fineAd.config = config;
fineAd.adMargin = adMargin;
fineAd.getAdvertisement = getAdvertisement;
fineAd.advertisementHits = advertisementHits;

19
src/views/studypath/finebi.vue

@ -216,11 +216,7 @@
</div> </div>
</el-scrollbar> </el-scrollbar>
<div style="display:float;width: 100%;height:80px;overflow: hidden;margin:20px 0;" class="m-dn" v-if="is_ad"> <div id="AD-83346c28538542f6b678220a47e6fee3" class="m-dn"></div>
<a :href="ad_clickurl" target="_blank">
<img :src="ad_imgurl" alt="BI学习路径banner" />
</a>
</div>
</div> </div>
</div> </div>
@ -807,7 +803,6 @@
import { reactive, toRefs } from "vue"; import { reactive, toRefs } from "vue";
import { studentCount } from "@/api/guide"; import { studentCount } from "@/api/guide";
import { getCourseNum } from "@/api/study"; import { getCourseNum } from "@/api/study";
import { adurl } from "@/api/ad";
import downMenu from "@/views/studypath/downMenu"; import downMenu from "@/views/studypath/downMenu";
import pathMenu from "@/views/studypath/pathMenu"; import pathMenu from "@/views/studypath/pathMenu";
export default { export default {
@ -860,17 +855,7 @@ export default {
resgetNode(); resgetNode();
// 广 // 广
const adgetNode = async () => { window.fineAd.getAdvertisement({ adId: "83346c28538542f6b678220a47e6fee3", top: 24 });
const res = await adurl(31);
if (res.code === 200) {
if (res.data.img_url != null) {
state.ad_imgurl = res.data.img_url;
state.ad_clickurl = res.data.click_url;
state.is_ad = true;
}
}
};
adgetNode();
// //
const resCourseNum = async (pid, tmp) => { const resCourseNum = async (pid, tmp) => {

21
src/views/studypath/finereportStudyPath2023.vue

@ -198,12 +198,7 @@
</div> </div>
</div> </div>
</el-scrollbar> </el-scrollbar>
<div id="AD-bfb30c067e5e449aac8ea667205fcfc3" class="m-dn"></div>
<div style="display:float;width: 100%;height:80px;overflow: hidden;margin:20px 0;" class="m-dn" v-if="is_ad">
<a :href="ad_clickurl" target="_blank">
<img :src="ad_imgurl" alt="FR学习路径banner" />
</a>
</div>
</div> </div>
</div> </div>
@ -654,7 +649,6 @@
<script> <script>
import { reactive, toRefs } from "vue"; import { reactive, toRefs } from "vue";
import { getCourseNum } from "@/api/study"; import { getCourseNum } from "@/api/study";
import { adurl } from "@/api/ad";
import downMenu from "@/views/studypath/downMenu"; import downMenu from "@/views/studypath/downMenu";
import { scrollToElementAnchor } from "@/utils/scrollTo"; import { scrollToElementAnchor } from "@/utils/scrollTo";
import pathMenu from "@/views/studypath/pathMenu"; import pathMenu from "@/views/studypath/pathMenu";
@ -691,18 +685,7 @@ export default {
cate_list: [], cate_list: [],
}); });
// 广 window.fineAd.getAdvertisement({ adId: "bfb30c067e5e449aac8ea667205fcfc3", top: 24 });
const adgetNode = async () => {
const res = await adurl(30);
if (res.code === 200) {
if (res.data.img_url != null) {
state.ad_imgurl = res.data.img_url;
state.ad_clickurl = res.data.click_url;
state.is_ad = true;
}
}
};
adgetNode();
// //
const resCourseNum = async () => { const resCourseNum = async () => {

19
src/views/studypath/jiandaoyun.vue

@ -203,11 +203,7 @@
</div> </div>
</el-scrollbar> </el-scrollbar>
<div style="display:float;width: 100%;height:80px;overflow: hidden;margin:20px 0;" class="m-dn" v-if="is_ad"> <div id="AD-ec2bf821df994fa5aa3cc950377a812e" class="m-dn"></div>
<a :href="ad_clickurl" target="_blank">
<img :src="ad_imgurl" alt="简道云学习路径banner" />
</a>
</div>
</div> </div>
</div> </div>
@ -679,7 +675,6 @@
import { reactive, toRefs } from "vue"; import { reactive, toRefs } from "vue";
import { studentCount } from "@/api/guide"; import { studentCount } from "@/api/guide";
import { getCourseNum } from "@/api/study"; import { getCourseNum } from "@/api/study";
import { adurl } from "@/api/ad";
import downMenu from "@/views/studypath/downMenu"; import downMenu from "@/views/studypath/downMenu";
import pathMenu from "@/views/studypath/pathMenu"; import pathMenu from "@/views/studypath/pathMenu";
export default { export default {
@ -726,17 +721,7 @@ export default {
resgetNode(); resgetNode();
// 广 // 广
const adgetNode = async () => { window.fineAd.getAdvertisement({ adId: "ec2bf821df994fa5aa3cc950377a812e", top: 24 });
const res = await adurl(32);
if (res.code === 200) {
if (res.data.img_url != null) {
state.ad_imgurl = res.data.img_url;
state.ad_clickurl = res.data.click_url;
state.is_ad = true;
}
}
};
adgetNode();
// //
const resCourseNum = async () => { const resCourseNum = async () => {

3
src/views/video/indexVideo.vue

@ -294,12 +294,11 @@
{ id: 6, name: "300元以上" }, { id: 6, name: "300元以上" },
], ],
sortList: [ sortList: [
{ id: 0, name: "默认排序", label: "按课程id从高到低", icon: "" }, { id: 0, name: "最近更新", label: "发布时间倒序", icon: "" },
{ id: 1, name: "学习人数", label: "学习人数从高到底", icon: "el-icon-caret-bottom" }, { id: 1, name: "学习人数", label: "学习人数从高到底", icon: "el-icon-caret-bottom" },
{ id: 2, name: "销量", label: "销量从高到低", icon: "el-icon-caret-bottom" }, { id: 2, name: "销量", label: "销量从高到低", icon: "el-icon-caret-bottom" },
{ id: 3, name: "价格", label: "价格从高到低", icon: "el-icon-caret-bottom" }, { id: 3, name: "价格", label: "价格从高到低", icon: "el-icon-caret-bottom" },
{ id: 4, name: "价格", label: "价格从低到高", icon: "el-icon-caret-top" }, { id: 4, name: "价格", label: "价格从低到高", icon: "el-icon-caret-top" },
{ id: 5, name: "更新时间", label: "发布日期倒序", icon: "el-icon-caret-bottom" },
], ],
priceRangeList: [], priceRangeList: [],
videoList: [], videoList: [],

Loading…
Cancel
Save