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:
49
src/i18n/index.js
Normal file
49
src/i18n/index.js
Normal 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
|
||||
21
src/i18n/locales/en.js
Normal file
21
src/i18n/locales/en.js
Normal file
@@ -0,0 +1,21 @@
|
||||
// 英文语言包 -- 通过动态 import() 加载,被打成独立 chunk,
|
||||
// 只看中文的访客不会下载此文件。
|
||||
export default {
|
||||
app: {
|
||||
title: 'Zikai',
|
||||
subtitle: 'Portfolio',
|
||||
nav: {
|
||||
projects: 'Projects',
|
||||
language: 'Language'
|
||||
}
|
||||
},
|
||||
common: {
|
||||
loading: 'Loading…',
|
||||
comingSoon: 'Coming soon',
|
||||
notAvailable: 'Not available',
|
||||
backToTop: 'Back to top'
|
||||
},
|
||||
tabs: {
|
||||
mobileGame: 'Mobile Game Project'
|
||||
}
|
||||
}
|
||||
20
src/i18n/locales/zh-CN.js
Normal file
20
src/i18n/locales/zh-CN.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// 中文语言包(默认语言,同步注入主 chunk,随首屏下发)
|
||||
export default {
|
||||
app: {
|
||||
title: 'Zikai',
|
||||
subtitle: '作品集',
|
||||
nav: {
|
||||
projects: '项目',
|
||||
language: '语言'
|
||||
}
|
||||
},
|
||||
common: {
|
||||
loading: '加载中…',
|
||||
comingSoon: '即将上线',
|
||||
notAvailable: '暂不可用',
|
||||
backToTop: '回到顶部'
|
||||
},
|
||||
tabs: {
|
||||
mobileGame: '移动游戏项目'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user