![](../../assets/img/selectImg.png)
@@ -86,6 +85,7 @@ import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
import { getImageQrcode, findImage } from "../../api/camera.js";
let CimgSrc = ref(""); // 相机拍照的图片路径,上传前需校验
+let CimgSrcYASUO = ref(""); // 压缩后的图片
let UimgSrc = ref(""); // 用户上传的图片路径,上传无需校验
let isSuccess = ref(false);
let isShowCanvas = ref(true);
@@ -99,6 +99,16 @@ let QRCodeUrl = ref("");
let showQrCode = ref(false);
let timer = ref(null);
+const getView = () => {
+ uni.getSystemInfo({
+ success: (res) => {
+ const viewportWidth = res.windowWidth; // 视口宽度
+ const viewportHeight = res.windowHeight; // 视口高度
+ alert(viewportWidth);
+ alert(viewportHeight);
+ },
+ });
+};
const startCamera = () => {
function getUserMedia(constraints, success, error) {
@@ -194,16 +204,18 @@ const startCamera = () => {
if (i == 0) {
clearInterval(timer);
- setTimeout(() => {
+ setTimeout(async () => {
uni.hideLoading();
// canvas.width = 1530;
// canvas.height = 950;
- canvas.width = 2400;
- canvas.height = 2400;
+ canvas.width = 1500;
+ canvas.height = 1500;
context.drawImage(video, 0, 0);
let dataURL = canvas.toDataURL("image/png");
+ console.log(dataURL);
CimgSrc.value = dataURL;
UimgSrc.value = "";
+
setTimeout(() => {
isShowCanvas.value = false;
isSuccess.value = true;
@@ -227,6 +239,41 @@ const startCamera = () => {
// 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 = () => {
console.log("Take Picture !");
@@ -253,14 +300,15 @@ const confirmPhoto = () => {
// alert(uni.getStorageSync("CcurrentUrl"), "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) {
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.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({
title: "正在检测人脸位置 2/3",
});
@@ -348,11 +419,12 @@ const checkImageByMetavatar = async (file, data) => {
authorization: uni.getStorageSync("token"),
},
timeout: 30000,
- formData: data,
+ // formData: data,
success: (res) => {
console.log(res, "上传成功");
const data = JSON.parse(res.data);
if (data.code == 200) {
+ uni.hideLoading();
uoloadImageAws(file);
} else {
uni.hideLoading();
@@ -363,6 +435,7 @@ const checkImageByMetavatar = async (file, data) => {
}
},
fail: (res) => {
+ uni.hideLoading();
uni.showToast({
title: "上传失败,请稍后再试",
icon: "none",
@@ -373,7 +446,7 @@ const checkImageByMetavatar = async (file, data) => {
};
// 上传图片到服务器(两步校验通过后)
-const uoloadImageAws = async (file, data) => {
+const uoloadImageAws = async (file) => {
uni.showLoading({
title: "检测完成,上传中 3/3",
});
@@ -384,7 +457,7 @@ const uoloadImageAws = async (file, data) => {
authorization: uni.getStorageSync("token"),
},
timeout: 30000,
- formData: data,
+ // formData: data,
success: (res) => {
console.log(res, "上传成功");
uni.hideLoading();
@@ -397,6 +470,7 @@ const uoloadImageAws = async (file, data) => {
});
setTimeout(() => {
// 将拍照照片地址存储到本地并清空上传照片地址
+ // uni.setStorageSync("CcurrentUrl", data.data.url);
uni.setStorageSync("CcurrentUrl", data.data.url);
uni.setStorageSync("UcurrentUrl", null);
uni.navigateTo({
@@ -404,6 +478,7 @@ const uoloadImageAws = async (file, data) => {
});
}, 1000);
} else {
+ uni.hideLoading();
uni.showToast({
title: "网络波动,请稍后再试",
icon: "error",
@@ -411,6 +486,7 @@ const uoloadImageAws = async (file, data) => {
}
},
fail: (res) => {
+ uni.hideLoading();
uni.showToast({
title: "上传失败,请稍后再试",
icon: "none",
@@ -427,6 +503,8 @@ const reTry = () => {
isShowCanvas.value = true;
CimgSrc.value = "";
UimgSrc.value = "";
+ CimgSrcYASUO.value = "";
+ uni.setStorageSync("CcurrentUrl", null);
setTimeout(() => {
startCamera();
}, 10);
@@ -470,6 +548,7 @@ const refreshUploadStatus = async (id) => {
showQrCode.value = false;
UimgSrc.value = imageUrl;
CimgSrc.value = "";
+ CimgSrcYASUO.value = "";
isShowCanvas.value = false;
isSuccess.value = true;
isUpload.value = true;
@@ -502,7 +581,7 @@ onMounted(() => {
const CimageUrl = uni.getStorageSync("CcurrentUrl");
const UimageUrl = uni.getStorageSync("UcurrentUrl");
if (CimageUrl || UimageUrl) {
- setTimeout(() => {
+ setTimeout(async () => {
showQrCode.value = false;
if (CimageUrl) {
UimgSrc.value = "";
@@ -511,6 +590,7 @@ onMounted(() => {
} else if (UimageUrl) {
UimgSrc.value = UimageUrl;
CimgSrc.value = "";
+ CimgSrcYASUO.value = "";
isUpload.value = true;
}
@@ -529,11 +609,13 @@ onMounted(() => {
// 重新设定120秒后触发的定时器
resetTimer.value = setTimeout(() => {
userInfoModulesPinia.clearStorage();
+ window.webview.raiseEvent("pageRefresh", "test_params");
uni.redirectTo({ url: "/pages/login/index" });
}, 300000);
});
resetTimer.value = setTimeout(() => {
userInfoModulesPinia.clearStorage();
+ window.webview.raiseEvent("pageRefresh", "test_params");
uni.redirectTo({ url: "/pages/login/index" });
}, 300000);
});
diff --git a/src/pages/chooseStyle/index.vue b/src/pages/chooseStyle/index.vue
index d68fb4f..bc2a892 100644
--- a/src/pages/chooseStyle/index.vue
+++ b/src/pages/chooseStyle/index.vue
@@ -280,11 +280,13 @@ onMounted(() => {
// 重新设定120秒后触发的定时器
resetTimer.value = setTimeout(() => {
userInfoModulesPinia.clearStorage();
+ window.webview.raiseEvent("pageRefresh", "test_params");
uni.redirectTo({ url: "/pages/login/index" });
}, 300000);
});
resetTimer.value = setTimeout(() => {
userInfoModulesPinia.clearStorage();
+ window.webview.raiseEvent("pageRefresh", "test_params");
uni.redirectTo({ url: "/pages/login/index" });
}, 300000);
});
diff --git a/src/pages/created/index.vue b/src/pages/created/index.vue
index b8ffc14..1581a64 100644
--- a/src/pages/created/index.vue
+++ b/src/pages/created/index.vue
@@ -289,13 +289,13 @@ onMounted(() => {
// 重新设定120秒后触发的定时器
resetTimer.value = setTimeout(() => {
userInfoModulesPinia.clearStorage();
-
+ window.webview.raiseEvent("pageRefresh", "test_params");
uni.redirectTo({ url: "/pages/login/index" });
}, 300000);
});
resetTimer.value = setTimeout(() => {
userInfoModulesPinia.clearStorage();
-
+ window.webview.raiseEvent("pageRefresh", "test_params");
uni.redirectTo({ url: "/pages/login/index" });
}, 300000);
});
diff --git a/src/pages/createing/index.vue b/src/pages/createing/index.vue
index db3f255..48f723d 100644
--- a/src/pages/createing/index.vue
+++ b/src/pages/createing/index.vue
@@ -93,6 +93,9 @@ onLoad(async (options) => {
await getInfo();
createing2();
}
+ if (uni.getStorageSync("UserId")) {
+ getUser2();
+ }
});
onShow(() => {
getInfo();
@@ -177,7 +180,7 @@ async function getQRCode() {
const data = {
// sn: "112233",
// sn: window.android.getIMEI(),
- sn: window.localStorage.getItem("androidIdByWindow"),
+ sn: window.localStorage.getItem("androidIdByWindow") || "112233",
type: 1,
};
const res = await getQRCodeApi(data);
@@ -327,6 +330,25 @@ onUnload(() => {
showQrCode.value == false; // 停止getUser()的递归
// uni.setStorageSync("UserId", null);
});
+
+//#endregion ---------------------
+
+//#region 获取次数
+async function getUser2() {
+ try {
+ const res = await getUserApi(uni.getStorageSync("UserId"));
+ // 如果接口200就说明已登录
+ if (res.code == 200 && res.data) {
+ // 查询支付状态 0:待支付,2:支付中,3:已支付
+ if (res.data.payStatus == 3) {
+ uni.setStorageSync("createTimes", res.data.createTimes);
+ userInfoModulesPinia.createTimes = res.data.createTimes;
+ }
+ }
+ } catch (err) {
+ console.log(err);
+ }
+}
//#endregion ---------------------
//#region 路由跳转
@@ -389,11 +411,13 @@ onMounted(() => {
// 重新设定120秒后触发的定时器
resetTimer.value = setTimeout(() => {
userInfoModulesPinia.clearStorage();
+ window.webview.raiseEvent("pageRefresh", "test_params");
uni.redirectTo({ url: "/pages/login/index" });
}, 300000);
});
resetTimer.value = setTimeout(() => {
userInfoModulesPinia.clearStorage();
+ window.webview.raiseEvent("pageRefresh", "test_params");
uni.redirectTo({ url: "/pages/login/index" });
}, 300000);
});
diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue
index 9b0a44a..76b673b 100644
--- a/src/pages/login/index.vue
+++ b/src/pages/login/index.vue
@@ -3,9 +3,11 @@
拍摄数码写真
- 1.0.5i
- 刷新
- 获取
+ 1.0.7i
+
+
+
@@ -36,7 +38,6 @@ function Imei() {
// const IMEI = window.android.getIMEI();
// const IMEI = window.android.getSerial();
// const IMEI = window.android.getTestStr();
-
uni.showToast({
// title: uni.getStorageSync("androidId"),
title: window.localStorage.getItem("androidIdByWindow"),