123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- import { Component } from 'react'
- import { View, Text, Button, Image, scrollView, Input } from '@tarojs/components'
- import * as api from '../../../service/index'
- import tool from '../../../common/tool'
- import Taro, { } from '@tarojs/taro'
- import './index.less'
- export default class collection extends Component {
- state = {
- consultImg: '',
- sizeIndex: 0,
- mass: 0,
- modelIndex: 0,
- isImage: false,
- isOpen: false,
- jumpurl: '',//广告id
- task_id: 0,//任务id
- repeat: 0,//广告次数
- drawTaskId: 0,//任务id
- is_week: 0,//是否是周卡用户
- models: {},//活动数据
- }
- componentWillMount () {
- this.getCoinTaskAd()
- this.getDraw51ImgIndex()
- }
- componentDidShow () {
- //接收裁剪图片
- let pages = Taro.getCurrentPages();
- let currentPage = pages[pages.length - 1]; // 获取当前页面
- console.log(currentPage, 'currentPage');
- if (process.env.TARO_ENV == 'weapp') {
- if (currentPage.__data__.consultImg) { // 获取值
- this.setState({
- consultImg: currentPage.__data__.consultImg,
- sizeIndex: currentPage.__data__.sizeIndex,
- isImage: true
- })
- currentPage.__data__.consultImg = ''
- }
- } else if (process.env.TARO_ENV == 'tt') {
- if (currentPage.data.consultImg) { // 获取值
- this.setState({
- consultImg: currentPage.data.consultImg,
- sizeIndex: currentPage.data.sizeIndex,
- isImage: true
- })
- currentPage.data.consultImg = ''
- }
- }
- }
- getDraw51ImgIndex () {
- api.getDraw51ImgIndex().then(res => {
- if (res.code == 200) {
- this.setState({
- is_week: res.data.is_week,
- models: res.data.models[0],
- consultImg: res.data.models[0].img
- })
- }
- })
- }
- getCoinTaskAd () {
- api.getCoinTaskAd().then(res => {
- if (res.code == 200) {
- this.setState({
- jumpurl: res.data[0].jumpurl,//广告id
- task_id: res.data[0].id,//任务id
- repeat: res.data[0].repeat
- })
- }
- })
- }
- changeOpen () {
- this.setState({
- isOpen: !this.state.isOpen
- })
- }
- //上传图片
- upLode () {
- let that = this
- Taro.chooseMedia({
- count: 1, // 默认
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
- mediaType: ['image'],
- sourceType: ['album', 'camera'],
- success: function (res) {
- console.log(res, 'res');
- const file = res.tempFiles[0].tempFilePath
- if (res.tempFiles[0].size > 2000000) {
- Taro.showToast({ title: '图片大小不能超过2M', icon: 'none' })
- return
- }
- let base64Img = Taro.getFileSystemManager().readFileSync(file, 'base64')
- Taro.showLoading({
- title: '图片检测中...',
- })
- api.imageDetection({ img_data: base64Img }).then(item=>{
- if (item.code==200) {
- Taro.hideLoading()
- Taro.navigateTo({
- url: `/moduleA/pages/upload/index?image=${file}`
- })
- }else{
- Taro.hideLoading()
- Taro.showToast({ title: item.msg, icon: 'none' })
- }
- })
- }
- })
- }
- //画图
- generatePictures () {
- if (!this.state.isImage) {
- Taro.showToast({ title: '请先上传图片', icon: 'none' })
- return
- }
- api.drawGcImg({ img_url: this.state.consultImg, style_id: this.state.creatInfo.models[this.state.modelIndex].id }).then(res => {
- if (res.code == 200) {
- Taro.navigateTo({
- url: `/moduleB/pages/comicDetail/index?task_id=${res.data.task_id}`
- })
- } else {
- Taro.hideLoading()
- Taro.showToast({ icon: 'none', title: res.msg })
- }
- })
- }
- //看广告画图
- playVideoGeneratePictures () {
- if (!this.state.isImage) {
- Taro.showToast({ title: '请先上传图片', icon: 'none' })
- return
- }
- api.drawGcImg({ img_url: this.state.consultImg, style_id: this.state.models.style_id }).then(res => {
- if (res.code == 200) {
- if (this.state.is_week == 1) {
- Taro.navigateTo({
- url: `/moduleB/pages/comicActivityDetail/index?task_id=${res.data.task_id}`
- })
- } else {
- this.setState({
- drawTaskId: res.data.task_id
- }, () => {
- this.playVideo()
- })
- }
- } else {
- Taro.hideLoading()
- Taro.showToast({ icon: 'none', title: res.msg })
- }
- })
- }
- //观看广告
- playVideo () {
- if (process.env.TARO_ENV == 'tt') {
- this.playVideoTT()
- } else {
- this.playVideoWeapp()
- }
- }
- //抖音激励广告
- playVideoTT () {
- let that = this
- Taro.showLoading({
- title: '加载中...',
- })
- const videoAd = tt.createRewardedVideoAd({ adUnitId: this.state.jumpurl });
- videoAd.show()
- videoAd.onError((err) => {
- Taro.hideLoading()
- switch (err.errCode) {
- case 1004:
- // 无合适的广告
- break;
- default:
- // 更多请参考错误码文档
- }
- });
- try {
- if (videoAd.closeHandler) {
- videoAd.offClose(videoAd.closeHandler);
- console.log("videoAd.offClose卸载成功");
- }
- } catch (e) {
- console.log("videoAd.offClose 卸载失败");
- console.error(e);
- }
- videoAd.closeHandler = function (data) {
- Taro.hideLoading()
- if (data.isEnded) {
- Taro.navigateTo({
- url: `/moduleB/pages/comicActivityDetail/index?task_id=${that.state.drawTaskId}`
- })
- } else {
- }
- }
- // 监听视频播放完成
- videoAd.onClose(videoAd.closeHandler);
- }
- //激励广告
- playVideoWeapp () {
- // 在页面中定义激励视频广告
- let adUnitId = this.state.jumpurl
- // 在页面中定义激励视频广告
- let videoAd = null
- let that = this
- console.log(videoAd, 'videoAd');
- // 在页面onLoad回调事件中创建激励视频广告实例
- if (wx.createRewardedVideoAd) {
- videoAd = wx.createRewardedVideoAd({
- adUnitId: adUnitId
- })
- videoAd.onLoad(() => { })
- videoAd.onError((err) => { })
- try {
- if (videoAd.closeHandler) {
- videoAd.offClose(videoAd.closeHandler);
- console.log("videoAd.offClose卸载成功");
- }
- } catch (e) {
- console.log("videoAd.offClose 卸载失败");
- console.error(e);
- }
- videoAd.closeHandler = function (res) {
- // 用户点击了【关闭广告】按钮
- if (res && res.isEnded || res === undefined) {
- // 正常播放结束,可以下发游戏奖励
- Taro.navigateTo({
- url: `/moduleB/pages/comicActivityDetail/index?task_id=${that.state.drawTaskId}`
- })
- } else {
- //提前关闭小程序
- }
- };
- videoAd.onClose(videoAd.closeHandler);
- }
- // 用户触发广告后,显示激励视频广告
- if (videoAd) {
- videoAd.show().catch(() => {
- // 失败重试
- videoAd.load()
- .then(() => videoAd.show())
- .catch(err => {
- Taro.showToast({
- title: '暂无广告',
- icon: 'none',
- duration: 2000
- })
- console.log('激励视频 广告显示失败')
- })
- })
- }
- }
- deleteImg () {
- this.setState({
- consultImg: 'http://video-img.fyshark.com/1681721632520%E4%B8%8A.png',
- isImage: false,
- })
- }
- onShareAppMessage = (res) => {
- let path = `/pages/index/index?c=${Taro.getStorageSync('user_id')}&s=rightTap`
- if (process.env.TARO_ENV == 'tt') {
- path = `/moduleB/pages/comic/index?c=channel_name&s=neibuguazai`
- }
- let shareData = {
- title: tool.shareTitle,
- path: path,
- imageUrl: tool.shareImg
- }
- return shareData;
- }
- changeMass (e) {
- this.setState({
- mass: e
- })
- }
- selectModel (item, index) {
- this.setState({
- modelIndex: index,
- })
- }
- //充值
- toOrder () {
- let that = this
- if (process.env.TARO_ENV === 'tt') {
- Taro.showLoading({
- title: '加载中...',
- })
- api.ttCreateOrder({ pay_info_id: this.state.models.shop_id }).then(res => {
- if (res.code == 200) {
- Taro.hideLoading()
- tt.pay({
- orderInfo: {
- order_id: res.data.order_id,
- order_token: res.data.order_token
- },
- service: 5,
- success (item) {
- if (item.code == 0) {
- Taro.showToast({
- title: '购买成功',
- icon: 'none',
- duration: 2000
- })
- that.getDraw51ImgIndex()
- setTimeout(() => {
- that.getDraw51ImgIndex()
- }, 2000);
- // 支付成功处理逻辑,只有res.code=0时,才表示支付成功
- // 但是最终状态要以商户后端结果为准
- }
- },
- fail (item) {
- // 调起收银台失败处理逻辑
- },
- });
- }
- })
- } else if (process.env.TARO_ENV === 'weapp') {
- Taro.getSystemInfo({
- success: function (res) {
- Taro.showLoading({
- title: '加载中...',
- })
- api.createOrder({ shop_id: that.state.models.shop_id }).then(res => {
- if (res.code == 200) {
- Taro.hideLoading()
- Taro.requestPayment({
- timeStamp: res.data.timeStamp,
- nonceStr: res.data.nonceStr,
- package: res.data.package,
- signType: res.data.signType,
- paySign: res.data.paySign,
- success: function (res) {
- // console.log(res);
- //添加2s延迟在刷新数据
- setTimeout(() => {
- that.getDraw51ImgIndex()
- Taro.showToast({
- title: '购买成功',
- icon: 'none',
- duration: 2000
- })
- }, 2000);
- },
- fail: function (err) {
- try {
- const res = Taro.getSystemInfoSync()
- console.log(res, 'iphone=====');
- } catch (e) {
- }
- }
- })
- }
- })
- }
- })
- }
- }
- toComic () {
- Taro.navigateTo({
- url: `/moduleB/pages/comic/index`
- })
- }
- render () {
- return (
- <View className='mine'>
- {
- !this.state.isImage ?
- <View className='before-painting'>
- <View className='title'>
- <Image className='title-img' src='http://video-img.fyshark.com/1682475695399title.png'></Image>
- </View>
- <View className='banner'>
- <View className='banner-content'>
- <Image className='content-img'
- mode='aspectFit'
- src={this.state.consultImg}
- ></Image>
- </View>
- <View className='step'>
- <Image className='step-img' src='http://video-img.fyshark.com/1682475185108123.png'>
- </Image>
- </View>
- </View>
- <View className='update' >
- <View className='update-button-more'
- onClick={e => (this.toComic())}
- >
- 更多风格
- </View>
- <View className='update-button'
- onClick={e => (this.upLode())}
- >
- 上传图片
- </View>
- </View>
- </View>
- :
- <View className='after-painting'>
- <View className='result-banner'>
- <View className='result-banner-content'>
- <Image className='result-content-img'
- mode='widthFix'
- src={this.state.consultImg}
- ></Image>
- {
- this.state.isImage &&
- <Image className='delete' src='http://video-img.fyshark.com/1680147210173guanbi.png' onClick={e => (this.deleteImg())}></Image>
- }
- </View>
- </View>
- <View className='after-tips'>照片已上传,还差最后一步</View>
- <View className='result-update' >
- {
- this.state.is_week == 0 &&
- <View className='result-recharge-button update-active'
- onClick={e => (tool.throttle(this.toOrder()), 2000)}
- >
- <View className='result-recharge-button-content'>
- <View className='result-recharge-button-top'>无广告急速制作</View>
- <View className='result-recharge-button-bottom'>一周/{this.state.models.money_week / 100}元</View>
- </View>
- </View>
- }
- <View className='result-update-button'
- onClick={e => (tool.throttle(this.playVideoGeneratePictures()), 2000)}
- >
- {
- this.state.is_week == 0 &&
- <Image className='result-update-img' src='http://video-img.fyshark.com/1682414441783aghidjnl.png'></Image>
- }
- {
- this.state.is_week == 1 ? '开始制作' : '看广告免费制作'
- }
- </View>
- </View>
- </View>
- }
- </View>
- )
- }
- }
|