Files
Backend-Api/ServiceHost/wwwroot/AssetsCamera/js/Index.min.js
2024-10-28 19:01:02 +03:30

14 lines
9.8 KiB
JavaScript

let timeout; const redirectTime = 6e5; function resetTimer() { clearTimeout(timeout), timeout = setTimeout(() => { window.location.href = "/Camera/CamStandby" }, 6e5) } window.onload = resetTimer, window.onmousemove = resetTimer, window.onmousedown = resetTimer, window.ontouchstart = resetTimer, window.onclick = resetTimer, window.onkeypress = resetTimer, window.onscroll = resetTimer, resetTimer(), window.onload = function () { setTimeout(function () { let e = document.getElementById("loader"); e.classList.add("hidden") }, 3e3), setTimeout(function () { loader.style.display = "none" }, 3500), document.getElementById("content").style.display = "block", setTimeout(function () { document.getElementById("content").style.opacity = 1 }, 100) }, $(document).ready(function () {
if ($(window).width() > 992 && ($("#desktopDisplay").show(), $("#mobileDisplay").hide(), $("#keypadSection").hide(), $("#mobileDisplay").html(""), $("#keypadSection").html("")), 992 >= $(window).width()) { $("#desktopDisplay").html(""), $("#desktopDisplay").hide(), $("#mobileDisplay").show(), document.getElementById("display"); let e = async () => { await Promise.all([faceapi.nets.ssdMobilenetv1.loadFromUri("\\weights\\"), faceapi.nets.faceRecognitionNet.loadFromUri("\\weights\\"), faceapi.nets.faceLandmark68Net.loadFromUri("\\weights\\")]) }; e(), startWebcam() } $("#form").attr("autocomplete", "off"), $("#password").attr("autocomplete", "new-password"), $("#password").on("keypress", function (e) { /[\u0600-\u06FF]/.test(String.fromCharCode(e.which)) && e.preventDefault() }), $("#passwordModal").on("shown.bs.modal", function () { $("#password").focus() }), $("#toggle-password").on("click", function () {
var e = $("#password"); "password" === e.attr("type") ? (e.attr("type", "text"), $(this).html(`
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="18" height="18">
<path stroke-linecap="round" stroke-linejoin="round" d="M3.98 8.223A10.477 10.477 0 0 0 1.934 12C3.226 16.338 7.244 19.5 12 19.5c.993 0 1.953-.138 2.863-.395M6.228 6.228A10.451 10.451 0 0 1 12 4.5c4.756 0 8.773 3.162 10.065 7.498a10.522 10.522 0 0 1-4.293 5.774M6.228 6.228 3 3m3.228 3.228 3.65 3.65m7.894 7.894L21 21m-3.228-3.228-3.65-3.65m0 0a3 3 0 1 0-4.243-4.243m4.242 4.242L9.88 9.88" />
</svg>
`)) : (e.attr("type", "password"), $(this).html(`
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="18" height="18">
<path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
</svg>
`))
})
}); var empId = -1, stop = !1; async function startWebcam() { await navigator.mediaDevices.getUserMedia({ video: !0, audio: !1 }).then(e => { video.srcObject = e, waiting.style.display = "block" }).catch(e => { console.error(e) }) } function stopWebcam() { window.location.reload() } async function firstLoad() { let e = await `${urlPath}/Camera?handler=ShowPicture&index=1&workshopId=11&label=1`, t = await `${urlPath}/Camera?handler=ShowPicture&index=2&workshopId=11&label=1`, a = await faceapi.fetchImage(e); await faceapi.detectSingleFace(a).withFaceLandmarks().withFaceDescriptor(); let o = await faceapi.fetchImage(t); await faceapi.detectSingleFace(o).withFaceLandmarks().withFaceDescriptor() } async function getLabeledFaceDescriptions() { let e = [], t = await `${urlPath}/Camera?handler=ShowPicture&index=1&workshopId=${workshopId}&label=${empId}`, a = await `${urlPath}/Camera?handler=ShowPicture&index=2&workshopId=${workshopId}&label=${empId}`, o = await faceapi.fetchImage(t), s = await faceapi.detectSingleFace(o).withFaceLandmarks().withFaceDescriptor(), n = await faceapi.fetchImage(a), i = await faceapi.detectSingleFace(n).withFaceLandmarks().withFaceDescriptor(); return await e.push(s.descriptor), await e.push(i.descriptor), new faceapi.LabeledFaceDescriptors(empId, e) } var reloadActionControl = !1; function roloadAgain() { $(".keypad-section").show(), $("#display canvas").remove(), $("#users").html(""), $("#btnOutOrIn").html(""), $("#inputField").val(""), $(".entered-numbers .num").text(""), $("#notFound").hide(), recognizing.style.display = "block", reloadActionControl = !0, reloadRec.style.display = "none", $("#roloadAgain").addClass("d-none") } function sendPersonelCodeToGetEmployeeId(e) { let t = $("#workshopId").val(); $.ajax({ async: !1, type: "GET", url: AjaxSendPersonelCodeToGetEmployeeId, data: { personelCode: Number(e), workshopId: Number(t) }, headers: { RequestVerificationToken: antiForgeryToken }, success: function (e) { if (e.isSuccess) empId = e.personId, endOfRecognition = !1, startWebcam(), $(".keypad-section").hide(); else { $("#errorMessage").text(e.message); return } }, failure: function (e) { console.log(5, e) } }) } function getPersonel(e) { let t = $("#workshopId").val(), a = document.getElementById("users"), o = $("#users"), s = $("#btnOutOrIn"), n = Number(e); n > 0 && $.ajax({ async: !1, type: "GET", url: AjaxEmployeeFlag, data: { employeeId: n, workshopId: Number(t) }, headers: { RequestVerificationToken: antiForgeryToken }, success: function (t) { if (t.flag > 0) { let n = document.createElement("span"); n.innerHTML = t.employeeName; let i = `<button type="button" id="out" class="btn-exit" onclick="out(${t.flag})">ثبت خروج</button>`; o.html(""), s.html(""), a.append(n), s.append(i) } else { let l = document.createElement("span"); l.innerHTML = t.employeeName; let r = `<button type="button" id="incom" class="btn-incom" onclick="inCom(${e})">ثبت ورود</button>`; o.html(""), s.html(""), a.appendChild(l), s.append(r) } }, failure: function (e) { console.log(5, e) } }) } function out(e) { $.ajax({ async: !1, type: "GET", url: AjaxOut, data: { flagId: Number(e) }, headers: { RequestVerificationToken: antiForgeryToken }, success: function (e) { e.isSuccess ? ($(".alert-success-msg").show(), $(".alert-success-msg p").text("خروج شما ثبت شد"), setTimeout(function () { $(".alert-success-msg").hide(), $(".alert-success-msg p").text("") }, 1500), roloadAgain()) : ($(".alert-msg").show(), $(".alert-msg p").text("خطا در ثبت اطلاعات"), setTimeout(function () { $(".alert-msg").hide(), $(".alert-msg p").text("") }, 1500)) }, failure: function (e) { console.log(5, e) } }) } function inCom(e) { let t = $("#workshopId").val(); $.ajax({ async: !1, type: "GET", url: AjaxInCom, data: { employeeId: Number(e), workshopId: Number(t) }, headers: { RequestVerificationToken: antiForgeryToken }, success: function (e) { e.isSuccess ? ($(".alert-success-msg").show(), $(".alert-success-msg p").text("ورود شما ثبت شد"), setTimeout(function () { $(".alert-success-msg").hide(), $(".alert-success-msg p").text("") }, 1500), roloadAgain()) : ($(".alert-msg").show(), $(".alert-msg p").text("خطا در ثبت اطلاعات"), setTimeout(function () { $(".alert-msg").hide(), $(".alert-msg p").text("") }, 1500)) }, failure: function (e) { console.log(5, e) } }) } function enterPersonnelCode() { var e = $("#inputField").val(); "" === e ? $("#errorMessage").text("کد پرسنلی خود را وارد کنید.") : ($("#errorMessage").text(""), sendPersonelCodeToGetEmployeeId(e)) } function openPersonnelModal() { window.location.href = "#showmodal=/Camera/Index?handler=PersonnelWorkshopAjax" } reloadRec.style.display = "none", endOfRecognition = !0, reloadRec.addEventListener("click", function () { $("#display canvas").remove(), $("#users").html(""), $("#btnOutOrIn").html(""), endOfRecognition = !1, stop = !1, recognizing.style.display = "block", reloadActionControl = !0, reloadRec.style.display = "none", notFound.style.display = "none", startWebcam() }), video.addEventListener("play", async () => { let e = new Date().getTime(); if (-1 == empId) await firstLoad(); else { let t = await getLabeledFaceDescriptions(), a = await new faceapi.FaceMatcher(t), o = await faceapi.createCanvasFromMedia(video); await display.append(o); let s = await { width: video.width, height: video.height }; await faceapi.matchDimensions(o, s); var n = await !1; let i = (new Date().getTime() - e) / 1e3; console.log(`time forloop elapsed is ${i}`); for (let l = 0; l < 10; l++)if (!1 === endOfRecognition) { waiting.style.display = "none", reloadActionControl = !0, recognizing.style.display = "block", console.log("start recog"); let r = await faceapi.detectSingleFace(video).withFaceLandmarks().withFaceDescriptor(); if (void 0 !== r) { let c = await faceapi.resizeResults(r, s); await o.getContext("2d").clearRect(0, 0, o.width, o.height); let d = await a.findBestMatch(c.descriptor); console.log("end recog"); let p = c.detection.box, m = new faceapi.draw.DrawBox(p, { label: "آنالیز چهره" }); await m.draw(o); let u = d.label, h = d.distance; u == empId && h <= .45 && (endOfRecognition = !0, stop = !0, notFound.style.display = "none", recognizing.style.display = "none", n = !0, await getPersonel(d.label)) } } n || (notFound.style.display = "block", recognizing.style.display = "none", reloadActionControl = !1, endOfRecognition = !0, stop = !0), reloadRec.style.display = "block", $("#roloadAgain").removeClass("d-none") } }), $(document).ready(function () { $(".keypad-numbers .item").click(function () { let e = $(this).text().trim(), t = $("#inputField").val(); $("#inputField").val(t + e), $(".entered-numbers .num").text(t + e) }), $("#cleanBtn").click(function () { $("#inputField").val(""), $(".entered-numbers .num").text("") }), $(".backspace-icon").click(function () { let e = $("#inputField").val().slice(0, -1); $("#inputField").val(e), $(".entered-numbers .num").text(e) }) });