123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- // index.js
- // 获取应用实例
- const app = getApp()
- import {
- VueLikePage
- } from '../../utils/page'
- import { CDN_URL,API_BASE_URL,TYPE } from '../../config/index'
- import {isPhoneX} from './../../utils/tools'
- import Router from '../../utils/routes'
- import Toast from '../../components/toast/toast';
- VueLikePage([],{
- data:{
- cdn_url:CDN_URL,
- isBackCamera:false,
- current:'1',
- currentImg:'',
- isSelect: false,
- form:''
- },
- methods:{
- onLoad:function (options) {
- let {id} = options
- this.setData({
- current:id
- })
- let left = app.globalData.deviceInfo.windowWidth - app.globalData.top.right
- isPhoneX().then(res => {
- this.setData({
- isIphoneX: res,
- top:app.globalData.top,
- left
- })
- })
- },
- onShow:function () {
- // this.reTake()
- if (this.data.form == 'work') {
- this.setData({
- form:''
- })
- this.reTake()
- }
- },
- loadcompele(){
- this.setData({
- loadCompele: true
- })
- },
- back(){
- if (this.data.currentImg) {
- this.reTake()
- }
- else{
- wx.navigateBack()
- }
- },
- changPosition(){
- this.setData({
- isBackCamera:!this.data.isBackCamera
- })
- },
- reTake(){
- this.setData({
- currentImg:'',
- isSelect:false
- })
- },
- submit(){
- let toast = Toast.loading({
- message:'正在生成中,请耐心等候',
- selector: '#loading-toast'
- });
-
- wx.uploadFile({
- url: `${API_BASE_URL}/api/uploadFaceSwap/${TYPE[this.data.current]}`,
- filePath: this.data.currentImg,
- name: 'file',
- success: (res)=>{
- let data = JSON.parse(res.data)
- if (data.code==0) {
- this.setData({
- work:data.msg
- })
- Router.push({
- url: 'work',
- query: {
- vr_link:data.msg,
- id: this.data.current
- }
- })
- }
- else{
- Toast.fail({
- message:this.data.isSelect?'无法识别人脸,请选取正脸照片':'无法识别人脸,请正对摄像头拍照',
- selector: '#fail-toast',
- callBack:()=>{
- if (this.data.isSelect) {
- this.back()
- wx.chooseImage({
- sourceType:["album"],
- count: 1,
- sizeType: ['original', 'compressed'],
- success:res =>{
- this.setData({
- currentImg: res.tempFilePaths[0],
- isSelect:true
- })
- },
- fail:error =>{
- console.log(error);
- }
- })
- }
- else{
- this.reTake()
- }
- }
- });
- }
- },
- fail:()=>{
- Toast.fail({
- message:this.data.isSelect?'无法识别人脸,请选取正脸照片':'无法识别人脸,请正对摄像头拍照',
- selector: '#fail-toast',
- callBack:()=>{
- if (this.data.isSelect) {
- this.back()
- wx.chooseImage({
- sourceType:["album"],
- count: 1,
- sizeType: ['original', 'compressed'],
- success:res =>{
- this.setData({
- currentImg: res.tempFilePaths[0],
- isSelect:true
- })
- },
- fail:error =>{
- console.log(error);
- }
- })
- }
- else{
- this.reTake()
- }
- }
- });
- },
- complete(){
- toast.hideLoading()
- }
- })
-
- },
- selectImage(){
- Toast.message({
- message:'请选取正脸照片',
- selector: '#tips-toast',
- callBack:()=>{
- wx.chooseImage({
- sourceType:["album"],
- count: 1,
- sizeType: ['original', 'compressed'],
- success:res =>{
- this.setData({
- currentImg: res.tempFilePaths[0],
- isSelect:true
- })
-
- console.log(this.data.currentImg,this.data.isSelect)
-
- },
- fail:error =>{
- console.log(error);
- }
- })
- }
- });
- },
- takePhoto() {
- const ctx = wx.createCameraContext()
- ctx.takePhoto({
- quality: 'high',
- success: (res) => {
- this.setData({
- currentImg: res.tempImagePath,
- isSelect:false
- })
- }
- })
- }
- }
- })
|