This commit is contained in:
ping 2025-11-20 17:07:23 +08:00
commit c01b49c43b
2 changed files with 152 additions and 153 deletions

View File

@ -92,184 +92,184 @@ Vue.use(HappyScroll)
// ==================== 防 F12 和右键检查功能开始 ==================== // ==================== 防 F12 和右键检查功能开始 ====================
// 只在生产环境启用防调试功能 // 只在生产环境启用防调试功能
if (process.env.NODE_ENV === 'production') { // if (process.env.NODE_ENV === 'production') {
// 禁止右键菜单 // // 禁止右键菜单
document.addEventListener('contextmenu', function(e) { // document.addEventListener('contextmenu', function(e) {
e.preventDefault(); // e.preventDefault();
return false; // return false;
}); // });
// 禁止F12和开发者工具快捷键 // // 禁止F12和开发者工具快捷键
document.addEventListener('keydown', function(e) { // document.addEventListener('keydown', function(e) {
// 禁止F12 // // 禁止F12
if (e.key === 'F12') { // if (e.key === 'F12') {
e.preventDefault(); // e.preventDefault();
return false; // return false;
} // }
// 禁止Ctrl+Shift+I (Chrome, Edge) // // 禁止Ctrl+Shift+I (Chrome, Edge)
if (e.ctrlKey && e.shiftKey && e.key === 'I') { // if (e.ctrlKey && e.shiftKey && e.key === 'I') {
e.preventDefault(); // e.preventDefault();
return false; // return false;
} // }
// 禁止Ctrl+Shift+J (Chrome) // // 禁止Ctrl+Shift+J (Chrome)
if (e.ctrlKey && e.shiftKey && e.key === 'J') { // if (e.ctrlKey && e.shiftKey && e.key === 'J') {
e.preventDefault(); // e.preventDefault();
return false; // return false;
} // }
// 禁止Ctrl+U (查看源代码) // // 禁止Ctrl+U (查看源代码)
if (e.ctrlKey && e.key === 'u') { // if (e.ctrlKey && e.key === 'u') {
e.preventDefault(); // e.preventDefault();
return false; // return false;
} // }
// 禁止Ctrl+Shift+C (开发者工具检查元素) // // 禁止Ctrl+Shift+C (开发者工具检查元素)
if (e.ctrlKey && e.shiftKey && e.key === 'C') { // if (e.ctrlKey && e.shiftKey && e.key === 'C') {
e.preventDefault(); // e.preventDefault();
return false; // return false;
} // }
// 禁止Ctrl+Shift+J (Firefox) // // 禁止Ctrl+Shift+J (Firefox)
if (e.ctrlKey && e.shiftKey && e.key === 'K') { // if (e.ctrlKey && e.shiftKey && e.key === 'K') {
e.preventDefault(); // e.preventDefault();
return false; // return false;
} // }
}); // });
// 更准确的开发者工具检测 // // 更准确的开发者工具检测
let isDevToolsOpened = false; // let isDevToolsOpened = false;
// 方法1: 检查开发者工具宽度 // // 方法1: 检查开发者工具宽度
function checkDevToolsByWidth() { // function checkDevToolsByWidth() {
const threshold = 160; // 开发者工具通常至少160px宽 // const threshold = 160; // 开发者工具通常至少160px宽
const widthThreshold = window.outerWidth - window.innerWidth > threshold; // const widthThreshold = window.outerWidth - window.innerWidth > threshold;
const heightThreshold = window.outerHeight - window.innerHeight > threshold; // const heightThreshold = window.outerHeight - window.innerHeight > threshold;
return widthThreshold || heightThreshold; // return widthThreshold || heightThreshold;
} // }
// 方法2: 检查debugger执行时间更宽松的阈值 // // 方法2: 检查debugger执行时间更宽松的阈值
function checkDevToolsByDebugger() { // function checkDevToolsByDebugger() {
return new Promise((resolve) => { // return new Promise((resolve) => {
const start = performance.now(); // const start = performance.now();
debugger; // debugger;
const end = performance.now(); // const end = performance.now();
// 使用更宽松的阈值,避免误报 // // 使用更宽松的阈值,避免误报
resolve(end - start > 200); // resolve(end - start > 200);
}); // });
} // }
// 方法3: 检查控制台是否打开 // // 方法3: 检查控制台是否打开
function checkDevToolsByConsole() { // function checkDevToolsByConsole() {
const element = new Image(); // const element = new Image();
Object.defineProperty(element, 'id', { // Object.defineProperty(element, 'id', {
get: function() { // get: function() {
isDevToolsOpened = true; // isDevToolsOpened = true;
} // }
}); // });
console.log(element); // console.log(element);
console.clear(); // 清除测试日志 // console.clear(); // 清除测试日志
} // }
// 方法4: 检查Eruda等移动端调试工具 // // 方法4: 检查Eruda等移动端调试工具
function checkMobileDevTools() { // function checkMobileDevTools() {
return !!(window.eruda || window.__eruda || window.vConsole); // return !!(window.eruda || window.__eruda || window.vConsole);
} // }
// 处理检测到调试器的情况 // // 处理检测到调试器的情况
function handleDebuggerDetected() { // function handleDebuggerDetected() {
if (!isDevToolsOpened) { // if (!isDevToolsOpened) {
isDevToolsOpened = true; // isDevToolsOpened = true;
// 可以选择以下一种或多种处理方式 // // 可以选择以下一种或多种处理方式
// 1. 显示警告信息(推荐) // // 1. 显示警告信息(推荐)
alert('检测到开发者工具已打开,为了系统安全,请关闭开发者工具。'); // alert('检测到开发者工具已打开,为了系统安全,请关闭开发者工具。');
// 2. 跳转到关于页面或其他安全页面 // // 2. 跳转到关于页面或其他安全页面
// window.location.href = '/about'; // // window.location.href = '/about';
// 3. 清空敏感数据 // // 3. 清空敏感数据
// sessionStorage.clear(); // // sessionStorage.clear();
// localStorage.clear(); // // localStorage.clear();
// 4. 关闭窗口(慎用) // // 4. 关闭窗口(慎用)
// window.close(); // // window.close();
// 5. 禁用页面交互 // // 5. 禁用页面交互
// document.body.innerHTML = '<h1>请关闭开发者工具后刷新页面</h1>'; // // document.body.innerHTML = '<h1>请关闭开发者工具后刷新页面</h1>';
} // }
} // }
// 定期检查(使用更宽松的间隔) // // 定期检查(使用更宽松的间隔)
const checkInterval = setInterval(async function() { // const checkInterval = setInterval(async function() {
// 如果已经检测到开发工具打开,停止检查 // // 如果已经检测到开发工具打开,停止检查
if (isDevToolsOpened) { // if (isDevToolsOpened) {
clearInterval(checkInterval); // clearInterval(checkInterval);
return; // return;
} // }
// 检查移动端调试工具 // // 检查移动端调试工具
if (checkMobileDevTools()) { // if (checkMobileDevTools()) {
handleDebuggerDetected(); // handleDebuggerDetected();
return; // return;
} // }
// 检查窗口大小 // // 检查窗口大小
if (checkDevToolsByWidth()) { // if (checkDevToolsByWidth()) {
handleDebuggerDetected(); // handleDebuggerDetected();
return; // return;
} // }
// 检查debugger异步 // // 检查debugger异步
const isDebugging = await checkDevToolsByDebugger(); // const isDebugging = await checkDevToolsByDebugger();
if (isDebugging) { // if (isDebugging) {
handleDebuggerDetected(); // handleDebuggerDetected();
return; // return;
} // }
// 偶尔检查控制台(不要太频繁) // // 偶尔检查控制台(不要太频繁)
if (Math.random() < 0.1) { // 10%的概率检查 // if (Math.random() < 0.1) { // 10%的概率检查
checkDevToolsByConsole(); // checkDevToolsByConsole();
} // }
}, 2000); // 每2秒检查一次减少性能影响 // }, 2000); // 每2秒检查一次减少性能影响
// 监听窗口大小变化(添加去抖) // // 监听窗口大小变化(添加去抖)
let resizeTimer; // let resizeTimer;
window.addEventListener('resize', function() { // window.addEventListener('resize', function() {
clearTimeout(resizeTimer); // clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() { // resizeTimer = setTimeout(function() {
if (checkDevToolsByWidth() && !isDevToolsOpened) { // if (checkDevToolsByWidth() && !isDevToolsOpened) {
handleDebuggerDetected(); // handleDebuggerDetected();
} // }
}, 500); // }, 500);
}); // });
// 禁用控制台输出(可选,根据需求开启) // // 禁用控制台输出(可选,根据需求开启)
// 注意这会影响你自己的console.log调试建议只在生产环境使用 // // 注意这会影响你自己的console.log调试建议只在生产环境使用
if (typeof console !== 'undefined') { // if (typeof console !== 'undefined') {
const noop = () => {}; // const noop = () => {};
const methods = ['log', 'debug', 'info', 'warn', 'error', 'table', 'dir', 'trace']; // const methods = ['log', 'debug', 'info', 'warn', 'error', 'table', 'dir', 'trace'];
methods.forEach(method => { // methods.forEach(method => {
console[method] = noop; // console[method] = noop;
}); // });
// 防止重写console被绕过 // // 防止重写console被绕过
Object.defineProperty(window, 'console', { // Object.defineProperty(window, 'console', {
get: function() { // get: function() {
return { // return {
log: noop, debug: noop, info: noop, warn: noop, error: noop, // log: noop, debug: noop, info: noop, warn: noop, error: noop,
table: noop, dir: noop, trace: noop // table: noop, dir: noop, trace: noop
}; // };
}, // },
set: function() {} // set: function() {}
}); // });
} // }
console.log('防调试保护已启用'); // console.log('防调试保护已启用');
} // }
// ==================== 防 F12 和右键检查功能结束 ==================== // ==================== 防 F12 和右键检查功能结束 ====================
Vue.use(Element, { Vue.use(Element, {

View File

@ -64,8 +64,7 @@
<p><i class="el-icon-phone"></i> 手机号: {{ userInfo.mobile }}</p> <p><i class="el-icon-phone"></i> 手机号: {{ userInfo.mobile }}</p>
<p><i class="el-icon-message"></i> 邮箱: {{ userInfo.email }}</p> <p><i class="el-icon-message"></i> 邮箱: {{ userInfo.email }}</p>
</div> </div>
</div> </div>· </div>
</div>
<div class="price card"> <div class="price card">
<div class="title">账户余额</div> <div class="title">账户余额</div>