Browse Source

feature:新增流量主代码

feature-1.0
Penny 3 years ago
parent
commit
6354387f62
  1. 426
      pages/creator/imgDetail.vue

426
pages/creator/imgDetail.vue

@ -34,11 +34,6 @@
</template>
<script>
let isplayOver = false;
let timer = 0;
let Timer = null;
let stayTime = 0;
let isOverTask = false
import {
detailsTiktokImg, //
judgeTiktokLike, //
@ -53,7 +48,7 @@
checkUserCanDownload//
} from '@/api/creator.js'
import {loginTiktok} from '@/api/auth.js'
import tiktokAd from '@/utils/tiktokAd.js'
// import tiktokAd from '@/utils/tiktokAd.js'
export default {
data() {
return {
@ -71,11 +66,8 @@
likeColor: '#ef223c',
collectColor: '#dcaa04',
urlParamId: undefined,
htime: 0, //广
mintime: 999999999, //
taskhide: false,
starttask: false,
done: false,
isplayOver: false,
downloadUrl: undefined,
adList:['0qfnoa4053uwkefbas','2v63zq5hvfclpxmurl','d4ltbnxa23zp2hhqwe'] //广
}
},
@ -83,72 +75,19 @@
if (option?.id) {
this.urlParamId = option.id;
}
isOverTask = false;
this.isplayOver = false;
//广
let num = Math.floor(Math.random() * this.adList.length + 1)-1;
console.log('随机激励视频id为:',this.adList[num])
//console.log('id',this.adList[num])
//tiktokAd.rewarded.load(this.adList[num])
this.loadAdvertise(this.adList[num]);
},
onHide: function() {
var htime = Date.now()
this.taskhide = true
this.htime = htime
onShow() {
this.achieveSaveImg();
},
onShow: function() {
var that = this;
if (isOverTask) {
return
}
if (this.taskhide) {
var stime = Date.now()
var lasttime = stime - this.htime;
stayTime = lasttime
if (!isplayOver) {
uni.showModal({
title: '任务失败',
content: '广告未播放完成',
showCancel: false,
confirmText: '知道了'
})
return
}
if (lasttime < this.mintime && this.mintime > 0) {
uni.showModal({
title: '任务失败',
content: '广告停留时间需要大于' + this.mintime / 1000 + '秒',
showCancel: false,
confirmText: '知道了'
})
// that.setData({
// taskhide: false
// })
that.taskhide = false;
} else {
if (that.hudian > 0) {
this.done = true;
this.starttask = true;
isOverTask = true;
uni.showModal({
title: '任务完成',
content: '点击右上角关闭按钮',
showCancel: false,
confirmText: '知道了'
})
} else {
uni.showModal({
title: '任务完成',
content: '你已经完成此任务!!',
showCancel: false,
confirmText: '确定',
complete: function() {
this.done = true
this.starttask = true
}
})
}
}
}
onHide() {
//广
this.isplayOver = false;
},
created() {
const detailId = uni.getStorageSync('detailId')
@ -177,84 +116,46 @@
}
},
methods: {
onUnload() {
//
clearInterval(Timer)
},
//广
statTimer() {
Timer = setInterval(() => {
timer++;
if (timer >= 16) {
isplayOver = true;
clearInterval(Timer)
}
}, 1000)
},
//广
loadAdvertise(e){
loadAdvertise(adId){
// 广
let videoAd = null
var that = this
// onLoad广
if (tt.createRewardedVideoAd) {
videoAd = tt.createRewardedVideoAd({
adUnitId: e
adUnitId: adId
})
this.videoAd = videoAd
that.videoAd = videoAd
videoAd.onLoad(() => {
console.log('激励视频广告'+e+'加载成功')
console.log('激励视频广告'+adId+'加载成功')
})
videoAd.onError((err) => {
that.err()
})
videoAd.onClose((res) => {
if (res && res.isEnded) {
if (res && res.isEnded || res === undefined) {
//
if (that.htime == 0) {
wx.showModal({
title: '您没有点击广告',
content: '点击视频广告下方的按钮进入广告停留' + that.mintime / 1000 + '秒后关闭广告即可',
showCancel: false
})
} else {
if (stayTime < this.mintime && this.mintime > 0) {
wx.showModal({
title: '图片下载失败',
content: '广告停留时间需要大于' + this.mintime / 1000 + '秒',
showCancel: false,
confirmText: '知道了'
})
this.taskhide = true
} else {
if (isOverTask) {
//this.gotoAdPage()
console.log('广告点击观看完毕!')
}
this.starttask = true;
console.log('this.starttask ',this.starttask)
}
}
that.isplayOver = true;
console.log('激励视频广告观看完毕',isplayOver)
} else {
timer = 0;
isplayOver = false;
wx.showToast({
title: '您还没有看完视频,无法获取奖励',
that.isplayOver = false;
console.log('激励视频广告尚未看完',that.isplayOver)
uni.showToast({
title: '您还没有看完视频,无法下载图片',
icon: 'none'
})
this.done = false;
this.starttask = false;
}
})
}
},
//广
showAdvertise(){
showAdvertise(url){
let videoAd = this.videoAd
this.statTimer()
this.downloadUrl = url;
//console.log('广url',url);
//console.log('this.downloadUrl广',this.downloadUrl);
videoAd.show().catch(() => {
//
videoAd.load()
@ -265,9 +166,7 @@
content: '请稍后重试',
showCancel: false,
complete: function() {
that.done = true;
that.starttask = true;
// that.cuowu = true;
this.isplayOver = false;
}
})
})
@ -576,6 +475,161 @@
this.download(url)
}
},
//广
achieveSaveImg(){
let that = this;
console.log('广告状态',that.isplayOver)
if(that.isplayOver){
//广
let url = that.downloadUrl;
//console.log('that.downloadUrl广',that.downloadUrl);
//console.log('url广',url);
uni.showLoading({
title: '正在保存图片...',
success() {
//
uni.getSetting({
success(res){
//console.log('res',res)
//
if (!res.authSetting["scope.album"]) {
//
uni.authorize({
scope: "scope.album",
success: () => {
//
uni.downloadFile({
url,
success: (res) => {
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
//
filePath: res.tempFilePath,
success: (res) => {
},
fail: (res) => {
return uni.showToast({
title: res.errMsg,
icon: 'none'
});
},
complete: (res) => {
uni.hideLoading();
if (res.errMsg !== "saveImageToPhotosAlbum:ok") {
return uni.showToast({
title: "下载失败!",
icon: 'none'
});
} else {
return uni
.showToast({
title: "下载成功!",
icon: 'none',
success() {
//
that.insertPreAdProfit();
that.insertPreInviteProfit();
}
});
}
},
});
} else {
uni.showToast({
title: "下载失败!",
icon: 'none'
});
}
}
})
},
//
fail: () => {
uni.hideLoading();
uni.showModal({
title: "您已拒绝获取相册权限",
content: "是否进入权限管理,调整授权?",
success: (res) => {
if (res.confirm) {
//
uni.openSetting({
success: (res) => {
},
});
} else if (res.cancel) {
return uni.showToast({
title: "已取消!",
icon: 'none'
});
}
},
});
},
});
} else {
//
//console.log(',',url);
//
uni.downloadFile({
url,
success: (res) => {
console.log('进入图片下载',res);
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
//
filePath: res.tempFilePath,
success: (res) => {
console.log('保存图片状态',res);
},
fail: (res) => {
return uni.showToast({
title: res.errMsg,
icon: 'none'
});
},
complete: (res) => {
uni.hideLoading();
if (res.errMsg !== "saveImageToPhotosAlbum:ok") {
return uni.showToast({
title: "下载失败!",
icon: 'none'
});
} else {
return uni.showToast({
title: "下载成功!",
icon: 'none',
success() {
//
that.insertPreAdProfit();
that.insertPreInviteProfit();
that.isplayOver = false;
}
});
}
},
});
} else {
uni.showToast({
title: "下载失败!",
icon: 'none'
});
}
}
})
}
},
fail: (res) => {},
});
}
});
}else{
//广
//console.log('广')
}
},
//
download(url) {
let that = this;
@ -583,123 +637,7 @@
//
that.isDownload = true
//广
this.showAdvertise();
// const result = await tiktokAd.rewarded.show();
// console.log('',result)
// if(result.achieveStatus === true){
// console.log(':',result.achieveStatus)
// }
uni.showLoading({
title: '正在保存图片...'
});
console.log('test123')
//
// uni.getSetting({
// success: (res) => {
// //
// if (!res.authSetting["scope.writePhotosAlbum"]) {
// //
// uni.authorize({
// scope: "scope.album",
// success: () => {
// //
// uni.downloadFile({
// url,
// success: (res) => {
// if (res.statusCode === 200) {
// uni.saveImageToPhotosAlbum({
// //
// filePath: res.tempFilePath,
// success: (res) => {
// },
// fail: (res) => {
// return uni.showToast({
// title: res.errMsg,
// icon: 'none'
// });
// },
// complete: (res) => {
// uni.hideLoading();
// if (res.errMsg !== "saveImageToPhotosAlbum:ok") {
// return uni.showToast({
// title: "",
// icon: 'none'
// });
// } else {
// return uni
// .showToast({
// title: "",
// icon: 'none',
// success() {
// //
// that.insertPreAdProfit();
// that.insertPreInviteProfit();
// }
// });
// }
// },
// });
// } else {
// uni.showToast({
// title: "",
// icon: 'none'
// });
// }
// }
// })
// },
// //
// fail: () => {
// uni.hideLoading();
// uni.showModal({
// title: "",
// content: "",
// success: (res) => {
// if (res.confirm) {
// //
// uni.openSetting({
// success: (res) => {
// },
// });
// } else if (res.cancel) {
// return uni.showToast({
// title: "",
// icon: 'none'
// });
// }
// },
// });
// },
// });
// } else {
// //
// uni.saveImageToPhotosAlbum({
// filePath: url,
// success: (res) => {
// uni.hideLoading();
// return uni.showToast({
// title: "",
// icon: 'none'
// });
// },
// fail: (res) => {
// uni.hideLoading();
// return uni.showToast({
// title: res.errMsg,
// icon: 'none'
// });
// },
// //
// complete: (res) => {
// uni.hideLoading();
// },
// });
// }
// },
// fail: (res) => {},
// });
that.showAdvertise(url);
} else {
// canDownloadtrue
uni.showToast({

Loading…
Cancel
Save