Browse Source

feature:新增AI绘画相关内容

feature-1.0
Penny 3 years ago
parent
commit
7bd4d683d5
  1. 24
      pages/ai/paint/paint.vue
  2. 18
      pages/ai/paint/paintDetail.vue
  3. 398
      pages/creator/imgDetail.vue

24
pages/ai/paint/paint.vue

@ -87,6 +87,7 @@
<script> <script>
import base64ToImg from '@/utils/base64Utils'; import base64ToImg from '@/utils/base64Utils';
import {getPaintStyle, getPrompt, textToImg} from '@/api/paint.js'; import {getPaintStyle, getPrompt, textToImg} from '@/api/paint.js';
import tiktokAd from '@/utils/tiktokAd.js'
export default { export default {
data() { data() {
return { return {
@ -95,13 +96,14 @@
width: undefined, width: undefined,
modelName: undefined, modelName: undefined,
styleName: undefined, styleName: undefined,
promptText: undefined promptText: undefined,
}, },
checkData:{ checkData:{
checkPrompt: undefined, //true;false checkPrompt: undefined, //true;false
checkStyleBox: undefined, //true;false checkStyleBox: undefined, //true;false
checkSize: undefined, //true;false checkSize: undefined, //true;false
}, },
advertise: '0qfnoa4053uwkefbas',
userInfo: {}, userInfo: {},
noClick:true, // noClick:true, //
promptList: [], promptList: [],
@ -139,9 +141,28 @@
this.checkLogin(); this.checkLogin();
this.getPaintStyleList(); this.getPaintStyleList();
this.getPrompt(); this.getPrompt();
//this.initReward();//广
//tiktokAd.rewarded.load('0qfnoa4053uwkefbas');
}, },
methods: { methods: {
//广
initReward(){
let that = this;
//console.log('that.advertise',that.advertise)
tiktokAd.rewarded.load('0qfnoa4053uwkefbas', () => {
console.log('进入了广告');
// uni.setClipboardData({
// data: that.draw.draw_text
// })
})
},
//
// //
checkLogin(){ checkLogin(){
let that = this; let that = this;
@ -170,6 +191,7 @@
}, },
// //
startPaint(){ startPaint(){
//tiktokAd.rewarded.show();
// //
const that = this; const that = this;
//console.log('prompt',that.formData.promptText) //console.log('prompt',that.formData.promptText)

18
pages/ai/paint/paintDetail.vue

@ -89,12 +89,14 @@
<script> <script>
import base64ToImg from '@/utils/base64Utils'; import base64ToImg from '@/utils/base64Utils';
import rewarded from '@/utils/tiktokAd.js'
import { textToImg} from '@/api/paint.js'; import { textToImg} from '@/api/paint.js';
import {loginTiktok} from '@/api/auth.js' import {loginTiktok} from '@/api/auth.js'
export default { export default {
data() { data() {
return { return {
//广
adStatus: false,
imgHeight: undefined, imgHeight: undefined,
imgWidth: undefined, imgWidth: undefined,
transImg: undefined, transImg: undefined,
@ -126,6 +128,10 @@
} }
}); });
//广
//initReward();
}, },
onShareTimeline() { onShareTimeline() {
let _this = this let _this = this
@ -155,6 +161,16 @@
}, },
methods: { methods: {
//广
// initReward(){
// let that = this;
// rewarded.load(that.spool.reward.id, () => {
// uni.setClipboardData({
// data: that.draw.draw_text
// })
// })
// },
// //
async loginFunc(res, userInfo, callBack) { async loginFunc(res, userInfo, callBack) {
const params = { const params = {

398
pages/creator/imgDetail.vue

@ -34,6 +34,11 @@
</template> </template>
<script> <script>
let isplayOver = false;
let timer = 0;
let Timer = null;
let stayTime = 0;
let isOverTask = false
import { import {
detailsTiktokImg, // detailsTiktokImg, //
judgeTiktokLike, // judgeTiktokLike, //
@ -45,9 +50,10 @@
queryCreatorScanCodeById, // queryCreatorScanCodeById, //
insertOrUpdatePreAdProfit, ///广 insertOrUpdatePreAdProfit, ///广
insertOrUpdatePreInviteProfit, // / insertOrUpdatePreInviteProfit, // /
checkUserCanDownload // checkUserCanDownload//
} from '@/api/creator.js' } from '@/api/creator.js'
import {loginTiktok} from '@/api/auth.js' import {loginTiktok} from '@/api/auth.js'
import tiktokAd from '@/utils/tiktokAd.js'
export default { export default {
data() { data() {
return { return {
@ -65,12 +71,84 @@
likeColor: '#ef223c', likeColor: '#ef223c',
collectColor: '#dcaa04', collectColor: '#dcaa04',
urlParamId: undefined, urlParamId: undefined,
htime: 0, //广
mintime: 999999999, //
taskhide: false,
starttask: false,
done: false,
adList:['0qfnoa4053uwkefbas','2v63zq5hvfclpxmurl','d4ltbnxa23zp2hhqwe'] //广
} }
}, },
onLoad(option){ onLoad(option){
if (option?.id) { if (option?.id) {
this.urlParamId = 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() { created() {
const detailId = uni.getStorageSync('detailId') const detailId = uni.getStorageSync('detailId')
@ -99,6 +177,103 @@
} }
}, },
methods: { 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) { async getImgDetail(id) {
const res = await detailsTiktokImg(id) const res = await detailsTiktokImg(id)
@ -392,7 +567,7 @@
}) })
} }
}, },
authDownload(url) { authDownload(url) {
if (!this.userInfo) { if (!this.userInfo) {
this.getUserInfoLogin(() => { this.getUserInfoLogin(() => {
this.download(url) this.download(url)
@ -402,121 +577,129 @@
} }
}, },
// //
download(url) { download(url) {
let that = this; let that = this;
if (that.canDownload !== true) { if (that.canDownload !== true) {
// //
that.isDownload = 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({ uni.showLoading({
title: '正在保存图片...' title: '正在保存图片...'
}); });
console.log('test123')
// //
uni.getSetting({ // uni.getSetting({
success: (res) => { // success: (res) => {
// // //
if (!res.authSetting["scope.writePhotosAlbum"]) { // if (!res.authSetting["scope.writePhotosAlbum"]) {
// // //
uni.authorize({ // uni.authorize({
scope: "scope.album", // scope: "scope.album",
success: () => { // success: () => {
// // //
uni.downloadFile({ // uni.downloadFile({
url, // url,
success: (res) => { // success: (res) => {
if (res.statusCode === 200) { // if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({ // uni.saveImageToPhotosAlbum({
// // //
filePath: res.tempFilePath, // filePath: res.tempFilePath,
success: (res) => { // success: (res) => {
}, // },
fail: (res) => { // fail: (res) => {
return uni.showToast({ // return uni.showToast({
title: res.errMsg, // title: res.errMsg,
icon: 'none' // icon: 'none'
}); // });
}, // },
complete: (res) => { // complete: (res) => {
uni.hideLoading(); // uni.hideLoading();
if (res.errMsg !== "saveImageToPhotosAlbum:ok") { // if (res.errMsg !== "saveImageToPhotosAlbum:ok") {
return uni.showToast({ // return uni.showToast({
title: "下载失败!", // title: "",
icon: 'none' // icon: 'none'
}); // });
} else { // } else {
return uni // return uni
.showToast({ // .showToast({
title: "下载成功!", // title: "",
icon: 'none', // icon: 'none',
success() { // success() {
// // //
that.insertPreAdProfit(); // that.insertPreAdProfit();
that.insertPreInviteProfit(); // that.insertPreInviteProfit();
} // }
}); // });
} // }
}, // },
}); // });
} else { // } else {
uni.showToast({ // uni.showToast({
title: "下载失败!", // title: "",
icon: 'none' // icon: 'none'
}); // });
} // }
} // }
}) // })
}, // },
// // //
fail: () => { // fail: () => {
uni.hideLoading(); // uni.hideLoading();
uni.showModal({ // uni.showModal({
title: "您已拒绝获取相册权限", // title: "",
content: "是否进入权限管理,调整授权?", // content: "",
success: (res) => { // success: (res) => {
if (res.confirm) { // if (res.confirm) {
// // //
uni.openSetting({ // uni.openSetting({
success: (res) => { // success: (res) => {
}, // },
}); // });
} else if (res.cancel) { // } else if (res.cancel) {
return uni.showToast({ // return uni.showToast({
title: "已取消!", // title: "",
icon: 'none' // icon: 'none'
}); // });
} // }
}, // },
}); // });
}, // },
}); // });
} else { // } else {
// // //
uni.saveImageToPhotosAlbum({ // uni.saveImageToPhotosAlbum({
filePath: url, // filePath: url,
success: (res) => { // success: (res) => {
uni.hideLoading(); // uni.hideLoading();
return uni.showToast({ // return uni.showToast({
title: "保存成功!", // title: "",
icon: 'none' // icon: 'none'
}); // });
}, // },
fail: (res) => { // fail: (res) => {
uni.hideLoading(); // uni.hideLoading();
return uni.showToast({ // return uni.showToast({
title: res.errMsg, // title: res.errMsg,
icon: 'none' // icon: 'none'
}); // });
}, // },
// // //
complete: (res) => { // complete: (res) => {
uni.hideLoading(); // uni.hideLoading();
}, // },
}); // });
} // }
}, // },
fail: (res) => {}, // fail: (res) => {},
}); // });
} else { } else {
// canDownloadtrue // canDownloadtrue
uni.showToast({ uni.showToast({
@ -526,6 +709,7 @@
} }
}, },
// //
share() { share() {
uni.showToast({ uni.showToast({

Loading…
Cancel
Save