Files
wecom_it_smart_desk/frontend-h5/src/main.ts
T

65 lines
2.6 KiB
TypeScript
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.
// =============================================================================
// 企微IT智能服务台 — H5用户端应用入口
// =============================================================================
// 说明:Vue3 应用入口文件,负责:
// 1. 创建 Vue 应用实例
// 2. 注册 Vant4 移动端组件库
// 3. 注册 Pinia 状态管理
// 4. 注册 Vue Router 路由
// 5. 挂载到 DOM
// =============================================================================
import { createApp } from 'vue'
// 根组件
import App from './App.vue'
// 路由配置
import router from './router'
// Pinia 状态管理
import { createPinia } from 'pinia'
// 全局样式
import './styles/global.css'
// 创建 Vue 应用实例
const app = createApp(App)
// --------------------------------------------------------------------------
// 注册插件
// --------------------------------------------------------------------------
// Pinia: 状态管理(存储会话信息、摇人状态等)
app.use(createPinia())
// Vue Router: 路由管理(页面跳转)
app.use(router)
// 注意:Vant 组件通过 vite 插件 unplugin-vue-components 按需自动导入,
// 不需要在这里手动注册,减小打包体积
// --------------------------------------------------------------------------
// v0.5.2:挂载应用 + 显式关闭骨架屏(避免 :empty 选择器失效)
// --------------------------------------------------------------------------
// 1. 记录挂载开始时间(用于最小显示时间)
const mountStart = Date.now()
// 2. 最小显示时间 500ms(防止 Vue 太快挂载导致骨架屏"闪一下看不见")
const MIN_SKELETON_DISPLAY_MS = 500
app.mount('#app')
// 3. 挂载完成后,主动给 body 加 .app-loaded 类名,触发 CSS 隐藏骨架屏
// 比之前用 :empty 选择器更可靠(尤其在 Vue mount < 100ms 的情况下)
const elapsed = Date.now() - mountStart
if (elapsed >= MIN_SKELETON_DISPLAY_MS) {
document.body.classList.add('app-loaded')
} else {
setTimeout(() => {
document.body.classList.add('app-loaded')
}, MIN_SKELETON_DISPLAY_MS - elapsed)
}
// --------------------------------------------------------------------------
// 企微 OAuth2 授权检查(已迁移至路由守卫 router/index.ts
// --------------------------------------------------------------------------
// OAuth2 授权逻辑现在在路由守卫中统一处理:
// 1. 检查 URL 中的 code 参数
// 2. 有 code → 调用后端 OAuth2 回调
// 3. 无 code → 跳转企微授权页面
// 参见:frontend-h5/src/router/index.ts 中的 router.beforeEach