2025-12-20 17:39:32 +08:00
|
|
|
|
import { createApp } from 'vue'
|
|
|
|
|
|
import App from './App.vue'
|
|
|
|
|
|
import router, { setupRouter } from '@/router'
|
|
|
|
|
|
import i18n from '@/i18n/index'
|
|
|
|
|
|
import { setupStore } from '@/store'
|
|
|
|
|
|
import { setupNaive, setupDirectives, setupCustomComponents, initFunction } from '@/plugins'
|
|
|
|
|
|
import { GoAppProvider } from '@/components/GoAppProvider/index'
|
|
|
|
|
|
import { setHtmlTheme, getUrlQueryParams } from '@/utils'
|
|
|
|
|
|
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
|
|
|
|
|
|
import { SystemStoreUserInfoEnum, SystemStoreEnum } from '@/store/modules/systemStore/systemStore.d'
|
|
|
|
|
|
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
|
|
|
|
|
import { ThemeEnum } from '@/enums/styleEnum'
|
|
|
|
|
|
import { addCollection } from 'iconify-icon'
|
|
|
|
|
|
import uimIcons from '@iconify/json/json/uim.json'
|
|
|
|
|
|
import lineMdIcons from '@iconify/json/json/line-md.json'
|
|
|
|
|
|
import wiIcons from '@iconify/json/json/wi.json'
|
|
|
|
|
|
|
|
|
|
|
|
// 引入全局样式
|
|
|
|
|
|
import '@/styles/pages/index.scss'
|
|
|
|
|
|
// 引入动画
|
|
|
|
|
|
import 'animate.css/animate.min.css'
|
|
|
|
|
|
// 引入标尺
|
|
|
|
|
|
import 'vue3-sketch-ruler/lib/style.css'
|
|
|
|
|
|
// 注册图标
|
|
|
|
|
|
addCollection(uimIcons)
|
|
|
|
|
|
addCollection(lineMdIcons)
|
|
|
|
|
|
addCollection(wiIcons)
|
|
|
|
|
|
|
|
|
|
|
|
async function appInit() {
|
|
|
|
|
|
const goAppProvider = createApp(GoAppProvider)
|
|
|
|
|
|
|
|
|
|
|
|
const app = createApp(App)
|
|
|
|
|
|
|
|
|
|
|
|
// 注册全局常用的 naive-ui 组件
|
|
|
|
|
|
setupNaive(app)
|
|
|
|
|
|
|
|
|
|
|
|
// 注册全局自定义指令
|
|
|
|
|
|
setupDirectives(app)
|
|
|
|
|
|
|
|
|
|
|
|
// 注册全局自定义组件
|
|
|
|
|
|
setupCustomComponents(app)
|
|
|
|
|
|
|
|
|
|
|
|
// 挂载状态管理
|
|
|
|
|
|
setupStore(app)
|
|
|
|
|
|
|
|
|
|
|
|
// iframe 嵌入模式:从 URL 参数中提取 token 并自动登录
|
|
|
|
|
|
const urlParams = getUrlQueryParams()
|
2025-12-27 12:57:38 +08:00
|
|
|
|
const systemStore = useSystemStore()
|
|
|
|
|
|
|
2025-12-20 17:39:32 +08:00
|
|
|
|
if (urlParams.token) {
|
2025-12-27 12:57:38 +08:00
|
|
|
|
// URL 中有 token,保存到本地
|
2025-12-20 17:39:32 +08:00
|
|
|
|
systemStore.setItem(SystemStoreEnum.USER_INFO, {
|
|
|
|
|
|
[SystemStoreUserInfoEnum.USER_TOKEN]: urlParams.token,
|
|
|
|
|
|
[SystemStoreUserInfoEnum.TOKEN_NAME]: 'token',
|
|
|
|
|
|
[SystemStoreUserInfoEnum.USER_ID]: 'iframe-user',
|
|
|
|
|
|
[SystemStoreUserInfoEnum.USER_NAME]: 'iframe-user',
|
|
|
|
|
|
[SystemStoreUserInfoEnum.NICK_NAME]: 'iframe-user',
|
|
|
|
|
|
})
|
2025-12-27 12:57:38 +08:00
|
|
|
|
console.log('[GoView] iframe 模式:已从 URL 参数中获取 token 并保存到本地')
|
2025-12-20 17:39:32 +08:00
|
|
|
|
} else {
|
2025-12-27 12:57:38 +08:00
|
|
|
|
// URL 中没有 token,从本地读取
|
|
|
|
|
|
const localToken = systemStore.getUserInfo?.[SystemStoreUserInfoEnum.USER_TOKEN]
|
|
|
|
|
|
if (localToken) {
|
|
|
|
|
|
console.log('[GoView] iframe 模式:已从本地存储读取 token')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.warn('[GoView] iframe 模式:URL 和本地都没有 token')
|
|
|
|
|
|
}
|
2025-12-20 17:39:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// iframe 嵌入模式:从 URL 参数中提取 mode 并设置主题
|
2025-12-27 12:57:38 +08:00
|
|
|
|
const designStore = useDesignStore()
|
|
|
|
|
|
|
2025-12-20 17:39:32 +08:00
|
|
|
|
if (urlParams.mode) {
|
2025-12-27 12:57:38 +08:00
|
|
|
|
// URL 中有 mode,设置主题并保存到本地
|
2025-12-20 17:39:32 +08:00
|
|
|
|
const isDark = urlParams.mode === 'dark'
|
|
|
|
|
|
const themeName = isDark ? ThemeEnum.DARK : ThemeEnum.LIGHT
|
|
|
|
|
|
|
|
|
|
|
|
if (designStore.themeName !== themeName) {
|
2025-12-23 01:06:06 +08:00
|
|
|
|
designStore.setTheme(isDark)
|
|
|
|
|
|
console.log(`[GoView] iframe 模式:已设置主题为 ${urlParams.mode} 并存储到本地`)
|
2025-12-20 17:39:32 +08:00
|
|
|
|
}
|
2025-12-27 12:57:38 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
// URL 中没有 mode,使用本地已保存的主题
|
|
|
|
|
|
console.log(`[GoView] iframe 模式:使用本地主题 ${designStore.themeName}`)
|
2025-12-20 17:39:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解决路由守卫,Axios中可使用,Dialog,Message 等全局组件
|
|
|
|
|
|
goAppProvider.mount('#appProvider', true)
|
|
|
|
|
|
|
|
|
|
|
|
// 挂载路由
|
|
|
|
|
|
setupRouter(app)
|
|
|
|
|
|
|
|
|
|
|
|
// 路由准备就绪后挂载APP实例
|
|
|
|
|
|
await router.isReady()
|
|
|
|
|
|
|
|
|
|
|
|
// Store 准备就绪后处理主题色
|
|
|
|
|
|
setHtmlTheme()
|
|
|
|
|
|
|
|
|
|
|
|
// 语言注册
|
|
|
|
|
|
app.use(i18n)
|
|
|
|
|
|
|
|
|
|
|
|
// 挂载到页面
|
|
|
|
|
|
app.mount('#app', true)
|
|
|
|
|
|
|
|
|
|
|
|
// 挂载到 window
|
|
|
|
|
|
window['$vue'] = app
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
appInit().then(() => {
|
|
|
|
|
|
initFunction()
|
|
|
|
|
|
})
|
|
|
|
|
|
|