feat: init mainPage portfolio site

Vue 3 模块化作品集主页,浅色极简风格,中英双语懒加载 i18n。

- 模块注册表(import.meta.glob)约定式收集项目模块,新增页签无需改导航/路由
- i18n: 中文同步注入主 chunk,英文动态 import() 拆独立 chunk,仅切换时下载
- 第一个页签 mobile-game: 展示 448/449 移动游戏毕设(概览/截图轮播/版本时间线/团队/排行榜/ML视频)
- 排行榜复用 /449/449rest.php,失败优雅降级
- 构建: vite outDir=/root/html,emptyOutDir=false,产物用 mainPage/ 命名空间
- 样式: CSS 变量令牌,无 UI 框架运行时依赖
This commit is contained in:
Zikai
2026-07-12 14:18:35 +00:00
commit 15af291da0
31 changed files with 2927 additions and 0 deletions

49
src/i18n/index.js Normal file
View File

@@ -0,0 +1,49 @@
import { createI18n } from 'vue-i18n'
import zhCN from './locales/zh-CN.js'
// ★ 懒加载设计:创建实例时只同步注入中文(默认语言)。
// 英文 (en.js) 通过 useI18nLazy 中的动态 import() 按需加载,
// 被 Vite/Rollup 拆成独立 chunk只看中文的访客永不下载英文资源。
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
fallbackLocale: 'zh-CN',
messages: {
'zh-CN': zhCN
}
})
// 已加载语言集合,避免重复 import
const loadedLocales = new Set(['zh-CN'])
/**
* 懒加载并切换到目标语言。
* 首次切换某语言时才动态 import 其语言包并 mergeLocaleMessage
* 之后切换仅在已加载集合内完成(无网络请求)。
*/
export async function loadLocaleAsync(locale) {
if (i18n.locale.value === locale) return
if (loadedLocales.has(locale)) {
i18n.locale.value = locale
document.documentElement.setAttribute('lang', locale)
return
}
let messages
if (locale === 'en') {
// 动态 import -> 独立 chunk切换时才下载
messages = (await import('./locales/en.js')).default
} else {
// 未知语言回退到中文
i18n.locale.value = 'zh-CN'
document.documentElement.setAttribute('lang', 'zh-CN')
return
}
i18n.mergeLocaleMessage(locale, messages)
loadedLocales.add(locale)
i18n.locale.value = locale
document.documentElement.setAttribute('lang', locale)
}
export default i18n