Browse Source

feature-tiktok-1.0:fix bug

feature-1.0
chengkun 4 years ago
parent
commit
14f3f44568
  1. 9
      api/creator.js
  2. 2
      pages/creator/creator.vue
  3. 328
      pages/creator/imgDetail.vue

9
api/creator.js

@ -109,4 +109,13 @@ export function insertOrUpdatePreInviteProfit(data) {
method: 'post', method: 'post',
data data
}) })
}
// 检查某平台用户当日下载次数是否超标
export function checkUserCanDownload(data) {
return request({
url: `${serviceTitle}/img/mini/tiktok/checkUserCanDownload`,
method: 'post',
data
})
} }

2
pages/creator/creator.vue

@ -66,7 +66,7 @@
duration: 1000, duration: 1000,
indicatorDots: true, indicatorDots: true,
pageNum: 1, pageNum: 1,
pageSize: 2, pageSize: 10,
creatorInfo: {} creatorInfo: {}
} }
}, },

328
pages/creator/imgDetail.vue

@ -42,7 +42,8 @@
tiktokUnCollect, // 取消收藏 tiktokUnCollect, // 取消收藏
queryCreatorScanCodeById, //获取艺术家搜索码 queryCreatorScanCodeById, //获取艺术家搜索码
insertOrUpdatePreAdProfit, //新增/更新艺术家即将入账广告收益 insertOrUpdatePreAdProfit, //新增/更新艺术家即将入账广告收益
insertOrUpdatePreInviteProfit // 新增/更新艺术家即将入账邀请收益 insertOrUpdatePreInviteProfit, // 新增/更新艺术家即将入账邀请收益
checkUserCanDownload // 检查某平台用户当日下载次数是否超标
} from '@/api/creator.js' } from '@/api/creator.js'
export default { export default {
data() { data() {
@ -52,8 +53,9 @@
isDownload: false, // 是否已下载 isDownload: false, // 是否已下载
isLike: false, // 是否点赞/喜欢 isLike: false, // 是否点赞/喜欢
isCollect: false, // 是否收藏, isCollect: false, // 是否收藏,
scanCode: undefined ,//艺术家搜索码 scanCode: undefined, //艺术家搜索码
canDownload: false //能否下载 false为能下载
} }
}, },
created() { created() {
@ -69,7 +71,7 @@
console.log(res) console.log(res)
} }
return { return {
title: '来看看艺术家['+this.scanCode+']精心准备的图片吧~', title: '来看看艺术家[' + this.scanCode + ']精心准备的图片吧~',
path: `/pages/creator/imgDetail?id=${this.userInfo.id}`, path: `/pages/creator/imgDetail?id=${this.userInfo.id}`,
bgImgUrl: `${this.detailMsg.imgUrl}` bgImgUrl: `${this.detailMsg.imgUrl}`
} }
@ -82,14 +84,14 @@
// 图片详情 // 图片详情
async getImgDetail(id) { async getImgDetail(id) {
const res = await detailsTiktokImg(id) const res = await detailsTiktokImg(id)
console.log('res',res) console.log('res', res)
if (res.data.code === 200) { if (res.data.code === 200) {
this.detailMsg = res.data.data this.detailMsg = res.data.data
console.log('图片详情', res) console.log('图片详情', res)
const result = await queryCreatorScanCodeById(this.detailMsg.creatorId) const result = await queryCreatorScanCodeById(this.detailMsg.creatorId)
if(result.data.code === 200){ if (result.data.code === 200) {
this.scanCode = result.data.data.scanCode this.scanCode = result.data.data.scanCode
}else{ } else {
uni.showToast({ uni.showToast({
title: '该艺术家不存在!', title: '该艺术家不存在!',
icon: 'none' icon: 'none'
@ -102,6 +104,7 @@
console.log('userInfo', this.userInfo) console.log('userInfo', this.userInfo)
this.searchIsLike() this.searchIsLike()
this.searchisCollect() this.searchisCollect()
this.checkUserDownload()
} }
}) })
} else { } else {
@ -202,11 +205,12 @@
}, },
//写入图片广告收益 //写入图片广告收益
async insertPreAdProfit(){ async insertPreAdProfit() {
const params = { const params = {
imgId: this.detailMsg.id, imgId: this.detailMsg.id,
creatorId: this.detailMsg.creatorId, creatorId: this.detailMsg.creatorId,
scanCode: this.scanCode, scanCode: this.scanCode,
userId: this.userInfo.id,
appType: '0', appType: '0',
platform: '0' platform: '0'
} }
@ -214,16 +218,16 @@
if (res.data.code === 200) { if (res.data.code === 200) {
console.log("写入广告收益成功!") console.log("写入广告收益成功!")
this.adResult = res.data.code; this.adResult = res.data.code;
}else{ } else {
uni.showToast({ uni.showToast({
title: '图片下载失败!', title: '图片下载失败!',
icon: 'none' icon: 'none'
}) })
} }
}, },
//写入图片邀请收益 //写入图片邀请收益
async insertPreInviteProfit(){ async insertPreInviteProfit() {
const params = { const params = {
imgId: this.detailMsg.id, imgId: this.detailMsg.id,
creatorId: this.detailMsg.creatorId, creatorId: this.detailMsg.creatorId,
@ -235,146 +239,179 @@
if (res.data.code === 200) { if (res.data.code === 200) {
console.log("写入邀请收益成功"); console.log("写入邀请收益成功");
this.inviteResult = res.data.code; this.inviteResult = res.data.code;
}else{ } else {
uni.showToast({ uni.showToast({
title: '图片下载失败!', title: '图片下载失败!',
icon: 'none' icon: 'none'
}) })
} }
}, },
//检查某平台用户当日下载次数是否超标
async checkUserDownload() {
const params = {
userId: this.userInfo.id,
appType: '0',
platform: '0'
}
const res = await checkUserCanDownload(params);
if (res.data.code === 200) {
console.log("当日下载结果为", res.data.data)
this.canDownload = res.data.data;
} else {
uni.showToast({
title: '检查下载状态失败!',
icon: 'none'
})
}
},
// 下载 // 下载
download(url) { download(url) {
this.isDownload = true let that = this;
uni.showLoading({ if (this.canDownload != true) {
title: '正在保存图片...' //满足可下载条件
}); this.isDownload = true
this.insertPreAdProfit(); uni.showLoading({
this.insertPreInviteProfit(); title: '正在保存图片...'
console.log('广告响应结果',this.adResult); });
console.log('邀请响应',this.inviteResult) //获取用户的当前设置。获取相册权限
// if(aResult === 200 && iResult === 200){ uni.getSetting({
success: (res) => {
// } //如果没有相册权限
//获取用户的当前设置。获取相册权限 if (!res.authSetting["scope.writePhotosAlbum"]) {
uni.getSetting({ //向用户发起授权请求
success: (res) => { tt.authorize({
//如果没有相册权限 scope: "scope.album",
if (!res.authSetting["scope.writePhotosAlbum"]) { success: () => {
//向用户发起授权请求 //授权成功保存图片到系统相册
tt.authorize({ uni.downloadFile({
scope: "scope.album", url,
success: () => { success: (res) => {
//授权成功保存图片到系统相册 console.log('下载路径', res)
uni.downloadFile({ if (res.statusCode === 200) {
url, uni.saveImageToPhotosAlbum({
success: (res) => { //图片路径,不支持网络图片路径
console.log('下载路径', res) filePath: res
if (res.statusCode === 200) { .tempFilePath,
uni.saveImageToPhotosAlbum({ success: (res) => {
//图片路径,不支持网络图片路径 console.log(
filePath: res.tempFilePath, 'success',
success: (res) => { res)
console.log(
'success',
res)
}, },
fail: (res) => { fail: (res) => {
console.log('fail', console.log(
res) 'fail',
return uni res)
.showToast({
title: res
.errMsg,
icon: 'none'
});
},
complete: (res) => {
uni.hideLoading();
if (res.errMsg !==
"saveImageToPhotosAlbum:ok"
) {
return uni
.showToast({
title: "下载失败!",
icon: 'none'
});
} else {
return uni return uni
.showToast({ .showToast({
title: "下载成功!", title: res
.errMsg,
icon: 'none' icon: 'none'
}); });
} },
}, complete: (res) => {
}); uni
} else { .hideLoading();
uni.showToast({ if (res
title: "下载失败!", .errMsg !==
icon: 'none' "saveImageToPhotosAlbum:ok"
}); ) {
} return uni
} .showToast({
}) title: "下载失败!",
}, icon: 'none'
//授权失败 });
fail: () => { } else {
uni.hideLoading(); return uni
uni.showModal({ .showToast({
title: "您已拒绝获取相册权限", title: "下载成功!",
content: "是否进入权限管理,调整授权?", icon: 'none',
success: (res) => { success() {
if (res.confirm) { that.insertPreAdProfit();
//调起客户端小程序设置界面,返回用户设置的操作结果。(重新让用户授权) that.insertPreInviteProfit();
uni.openSetting({ }
success: ( });
res) => { }
console },
.log( });
res } else {
.authSetting uni.showToast({
); title: "下载失败!",
}, icon: 'none'
}); });
} else if (res.cancel) { }
return uni.showToast({
title: "已取消!",
icon: 'none'
});
} }
}, })
}); },
}, //授权失败
}); fail: () => {
} else { uni.hideLoading();
//如果已有相册权限,直接保存图片到系统相册 uni.showModal({
uni.saveImageToPhotosAlbum({ title: "您已拒绝获取相册权限",
filePath: url, content: "是否进入权限管理,调整授权?",
success: (res) => { success: (res) => {
uni.hideLoading(); if (res.confirm) {
return uni.showToast({ //调起客户端小程序设置界面,返回用户设置的操作结果。(重新让用户授权)
title: "保存成功!", uni.openSetting({
icon: 'none' success: (
}); res) => {
}, console
fail: (res) => { .log(
uni.hideLoading(); res
console.log(res.errMsg); .authSetting
return uni.showToast({ );
title: res.errMsg, },
icon: 'none' });
}); } else if (res.cancel) {
}, return uni.showToast({
//无论成功失败都走的回调 title: "已取消!",
complete: (res) => { icon: 'none'
uni.hideLoading(); });
}, }
}); },
} });
}, },
fail: (res) => {}, });
}); } else {
//如果已有相册权限,直接保存图片到系统相册
uni.saveImageToPhotosAlbum({
filePath: url,
success: (res) => {
uni.hideLoading();
return uni.showToast({
title: "保存成功!",
icon: 'none'
});
},
fail: (res) => {
uni.hideLoading();
console.log(res.errMsg);
return uni.showToast({
title: res.errMsg,
icon: 'none'
});
},
//无论成功失败都走的回调
complete: (res) => {
uni.hideLoading();
},
});
}
},
fail: (res) => {},
});
} else {
//不满足可下载条件 canDownload为true状态
uni.showToast({
title: '当日下载次数已用完,请明日再来!',
icon: 'none'
})
}
}, },
// 分享 // 分享
share() { share() {
@ -407,20 +444,23 @@
right: 10px; right: 10px;
border-radius: 60px; border-radius: 60px;
padding-top: 40rpx; padding-top: 40rpx;
.share-box{
.share-box {
>button{
line-height: 0!important; >button {
line-height: 0 !important;
padding: 0; padding: 0;
outline: none; outline: none;
background: none; background: none;
border: none; border: none;
} }
>button::after{
>button::after {
border: none; border: none;
} }
} }
.toolbar-box { .toolbar-box {
height: 60px; height: 60px;
text-align: center; text-align: center;

Loading…
Cancel
Save