抖音小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

795 lines
22 KiB

<template>
3 years ago
<view>
<view class="imgDetail">
<image class="main-img" :src="detailMsg.imgUrl" mode="widthFix"></image>
</view>
<view class="toolbar" v-if="detailMsg.imgUrl">
<view class="toolbar-box">
<uni-icons v-if="detailMsg.isHot ==='0'" class="tool-bar-icon" custom-prefix="iconfont" :type="'icon-hot'" size="24" ></uni-icons>
<uni-icons v-else class="tool-bar-icon" custom-prefix="iconfont" :type="'icon-hot'" size="24" :color="likeColor"></uni-icons>
</view>
3 years ago
<view class="toolbar-box" @click="$noMultipleClicks(authDownload,detailMsg.imgUrl)">
3 years ago
<uni-icons v-if="isDownload" class="tool-bar-icon" custom-prefix="iconfont" :type="'icon-xiazai'" size="24" ></uni-icons>
<uni-icons v-else class="tool-bar-icon" custom-prefix="iconfont" :type="'icon-xiazai'" size="24" ></uni-icons>
<text>下载</text>
</view>
3 years ago
<view class="toolbar-box" @click="$noMultipleClicks(likeCollect,'isLike')">
3 years ago
<uni-icons v-if="isLike" class="tool-bar-icon" custom-prefix="iconfont" :type="'icon-yixihuan'" size="24" :color="likeColor"></uni-icons>
<uni-icons v-else class="tool-bar-icon" custom-prefix="iconfont" :type="'icon-weixihuan'" size="24" ></uni-icons>
<text>喜欢</text>
</view>
3 years ago
<view class="toolbar-box" @click="$noMultipleClicks(likeCollect,'isCollect')">
3 years ago
<uni-icons v-if="isCollect" class="tool-bar-icon" custom-prefix="iconfont" :type="'icon-yishoucang'" size="24" :color="collectColor"></uni-icons>
<uni-icons v-else class="tool-bar-icon" custom-prefix="iconfont" :type="'icon-weishoucang'" size="24" ></uni-icons>
<text>收藏</text>
</view>
<view class="toolbar-box share-box">
<button open-type="share">
<uni-icons class="tool-bar-icon" custom-prefix="iconfont" :type="'icon-fenxiang1'" size="24" ></uni-icons>
<text>分享</text>
</button>
</view>
</view>
</view>
</template>
<script>
let isplayOver = false;
let timer = 0;
let Timer = null;
let stayTime = 0;
let isOverTask = false
import {
detailsTiktokImg, // 获取图片详情
judgeTiktokLike, // 查询是否点赞过
judgeTiktokCollect, // 查询是否收藏过
tiktokLike, // 点赞
tiktokUnLike, // 取消点赞
tiktokCollect, // 收藏
tiktokUnCollect, // 取消收藏
queryCreatorScanCodeById, //获取艺术家搜索码
insertOrUpdatePreAdProfit, //新增/更新艺术家即将入账广告收益
insertOrUpdatePreInviteProfit, // 新增/更新艺术家即将入账邀请收益
checkUserCanDownload// 检查某平台用户当日下载次数是否超标
} from '@/api/creator.js'
3 years ago
import {loginTiktok} from '@/api/auth.js'
import tiktokAd from '@/utils/tiktokAd.js'
export default {
data() {
return {
detailMsg: {}, // 图片信息
3 years ago
userInfo: undefined, // 登录用户信息
isDownload: false, // 是否已下载
isLike: false, // 是否点赞/喜欢
isCollect: false, // 是否收藏,
scanCode: undefined, //艺术家搜索码
3 years ago
noClick:true, //防止重复提交
3 years ago
artist: {},
3 years ago
canDownload: false, //能否下载 false为能下载
3 years ago
whiteColor: '#FFFFFF',
primaryColor: '#1a94bc',
likeColor: '#ef223c',
collectColor: '#dcaa04',
urlParamId: undefined,
htime: 0, //广告点击
mintime: 999999999, //最短持续时间
taskhide: false,
starttask: false,
done: false,
adList:['0qfnoa4053uwkefbas','2v63zq5hvfclpxmurl','d4ltbnxa23zp2hhqwe'] //激励视频广告列表
3 years ago
}
},
onLoad(option){
if (option?.id) {
this.urlParamId = option.id;
}
isOverTask = false;
//随机选择一个激励视频广告初始化
let num = Math.floor(Math.random() * this.adList.length + 1)-1;
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: 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
}
})
}
}
}
},
created() {
const detailId = uni.getStorageSync('detailId')
if (detailId) {
this.getImgDetail(detailId)
} else {
3 years ago
//可能是路径参数
3 years ago
this.urlParamId && this.getImgDetail(this.urlParamId);
}
},
onShareAppMessage(res) {
let that = this;
if (res.from === 'button') { // 来自页面内分享按钮
console.log(res)
}
return {
title: '来看看艺术家[' + that.scanCode + ']精心准备的图片吧~',
path: `/pages/creator/imgDetail?id=${that.detailMsg.id}`,
3 years ago
bgImgUrl: `${that.detailMsg.imgUrl}`,
success() {
uni.showToast({
title: '分享成功',
icon: 'none',
})
}
}
},
methods: {
onUnload() {
//清除定时器
clearInterval(Timer)
},
//开启激励视频广告停留计时器
statTimer() {
Timer = setInterval(() => {
timer++;
if (timer >= 16) {
isplayOver = true;
clearInterval(Timer)
}
}, 1000)
},
//加载激励视频广告
loadAdvertise(e){
// 在页面中定义激励视频广告
let videoAd = null
var that = this
// 在页面onLoad回调事件中创建激励视频广告实例
if (tt.createRewardedVideoAd) {
videoAd = tt.createRewardedVideoAd({
adUnitId: e
})
this.videoAd = videoAd
videoAd.onLoad(() => {
console.log('激励视频广告'+e+'加载成功')
})
videoAd.onError((err) => {
that.err()
})
videoAd.onClose((res) => {
if (res && res.isEnded) {
// 正常播放结束,可以下发游戏奖励
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)
}
}
} else {
timer = 0;
isplayOver = false;
wx.showToast({
title: '您还没有看完视频,无法获取奖励',
icon: 'none'
})
this.done = false;
this.starttask = false;
}
})
}
},
//展示激励视频广告
showAdvertise(){
let videoAd = this.videoAd
this.statTimer()
videoAd.show().catch(() => {
// 失败重试
videoAd.load()
.then(() => videoAd.show())
.catch(err => {
uni.showModal({
title: '图片下载失败',
content: '请稍后重试',
showCancel: false,
complete: function() {
that.done = true;
that.starttask = true;
// that.cuowu = true;
}
})
})
})
},
// 图片详情
async getImgDetail(id) {
const res = await detailsTiktokImg(id)
if (res.data.code === 200) {
3 years ago
if (!res.data?.data){
3 years ago
uni.showToast({
title: '获取图片信息失败',
icon: 'none'
})
}
this.detailMsg = res.data.data
const result = await queryCreatorScanCodeById(this.detailMsg.creatorId)
if (result.data.code === 200) {
3 years ago
this.artist = result.data.data;
this.scanCode = result.data.data.scanCode
} else {
uni.showToast({
title: '该艺术家不存在!',
icon: 'none'
})
}
uni.getStorage({
key: 'userInfo',
success: res => {
this.userInfo = res.data
this.searchIsLike()
this.searchisCollect()
this.checkUserDownload()
}
})
} else {
uni.showToast({
title: '请输入艺术家代号',
icon: 'none'
})
}
},
// 查询是否点赞
3 years ago
async searchIsLike(token) {
const params = {
imgId: this.detailMsg.id,
userId: this.userInfo.id
}
3 years ago
const res = await judgeTiktokLike(params,token)
if (res.data.code === 200) {
this.isLike = res.data.data
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
},
// 查询是否收藏过
3 years ago
async searchisCollect(token) {
const params = {
imgId: this.detailMsg.id,
userId: this.userInfo.id
}
3 years ago
const res = await judgeTiktokCollect(params,token)
if (res.data.code === 200) {
this.isCollect = res.data.data
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
},
3 years ago
async lickRequest() {
const params = {
imgId: this.detailMsg.id,
userId: this.userInfo.id
}
let isLike = this.isLike
if (!isLike) {
//点赞
const res = await tiktokLike(params)
if (res.data.code === 200) {
this.isLike = !isLike
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
} else {
//取消点赞
const res = await tiktokUnLike(params)
if (res.data.code === 200) {
this.isLike = !isLike
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
}
},
async collectRequest() {
3 years ago
const params = {
imgId: this.detailMsg.id,
userId: this.userInfo.id
}
let isCollect = this.isCollect
if (!isCollect) {
//收藏
3 years ago
const res = await tiktokCollect(params)
3 years ago
if (res.data.code === 200) {
this.isCollect = !isCollect
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
} else {
//取消收藏
3 years ago
const res = await tiktokUnCollect(params)
3 years ago
if (res.data.code === 200) {
this.isCollect = !isCollect
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
}
},
3 years ago
async lickOrCollect(val) {
3 years ago
if (val === 'isLike') {
3 years ago
await this.lickRequest();
3 years ago
} else if (val === 'isCollect') {
3 years ago
await this.collectRequest();
3 years ago
}
},
// 点赞/收藏
3 years ago
likeCollect(val) {
if (!this.userInfo) {
3 years ago
this.getUserInfoLogin(res => {
succ
this.lickOrCollect(val)
3 years ago
})
} else {
this.lickOrCollect(val)
}
},
async loginFunc(res, userInfo, callBack) {
const params = {
code: res.code,
encryptedData: userInfo.encryptedData,
iv: userInfo.iv
}
// 用户授权登录
await loginTiktok(params).then(res => {
if (res.data.code === 200) {
uni.setStorage({
key: 'userInfo',
data: res.data.data.userInfo,
})
this.userInfo = res.data.data.userInfo;
3 years ago
console.log('this.userInfo',this.userInfo)
3 years ago
uni.setStorage({
key: 'token',
data: res.data.data.access_token
})
3 years ago
let headers = {
TiktokAuthorization: res.data.data.access_token
}
this.checkUserDownload(headers)
callBack && callBack(headers)
this.searchIsLike(headers)
this.searchisCollect(headers)
3 years ago
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
}).catch(res => {})
},
// 获取用户信息
async getUserInfoLogin(callBack) {
uni.getSetting({
success: (settingObj) => {
if (settingObj.authSetting['scope.userInfo'] === undefined || settingObj.authSetting['scope.userInfo']) {
uni.login({
force: true,
success: (res) => {
uni.getUserInfo({
withCredentials: true,
success: async (userInfo) => {
await this.loginFunc(res, userInfo, callBack)
},
})
},
})
} else {
uni.showModal({
title: '您已拒绝授权用户信息',
content: '是否进入权限管理,调整授权?',
success: function (res) {
if (res.confirm) {
uni.openSetting({
success: (settingRes) => {
if (settingRes.authSetting['scope.userInfo']) {
uni.login({
force: true,
success: (res) => {
uni.getUserInfo({
withCredentials: true,
success: async (userInfo) => {
await this.loginFunc(res, userInfo, callBack)
},
})
},
})
}
},
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
}
})
},
//写入图片广告收益
3 years ago
async insertPreAdProfit() {
let that = this;
const params = {
imgId: that.detailMsg.id,
creatorId: that.detailMsg.creatorId,
scanCode: that.scanCode,
userId: that.userInfo.id,
appType: '0',
platform: '0'
}
3 years ago
const res = await insertOrUpdatePreAdProfit(params);
if (res.data.code === 200) {
console.log("写入广告收益成功!")
that.adResult = res.data.code;
} else {
uni.showToast({
title: '图片下载失败!',
icon: 'none'
})
}
},
//写入图片邀请收益
3 years ago
async insertPreInviteProfit() {
let that = this;
const params = {
imgId: that.detailMsg.id,
creatorId: that.detailMsg.creatorId,
scanCode: that.scanCode,
appType: '0',
platform: '0'
}
3 years ago
const res = await insertOrUpdatePreInviteProfit(params)
if (res.data.code === 200) {
3 years ago
// console.log("写入邀请收益成功");
that.inviteResult = res.data.code;
} else {
uni.showToast({
title: '图片下载失败!',
icon: 'none'
})
}
},
//检查某平台用户当日下载次数是否超标
3 years ago
async checkUserDownload(token) {
const params = {
userId: this.userInfo.id,
appType: '0',
platform: '0'
}
3 years ago
const res = await checkUserCanDownload(params,token);
if (res.data.code === 200) {
console.log("当日下载结果为", res.data.data)
this.canDownload = res.data.data;
} else {
uni.showToast({
title: '检查下载状态失败!',
icon: 'none'
})
}
},
authDownload(url) {
3 years ago
if (!this.userInfo) {
3 years ago
this.getUserInfoLogin(() => {
this.download(url)
3 years ago
})
} else {
this.download(url)
}
},
// 下载
download(url) {
let that = this;
3 years ago
if (that.canDownload !== true) {
//满足可下载条件
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) => {
3 years ago
// },
// });
// } 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) => {},
// });
} else {
//不满足可下载条件 canDownload为true状态
uni.showToast({
title: '当日下载次数已用完,请明日再来!',
icon: 'none'
})
}
},
// 分享
share() {
uni.showToast({
title: '分享',
icon: 'none'
})
},
}
}
</script>
3 years ago
<style lang="scss">
.imgDetail {
height: 100vh;
width: 100vw;
3 years ago
overflow: auto;
position: relative;
3 years ago
display: flex;
align-items: center;
justify-content: center;
.main-img {
width: 100%;
height: 100%;
3 years ago
box-shadow: 2rpx 4rpx 8rpx rgba(0, 0, 0, 0.25);
}
3 years ago
}
3 years ago
.toolbar {
width: 60px;
background-color: rgba(248, 248, 248, 0.5);
/* 模糊大小就是靠的blur这个函数中的数值大小 */
backdrop-filter: blur(4rpx);
position: fixed;
bottom: 120rpx;
right: 40rpx;
border-radius: 60px;
padding-top: 40rpx;
box-shadow: 2rpx 4rpx 8rpx rgba(0, 0, 0, 0.25);
3 years ago
.share-box {
3 years ago
>button {
line-height: 0 !important;
padding: 0;
outline: none;
background: none;
border: none;
3 years ago
}
3 years ago
>button::after {
border: none;
}
}
3 years ago
.toolbar-box {
height: 60px;
text-align: center;
margin-bottom: 40rpx;
3 years ago
text {
display: block;
text-align: center;
line-height: 60rpx;
font-size: 12px;
}
3 years ago
image {
width: 50rpx;
height: 50rpx;
margin: 0 auto;
}
}
3 years ago
.toolbar-box:first-child {
line-height: 40rpx;
height: 40rpx;
}
3 years ago
}
</style>