This commit is contained in:
2023-09-17 13:18:59 +08:00
parent bf05f771f7
commit 9e871e4079
23 changed files with 1086 additions and 606 deletions

View File

@@ -24,11 +24,11 @@
<view class="mt20">
<view class="title fontColor">第二步 核实后再提交</view>
<u--form labelPosition="left" labelWidth="80" :model="form" :rules="rules" ref="form1">
<u-form-item label="姓名" :required="true" prop="name" borderBottom ref="item1">
<u--input v-model="form.name" border="none"></u--input>
<u-form-item label="姓名" :required="true" prop="idCardName" borderBottom ref="item1">
<u--input v-model="form.idCardName" border="none"></u--input>
</u-form-item>
<u-form-item label="身份证号" :required="true" prop="idNum" borderBottom ref="item2">
<u--input v-model="form.idNum" border="none"></u--input>
<u-form-item label="身份证号" :required="true" prop="sfzmhm" borderBottom ref="item2">
<u--input v-model="form.sfzmhm" border="none"></u--input>
</u-form-item>
</u--form>
</view>
@@ -42,6 +42,9 @@
<script>
import storage from '@/jtools/storage';
import {
addInfo,
} from '@/jtools/api/index';
export default {
data() {
const shenfenzhen = (rule, value, callback) => {
@@ -50,20 +53,21 @@
}
return {
form: {
name: '',
idNum: ''
idCardName: '',
sfzmhm: ''
},
driverLicenseImg:'',
fileList:[],
fileList1: [],
uploadList: [],
saving: false,
rules: {
name: [{
idCardName: [{
required: true,
message: '请输入姓名',
trigger: ['blur', 'change']
}],
idNum: [{
sfzmhm: [{
required: true,
message: '请输入身份证号',
trigger: ['blur', 'change']
@@ -78,13 +82,6 @@
};
},
onReady() {
if(storage.get('photoForm')){
this.fileList=storage.get('photoForm').file
this.form={
name: storage.get('photoForm').name,
idNum: storage.get('photoForm').idNum
}
}
this.$refs.form1.setRules(this.rules);
},
methods: {
@@ -95,7 +92,17 @@
},
// 新增图片
async afterRead(event) {
// this.compressImage(event.file);
let imageInfoObj = await uni.getImageInfo({src: event.file[0].url})
console.log(imageInfoObj);
if(imageInfoObj.width!=720&&imageInfoObj.height!=720){
uni.showToast({
icon:'error',
title:'证件照尺寸有误'
})
this.fileList=[]
return false
}
this.driverLicenseImg = this.urlTobase64(event.file[0].url)
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
const lists = [].concat(event.file);
this.fileList=lists
@@ -129,62 +136,47 @@
this.$refs.form1.validate().then((valid) => {
if (valid) {
const param={
file:this.fileList,
...this.form
driverLicenseImg:this.driverLicenseImg,
...this.form,
schoolOrgCode:'340103000700',
operater:'1d08daf852cf4ee28f67cb583f538cbf'
}
storage.set('photoForm',param)
uni.showToast({
title:"提交成功!",
duration:2000,
addInfo(param).then(resp=>{
uni.showToast({
title:"提交成功!",
duration:2000,
})
setTimeout(()=>{
uni.navigateBack()
},1000)
})
setTimeout(()=>{
uni.navigateBack()
},1000)
} else {
console.log('验证失败');
}
});
},
async compressImage(image) {
const img = new Image();
img.src = image.url;
img.onload = async () => {
const canvas = document.createElement('canvas'); // 创建Canvas对象(画布)
const context = canvas.getContext('2d');
// 默认按比例压缩
const cw = img.width;
const ch = img.height;
let w = img.width;
let h = img.height;
canvas.width = w;
canvas.height = h;
if (cw > 400 && cw > ch) {
w = 400;
h = (400 * ch) / cw;
canvas.width = w;
canvas.height = h;
}
if (ch > 400 && ch > cw) {
h = 400;
w = (400 * cw) / ch;
canvas.width = w;
canvas.height = h;
}
// 生成canvas
let base64;
// 创建属性节点
context.clearRect(0, 0, 0, w, h);
context.drawImage(img, 0, 0, w, h);
if (image.size > 2000000) {
// 如果图片超过2m,则进行压缩
base64 = canvas.toDataURL(image['type'], 0.5);
}
const result = await this.uploadFilePromise(base64 || image.url);
this.uploadList.push(result);
};
urlTobase64(url){
let base64=''
console.log(url);
return new Promise((resolve, reject) => {
uni.getFileSystemManager().readFile({
filePath: url, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success: res => { //成功的回调
console.log(res);
base64 = 'data:image/jpeg;base64,' + res.data //不加上这串字符,在页面无法显示的哦
resolve(base64);
},fail: (e) => {
console.log("图片转换失败");
reject(e)
}
})
});
}
}
};
</script>