Browse Source

添加首页广告

master
caichunsheng 4 years ago
parent
commit
ae5b6c843a
  1. 242
      pages/index/index.js
  2. 31
      pages/index/index.wxml
  3. 53
      pages/index/index.wxss

242
pages/index/index.js

@ -33,14 +33,45 @@ Page({
otherPlat: null,
activeBannerIndex: 0,
smBannerIndex: 0,
indexSeason: {}
indexSeason: {},
startList: [], // 启动页广告
alertSwipeList: [], //弹窗广告
showAdv: false, //弹窗开关
showFullAdv: true, //全屏广告开关
time: 5 //全屏广告剩余时间
},
onLoad: function (options) {
//全屏广告
wx.hideTabBar() //这里隐藏了底部导航栏
commonApi._post("adv/getAdv", {
position: 2,
type_id: 5
}).then(res => {
if (res.data.length > 0) {
let timer = setInterval(() => {
this.setData({
time: this.data.time - 1
})
if (this.data.time == 0) {
timer = null
this.setData({
showFullAdv: false
})
if (!this.data.alertSwipeList>0)
wx.showTabBar() //倒计时结束清楚定时器显示导航栏
}
}, 1000)
this.setData({
startList: res.data || []
})
}
})
if (options.from) {
app.globalData.from = options.from;
}
let systemInfo = wx.getSystemInfoSync(), rect = wx.getMenuButtonBoundingClientRect();
let systemInfo = wx.getSystemInfoSync(),
rect = wx.getMenuButtonBoundingClientRect();
let height = (rect.top - systemInfo.statusBarHeight) * 2 + rect.height;
wx.getLocation({
type: 'gcj02',
@ -147,6 +178,39 @@ Page({
xiaobanner: res.data || []
})
})
//弹窗广告
commonApi._post("adv/getAdv", {
position: 3,
type_id: 5
}).then(res => {
if (res.data.length > 0) {
this.setData({
alertSwipeList: res.data || [],
showAdv: true
})
}
})
},
//关闭弹窗广告
closeAdv: function () {
this.setData({
showAdv: false
})
wx.showTabBar({
animation: true,
})
},
//关闭全屏广告
closeFullAdv:function(){
this.setData({
showFullAdv:false
})
if (!this.data.alertSwipeList.length>0) {
wx.showTabBar({
animation: true,
})
}
},
getWeather: function () {
commonApi._post('pbservice/Ztfw/getWeather').then(res => {
@ -156,8 +220,7 @@ Page({
})
})
},
saleDetail: function () {
},
saleDetail: function () {},
getTwoProduct: function () {
// 获取首页限时特惠
commonApi._post('act/fast_sale_now', {
@ -209,17 +272,18 @@ Page({
})
},
getFourProduct: function () {
let item = this.data.indexHot[this.data.hotIndex], service = "product/get_product_by_tag", data = {
tag_id: item.id,
offset: 0,
limit: 4,
sort: 'weight',
order: 'desc'
};
let item = this.data.indexHot[this.data.hotIndex],
service = "product/get_product_by_tag",
data = {
tag_id: item.id,
offset: 0,
limit: 4,
sort: 'weight',
order: 'desc'
};
if (item.type == 'scene') {
service = "scene/get_scene_by_tag";
}
else if (item.type == 'movie') {
} else if (item.type == 'movie') {
service = "Cinema/getHotMovieList";
data = {
page: 1,
@ -238,8 +302,7 @@ Page({
wx.navigateTo({
url: '/pages/list/movieticket/list/info/index?id=' + item.third_id + '&title=' + item.title,
})
}
else {
} else {
util.gotoDetail(item)
}
},
@ -248,9 +311,11 @@ Page({
util.gotoDetail(item)
},
gotoPath: function (e) {
console.log(e)
console.log(e)
if (e.currentTarget.dataset.event) {
this.pagePoint({ event: e.currentTarget.dataset.event }, 1)
this.pagePoint({
event: e.currentTarget.dataset.event
}, 1)
}
if (e.currentTarget.dataset.title == '书香借阅') {
wx.navigateToMiniProgram({
@ -258,7 +323,7 @@ Page({
path: 'pages/home/home'
})
return;
}else if (e.currentTarget.dataset.title == '12348') {
} else if (e.currentTarget.dataset.title == '12348') {
wx.navigateToMiniProgram({
appId: 'wxcdfd45c001466ba3',
path: 'pages/index/index'
@ -280,7 +345,9 @@ Page({
},
gotoUrl: function (e) {
if (e.currentTarget.dataset.event) {
this.pagePoint({ event: e.currentTarget.dataset.event }, 1)
this.pagePoint({
event: e.currentTarget.dataset.event
}, 1)
}
let url = e.currentTarget.dataset.url;
app.globalData.weburl = url;
@ -289,7 +356,8 @@ Page({
})
},
gotoMini: function (e) {
let appid = e.currentTarget.dataset.appid, path = e.currentTarget.dataset.path
let appid = e.currentTarget.dataset.appid,
path = e.currentTarget.dataset.path
wx.navigateToMiniProgram({
appId: appid,
path: path
@ -334,8 +402,7 @@ Page({
res.data.map(item => {
if (item.ext.display_tags) {
item.ext.display_tags = item.ext.display_tags.split(",").splice(0, 2)
}
else {
} else {
item.ext.display_tags = []
}
})
@ -366,8 +433,7 @@ Page({
wx.navigateTo({
url: '/pages/info/strategyInfo/index?id=' + item.s_id,
})
}
else {
} else {
util.gotoDetail(item.ext);
}
},
@ -407,24 +473,22 @@ Page({
wx.navigateTo({
url: "/pages/pbService/web/index"
})
}
else {
} else {
let page = item.tdata.split("/");
page = page[page.length - 1].split("?")
console.log(page[0])
let url = this.data.urltopage[page[0]];
if (url && url.indexOf('map') != -1) {
let types = ['', 'scenic', 'venue', 'post', 'restaurant', 'relic', 'tenscenic', 'cinema', 'academes'], type = page[1] ? page[1].split("=") : [];
let types = ['', 'scenic', 'venue', 'post', 'restaurant', 'relic', 'tenscenic', 'cinema', 'academes'],
type = page[1] ? page[1].split("=") : [];
wx.reLaunch({
url: url + "?type=" + (type[1] ? types.findIndex(t => t == type[1]) : null)
})
}
else if (url) {
} else if (url) {
wx.navigateTo({
url: url,
})
}
else {
} else {
app.globalData.weburl = item.tdata;
wx.navigateTo({
url: "/pages/pbService/web/index"
@ -439,8 +503,7 @@ Page({
let weburl = item.tdata.page
if (weburl.indexOf('?') != -1) {
weburl += '&authCode=' + res.data;
}
else {
} else {
weburl += '?authCode=' + res.data
}
wx.navigateToMiniProgram({
@ -453,8 +516,7 @@ Page({
path: item.tdata.page
})
})
}
else {
} else {
wx.navigateToMiniProgram({
appId: item.tdata.appid,
path: item.tdata.page
@ -476,19 +538,16 @@ Page({
appId: info[0],
path: info[1]
})
}
else if (item.href.indexOf('map/index') != -1) {
} else if (item.href.indexOf('map/index') != -1) {
wx.reLaunch({
url: item.href
})
}
else {
} else {
wx.navigateTo({
url: item.href,
})
}
}
else if (item.action == "web") {
} else if (item.action == "web") {
app.globalData.weburl = item.href;
wx.navigateTo({
url: "/pages/pbService/web/index",
@ -541,6 +600,92 @@ Page({
}
})
},
bannerJumpNew(item) {
let that = this
item = item.currentTarget.dataset.item
console.log(item);
if (item.tdata == '') return
that.pagePoint({
event: "banner_click",
type: 'banner'
}, 1)
switch (item.jump_type) {
case 0:
break;
case 1:
util.gotoDetail(item.product_model)
break;
case 2:
if (item.front_model && item.front_model.mini) {
wx.navigateTo({
url: "/" + item.front_model.mini
})
}
break;
case 3:
if ((item.tdata.indexOf('http://') != -1 || item.tdata.indexOf('https://') != -1) && item.tdata.indexOf('m.cloud.sz-trip.com') == -1) {
// 外部h5
console.log(item.tdata)
app.globalData.weburl = item.tdata;
wx.navigateTo({
url: "/pages/pbService/web/index"
})
} else {
let page = item.tdata.split("/");
page = page[page.length - 1].split("?")
console.log(page[0])
let url = this.data.urltopage[page[0]];
if (url && url.indexOf('map') != -1) {
let types = ['', 'scenic', 'venue', 'post', 'restaurant', 'relic', 'tenscenic', 'cinema', 'academes'],
type = page[1] ? page[1].split("=") : [];
wx.reLaunch({
url: url + "?type=" + (type[1] ? types.findIndex(t => t == type[1]) : null)
})
} else if (url) {
wx.navigateTo({
url: url,
})
} else {
app.globalData.weburl = item.tdata;
wx.navigateTo({
url: "/pages/pbService/web/index"
})
}
}
break;
case 4:
if (item.tdata.appid == 'wxe5ca0f71e918e352' && wx.getStorageSync('jstrip_userid')) {
// 如果是苏心游的小程序 直接把authCode带过去
userApi.user_post("user/getJumpThirdAppCode", {}).then(res => {
let weburl = item.tdata.page
if (weburl.indexOf('?') != -1) {
weburl += '&authCode=' + res.data;
} else {
weburl += '?authCode=' + res.data
}
wx.navigateToMiniProgram({
appId: item.tdata.appid,
path: weburl
})
}).catch(err => {
wx.navigateToMiniProgram({
appId: item.tdata.appid,
path: item.tdata.page
})
})
} else {
wx.navigateToMiniProgram({
appId: item.tdata.appid,
path: item.tdata.page
})
}
break;
default:
break;
}
return
},
onReady: function () {
if (app.globalData.configJson) {
this.setData({
@ -551,8 +696,7 @@ Page({
})
console.log(app.globalData.configJson)
this.getFourProduct()
}
else {
} else {
setTimeout(() => {
this.onReady()
}, 300)
@ -565,14 +709,12 @@ Page({
wx.navigateTo({
url: "/pages/pbService/web/index"
})
}
else if (item.type == 'mini') {
} else if (item.type == 'mini') {
wx.navigateToMiniProgram({
appId: item.appid,
path: item.path
})
}
else if (item.type == 'page') {
} else if (item.type == 'page') {
wx.navigateTo({
url: item.page,
})
@ -582,7 +724,9 @@ Page({
util.pagePoint(e, type)
},
onShow: function () {
this.pagePoint({ event: 'home_view' }, 1)
this.pagePoint({
event: 'home_view'
}, 1)
},
/**
@ -591,4 +735,4 @@ Page({
onShareAppMessage: function () {
}
})
})

31
pages/index/index.wxml

@ -20,7 +20,7 @@
<view class="textOver">搜索想要的旅游产品或服务</view>
</navigator>
</view>
<view style="position:relative">
<view style="position:relative" >
<swiper class="swiper" autoplay="{{true}}" interval="{{5000}}" duration="{{300}}" bindchange="changeBannerIndex">
<block wx:for="{{banner}}" wx:key="*this">
<swiper-item bindtap="bannerClick" data-item="{{item}}">
@ -197,8 +197,8 @@
</view>
<view bindtap="gotoUrl" data-event="book_click" data-title="文博会" data-url="https://yscbh.sz-trip.com/"
class="pbservice-item">
<image src="https://static.ticket.sz-trip.com/uploads/20220806/c544e31e5c9c910292450b2c349ae6e2.png" mode="widthFix"></image>
<view>文博会</view>
<image src="https://static.ticket.sz-trip.com/uploads/20220810/ceb07b75aa3df20d7f1de22e2588332a.png" mode="widthFix"></image>
<view>云上文博会</view>
</view>
<view bindtap="gotoUrl" data-event="cloud_click" data-title="云上观展"
data-url="https://m.cloud.sz-trip.com/CloudPerform2022" class="pbservice-item">
@ -411,4 +411,27 @@
<image bindtap="closePrice" style="width:80rpx;margin-top:40rpx"
src="https://sz-qd.oss-cn-hangzhou.aliyuncs.com/xcxImages/videoprize/allclose.png" mode="widthFix"></image>
</view>
</view>
</view>
<!-- 广告弹窗 -->
<view class="zzc" bindtap="closeAdv" wx:if="{{showAdv}}" ></view>
<view class="alertavd" wx:if="{{showAdv}}">
<swiper class="alertsp" indicator-dots='{{true}}' indicator-color="rgba(255,255,255,0.5)" autoplay="{{true}}" interval="{{3000}}" duration="{{300}}" indicator-active-color="white">
<block wx:for="{{alertSwipeList}}" wx:key="*this">
<swiper-item data-item="{{item}}" bindtap="bannerJumpNew" >
<image src="{{item.head_img}}" style="width: 100%;height: 100%;" mode="widthFix"></image>
</swiper-item>
</block>
</swiper>
<image bindtap="closeAdv" style="width: 100rpx; height: 100rpx;transform: translate(200rpx,6rpx);" src="https://static.ticket.sz-trip.com/uploads/20220810/f4bb1a4f0b5eb394e6ca6e4f03aaa1e0.png"></image>
</view>
<!-- 广告弹窗结束 -->
<view class="fullavd" wx:if="{{showFullAdv}}">
<view class="time" bindtap="closeFullAdv">跳过 {{time}}</view>
<swiper class="fullsp" autoplay="{{true}}" interval="{{3000}}" duration="{{300}}" indicator-active-color="white">
<block wx:for="{{startList}}" wx:key="*this">
<swiper-item data-item="{{item}}" bindtap="bannerJumpNew" >
<image src="{{item.head_img}}" style="width: 100%;height: 100%;" mode="widthFix"></image>
</swiper-item>
</block>
</swiper>
</view>

53
pages/index/index.wxss

@ -669,4 +669,57 @@
width: 20rpx;
height: 7rpx;
border-radius: 3rpx;
}
/* 弹窗广告 */
.zzc{
background: gray;
position: fixed;
left: 0px;
top: 0px;
width:100%;
height: 100%;
z-index: 998;
filter: alpha(opacity=80);
opacity: 0.8 !important;
}
.alertavd{
width: 500rpx;
height: 500rpx;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-250rpx,-150rpx);
z-index: 999;
}
.alertsp{
width: 100%;
height: 100%;
z-index: 1000;
}
.fullavd{
position: fixed;
left: 0px;
top: 0px;
width:100%;
height: 100%;
z-index: 1001;
background-color: #fff;
}
.fullsp{
width: 100%;
height: 100%;
}
.time{
width: 150rpx;
height: 60rpx;
background-color: #999999;
color: #fff;
position: absolute;
right: 20rpx;
top: 200rpx;
border-radius:6rpx ;
text-align: center;
line-height: 60rpx;
z-index: 1002;
}
Loading…
Cancel
Save