身份证正面,文件上传

This commit is contained in:
2024-09-20 16:10:08 +08:00
parent e768f9c8f8
commit 250e68bed7

View File

@ -16,23 +16,29 @@
<img class="startImg" src="@/assets/start.png" />
<span>身份证正面</span>
</div>
<van-field label="文件上传">
<template slot="input">
<!-- 上传组件要兼容安卓必须设置before-read对文件进行预处理 -->
<van-uploader :before-read="beforeRead" accept="image/*" v-model="identityCardFrontList"
:preview-size="54"
:max-count="1" :after-read="identityCardFrontHandler" />
</template>
</van-field>
<!-- <van-uploader
<!-- <el-upload
:action="baseURL + '/order/uploadImage'"
:headers='authorization'
accept=".png,.jpg,.jpeg,.zip,.rar,.xlsx,.xsavels,.pdf,.PDF,.doc,.docx"
:on-success="changeHandle"
:before-upload="beforeAvatarUpload"
class="avatar-uploader"
:show-file-list="false"
>
<el-button slot="default" style="margin: 15px" size="mini" type="primary"
class="add">
点击上传
</el-button>
</el-upload>-->
<van-uploader
v-model="identityCardFrontList"
:before-read="beforeRead"
:after-read="identityCardFrontHandler"
:max-count="1"
capture="camera"
:preview-size="54"
accept="image/png, image/jpeg"
/>-->
/>
</div>
<div class="lineBot"></div>
<div class="itemContent">
@ -153,6 +159,8 @@ export default {
mixins:[myMixins],
data(){
return{
baseURL:'',
licenseOcrInfo:'',
id:'',
driverName:"",
driverPhone:"",
@ -178,11 +186,22 @@ export default {
idCardAuthority:'',
idCardValidStartTime:'',
idCardValidEndTime:'',
token:''
authorization:{Authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzb25nIiwiYXVkIjpbInN1cHBsaWVyLWFwcCJdLCJuYmYiOjE3MjY4MDk4MTQsInVzZXJfaW5mbyI6eyJ1c2VySWQiOjU0NjU0LCJwaG9uZSI6IjE3NjMwMDM1NjU4IiwibmFtZSI6InNvbmciLCJzdXBwbGllck5hbWUiOiLkuIrmtbfmtYvor5XkvpvlupTllYYiLCJzdXBwbGllcklkIjozMzA0MSwic3VwcGxpZXJUeXBlIjoyLCJ1c2VybmFtZSI6InNvbmciLCJ1c2VyVHlwZSI6InJlc2N1ZUFwcCIsImRldmljZUlkIjoiMTkwZTM1ZjdlMTRhYzdjMDAwNyIsImF1dGhvcml0aWVzIjpbXX0sInNjb3BlIjpbImFsbCJdLCJpc3MiOiJodHRwczovL3Npbm9hc3Npc3QuY29tIiwiZXhwIjoxNzI2ODk2MjE0LCJpYXQiOjE3MjY4MDk4MTR9.5KTAMXZf8ll6HS4Z49YJQ1HiRvHr79Q1goDAGEtsBmY'},
fileList:'',
file:'',
}
},
mounted() {
this.token = localStorage.getItem('token');
if (window.location.href.includes('www.sinoassist.com')) {
this.baseURL = 'https://api.sinoassist.com'
} else if (window.location.href.includes('ccreview.sino-assist.com')) {
this.baseURL = 'https://api.sinoassist.com'
} else {
// this.baseURL = 'https://api1.sino-assist.com'
this.baseURL = 'http://localhost:8080'
}
// this.authorization={Authorization: localStorage.getItem('token')}
// this.requestPermissions();
this.id = this.$route.params?.id;
this.driverName = this.$route.params?.name;
@ -239,29 +258,23 @@ export default {
isUse(e){
this.states=e
},
// 返回布尔值
beforeRead(file) {
this.$toast('beforeReadbeforeReadbeforeRead');
console.log("beforeRead",file)
if (file.type !== 'image/jpeg') {
this.$toast('请上传 jpg 格式图片');
return false;
}
return true;
/* beforeAvatarUpload(file){
this.licenseOcrInfo= file
},
async changeHandle() {
const formData = new FormData()
formData.append('file', this.licenseOcrInfo);
/!* await this.$post(this.$api.supplier.supplierApproval.recognizeBusinessLicense, formData).then((res) => {
});*!/
},*/
beforeRead(){
console.log("-----------")
},
async identityCardFrontHandler(file, detail) { // 上传身份证正面照片
console.log("检查文件类型",file, detail)
// 检查文件类型
if (!file.file.type.startsWith('image/')) {
this.$toast('请选择图片文件');
return;
}
console.log("上传身份证正面照片",file)
// 检查文件大小
if (file.file.size > 5 * 1024 * 1024) {
this.$toast('文件大小不能超过 5MB');
// return;
}
const formData = new FormData();
formData.append("file" , file.file);
let res = await uploadImage(formData)