From 10c58a72ce82e9145a801db10dd059946395fb62 Mon Sep 17 00:00:00 2001 From: hrx <18603305412@163.com> Date: Thu, 20 Nov 2025 10:14:52 +0800 Subject: [PATCH] updata --- f/web-kboss/src/main.js | 132 ++++++++++++++++++ .../customerInformationList/index.vue | 1 - f/web-kboss/vue.config.js | 40 ++++++ 3 files changed, 172 insertions(+), 1 deletion(-) diff --git a/f/web-kboss/src/main.js b/f/web-kboss/src/main.js index a8cef51..504e5c6 100644 --- a/f/web-kboss/src/main.js +++ b/f/web-kboss/src/main.js @@ -90,6 +90,138 @@ Vue.use(HappyScroll) // mockXHR() // } +// ==================== 防 F12 和右键检查功能开始 ==================== +// 只在生产环境启用防调试功能 +if (process.env.NODE_ENV === 'production') { + // 禁止右键菜单 + document.addEventListener('contextmenu', function(e) { + e.preventDefault(); + return false; + }); + + // 禁止F12和开发者工具快捷键 + document.addEventListener('keydown', function(e) { + // 禁止F12 + if (e.key === 'F12') { + e.preventDefault(); + return false; + } + + // 禁止Ctrl+Shift+I (Chrome, Edge) + if (e.ctrlKey && e.shiftKey && e.key === 'I') { + e.preventDefault(); + return false; + } + + // 禁止Ctrl+Shift+J (Chrome) + if (e.ctrlKey && e.shiftKey && e.key === 'J') { + e.preventDefault(); + return false; + } + + // 禁止Ctrl+U (查看源代码) + if (e.ctrlKey && e.key === 'u') { + e.preventDefault(); + return false; + } + + // 禁止Ctrl+Shift+C (开发者工具检查元素) + if (e.ctrlKey && e.shiftKey && e.key === 'C') { + e.preventDefault(); + return false; + } + + // 禁止Ctrl+Shift+J (Firefox) + if (e.ctrlKey && e.shiftKey && e.key === 'K') { + e.preventDefault(); + return false; + } + }); + + // 检测开发者工具是否打开 + let lastTime = Date.now(); + function checkDebugger() { + const currentTime = Date.now(); + if (currentTime - lastTime > 100) { + // 如果时间差大于100ms,可能是在调试 + handleDebuggerDetected(); + } + lastTime = currentTime; + } + + // 处理检测到调试器的情况 + function handleDebuggerDetected() { + // 可以采取以下措施之一: + + // 1. 显示警告信息(推荐) + alert('检测到开发者工具已打开,为了系统安全,请关闭开发者工具。'); + + // 2. 跳转到关于页面或其他安全页面 + // window.location.href = '/about'; + + // 3. 清空敏感数据 + // sessionStorage.clear(); + // localStorage.clear(); + + // 4. 关闭窗口(慎用) + // window.close(); + } + + // 定期检查 + setInterval(function() { + checkDebugger(); + // 使用debugger检测 + (function() { + const startTime = Date.now(); + debugger; + const endTime = Date.now(); + if (endTime - startTime > 100) { + handleDebuggerDetected(); + } + })(); + }, 1000); + + // 禁用控制台输出(可选,根据需求开启) + // 注意:这会影响你自己的console.log调试,建议只在生产环境使用 + if (typeof console !== 'undefined') { + const noop = () => {}; + const methods = ['log', 'debug', 'info', 'warn', 'error', 'table', 'dir', 'trace']; + methods.forEach(method => { + console[method] = noop; + }); + + // 防止重写console被绕过 + Object.defineProperty(window, 'console', { + get: function() { + return { + log: noop, debug: noop, info: noop, warn: noop, error: noop, + table: noop, dir: noop, trace: noop + }; + }, + set: function() {} + }); + } + + // 检测窗口大小变化(开发者工具打开时窗口大小会变化) + let lastWidth = window.innerWidth; + let lastHeight = window.innerHeight; + + window.addEventListener('resize', function() { + const currentWidth = window.innerWidth; + const currentHeight = window.innerHeight; + + if (Math.abs(currentWidth - lastWidth) > 100 || Math.abs(currentHeight - lastHeight) > 100) { + handleDebuggerDetected(); + } + + lastWidth = currentWidth; + lastHeight = currentHeight; + }); + + console.log('防调试保护已启用'); +} +// ==================== 防 F12 和右键检查功能结束 ==================== + Vue.use(Element, { size: Cookies.get('size') || 'medium' // set element-ui default size // locale: enLang // 如果使用中文,无需设置,请删除 diff --git a/f/web-kboss/src/views/sales/customerManagement/customerInformationList/index.vue b/f/web-kboss/src/views/sales/customerManagement/customerInformationList/index.vue index 939e66d..e619926 100644 --- a/f/web-kboss/src/views/sales/customerManagement/customerInformationList/index.vue +++ b/f/web-kboss/src/views/sales/customerManagement/customerInformationList/index.vue @@ -403,7 +403,6 @@ export default { background-color: #f5f7fa; min-height: calc(100vh - 40px); box-sizing: border-box; - .table-container { background: #fff; border-radius: 8px; diff --git a/f/web-kboss/vue.config.js b/f/web-kboss/vue.config.js index 9bee4dc..ac1ec45 100644 --- a/f/web-kboss/vue.config.js +++ b/f/web-kboss/vue.config.js @@ -94,6 +94,32 @@ module.exports = { alias: { '@': resolve('src') } + }, + // 生产环境去除console和debugger + optimization: { + minimizer: [ + { + apply: (compiler) => { + // 只在生产环境生效 + if (process.env.NODE_ENV === 'production') { + const TerserPlugin = require('terser-webpack-plugin') + new TerserPlugin({ + terserOptions: { + compress: { + drop_console: true, // 移除console + drop_debugger: true, // 移除debugger + pure_funcs: ['console.log', 'console.info', 'console.warn', 'console.error'] // 移除特定的console方法 + }, + mangle: true, // 代码混淆 + output: { + comments: false // 移除注释 + } + } + }).apply(compiler) + } + } + } + ] } }, chainWebpack(config) { @@ -128,6 +154,8 @@ module.exports = { symbolId: 'icon-[name]' }) .end() + + // 生产环境配置 config .when(process.env.NODE_ENV !== 'development', config => { @@ -165,7 +193,19 @@ module.exports = { }) // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk config.optimization.runtimeChunk('single') + + // 生产环境启用代码压缩和优化 + config.optimization.minimize(true) } ) + + // 添加防调试插件配置(可选) + if (process.env.NODE_ENV === 'production') { + // 可以在这里添加其他生产环境特定的防调试配置 + config.plugin('define').tap(args => { + args[0]['process.env'].DISABLE_DEBUG = 'true' + return args + }) + } } }