fix: 首次访问获取客户端默认语言/静态路由title

This commit is contained in:
TsMask
2023-11-20 18:12:29 +08:00
parent 9fdd322757
commit e9054e320f
13 changed files with 142 additions and 35 deletions

View File

@@ -1,8 +1,27 @@
<script setup lang="ts">
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import useI18n from '@/hooks/useI18n';
import useAppStore from '@/store/modules/app';
const router = useRouter();
const route = useRoute();
const appStore = useAppStore();
const { t } = useI18n();
/**
* 国际化翻译转换
*/
function fnLocale() {
let title = route.meta.title as string;
if (title.indexOf('router.') !== -1) {
title = t(title);
}
appStore.setTitle(title);
}
onMounted(() => {
fnLocale();
});
</script>
<template>

View File

@@ -1,6 +1,26 @@
<script setup lang="ts">
import { onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import useI18n from '@/hooks/useI18n';
import useAppStore from '@/store/modules/app';
const route = useRoute();
const appStore = useAppStore();
const { t } = useI18n();
/**
* 国际化翻译转换
*/
function fnLocale() {
let title = route.meta.title as string;
if (title.indexOf('router.') !== -1) {
title = t(title);
}
appStore.setTitle(title);
}
onMounted(() => {
fnLocale();
});
</script>
<template>

View File

@@ -21,9 +21,9 @@ let state = reactive({
/**表单属性 */
from: {
/**账号 */
username: '',
username: 'supervisor',
/**密码 */
password: '',
password: 'rootaa',
/**验证码 */
code: '',
/**验证码uuid */
@@ -96,10 +96,22 @@ const calcBG = computed(() => {
backgroundSize: 'cover',
};
}
return undefined
return undefined;
});
/**
* 国际化翻译转换
*/
function fnLocale() {
let title = route.meta.title as string;
if (title.indexOf('router.') !== -1) {
title = t(title);
}
appStore.setTitle(title);
}
onMounted(() => {
fnLocale()
fnGetCaptcha();
});

View File

@@ -1,15 +1,16 @@
<script lang="ts" setup>
import { GlobalFooter } from '@ant-design-vue/pro-layout';
import { Modal, message } from 'ant-design-vue/lib';
import { reactive, toRaw } from 'vue';
import { onMounted, reactive, toRaw } from 'vue';
import { register } from '@/api/login';
import { regExpPasswd, regExpUserName } from '@/utils/regular-utils';
import { useRouter } from 'vue-router';
import { useRouter, useRoute } from 'vue-router';
import useAppStore from '@/store/modules/app';
import useI18n from '@/hooks/useI18n';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
const { t } = useI18n();
const router = useRouter();
const route = useRoute();
const appStore = useAppStore();
let state = reactive({
@@ -68,6 +69,21 @@ function fnFinish() {
state.formClick = false;
});
}
/**
* 国际化翻译转换
*/
function fnLocale() {
let title = route.meta.title as string;
if (title.indexOf('router.') !== -1) {
title = t(title);
}
appStore.setTitle(title);
}
onMounted(() => {
fnLocale();
});
</script>
<template>