变量定义,title优化

This commit is contained in:
Gary Fu
2023-12-24 13:22:36 +08:00
parent 6696f56ee5
commit f4f25798b9
7 changed files with 19 additions and 6 deletions

3
.env Normal file
View File

@@ -0,0 +1,3 @@
# 程序名称
VITE_APP_NAME=Simple Element+

View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
<title>%VITE_APP_NAME%</title>
</head>
<body>
<div id="app"></div>

View File

@@ -1,9 +1,13 @@
<script setup>
import { useGlobalConfigStore } from '@/stores/GlobalConfigStore'
import { $changeLocale, elementLocale } from '@/messages'
import { $changeLocale, elementLocale, $i18nBundle } from '@/messages'
import { useTitle } from '@vueuse/core'
import { computed } from 'vue'
const globalConfigStore = useGlobalConfigStore()
$changeLocale(globalConfigStore.currentLocale)
const title = computed(() => $i18nBundle('common.label.title'))
useTitle(title)
</script>
<template>

View File

@@ -1,6 +1,7 @@
import { baseMessages } from '@/messages/base'
export const common = baseMessages()
common.label.title = '简单Element+模板'
common.label.login = '登录'
common.label.index = '首页'
common.label.langCn = '中文'

View File

@@ -1,6 +1,7 @@
import { baseMessages } from '@/messages/base'
export const common = baseMessages()
common.label.title = 'Simple Element+'
common.label.login = 'Login'
common.label.index = 'Home'
common.label.langCn = '中文'

View File

@@ -1,4 +1,4 @@
import { createI18n } from 'vue-i18n'
import { createI18n, useI18n } from 'vue-i18n'
import { ref } from 'vue'
import messagesCn from './messages_cn'
import messagesEn from './messages_en'
@@ -41,7 +41,7 @@ export const $changeLocale = locale => {
* @param {boolean} replaceEmpty 为空是否用不为空的数据代替
* @returns {*}
*/
export const $i18nMsg = function (cn, en, replaceEmpty) {
export const $i18nMsg = (cn, en, replaceEmpty) => {
const { currentLocale } = useGlobalConfigStore()
console.log(currentLocale)
if (currentLocale === GlobalLocales.CN) {
@@ -50,12 +50,15 @@ export const $i18nMsg = function (cn, en, replaceEmpty) {
return replaceEmpty ? (en || cn) : en
}
export const $i18nBundle = i18n.global.t
export default {
install (app) {
app.use(i18n)
Object.assign(app.config.globalProperties, {
$changeLocale,
$i18nMsg
$i18nMsg,
$i18nBundle
})
}
}

View File

@@ -1,6 +1,7 @@
import { GlobalLayoutMode, GlobalLocales } from '@/consts/GlobalConstants'
import { useGlobalConfigStore } from '@/stores/GlobalConfigStore'
import { ref } from 'vue'
import { $i18nBundle } from '@/messages'
export const useBaseTopMenus = () => {
const globalConfigStore = useGlobalConfigStore()
@@ -86,7 +87,7 @@ export const useBusinessMenus = () => {
return ref([
{
icon: 'HomeFilled',
label: 'Simple Element Plus'
labelIf: () => $i18nBundle('common.label.title')
},
{
icon: 'setting',