import { VCAM_LIST } from "@/constants/constant-namelist"; import { store } from "@/store/store"; import { execLocal, fileExists } from "@/utils/nativeMethods"; import { watch } from "vue"; export function useVCamChecker() { /** 检测出错则提示;检测通过则将禁用登录按钮的flag置为false */ async function checkVCamTxt() { let cameraInfo; try { const fs: typeof import("fs") = window.nodeRequire("fs"); try { cameraInfo = fs.readFileSync("CameraInfo.txt", "utf-8"); } catch (error) { logger({ cnl: ["local", "server"], key: "checkVCamTxt", pgu: "AUTO", dtl: "CameraInfo.txt出错--0", ejn: JSON.stringify(error), }); await new Promise((resolve2) => setTimeout(resolve2, 3000)); cameraInfo = fs.readFileSync("CameraInfo.txt", "utf-8"); } } catch (error) { logger({ cnl: ["local", "server"], key: "checkVCamTxt", pgu: "AUTO", stk: error instanceof Error ? error.message : JSON.stringify(error), dtl: "读取CameraInfo.txt出错", ext: { errorType: "e-02", applicationNames: cameraInfo }, }); $message.error("系统检测出错(e-02),请退出程序后重试!", { duration: 2 * 24 * 60 * 60, }); return; } let found = false; if (cameraInfo && cameraInfo.trim()) { for (const vc of VCAM_LIST) { if (cameraInfo.toUpperCase().includes(vc.toUpperCase())) { found = true; $message.info("在考试期间,请关掉虚拟摄像头软件,诚信考试。", { duration: 2 * 24 * 60 * 60, }); logger({ cnl: ["local", "server"], key: "checkVCamTxt", pgu: "AUTO", dtl: "提示CameraInfo.txt成功", ext: { applicationNames: cameraInfo }, }); } } } disableLoginBtnBecauseVCam = found; } let disableLoginBtnBecauseVCam = $ref(true); const QECSConfig = $computed(() => store.QECSConfig); watch(QECSConfig, async () => { if ( !QECSConfig.PREVENT_CHEATING_CONFIG.includes("DISABLE_VIRTUAL_CAMERA") ) { disableLoginBtnBecauseVCam = false; return; } if (import.meta.env.DEV) return; const fs: typeof import("fs") = window.nodeRequire("fs"); try { fileExists("CameraInfo.txt") && fs.unlinkSync("CameraInfo.txt"); } catch (error) { console.log(error); logger({ cnl: ["local", "server"], key: "checkVCamTxt", dtl: "unlink CameraInfo.txt 失败", }); } await execLocal("multiCamera.exe"); await checkVCamTxt(); }); return { disableLoginBtnBecauseVCam: $$(disableLoginBtnBecauseVCam) }; }