updata
This commit is contained in:
parent
be99c8618d
commit
10c58a72ce
@ -90,6 +90,138 @@ Vue.use(HappyScroll)
|
|||||||
// mockXHR()
|
// 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, {
|
Vue.use(Element, {
|
||||||
size: Cookies.get('size') || 'medium' // set element-ui default size
|
size: Cookies.get('size') || 'medium' // set element-ui default size
|
||||||
// locale: enLang // 如果使用中文,无需设置,请删除
|
// locale: enLang // 如果使用中文,无需设置,请删除
|
||||||
|
|||||||
@ -403,7 +403,6 @@ export default {
|
|||||||
background-color: #f5f7fa;
|
background-color: #f5f7fa;
|
||||||
min-height: calc(100vh - 40px);
|
min-height: calc(100vh - 40px);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
.table-container {
|
.table-container {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
|||||||
@ -94,6 +94,32 @@ module.exports = {
|
|||||||
alias: {
|
alias: {
|
||||||
'@': resolve('src')
|
'@': 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) {
|
chainWebpack(config) {
|
||||||
@ -128,6 +154,8 @@ module.exports = {
|
|||||||
symbolId: 'icon-[name]'
|
symbolId: 'icon-[name]'
|
||||||
})
|
})
|
||||||
.end()
|
.end()
|
||||||
|
|
||||||
|
// 生产环境配置
|
||||||
config
|
config
|
||||||
.when(process.env.NODE_ENV !== 'development',
|
.when(process.env.NODE_ENV !== 'development',
|
||||||
config => {
|
config => {
|
||||||
@ -165,7 +193,19 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
|
// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
|
||||||
config.optimization.runtimeChunk('single')
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user