1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2026-05-13 19:35:07 +00:00
Classworks/src/main.js

62 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* main.js
*
* 精简启动流水线:快速挂载 Vue app重型依赖Sentry/Clarity异步加载
*/
// 核心插件Vuetify / Router / Pinia
import { registerPlugins } from '@/plugins'
// Components
import App from './App.vue'
import GlobalMessage from '@/components/GlobalMessage.vue'
// Composables
import { createApp } from 'vue'
import messageService from './utils/message'
const app = createApp(App)
registerPlugins(app)
app.use(messageService)
app.component('GlobalMessage', GlobalMessage)
// 挂载 Vue app首要目标尽快渲染首屏
app.mount('#app')
// ====== 以下全部异步,不阻塞首屏渲染 ======
// 异步初始化 Sentry延迟到首帧渲染完成后防止 errorHandler 与渲染周期冲突)
setTimeout(() => {
import('./utils/sentry').then(({ initSentry }) => {
const router = app.config.globalProperties.$router
initSentry(app, router)
}).catch((err) => {
console.warn('Sentry 初始化失败:', err)
})
}, 1000)
// 异步加载 Clarity在页面完全加载后
const loadClarity = async () => {
try {
const { getVisitorId } = await import('./utils/visitorId')
const Clarity = (await import('@microsoft/clarity')).default
Clarity.init('rhp8uqoc3l')
const visitorId = await getVisitorId()
console.log('Visitor ID:', visitorId)
Clarity.identify(visitorId)
Clarity.setTag('fingerprintjs', visitorId)
} catch (error) {
console.warn('Clarity 加载或标识设置失败:', error)
}
}
if (document.readyState === 'complete') {
loadClarity()
} else {
window.addEventListener('load', loadClarity, { once: true })
}