|
@@ -9,7 +9,6 @@ |
|
|
:controls="false" |
|
|
:controls="false" |
|
|
:enable-progress-gesture="false" |
|
|
:enable-progress-gesture="false" |
|
|
></video> |
|
|
></video> |
|
|
|
|
|
|
|
|
<div v-if="!isSuccess"> |
|
|
<div v-if="!isSuccess"> |
|
|
<div class="selectImg" @click="uploadImg"> |
|
|
<div class="selectImg" @click="uploadImg"> |
|
|
<img src="../../assets/img/selectImg.png" /> |
|
|
<img src="../../assets/img/selectImg.png" /> |
|
@@ -86,6 +85,7 @@ import { onLoad, onShow, onUnload } from "@dcloudio/uni-app"; |
|
|
import { getImageQrcode, findImage } from "../../api/camera.js"; |
|
|
import { getImageQrcode, findImage } from "../../api/camera.js"; |
|
|
|
|
|
|
|
|
let CimgSrc = ref(""); // 相机拍照的图片路径,上传前需校验 |
|
|
let CimgSrc = ref(""); // 相机拍照的图片路径,上传前需校验 |
|
|
|
|
|
let CimgSrcYASUO = ref(""); // 压缩后的图片 |
|
|
let UimgSrc = ref(""); // 用户上传的图片路径,上传无需校验 |
|
|
let UimgSrc = ref(""); // 用户上传的图片路径,上传无需校验 |
|
|
let isSuccess = ref(false); |
|
|
let isSuccess = ref(false); |
|
|
let isShowCanvas = ref(true); |
|
|
let isShowCanvas = ref(true); |
|
@@ -99,6 +99,16 @@ let QRCodeUrl = ref(""); |
|
|
let showQrCode = ref(false); |
|
|
let showQrCode = ref(false); |
|
|
|
|
|
|
|
|
let timer = ref(null); |
|
|
let timer = ref(null); |
|
|
|
|
|
const getView = () => { |
|
|
|
|
|
uni.getSystemInfo({ |
|
|
|
|
|
success: (res) => { |
|
|
|
|
|
const viewportWidth = res.windowWidth; // 视口宽度 |
|
|
|
|
|
const viewportHeight = res.windowHeight; // 视口高度 |
|
|
|
|
|
alert(viewportWidth); |
|
|
|
|
|
alert(viewportHeight); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
const startCamera = () => { |
|
|
const startCamera = () => { |
|
|
function getUserMedia(constraints, success, error) { |
|
|
function getUserMedia(constraints, success, error) { |
|
@@ -194,16 +204,18 @@ const startCamera = () => { |
|
|
if (i == 0) { |
|
|
if (i == 0) { |
|
|
clearInterval(timer); |
|
|
clearInterval(timer); |
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
|
setTimeout(async () => { |
|
|
uni.hideLoading(); |
|
|
uni.hideLoading(); |
|
|
// canvas.width = 1530; |
|
|
// canvas.width = 1530; |
|
|
// canvas.height = 950; |
|
|
// canvas.height = 950; |
|
|
canvas.width = 2400; |
|
|
|
|
|
canvas.height = 2400; |
|
|
|
|
|
|
|
|
canvas.width = 1500; |
|
|
|
|
|
canvas.height = 1500; |
|
|
context.drawImage(video, 0, 0); |
|
|
context.drawImage(video, 0, 0); |
|
|
let dataURL = canvas.toDataURL("image/png"); |
|
|
let dataURL = canvas.toDataURL("image/png"); |
|
|
|
|
|
console.log(dataURL); |
|
|
CimgSrc.value = dataURL; |
|
|
CimgSrc.value = dataURL; |
|
|
UimgSrc.value = ""; |
|
|
UimgSrc.value = ""; |
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
isShowCanvas.value = false; |
|
|
isShowCanvas.value = false; |
|
|
isSuccess.value = true; |
|
|
isSuccess.value = true; |
|
@@ -227,6 +239,41 @@ const startCamera = () => { |
|
|
// console.log(dataURL); |
|
|
// console.log(dataURL); |
|
|
// }); |
|
|
// }); |
|
|
}; |
|
|
}; |
|
|
|
|
|
//压缩图片 |
|
|
|
|
|
function compressBase64Image(base64String, maxWidth, maxHeight) { |
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
const img = new Image(); |
|
|
|
|
|
img.src = base64String; |
|
|
|
|
|
|
|
|
|
|
|
img.onload = function () { |
|
|
|
|
|
const canvas = document.createElement("canvas"); |
|
|
|
|
|
let width = img.width; |
|
|
|
|
|
let height = img.height; |
|
|
|
|
|
|
|
|
|
|
|
if (width > maxWidth) { |
|
|
|
|
|
height *= maxWidth / width; |
|
|
|
|
|
width = maxWidth; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (height > maxHeight) { |
|
|
|
|
|
width *= maxHeight / height; |
|
|
|
|
|
height = maxHeight; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const ctx = canvas.getContext("2d"); |
|
|
|
|
|
canvas.width = width; |
|
|
|
|
|
canvas.height = height; |
|
|
|
|
|
ctx.drawImage(img, 0, 0, width, height); |
|
|
|
|
|
|
|
|
|
|
|
const compressedBase64 = canvas.toDataURL("image/jpeg"); |
|
|
|
|
|
resolve(compressedBase64); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
img.onerror = function (error) { |
|
|
|
|
|
reject(error); |
|
|
|
|
|
}; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const takePicture = () => { |
|
|
const takePicture = () => { |
|
|
console.log("Take Picture !"); |
|
|
console.log("Take Picture !"); |
|
@@ -253,14 +300,15 @@ const confirmPhoto = () => { |
|
|
// alert(uni.getStorageSync("CcurrentUrl"), "CcurrentUrl"); |
|
|
// alert(uni.getStorageSync("CcurrentUrl"), "CcurrentUrl"); |
|
|
// // let CimageUrl = uni.getStorageSync("CcurrentUrl"); |
|
|
// // let CimageUrl = uni.getStorageSync("CcurrentUrl"); |
|
|
// // 用户上一次使用相机拍照的照片,从本地回显,已通过校验,直接放行 |
|
|
// // 用户上一次使用相机拍照的照片,从本地回显,已通过校验,直接放行 |
|
|
// if (uni.getStorageSync("CcurrentUrl")) { |
|
|
|
|
|
// uni.navigateTo({ |
|
|
|
|
|
// url: `/pages/createing/index?imageUrl=${CimgSrc.value}&id=${modelId.value}`, |
|
|
|
|
|
// }); |
|
|
|
|
|
// // 用户使用相机拍照的照片,未校验,走完校验流程放行 |
|
|
|
|
|
// } else { |
|
|
|
|
|
// } |
|
|
|
|
|
dealImage(CimgSrc.value); |
|
|
|
|
|
|
|
|
if (uni.getStorageSync("CcurrentUrl")) { |
|
|
|
|
|
uni.navigateTo({ |
|
|
|
|
|
url: `/pages/createing/index?imageUrl=${CimgSrc.value}&id=${modelId.value}`, |
|
|
|
|
|
}); |
|
|
|
|
|
// // 用户使用相机拍照的照片,未校验,走完校验流程放行 |
|
|
|
|
|
} else { |
|
|
|
|
|
dealImage(CimgSrc.value); |
|
|
|
|
|
} |
|
|
|
|
|
// dealImage(CimgSrcYASUO.value); |
|
|
} |
|
|
} |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
@@ -272,14 +320,27 @@ const confirmPhoto = () => { |
|
|
// 用户上传的照片,已通过校验,直接放行 |
|
|
// 用户上传的照片,已通过校验,直接放行 |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const dealImage = (imageUrl) => { |
|
|
|
|
|
uni.showLoading({ |
|
|
|
|
|
title: "上传中,马上就好", |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 将二进制数据转换为 Blob 对象 |
|
|
|
|
|
let blob = dataURLtoBlob(imageUrl); |
|
|
|
|
|
checkImageByBaidu(blob); |
|
|
|
|
|
|
|
|
const dealImage = async (imageUrl) => { |
|
|
|
|
|
try { |
|
|
|
|
|
uni.showLoading({ |
|
|
|
|
|
title: "上传中,马上就好", |
|
|
|
|
|
}); |
|
|
|
|
|
await compressBase64Image(imageUrl, 1200, 1200) |
|
|
|
|
|
.then((compressedBase64) => { |
|
|
|
|
|
CimgSrcYASUO.value = compressedBase64; |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
console.error("压缩失败", error); |
|
|
|
|
|
}); |
|
|
|
|
|
// 将二进制数据转换为 Blob 对象 |
|
|
|
|
|
// let blob = await dataURLtoBlob(imageUrl); |
|
|
|
|
|
// checkImageByBaidu(blob); |
|
|
|
|
|
// let blob = await dataURLtoBlob(imageUrl); |
|
|
|
|
|
// console.log(dataURLtoBlob(imageUrl)); |
|
|
|
|
|
checkImageByBaidu(dataURLtoBlob(CimgSrcYASUO.value)); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error("压缩失败", error); |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -301,43 +362,53 @@ const dataURLtoBlob = (dataurl) => { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 百度图片校验 |
|
|
// 百度图片校验 |
|
|
const checkImageByBaidu = async (file, data) => { |
|
|
|
|
|
uni.showLoading({ |
|
|
|
|
|
title: "正在检测图片合法性 1/3", |
|
|
|
|
|
}); |
|
|
|
|
|
uni.uploadFile({ |
|
|
|
|
|
url: BASE_URL + "api/baidu/checkPhoto", |
|
|
|
|
|
file, |
|
|
|
|
|
header: { |
|
|
|
|
|
authorization: uni.getStorageSync("token"), |
|
|
|
|
|
}, |
|
|
|
|
|
timeout: 30000, |
|
|
|
|
|
formData: data, |
|
|
|
|
|
success: (res) => { |
|
|
|
|
|
console.log(res, "上传成功"); |
|
|
|
|
|
const data = JSON.parse(res.data); |
|
|
|
|
|
if (data.code == 200) { |
|
|
|
|
|
checkImageByMetavatar(file); |
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
const checkImageByBaidu = async (file) => { |
|
|
|
|
|
try { |
|
|
|
|
|
uni.showLoading({ |
|
|
|
|
|
title: "正在检测图片合法性 1/3", |
|
|
|
|
|
}); |
|
|
|
|
|
uni.uploadFile({ |
|
|
|
|
|
url: BASE_URL + "api/baidu/checkPhoto", |
|
|
|
|
|
file, |
|
|
|
|
|
header: { |
|
|
|
|
|
authorization: uni.getStorageSync("token"), |
|
|
|
|
|
}, |
|
|
|
|
|
timeout: 30000, |
|
|
|
|
|
// formData: data, |
|
|
|
|
|
success: (res) => { |
|
|
|
|
|
console.log(res, "上传成功"); |
|
|
|
|
|
const data = JSON.parse(res.data); |
|
|
|
|
|
if (data.code == 200) { |
|
|
|
|
|
uni.hideLoading(); |
|
|
|
|
|
checkImageByMetavatar(file); |
|
|
|
|
|
} else { |
|
|
|
|
|
uni.hideLoading(); |
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
title: "图片不合规哦,请更换一张", |
|
|
|
|
|
icon: "error", |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
fail: (res) => { |
|
|
uni.hideLoading(); |
|
|
uni.hideLoading(); |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
|
title: "图片不合规哦,请更换一张", |
|
|
|
|
|
icon: "error", |
|
|
|
|
|
|
|
|
title: "上传失败,请稍后再试", |
|
|
|
|
|
icon: "none", |
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
fail: (res) => { |
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
title: "上传失败,请稍后再试", |
|
|
|
|
|
icon: "none", |
|
|
|
|
|
}); |
|
|
|
|
|
console.log(res, "上传失败"); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
console.log(res, "上传失败"); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
uni.hideLoading(); |
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
title: "请求失败,请稍后再试", |
|
|
|
|
|
icon: "none", |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 邃芒人脸校验 |
|
|
// 邃芒人脸校验 |
|
|
const checkImageByMetavatar = async (file, data) => { |
|
|
|
|
|
|
|
|
const checkImageByMetavatar = async (file) => { |
|
|
uni.showLoading({ |
|
|
uni.showLoading({ |
|
|
title: "正在检测人脸位置 2/3", |
|
|
title: "正在检测人脸位置 2/3", |
|
|
}); |
|
|
}); |
|
@@ -348,11 +419,12 @@ const checkImageByMetavatar = async (file, data) => { |
|
|
authorization: uni.getStorageSync("token"), |
|
|
authorization: uni.getStorageSync("token"), |
|
|
}, |
|
|
}, |
|
|
timeout: 30000, |
|
|
timeout: 30000, |
|
|
formData: data, |
|
|
|
|
|
|
|
|
// formData: data, |
|
|
success: (res) => { |
|
|
success: (res) => { |
|
|
console.log(res, "上传成功"); |
|
|
console.log(res, "上传成功"); |
|
|
const data = JSON.parse(res.data); |
|
|
const data = JSON.parse(res.data); |
|
|
if (data.code == 200) { |
|
|
if (data.code == 200) { |
|
|
|
|
|
uni.hideLoading(); |
|
|
uoloadImageAws(file); |
|
|
uoloadImageAws(file); |
|
|
} else { |
|
|
} else { |
|
|
uni.hideLoading(); |
|
|
uni.hideLoading(); |
|
@@ -363,6 +435,7 @@ const checkImageByMetavatar = async (file, data) => { |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
fail: (res) => { |
|
|
fail: (res) => { |
|
|
|
|
|
uni.hideLoading(); |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
|
title: "上传失败,请稍后再试", |
|
|
title: "上传失败,请稍后再试", |
|
|
icon: "none", |
|
|
icon: "none", |
|
@@ -373,7 +446,7 @@ const checkImageByMetavatar = async (file, data) => { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 上传图片到服务器(两步校验通过后) |
|
|
// 上传图片到服务器(两步校验通过后) |
|
|
const uoloadImageAws = async (file, data) => { |
|
|
|
|
|
|
|
|
const uoloadImageAws = async (file) => { |
|
|
uni.showLoading({ |
|
|
uni.showLoading({ |
|
|
title: "检测完成,上传中 3/3", |
|
|
title: "检测完成,上传中 3/3", |
|
|
}); |
|
|
}); |
|
@@ -384,7 +457,7 @@ const uoloadImageAws = async (file, data) => { |
|
|
authorization: uni.getStorageSync("token"), |
|
|
authorization: uni.getStorageSync("token"), |
|
|
}, |
|
|
}, |
|
|
timeout: 30000, |
|
|
timeout: 30000, |
|
|
formData: data, |
|
|
|
|
|
|
|
|
// formData: data, |
|
|
success: (res) => { |
|
|
success: (res) => { |
|
|
console.log(res, "上传成功"); |
|
|
console.log(res, "上传成功"); |
|
|
uni.hideLoading(); |
|
|
uni.hideLoading(); |
|
@@ -397,6 +470,7 @@ const uoloadImageAws = async (file, data) => { |
|
|
}); |
|
|
}); |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
// 将拍照照片地址存储到本地并清空上传照片地址 |
|
|
// 将拍照照片地址存储到本地并清空上传照片地址 |
|
|
|
|
|
// uni.setStorageSync("CcurrentUrl", data.data.url); |
|
|
uni.setStorageSync("CcurrentUrl", data.data.url); |
|
|
uni.setStorageSync("CcurrentUrl", data.data.url); |
|
|
uni.setStorageSync("UcurrentUrl", null); |
|
|
uni.setStorageSync("UcurrentUrl", null); |
|
|
uni.navigateTo({ |
|
|
uni.navigateTo({ |
|
@@ -404,6 +478,7 @@ const uoloadImageAws = async (file, data) => { |
|
|
}); |
|
|
}); |
|
|
}, 1000); |
|
|
}, 1000); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
uni.hideLoading(); |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
|
title: "网络波动,请稍后再试", |
|
|
title: "网络波动,请稍后再试", |
|
|
icon: "error", |
|
|
icon: "error", |
|
@@ -411,6 +486,7 @@ const uoloadImageAws = async (file, data) => { |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
fail: (res) => { |
|
|
fail: (res) => { |
|
|
|
|
|
uni.hideLoading(); |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
|
title: "上传失败,请稍后再试", |
|
|
title: "上传失败,请稍后再试", |
|
|
icon: "none", |
|
|
icon: "none", |
|
@@ -427,6 +503,8 @@ const reTry = () => { |
|
|
isShowCanvas.value = true; |
|
|
isShowCanvas.value = true; |
|
|
CimgSrc.value = ""; |
|
|
CimgSrc.value = ""; |
|
|
UimgSrc.value = ""; |
|
|
UimgSrc.value = ""; |
|
|
|
|
|
CimgSrcYASUO.value = ""; |
|
|
|
|
|
uni.setStorageSync("CcurrentUrl", null); |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
startCamera(); |
|
|
startCamera(); |
|
|
}, 10); |
|
|
}, 10); |
|
@@ -470,6 +548,7 @@ const refreshUploadStatus = async (id) => { |
|
|
showQrCode.value = false; |
|
|
showQrCode.value = false; |
|
|
UimgSrc.value = imageUrl; |
|
|
UimgSrc.value = imageUrl; |
|
|
CimgSrc.value = ""; |
|
|
CimgSrc.value = ""; |
|
|
|
|
|
CimgSrcYASUO.value = ""; |
|
|
isShowCanvas.value = false; |
|
|
isShowCanvas.value = false; |
|
|
isSuccess.value = true; |
|
|
isSuccess.value = true; |
|
|
isUpload.value = true; |
|
|
isUpload.value = true; |
|
@@ -502,7 +581,7 @@ onMounted(() => { |
|
|
const CimageUrl = uni.getStorageSync("CcurrentUrl"); |
|
|
const CimageUrl = uni.getStorageSync("CcurrentUrl"); |
|
|
const UimageUrl = uni.getStorageSync("UcurrentUrl"); |
|
|
const UimageUrl = uni.getStorageSync("UcurrentUrl"); |
|
|
if (CimageUrl || UimageUrl) { |
|
|
if (CimageUrl || UimageUrl) { |
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
|
setTimeout(async () => { |
|
|
showQrCode.value = false; |
|
|
showQrCode.value = false; |
|
|
if (CimageUrl) { |
|
|
if (CimageUrl) { |
|
|
UimgSrc.value = ""; |
|
|
UimgSrc.value = ""; |
|
@@ -511,6 +590,7 @@ onMounted(() => { |
|
|
} else if (UimageUrl) { |
|
|
} else if (UimageUrl) { |
|
|
UimgSrc.value = UimageUrl; |
|
|
UimgSrc.value = UimageUrl; |
|
|
CimgSrc.value = ""; |
|
|
CimgSrc.value = ""; |
|
|
|
|
|
CimgSrcYASUO.value = ""; |
|
|
isUpload.value = true; |
|
|
isUpload.value = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -529,11 +609,13 @@ onMounted(() => { |
|
|
// 重新设定120秒后触发的定时器 |
|
|
// 重新设定120秒后触发的定时器 |
|
|
resetTimer.value = setTimeout(() => { |
|
|
resetTimer.value = setTimeout(() => { |
|
|
userInfoModulesPinia.clearStorage(); |
|
|
userInfoModulesPinia.clearStorage(); |
|
|
|
|
|
window.webview.raiseEvent("pageRefresh", "test_params"); |
|
|
uni.redirectTo({ url: "/pages/login/index" }); |
|
|
uni.redirectTo({ url: "/pages/login/index" }); |
|
|
}, 300000); |
|
|
}, 300000); |
|
|
}); |
|
|
}); |
|
|
resetTimer.value = setTimeout(() => { |
|
|
resetTimer.value = setTimeout(() => { |
|
|
userInfoModulesPinia.clearStorage(); |
|
|
userInfoModulesPinia.clearStorage(); |
|
|
|
|
|
window.webview.raiseEvent("pageRefresh", "test_params"); |
|
|
uni.redirectTo({ url: "/pages/login/index" }); |
|
|
uni.redirectTo({ url: "/pages/login/index" }); |
|
|
}, 300000); |
|
|
}, 300000); |
|
|
}); |
|
|
}); |
|
|