111 lines
3.1 KiB
JavaScript
111 lines
3.1 KiB
JavaScript
import './assets/main.css'
|
||
import { logEnvInfo } from './utils/env.js'
|
||
import { versionChecker } from './utils/versionChecker.js'
|
||
import { imageCacheManager } from '@/utils/imageCacheManager'
|
||
import { smartImage } from './directives/smartImage.js'
|
||
import { createPinia } from 'pinia'
|
||
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||
import { createApp } from 'vue'
|
||
import i18n, { initI18n, setLocale } from './locales/i18n'
|
||
|
||
import App from './App.vue'
|
||
import router from './router'
|
||
import { useLangStore } from '@/stores/lang' // 移动到顶部
|
||
|
||
// 初始化环境信息
|
||
logEnvInfo()
|
||
|
||
// 版本检查后添加
|
||
versionChecker.checkVersion().then(() => {
|
||
// 主动清理过期的图片缓存
|
||
imageCacheManager.clearOldCaches()
|
||
})
|
||
|
||
// 初始化权限系统
|
||
console.debug('🔐 Permission system initialized')
|
||
const pinia = createPinia()
|
||
pinia.use(piniaPluginPersistedstate) //将插件添加到 pinia 实例上
|
||
|
||
const app = createApp(App)
|
||
|
||
// 注册智能图片指令
|
||
app.directive('smart-img', smartImage)
|
||
|
||
app.use(router)
|
||
app.use(pinia)
|
||
|
||
// 然后初始化 i18n(此时 Pinia 已可用)
|
||
// 获取 langStore 并传递给 initI18n
|
||
const langStore = useLangStore() // 直接使用 import 的函数
|
||
|
||
//排行榜
|
||
const RankingPage = [
|
||
'/top-list', //排行榜
|
||
'/weekly-star', //每周明星
|
||
]
|
||
|
||
// 活动页面
|
||
const ACTIVITIES = [
|
||
'/recharge-reward', //充值奖励页面
|
||
|
||
'/Yemen-independence-day', //也门独立日
|
||
'/UAE-independence-day', //阿联酋独立日
|
||
]
|
||
|
||
// 固定语言(布局)的页面
|
||
const enPages = [...RankingPage, ...ACTIVITIES]
|
||
const arPages = []
|
||
|
||
// 获取当前页面路径
|
||
const hashPath = window.location.hash.replace('#', '')
|
||
const currentPage = hashPath.split('?')[0] // 提取纯路径部分,去除查询参数
|
||
|
||
// 检测URL参数并设置语言
|
||
const queryParams = hashPath.split('?')[1]
|
||
const urlParams = queryParams ? new URLSearchParams(queryParams) : new URLSearchParams()
|
||
const langParam = urlParams.get('lang')
|
||
|
||
let finalLang = null // 最终使用的语言
|
||
if (langParam) {
|
||
if (langParam === 'en') {
|
||
finalLang = 'en'
|
||
} else if (langParam.startsWith('ar')) {
|
||
finalLang = 'ar'
|
||
}
|
||
}
|
||
|
||
// 检查当前页面是否在固定英语的页面列表中
|
||
if (enPages.includes(currentPage)) {
|
||
// 强制设置为英语,不受URL参数影响
|
||
setLocale(langStore, 'en')
|
||
}
|
||
// 检查当前页面是否在固定阿拉伯语的页面列表中
|
||
else if (arPages.includes(currentPage)) {
|
||
// 强制设置为阿拉伯语,不受URL参数影响
|
||
setLocale(langStore, 'ar')
|
||
}
|
||
// 对于其他页面,如果有URL参数则按参数设置语言
|
||
else if (finalLang) {
|
||
console.log('langParam:', langParam)
|
||
console.log('finalLang:', finalLang)
|
||
setLocale(langStore, finalLang)
|
||
}
|
||
|
||
initI18n(langStore)
|
||
|
||
// 最后使用 i18n
|
||
app.use(i18n)
|
||
|
||
app.mount('#app')
|
||
|
||
// 定时检查逻辑
|
||
if (versionChecker.enableCheck) {
|
||
setInterval(async () => {
|
||
const versionResult = await versionChecker.checkServerVersion()
|
||
if (versionResult.shouldUpdate) {
|
||
// 自动处理更新,不需要用户交互
|
||
await versionChecker.handleVersionUpdate(versionResult.versionType)
|
||
}
|
||
}, 5 * 60 * 1000)
|
||
}
|