DESKTOP-B78GIPM\admin лет назад: 2
Родитель
Сommit
a7bae08c93
2 измененных файлов с 75 добавлено и 68 удалено
  1. 46 41
      pages/face/index.vue
  2. 29 27
      pages/index/index.vue

+ 46 - 41
pages/face/index.vue

@@ -253,42 +253,41 @@
 				let ctx = uni.createCanvasContext('cvs', this);
 				// let ctx = this.$refs.canvas.getContext("2d");
 				const _this = this
-				// this.intervalTakeImg = setInterval(() => {
-					
-				// }, 4000)
-				// 把当前视频帧内容渲染到canvas上
-				// ctx.drawImage(document.createElement('canvas'), 0, 0, 520, 520);
-				// 修改后代码 将 html2Cvs 修改为 (window.html2Cvs || html2Cvs)
-				html2Cvs(document.querySelector('video'), {
-					backgroundColor: null,
-					useCORS: true
-				}).then(cvs => {
-					let imgData = cvs.toDataURL('image/png')
-					this.faceImgData = imgData
-					// this.type = 2
-					this.faceRecognition()
-					// this.intervalTakeImg = null
-					// clearInterval(this.intervalTakeImg)
-					// ctx.drawImage(imgData, 0, 0, 520, 520);
-				})
-				// 转base64格式、图片格式转换、图片质量压缩
-				// console.log('canvas', document.createElement('canvas').toDataURL("image/jpeg", 0.7))
-				// return
-				let imgBase64 = document.createElement('canvas').toDataURL("image/jpeg", 0.7); // 由字节转换为KB 判断大小
-				// let imgBase64 = this.$refs["canvas"].toDataURL("image/jpeg", 0.7); // 由字节转换为KB 判断大小
-				// console.log('canver', this.$refs["canvas"])
-				
-				// console.log('%cHealthEduOnline.vue line:92 imgBase64', 'color: white; background-color: #26bfa5;', imgBase64);
-				let str = imgBase64.replace("data:image/jpeg;base64,", "");
-				let strLength = str.length;
-				let fileLength = parseInt(strLength - (strLength / 8) * 2); // 图片尺寸  用于判断
-				let size = (fileLength / 1024).toFixed(2);
-				console.log(size); // 上传拍照信息  调用接口上传图片 .........
-				
-				// 保存到本地
-				this.dialogCamera = false;
-				// this.faceRecognition()
-				clearInterval(this.intervalTakeImg)
+				this.intervalTakeImg = setInterval(() => {
+					// 把当前视频帧内容渲染到canvas上
+					// ctx.drawImage(document.createElement('canvas'), 0, 0, 520, 520);
+					// 修改后代码 将 html2Cvs 修改为 (window.html2Cvs || html2Cvs)
+					html2Cvs(document.querySelector('video'), {
+						backgroundColor: null,
+						useCORS: true
+					}).then(cvs => {
+						let imgData = cvs.toDataURL('image/png')
+						this.faceImgData = imgData
+						// this.type = 2
+						this.faceRecognition()
+						// this.intervalTakeImg = null
+						// clearInterval(this.intervalTakeImg)
+						// ctx.drawImage(imgData, 0, 0, 520, 520);
+					})
+					// 转base64格式、图片格式转换、图片质量压缩
+					// console.log('canvas', document.createElement('canvas').toDataURL("image/jpeg", 0.7))
+					// return
+					let imgBase64 = document.createElement('canvas').toDataURL("image/jpeg", 0.7); // 由字节转换为KB 判断大小
+					// let imgBase64 = this.$refs["canvas"].toDataURL("image/jpeg", 0.7); // 由字节转换为KB 判断大小
+					// console.log('canver', this.$refs["canvas"])
+
+					// console.log('%cHealthEduOnline.vue line:92 imgBase64', 'color: white; background-color: #26bfa5;', imgBase64);
+					let str = imgBase64.replace("data:image/jpeg;base64,", "");
+					let strLength = str.length;
+					let fileLength = parseInt(strLength - (strLength / 8) * 2); // 图片尺寸  用于判断
+					let size = (fileLength / 1024).toFixed(2);
+					console.log(size); // 上传拍照信息  调用接口上传图片 .........
+
+					// 保存到本地
+					this.dialogCamera = false;
+					// this.faceRecognition()
+					clearInterval(this.intervalTakeImg)
+				}, 4000)
 				// let ADOM = document.createElement("a");
 				// ADOM.href = imgBase64 ;
 				// ADOM.download = new Date().getTime() + ".jpeg";
@@ -315,18 +314,24 @@
 							this.name = res.data[0].name
 							this.getBasics()
 							this.closeCamera()
-							if(this.intervalTakeImg){
-								this.show = false
-								clearInterval(this.intervalTakeImg)
-								this.intervalTakeImg = null
-							}
+							// if(this.intervalTakeImg){
+							// 	this.show = false
+							// 	clearInterval(this.intervalTakeImg)
+							// 	this.intervalTakeImg = null
+							// }
 							// clearInterval(this.intervalTakeImg)
+							this.show = false
+							clearInterval(this.intervalTakeImg)
+							this.intervalTakeImg = null
 							return
 						}else{
 							// this.toAdd(res.data[0].name)
 							console.log('w')
 							this.type = 3
 							this.closeCamera()
+							this.show = false
+							clearInterval(this.intervalTakeImg)
+							this.intervalTakeImg = null
 							
 							return
 						}

+ 29 - 27
pages/index/index.vue

@@ -24,8 +24,8 @@
 
 		<view v-if="tobu == 1">
 			<u-swipe-action>
-				<u-swipe-action-item style="margin-bottom: 32rpx;" v-for="item in listData" :options="swipe"
-					:disabled="swipeShow" @click="cancelT(item)">
+				<u-swipe-action-item style="margin-bottom: 32rpx;" v-for="(item, index) in listData" :options="swipe"
+					:disabled="swipeShow" @click="cancelT(item)" :key="index">
 
 					<!-- 任务分块部分 -->
 					<view class="chunking">
@@ -213,25 +213,7 @@
 		watch:{
 			listData(newName, oldName){
 				let time = 1000
-				for(let item of newName){
-					if(item.headUrl == null){
-						setTimeout(()=>{
-							// 获取头像
-							this.$request({
-								url: this.$api.index.getPortrait,
-								data: {
-									id: item.studentId,
-									studentId: item.studentId,
-									// id: '1612686444118147074',
-									// studentId: '1612686444118147074',
-								}
-							}).then(res => {
-								item.headUrl = res.data
-							})
-						}, time)
-						time += 1000
-					}
-				}
+				
 			},
 		},
 		methods: {
@@ -247,7 +229,7 @@
 			getList() {
 				let data = {
 					pageNum: this.page,
-					pageSize: 10,
+					pageSize: 5,
 					type: this.tobu,
 				}
 				if(this.key){
@@ -256,7 +238,7 @@
 				this.$request({
 					url: this.$api.index.emergencyList,
 					data: data
-				}).then(res => {
+				}).then( res => {
 					if (res.code == 200) {
 						
 						for (let item of res.data.list) {
@@ -265,12 +247,12 @@
 						}
 						this.listData.push(...res.data.list)
 						this.total = res.data.total
-						if (res.data.total > 10) {
+						if (res.data.total > 5) {
 							this.status = 'loadmore'
 						} else {
 							this.status = 'nomore'
 						}
-						
+						this.getChildHead()
 					} else {
 						this.$u.toast(err.message)
 						this.status = 'nomore'
@@ -282,7 +264,27 @@
 					this.listData = []
 				})
 			},
-			
+			getChildHead(){
+				for(let index = 0 ;index< this.listData.length ;index++){
+					let item = this.listData[index]
+					if(item.headUrl) continue;
+					let existIndex = this.listData.findIndex(s=>s.studentId == item.studentId && s.headUrl)
+					if(existIndex > -1) {
+						item.headUrl = this.listData[existIndex].headUrl
+						continue;
+					}
+					 this.$request({
+						url: this.$api.index.getPortrait,
+						data: {
+							id: item.studentId,
+							studentId: item.studentId,
+						}
+					}).then((headRes)=>{
+						this.listData[index].headUrl = headRes.data
+						this.$set(this.listData,index,this.listData[index])
+					})
+				}
+			},
 			// 请求头像
 			getPortrait(id){
 				this.$request({
@@ -422,7 +424,7 @@
 			onReachBottom() {
 				// console.log(this.page, this.total)
 				setTimeout(() => {
-					if (this.total - this.page * 10 <= 0) {
+					if (this.total - this.page * 5 <= 0) {
 						this.status = 'nomore'
 						// console.log('ww')
 					} else {