|
|
@@ -74,6 +74,7 @@ |
|
|
|
|
|
|
|
<script setup> |
|
|
|
import { ref, onMounted } from "vue"; |
|
|
|
import { BASE_URL } from "../../utils/request"; |
|
|
|
import { onLoad, onShow, onUnload } from "@dcloudio/uni-app"; |
|
|
|
|
|
|
|
import { getImageQrcode, findImage } from "../../api/camera.js"; |
|
|
@@ -215,8 +216,130 @@ const confirmPhoto = () => { |
|
|
|
uni.navigateTo({ |
|
|
|
url: `/pages/createing/index?imageUrl=${UimgSrc.value}`, |
|
|
|
}); |
|
|
|
} else if (CimgSrc.value) { |
|
|
|
delImage(CimgSrc.value); |
|
|
|
} |
|
|
|
}; |
|
|
|
const delImage = (imageUrl) => { |
|
|
|
uni.showLoading({ |
|
|
|
title: "上传中,马上就好", |
|
|
|
}); |
|
|
|
|
|
|
|
let blob = dataURLtoBlob(imageUrl); |
|
|
|
// 将二进制数据转换为 Blob 对象 |
|
|
|
checkImageByBaidu(blob); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Base64字符串转二进制流 |
|
|
|
* @param {String} dataurl Base64字符串(字符串包含Data URI scheme,例如:data:image/png;base64, ) |
|
|
|
*/ |
|
|
|
const dataURLtoBlob = (dataurl) => { |
|
|
|
var arr = dataurl.split(","), |
|
|
|
mime = arr[0].match(/:(.*?);/)[1], |
|
|
|
bstr = atob(arr[1]), |
|
|
|
n = bstr.length, |
|
|
|
u8arr = new Uint8Array(n); |
|
|
|
while (n--) { |
|
|
|
u8arr[n] = bstr.charCodeAt(n); |
|
|
|
} |
|
|
|
return new Blob([u8arr], { |
|
|
|
type: mime, |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
// 百度图片校验 |
|
|
|
const checkImageByBaidu = async (file, data) => { |
|
|
|
uni.uploadFile({ |
|
|
|
url: BASE_URL + "api/baidu/checkPhoto", |
|
|
|
file, |
|
|
|
header: { |
|
|
|
authorization: uni.getStorageSync("token"), |
|
|
|
}, |
|
|
|
formData: data, |
|
|
|
success: (res) => { |
|
|
|
console.log(res, "上传成功"); |
|
|
|
const data = JSON.parse(res.data); |
|
|
|
if (data.code == 200) { |
|
|
|
checkImageByMetavatar(file); |
|
|
|
} else { |
|
|
|
uni.hideLoading(); |
|
|
|
uni.showToast({ |
|
|
|
title: "图片不合规哦,请更换一张", |
|
|
|
icon: "error", |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: (res) => { |
|
|
|
console.log(res, "上传失败"); |
|
|
|
}, |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
// 邃芒人脸校验 |
|
|
|
const checkImageByMetavatar = async (file, data) => { |
|
|
|
uni.uploadFile({ |
|
|
|
url: BASE_URL + "api/userDigital/checkPhoto", |
|
|
|
file, |
|
|
|
header: { |
|
|
|
authorization: uni.getStorageSync("token"), |
|
|
|
}, |
|
|
|
formData: data, |
|
|
|
success: (res) => { |
|
|
|
console.log(res, "上传成功"); |
|
|
|
const data = JSON.parse(res.data); |
|
|
|
if (data.code == 200) { |
|
|
|
uoloadImageAws(file); |
|
|
|
} else { |
|
|
|
uni.hideLoading(); |
|
|
|
uni.showToast({ |
|
|
|
title: "请参考提示区域调整站位哦", |
|
|
|
icon: "error", |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: (res) => { |
|
|
|
console.log(res, "上传失败"); |
|
|
|
}, |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
// 上传图片到服务器(两步校验通过后) |
|
|
|
const uoloadImageAws = async (file, data) => { |
|
|
|
uni.uploadFile({ |
|
|
|
url: BASE_URL + "api/upload/awsImgUpload", |
|
|
|
file, |
|
|
|
header: { |
|
|
|
authorization: uni.getStorageSync("token"), |
|
|
|
}, |
|
|
|
formData: data, |
|
|
|
success: (res) => { |
|
|
|
console.log(res, "上传成功"); |
|
|
|
uni.hideLoading(); |
|
|
|
const data = JSON.parse(res.data); |
|
|
|
if (data.code == 200) { |
|
|
|
uni.showToast({ |
|
|
|
title: "上传成功!", |
|
|
|
icon: "success", |
|
|
|
duration: 1500, |
|
|
|
}); |
|
|
|
setTimeout(() => { |
|
|
|
uni.navigateTo({ |
|
|
|
url: `/pages/createing/index?imageUrl=${data.data.url}`, |
|
|
|
}); |
|
|
|
}, 1000); |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: "网络波动,请稍后再试", |
|
|
|
icon: "error", |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: (res) => { |
|
|
|
console.log(res, "上传失败"); |
|
|
|
}, |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
// 不满意,重新拍一张 |
|
|
|
const reTry = () => { |
|
|
|