司机,车辆 添加ocr 识别

This commit is contained in:
2024-04-07 16:57:44 +08:00
parent 8891738455
commit 867cbee6c7
5 changed files with 394 additions and 32 deletions

View File

@ -178,3 +178,23 @@ export function userOperationPermissions(){
method:'POST',
})
}
// 上传图片
export function uploadImage(data){
return request({
url:'/order/uploadImage',
method:'POST',
contentType:'multipart/form-data',
data
})
}
// ocr 识别
export function ocrHandler(data){
return request({
url:'/agg-api/tencent-ocr/unifiedOCR',
method:'POST',
contentType:'application/json',
data
})
}

View File

@ -18,10 +18,10 @@ service.interceptors.request.use(
let reqUrl=config.url
config.data = config.contentType ? config.data : qs.stringify(config.data)
config.headers['Content-Type'] = config.contentType || 'application/x-www-form-urlencoded'
let token = localStorage.getItem('token');
// let token = localStorage.getItem('token');
// alert(token);
// let token='4099761587129c46b03c9316c9e866c9'
// let token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJTSENTR1lTIiwiYXVkIjpbInN1cHBsaWVyLWFwcCJdLCJuYmYiOjE3MDgzMjY3NTAsInVzZXJfaW5mbyI6eyJ1c2VySWQiOjUwMTk3LCJuYW1lIjoi5LiK5rW35rWL6K-V5L6b5bqU5ZWGIiwic3VwcGxpZXJOYW1lIjoi5LiK5rW35rWL6K-V5pyN5Yqh5ZWGIiwic3VwcGxpZXJJZCI6MzMwNDEsInN1cHBsaWVyVHlwZSI6MSwiaXNaZCI6MCwidXNlcm5hbWUiOiJTSENTR1lTIiwidXNlclR5cGUiOiJyZXNjdWVBcHAiLCJkZXZpY2VJZCI6IjJjMGU0N2JiMWQxNGYzYTY3YjhkOGRjMTUyM2VhMmQ3MCIsImF1dGhvcml0aWVzIjpbXX0sInNjb3BlIjpbImFsbCJdLCJpc3MiOiJodHRwczovL3Npbm9hc3Npc3QuY29tIiwiZXhwIjoxNzA4NDEzMTUwLCJpYXQiOjE3MDgzMjY3NTB9.hJ4TkZpsDW0c_-o4qopSxNyLyCtCRuuLzKAvH1xQgOw'
let token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzb25nIiwiYXVkIjpbInN1cHBsaWVyLWFwcCJdLCJuYmYiOjE3MTI0NTQ5NTMsInVzZXJfaW5mbyI6eyJ1c2VySWQiOjU0NjU0LCJwaG9uZSI6IjE3NjMwMDM1NjU4IiwibmFtZSI6InNvbmciLCJzdXBwbGllck5hbWUiOiJDLeS4iua1t-a1i-ivleacjeWKoeWVhiIsInN1cHBsaWVySWQiOjMzMDQxLCJzdXBwbGllclR5cGUiOjIsInVzZXJuYW1lIjoic29uZyIsInVzZXJUeXBlIjoicmVzY3VlQXBwIiwiZGV2aWNlSWQiOiIyMmI0OWNhMjBmOWI4MzMwZDk4NzIxNzNmMzllYTY4YmMiLCJhdXRob3JpdGllcyI6W119LCJzY29wZSI6WyJhbGwiXSwiaXNzIjoiaHR0cHM6Ly9zaW5vYXNzaXN0LmNvbSIsImV4cCI6MTcxMjU0MTM1MywiaWF0IjoxNzEyNDU0OTUzfQ.sPU9_OD_TOWcTwqmlawEGyo4mCPrEaRYw2R02gnvYJw'
// console.log("tokentokentoken",token)
if (reqUrl.includes("/driverApp")) {
config.headers['token'] = `${token}`;

View File

@ -11,7 +11,76 @@
@click-left="h5GoBack"
/>
</div>
<cell-group label="司机姓名" placeholder="请输入司机姓名" v-model="driverName" :disabled="supplierType ==1 ? true:false"/>
<div class="itemContent">
<div class="titleType">
<img class="startImg" src="@/assets/start.png" />
<span>身份证正面</span>
</div>
<van-uploader
v-model="identityCardFrontList"
:after-read="identityCardFrontHandler"
max-count="1"
:preview-size="54"
accept="image "
/>
</div>
<div class="lineBot"></div>
<div class="itemContent">
<div class="titleType">
<img class="startImg" src="@/assets/start.png" />
<span>身份证反面</span>
</div>
<van-uploader
v-model="identityCardContraryList"
:after-read="identityCardBackHandler"
max-count="1"
:preview-size="54"
accept="image "
/>
</div>
<div class="lineBot"></div>
<div class="itemContent">
<div class="titleType">
<img class="startImg" src="@/assets/start.png" />
<span>驾驶证主页</span>
</div>
<van-uploader
v-model="drivingLicenceFrontList"
:after-read="drivingLicenceFrontHandler"
max-count="1"
:preview-size="54"
accept="image "
/>
</div>
<div class="lineBot"></div>
<div class="itemContent">
<div class="titleType">
<img class="startImg" src="@/assets/start.png" />
<span>驾驶证副页</span>
</div>
<van-uploader
v-model="drivingLicenceContraryList"
:after-read="drivingLicenceContraryHandler"
max-count="1"
:preview-size="54"
accept="image "
/>
</div>
<div class="lineBot"></div>
<div class="itemContent">
<div class="titleType">
<span>头像</span>
</div>
<van-uploader
v-model="iconList"
:after-read="iconListHandler"
max-count="1"
:preview-size="54"
accept="image "
/>
</div>
<div class="lineBot"></div>
<cell-group label="司机姓名" placeholder="请输入司机姓名" v-model="driverName" aria-readonly="true" :disabled="supplierType ==1 ? true:false"/>
<cell-group label="手机号码" v-model="driverPhone" placeholder="请输入手机号" />
<cell-group label="身份证号" v-model="identityCardNumber" placeholder="请输入身份证号" />
<div class="itemContent">
@ -63,7 +132,7 @@
<script>
import {myMixins} from "@/utils/myMixins"
import {saveDriver} from "@/api/mine"
import {saveDriver, uploadImage, ocrHandler} from "@/api/mine"
import TwoCommonBtn from "@/components/twoBtnCommon.vue"
import CellGroup from "@/components/cellGroup.vue"
export default {
@ -80,7 +149,19 @@ export default {
activeIcon: require('@/assets/check.png'),
inactiveIcon: require('@/assets/uncheck.png'),
supplierType:'',
createTime:''
createTime:'',
identityCardFront: '', // 身份证正面
identityCardFrontList: [], // 身份证正面 列表
identityCardContrary: '', // 身份证反面
identityCardContraryList: [], // 身份证反面 列表
drivingLicenceFront: '', // 驾驶证正面
drivingLicenceFrontList: [], // 驾驶证正面 列表
drivingLicenceContrary: '', // 驾驶证反面
drivingLicenceContraryList: [], // 驾驶证反面 列表
icon: '',
iconList: [],
driverInfo: {},
drivingLicenceName: '',
}
},
mounted() {
@ -92,6 +173,20 @@ export default {
this.states = this.$route.params?.states;
this.supplierType=this.$route.params?.supplierType;
this.createTime=this.$route.params?.createTime;
this.driverInfo.drivingBeginDate = this.$route.params?.drivingBeginDate;
this.drivingLicenceContrary = this.$route.params?.drivingLicenceContrary;
this.drivingLicenceFront = this.$route.params?.drivingLicenceFront;
this.driverInfo.drivingLicenceValidityDate = this.$route.params?.drivingLicenceValidityDate;
this.icon = this.$route.params?.icon;
this.identityCardContrary = this.$route.params?.identityCardContrary;
this.identityCardFront = this.$route.params?.identityCardFront;
this.driverInfo.lssueDate = this.$route.params?.lssueDate;
this.drivingLicenceName = this.$route.params?.drivingLicenceName;
this.identityCardFrontList = [{ url : this.identityCardFront }];
this.identityCardContraryList = [{ url : this.identityCardContrary }];
this.drivingLicenceFrontList = [{ url : this.drivingLicenceFront }];
this.drivingLicenceContraryList = [{ url : this.drivingLicenceContrary }];
this.iconList = [{ url : this.icon }];
const selectElement = document.getElementById('mySelect');
selectElement.addEventListener('change', function() {
const selectedValue = selectElement.value;
@ -103,25 +198,122 @@ export default {
isUse(e){
this.states=e
},
async submitBtn(){
await saveDriver({
driverId:this.id ? this.id : '',
driverName:this.driverName ,
driverPhone:this.driverPhone,
identityCardNumber:this.identityCardNumber,
drivingModel:this.drivingModel,
states:Number(this.states),
createTime:this.createTime || ''
})
if(this.id){
this.$toast('修改成功')
}else{
this.$toast('添加成功')
async identityCardFrontHandler(file) { // 上传身份证正面照片
const formData = new FormData();
formData.append("file" , file.file);
let res = await uploadImage(formData)
this.identityCardFront = res.data;
await this.idCardOcrHandler();
},
async identityCardBackHandler(file) { // 上传身份证反面照片
const formData = new FormData();
formData.append("file" , file.file);
let res = await uploadImage(formData)
this.identityCardContrary = res.data;
},
async drivingLicenceFrontHandler(file) { // 上传驾驶证主页
const formData = new FormData();
formData.append("file" , file.file);
let res = await uploadImage(formData)
this.drivingLicenceFront = res.data;
await this.drivingLicenceOcrHandler();
},
async drivingLicenceContraryHandler(file) { // 上传驾驶证副页
const formData = new FormData();
formData.append("file" , file.file);
let res = await uploadImage(formData)
this.drivingLicenceContrary = res.data;
},
async iconListHandler(file) { // 上传头像
const formData = new FormData();
formData.append("file" , file.file);
let res = await uploadImage(formData)
this.icon = res.data;
},
async idCardOcrHandler() { // 身份证正面 ocr识别
let res = await ocrHandler({
ocrType: 1,
imageUrl: this.identityCardFront,
cardSide: 'FRONT'
})
this.driverName = res?.data?.name;
this.identityCardNumber = res?.data?.idNum;
if( this.drivingLicenceName && this.driverName != this.drivingLicenceName ) {
this.$toast('身份证信息与驾驶证信息不匹配')
}
},
async drivingLicenceOcrHandler() { // 驾驶证正面 ocr识别
let res = await ocrHandler({
ocrType: 2,
imageUrl: this.drivingLicenceFront,
cardSide: 'FRONT'
});
if( res?.data ) {
this.driverInfo.drivingBeginDate = res?.data?.dateOfFirstIssue;
this.driverInfo.lssueDate = res?.data?.dateOfFirstIssue ? (res?.data?.dateOfFirstIssue + ' 00:00:00') : '';
this.driverInfo.drivingLicenceValidityDate = res?.data?.endDate;
this.drivingModel = res.data?.class_;
this.drivingLicenceName = res.data?.name
if( this.driverName && this.drivingLicenceName != this.driverName ) {
this.$toast('身份证信息与驾驶证信息不匹配')
}
}
},
async submitBtn(){
if(!this.identityCardFront) {
this.$toast('身份证正面照未上传')
return
}
if(!this.identityCardContrary) {
this.$toast('身份证反面照未上传')
return
}
if(!this.drivingLicenceFront) {
this.$toast('驾驶证首页未上传')
return
}
if(!this.drivingLicenceContrary) {
this.$toast('驾驶证副页未上传')
return
}
if( this.drivingLicenceName != this.driverName ) {
this.$toast('身份证信息与驾驶证信息不匹配')
return
}
if( this.driverInfo.drivingLicenceValidityDate ) {
if( new Date(this.driverInfo.drivingLicenceValidityDate).getTime() < new Date().getTime() ) {
this.$toast('驾驶证已过期')
return
}
} else {
this.$toast('驾驶证信息识别错误,请重新上传')
return
}
await saveDriver({
driverId:this.id ? this.id : '',
driverName:this.driverName ,
driverPhone:this.driverPhone,
identityCardNumber:this.identityCardNumber,
drivingModel:this.drivingModel,
states:Number(this.states),
createTime:this.createTime || '',
identityCardFront: this.identityCardFront,
identityCardContrary: this.identityCardContrary,
drivingLicenceFront: this.drivingLicenceFront,
drivingLicenceContrary: this.drivingLicenceContrary,
icon: this.icon,
drivingLicenceName: this.drivingLicenceName,
...this.driverInfo
})
if(this.id){
this.$toast('修改成功')
}else{
this.$toast('添加成功')
}
setTimeout(()=>{
this.$router.back();
},2000)
},
},
},
components:{
TwoCommonBtn,
@ -137,6 +329,8 @@ export default {
@include wh(100%,100%);
box-sizing: border-box;
padding-left: 16px;
padding-bottom: 100px;
overflow-y: auto;
}
.mySelect{
@include fontWeightSize(bold,13px);

View File

@ -162,7 +162,16 @@ export default {
identityCardNumber:item.identityCardNumber,
states:item.states.code,
createTime:item.createTime,
supplierType:this.supplierType
supplierType:this.supplierType,
drivingBeginDate: item.drivingBeginDate,
drivingLicenceContrary: item.drivingLicenceContrary,
drivingLicenceFront: item.drivingLicenceFront,
drivingLicenceValidityDate: item.drivingLicenceValidityDate,
icon: item.icon,
identityCardContrary: item.identityCardContrary,
identityCardFront: item.identityCardFront,
lssueDate: item.lssueDate,
drivingLicenceName: item.drivingLicenceName
}
});
},
@ -249,4 +258,4 @@ export default {
}
}
</style>
</style>

View File

@ -12,6 +12,46 @@
/>
</div>
<div class="addContentWrap">
<div class="itemContent">
<div class="titleType">
<img class="startImg" src="@/assets/start.png" />
<span>行驶证首页</span>
</div>
<van-uploader
v-model="vehicleLicenseFrontList"
:after-read="vehicleLicenseFrontHandler"
max-count="1"
:preview-size="54"
accept="image "
/>
</div>
<div class="itemContent">
<div class="titleType">
<img class="startImg" src="@/assets/start.png" />
<span>行驶证副页</span>
</div>
<van-uploader
v-model="vehicleLicenseBackList"
:after-read="vehicleLicenseBackHandler"
max-count="1"
:preview-size="54"
accept="image "
/>
</div>
<div class="itemContent">
<div class="titleType">
<img class="startImg" src="@/assets/start.png" />
<span>车头照</span>
</div>
<van-uploader
v-model="vehicleFrontPhotoList"
:after-read="vehicleFrontPhotoHandler"
max-count="1"
:preview-size="54"
accept="image "
/>
</div>
<cell-group label="车牌号" placeholder="请输入车牌号" v-model="carNum" />
<div class="itemContent">
<div class="titleType">
@ -78,8 +118,9 @@
</template>
<script>
// uploadImage
import {myMixins} from "@/utils/myMixins"
import {vehicleTypeList,saveVehicle,getInfoById,supplierServiceTree} from "@/api/mine"
import {vehicleTypeList,saveVehicle,getInfoById,supplierServiceTree, uploadImage, ocrHandler} from "@/api/mine"
import TwoCommonBtn from "@/components/twoBtnCommon.vue"
import CellGroup from "@/components/cellGroup.vue";
export default {
@ -100,7 +141,14 @@ export default {
serviceIds:[],//车辆服务种类,
supplierServiceList:[],
show:false,
imageUrl: require('@/assets/arr_right.png')
imageUrl: require('@/assets/arr_right.png'),
vehicleLicenseFrontList: [],
vehicleLicenseBackList: [],
vehicleFrontPhotoList: [],
vehicleLicenseFront: '', // 行驶证首页
vehicleLicenseBack: '', // 行驶证副页
vehicleFrontPhoto: '', // 车头照
vehicleLicenseInfo: {},
}
},
async mounted() {
@ -116,6 +164,66 @@ export default {
await this.getSupplierServiceTree();
},
methods:{
async vehicleLicenseFrontHandler(file) { // 上传 行驶证首页
const formData = new FormData();
formData.append("file" , file.file);
let res = await uploadImage(formData)
this.vehicleLicenseFront = res.data;
await this.vehicleOcrHandler();
},
async vehicleLicenseBackHandler(file) { // 上传 行驶证副页
const formData = new FormData();
formData.append("file" , file.file);
let res = await uploadImage(formData);
this.vehicleLicenseBack = res.data;
await this.vehicleBackOcrHandler();
},
async vehicleFrontPhotoHandler(file) { // 上传 车头照
const formData = new FormData();
formData.append("file" , file.file);
let res = await uploadImage(formData);
this.vehicleFrontPhoto = res.data;
},
async vehicleOcrHandler() { // 行驶证首页 ocr 识别
let res = await ocrHandler({
ocrType: 3,
imageUrl: this.vehicleLicenseFront,
cardSide: 'FRONT'
})
if ( res?.data?.frontInfo ) {
let frontInfo = res?.data?.frontInfo;
this.carNum = frontInfo?.plateNo;
this.vehicleLicenseInfo.licensePlateNumber = frontInfo?.plateNo;
this.vehicleLicenseInfo.vehicleType = frontInfo?.vehicleType;
this.vehicleLicenseInfo.owner = frontInfo?.owner;
this.vehicleLicenseInfo.address = frontInfo?.address;
this.vehicleLicenseInfo.useNature = frontInfo?.useCharacter;
this.vehicleLicenseInfo.model = frontInfo?.model;
this.vehicleLicenseInfo.vinCode = frontInfo?.vin;
this.vehicleLicenseInfo.engineNumber = frontInfo?.engineNo;
this.vehicleLicenseInfo.registrationDate = frontInfo?.registerDate;
this.vehicleLicenseInfo.issueDate = frontInfo?.issueDate;
this.vehicleLicenseInfo.issueAuthority = frontInfo?.seal;
}
},
async vehicleBackOcrHandler() { // 行驶证副页 ocr 识别
let res = await ocrHandler({
ocrType: 3,
imageUrl: this.vehicleLicenseBack,
cardSide: 'BACK'
})
if(res?.data?.backInfo) {
let backInfo = res?.data?.backInfo;
this.vehicleLicenseInfo.recordNumber = backInfo?.fileNo;
this.vehicleLicenseInfo.passengerCapacity = backInfo?.allowNum;
this.vehicleLicenseInfo.totalWeight = backInfo?.totalMass;
this.vehicleLicenseInfo.curbWeight = backInfo?.curbWeight;
this.vehicleLicenseInfo.permittedWeight = backInfo?.loadQuality;
this.vehicleLicenseInfo.overallDimension = backInfo?.externalSize;
this.vehicleLicenseInfo.tractionWeight = backInfo?.TotalQuasiMass;
}
console.log('this.vehicle', this.vehicleLicenseInfo)
},
loadAll(i){
// console.log(i)
this.show = !this.show
@ -145,23 +253,54 @@ export default {
let res= await getInfoById({
vehicleId:this.id
})
let result=res.data;
this.id=result.vehicleId
this.carNum=result.plateNumber
this.isJoin=result.hasPolymerization.code
this.selectedOption=result.vehicleType;
this.serviceIds=result.serviceIds
let result=res.data;
this.id=result.vehicleId
this.carNum=result.plateNumber
this.isJoin=result.hasPolymerization.code
this.selectedOption=result.vehicleType;
this.serviceIds=result.serviceIds
this.vehicleLicenseFront = result.vehicleLicenseFront;
this.vehicleLicenseBack = result.vehicleLicenseBack;
this.vehicleFrontPhoto = result.vehicleFrontPhoto;
this.vehicleLicenseInfo = result.vehicleLicenseInfo;
this.vehicleLicenseFrontList = [{ url : this.vehicleLicenseFront }];
this.vehicleLicenseBackList = [{ url : this.vehicleLicenseBack }];
this.vehicleFrontPhotoList = [{ url : this.vehicleFrontPhoto }];
},
isChange(e){
this.isJoin=e
},
async submitBtn(){
if( !this.vehicleLicenseFront ) {
this.$toast('行驶证主页照片不能为空')
return
}
if( !this.vehicleLicenseBack ) {
this.$toast('行驶证副页照片不能为空')
return
}
if( !this.vehicleLicenseBack ) {
this.$toast('车头照片不能为空')
return
}
if( !this.vehicleLicenseInfo.licensePlateNumber ) {
this.$toast('行驶证主页识别失败')
return
}
if( !this.vehicleLicenseInfo.recordNumber ) {
this.$toast('行驶证副页识别失败')
return
}
await saveVehicle({
vehicleId:this.id ? this.id : '',
plateNumber:this.carNum ? this.carNum :'',
vehicleType:this.selectedOption ? this.selectedOption : '',
hasPolymerization:this.isJoin,
serviceIds:this.serviceIds ? this.serviceIds : []
serviceIds:this.serviceIds ? this.serviceIds : [],
vehicleLicenseFront: this.vehicleLicenseFront,
vehicleLicenseBack: this.vehicleLicenseBack,
vehicleFrontPhoto: this.vehicleFrontPhoto,
vehicleLicenseInfo: this.vehicleLicenseInfo,
})
if(this.id){
this.$toast('修改成功')
@ -274,4 +413,4 @@ export default {
margin: 40px 0 30px 8px;
}
}
</style>
</style>