123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- // 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'
- VueLikePage([],{
- data:{
- cdn_url:CDN_URL,
- isBackCamera:false,
- current:'1',
- currentImg:'',
- isSelect: false
- },
- methods:{
- onLoad:function (options) {
- let {id} = options
- this.setData({
- current:id
- })
- isPhoneX().then(res => {
- this.setData({
- isIphoneX: res
- })
- })
- },
- onShow:function () {
- // 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(){
- wx.showLoading({
- title: '处理中…',
- mask:true
- });
-
- 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{
- wx.showModal({
- title: '无法识别人脸,请正对摄像头拍照',
- showCancel:false
- });
- }
- },
- fail:()=>{
- wx.showModal({
- title: '无法识别人脸,请正对摄像头拍照',
- showCancel:false
- });
- },
- complete(){
- wx.hideLoading();
- }
- })
-
- },
- selectImage(){
- wx.chooseImage({
- sourceType:["album"],
- count: 1,
- sizeType: ['original', 'compressed'],
- success:res =>{
- console.log(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
- })
- }
- })
- }
- }
- })
|