<template>
<view>
<image :src="mySrc" style="width: 100%;"></image>
<view class="show">
<button type="primary" @click="selectimg()">请上传户口本页面</button>
</view>
<view>
<uni-section title="姓名" type="line">
<uni-card :is-shadow="false">
<text class="uni-body">{{personname}}</text>
</uni-card>
</uni-section>
<uni-section title="身份证号" type="line">
<uni-card :is-shadow="false">
<text class="uni-body">6105******</text>
</uni-card>
</uni-section>
<uni-section title="评论区" type="line" padding>
<uni-easyinput type="textarea" v-model="value" placeholder="请输入内容"></uni-easyinput>
</uni-section>
</view>
<uni-section title="评论得分" type="line" padding>
<uni-rate v-model="rateValue" @change="onChange" />
</uni-section>
<view>
<button type="primary">确定评论</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
mySrc: require("@/static/logo/lo3.png"),
personname:"",
};
},
methods: {
selectimg() {
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album'],
success: (res) => {
console.log(res.tempFilePaths[0]);
this.mySrc = res.tempFilePaths[0];
this.changeImgToBase64(res.tempFilePaths[0]);
}
});
},
changeImgToBase64(source_img) {
uni.getFileSystemManager().readFile({
filePath: source_img,
encoding: "base64",
success: (res) => {
console.log("加密之后的图片格式:" + JSON.stringify(res));
this.makeFinalResult(res.data);
},
});
},
async makeFinalResult(base64) {
let token = await uni.request({
url: 'https://aip.baidubce.com/oauth/2.0/token',
data: {
grant_type: 'client_credentials',
client_id: '2kKeVk6LvdFX8knIyYUodMDr',
client_secret: '9pSXGfzvv7q1Fo76WRkeyXVpZGrj8zxb',
},
success: (res) => {
console.log("获取token:===>" + res.data.access_token);
token = res.data.access_token;
},
});
uni.request({
url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/household_register?access_token=' + token,
method: 'POST',
data: {
image: base64,
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success: (res) => {
console.log("最终的结果:" + JSON.stringify(res));
//this.personname = res.words_result.Name.words;
},
});
},
},
};
</script>
<style lang="scss">
.show {
display: flex;
justify-content: center;
height: 100vh;
align-items: center;
}
<style>
最新发布