ios 拍照完成
This commit is contained in:
+84
-52
@@ -1,52 +1,84 @@
|
||||
<template>
|
||||
<view>
|
||||
<image class="logo" :src="img"></image>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {QrOpt,getQrData} from "@/uni_modules/xtf-qrcode"
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
title: 'Hello',
|
||||
img:"",
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
console.log("QrOpt")
|
||||
var that=this;
|
||||
getQrData({
|
||||
content:"xtf",
|
||||
logo:"/static/logo.png",
|
||||
logoW:80,
|
||||
logoH:80,
|
||||
qrSize:300,
|
||||
callback:function(data:string){
|
||||
that.img=data;
|
||||
}
|
||||
|
||||
} as QrOpt);
|
||||
//console.log(this.img)
|
||||
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.logo {
|
||||
height: 300px;
|
||||
width: 300px;
|
||||
margin: 100px auto 25px auto;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 18px;
|
||||
color: #8f8f94;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<view class="container">
|
||||
<text class="title">UniApp X 拍照测试</text>
|
||||
|
||||
<image v-if="imageUrl" :src="imageUrl" mode="aspectFit" class="preview-image"></image>
|
||||
|
||||
<button @click="takePhoto" type="primary">打开摄像头拍照</button>
|
||||
|
||||
<text v-if="errorMsg" class="error-text">{{ errorMsg }}</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="uts">
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
imageUrl: '' as string,
|
||||
errorMsg: '' as string
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
takePhoto() {
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sizeType: ['compressed'],
|
||||
sourceType: ['camera'], // 只从相机选择
|
||||
success: (res) => {
|
||||
console.log('拍照成功:', res);
|
||||
if (res.tempFilePaths && res.tempFilePaths.length > 0) {
|
||||
this.imageUrl = res.tempFilePaths[0];
|
||||
this.errorMsg = '';
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('拍照失败:', err);
|
||||
this.errorMsg = '拍照失败: ' + (err.errMsg || '未知错误');
|
||||
|
||||
// 权限被拒绝时引导用户去设置
|
||||
if (err.errMsg && err.errMsg.includes('permission')) {
|
||||
uni.showModal({
|
||||
title: '权限提示',
|
||||
content: '您已拒绝摄像头权限,请在设置中开启',
|
||||
confirmText: '去设置',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.openSetting();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 36px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
.preview-image {
|
||||
width: 500px;
|
||||
height: 500px;
|
||||
margin: 20px 0;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: #ff0000;
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user