1、拍照页⾯:
<template>
<view title="拍照">
<camera v-if="openCamera" device-position="front" frame-size="large" class="zipai" @error="error"> </camera>
<cover-image src="/static/image/renzheng_zz.png" class="zhezhao"></cover-image>
<cover-view class="wenzi fint34">请将正⾯⼈脸放在识别框中,进⾏拍摄</cover-view>
<cover-image class="paizhao" src="/static/image/renzheng_pz.png" @click="takePhoto"></cover-image>
</view>
</template>
<script>
export default {
徐嘉雯data() {
return {
openCamera:true
}
},
methods: {
takePhoto() {
const ctx = wx.createCameraContext()
ctx.takePhoto({
quality: 'high',
success: (res) => {
let tempFilePath = pImagePath
uni.navigateTo({
url:'/pages/renzhengwxtu/renzhengwxtu?src='+tempFilePath
})
给老师的祝福}
})
},
//⽤户拒绝授权摄像头
error(e) {
this.openCamera=false
wx.showModal({
title: '警告',
content: '若不授权使⽤摄像头,将⽆法使⽤拍照功能!',
cancelText: '不授权',
cancelColor: '#1ba9ba',
confirmText: '授权',
confirmColor: '#1ba9ba',
success:(res)=> {
if (firm) {//允许打开授权页⾯
//调起客户端⼩程序设置界⾯,返回⽤户设置的操作结果
wx.openSetting({
success:(res)=> {
res.authSetting = {
"scope.camera": true
}
this.openCamera=true
},
})
} else if (res.cancel) {//拒绝打开授权页⾯
wx.navigateBack({delta:1})
}
}
})
},
}
}
</script>
2、预览图⽚页⾯:
<template>
<view title="预览图⽚">
<image mode="widthFix" :src="src" class="renlian"></image> <view class="btns">
<text @click="takePhoto">重拍</text>
<text @click="usePhoto">使⽤照⽚</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
src: '',
timeId:null,
}
},
onLoad(option) {
this.src=option.src
},
onHide() {
clearTimeout(this.timeId);
this.timeId=null;
},
methods: {
takePhoto() {
uni.navigateBack({delta: 1});
},
usePhoto() {
this.$request.uploadFileMinipro(this.Renzheng); },
retoRenzheng(){
付梦妮图片this.timeId=setTimeout(()=>{
var pages = getCurrentPages();
var prevPage = pages[pages.length - 3]; //上⼀个页⾯
prevPage.fromTu= true;
uni.navigateBack({delta: 2});
},200);
},
你应该被呵护被珍惜被捧在手心上是什么歌}
}
</script>
3、上传图⽚⽅法:
// uploadFileMinipro
function uploadFileMinipro(tempFilePath,callback){
// 1.2 上传头像
let uin =GlobalUserInfo().id;
let reurl=common.ip;
uni.uploadFile({
url: reurl,
filePath: tempFilePath,
name: "file",
formData:{uin:uin},
success:(res)=>{
console.log("res=",res);
// 注意,这⾥获得是⼀个string,需要转换⼀下
let resData = JSON.parse(res.data);
if (resData.status == 1) {//<=0:⼈⼯返回的错误信息
setErrorMessage("上传成功");
侠盗飞车密级if (typeof callback === "function"){
callback();//刷新当前页⾯
}
} else if (resData.status < 1) {
胡歌 唐嫣
setErrorMessage(resData.msg)
} else {
setErrorMessage()
}
},
fail:(res)=>{
console.log("上传失败");
},
});
}
为⼤家推荐现在关注度⽐较⾼的⼩程序教程⼀篇:⼩编为⼤家精⼼整理的,希望喜欢。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
发布评论