feat: 首次提交NBA前端项目
This commit is contained in:
120
src/main.js
120
src/main.js
@@ -4,9 +4,127 @@ import 'element-plus/dist/index.css'
|
||||
import { createPinia } from 'pinia'
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
const app = createApp(App)
|
||||
const pinia = createPinia()
|
||||
|
||||
app.use(router)
|
||||
app.use(ElementPlus)
|
||||
app.use(createPinia())
|
||||
app.use(pinia)
|
||||
|
||||
// 应用启动时尝试根据后端 session 恢复登录态(需要后端正确返回 Set-Cookie)
|
||||
const userStore = useUserStore(pinia)
|
||||
userStore.fetchCurrentUser().catch(() => {
|
||||
// 静默失败,维持未登录状态
|
||||
})
|
||||
|
||||
app.mount('#app')
|
||||
|
||||
// ------------------ DevTools 防护(弱保护,易被绕过) ------------------
|
||||
// 说明:浏览器端无法绝对禁止 DevTools,以下脚本只是拦截常见快捷键并检测 DevTools 打开,
|
||||
// 在检测到时展示一个覆盖提示,增加逆向门槛,但有经验者仍可绕过。
|
||||
|
||||
// 拦截常见的打开 DevTools / 查看源码 的快捷键
|
||||
// function preventDevShortcuts(e) {
|
||||
// // F12
|
||||
// if (e.keyCode === 123) {
|
||||
// e.preventDefault()
|
||||
// return false
|
||||
// }
|
||||
// // Ctrl+Shift+I / Ctrl+Shift+J / Ctrl+U / Ctrl+S
|
||||
// if (e.ctrlKey && e.shiftKey && (e.key === 'I' || e.key === 'i' || e.key === 'J' || e.key === 'j')) {
|
||||
// e.preventDefault()
|
||||
// return false
|
||||
// }
|
||||
// if (e.ctrlKey && (e.key === 'U' || e.key === 'u' || e.key === 'S' || e.key === 's')) {
|
||||
// e.preventDefault()
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 禁用右键菜单(可选)
|
||||
// function preventContextMenu(e) {
|
||||
// // 如果你不想全局禁止右键,可以把这个函数内的逻辑改为更精确的判断
|
||||
// // e.preventDefault()
|
||||
// }
|
||||
|
||||
// // 检测 DevTools 是否打开(基于窗口尺寸差异的启发式方法)
|
||||
// function createDevToolsDetector(onOpen, onClose) {
|
||||
|
||||
// let devtoolsOpen = false
|
||||
// const threshold = 160 // 阈值,视浏览器和平台可调整
|
||||
|
||||
// function scan() {
|
||||
// try {
|
||||
// const widthDiff = window.outerWidth - window.innerWidth
|
||||
// const heightDiff = window.outerHeight - window.innerHeight
|
||||
// const currentlyOpen = widthDiff > threshold || heightDiff > threshold
|
||||
// if (currentlyOpen && !devtoolsOpen) {
|
||||
// devtoolsOpen = true
|
||||
// onOpen && onOpen()
|
||||
// } else if (!currentlyOpen && devtoolsOpen) {
|
||||
// devtoolsOpen = false
|
||||
// onClose && onClose()
|
||||
// }
|
||||
// } catch (e) {
|
||||
// // 忽略
|
||||
// }
|
||||
// }
|
||||
|
||||
// const id = setInterval(scan, 800)
|
||||
// // 返回停止检测的函数
|
||||
// return () => clearInterval(id)
|
||||
// }
|
||||
|
||||
// // 显示覆盖提示(简单实现)
|
||||
// function showOverlayMessage() {
|
||||
// debugger
|
||||
// if (document.getElementById('__devtools_block_overlay')) return
|
||||
// const o = document.createElement('div')
|
||||
// o.id = '__devtools_block_overlay'
|
||||
// Object.assign(o.style, {
|
||||
// position: 'fixed',
|
||||
// inset: '0',
|
||||
// background: 'rgba(0,0,0,0.7)',
|
||||
// color: '#fff',
|
||||
// display: 'flex',
|
||||
// alignItems: 'center',
|
||||
// justifyContent: 'center',
|
||||
// zIndex: '999999',
|
||||
// textAlign: 'center',
|
||||
// padding: '20px'
|
||||
// })
|
||||
// o.innerHTML = `<div style="max-width:560px"><h2 style="margin:0 0 12px;font-size:20px">检测到开发者工具</h2><p style="margin:0 0 18px;color:#ddd">为保护内容,当前页面在检测到开发者工具打开时被屏蔽。若要继续,请刷新页面或关闭开发者工具。</p><button id="__devtools_block_close" style="padding:10px 16px;border-radius:6px;border:none;background:#1890ff;color:#fff;font-weight:600;cursor:pointer">刷新页面</button></div>`
|
||||
// document.body.appendChild(o)
|
||||
// const btn = document.getElementById('__devtools_block_close')
|
||||
// if (btn) btn.addEventListener('click', () => location.reload())
|
||||
// }
|
||||
|
||||
// function removeOverlayMessage() {
|
||||
// const el = document.getElementById('__devtools_block_overlay')
|
||||
// if (el) el.remove()
|
||||
// }
|
||||
|
||||
// // 启动防护(放在监听器里以避免 SSR 问题)
|
||||
// if (typeof window !== 'undefined') {
|
||||
// window.addEventListener('keydown', preventDevShortcuts, { capture: true })
|
||||
// window.addEventListener('contextmenu', preventContextMenu, { capture: true })
|
||||
|
||||
// const stopDetector = createDevToolsDetector(() => {
|
||||
// // 打开时触发:显示覆盖提示
|
||||
// try { showOverlayMessage() } catch (e) {}
|
||||
// }, () => {
|
||||
// // 关闭时触发:移除覆盖
|
||||
// try { removeOverlayMessage() } catch (e) {}
|
||||
// })
|
||||
|
||||
// // 可选:在页面卸载时清理
|
||||
// window.addEventListener('beforeunload', () => {
|
||||
// window.removeEventListener('keydown', preventDevShortcuts, { capture: true })
|
||||
// window.removeEventListener('contextmenu', preventContextMenu, { capture: true })
|
||||
// stopDetector()
|
||||
// })
|
||||
// }
|
||||
|
||||
// ------------------ End DevTools 防护 ------------------
|
||||
|
||||
Reference in New Issue
Block a user