feat: UI i18n depends on router (#289)

This commit is contained in:
Dream Hunter
2024-06-01 12:12:13 +08:00
committed by GitHub
parent 7a368d7b23
commit b792c196c1
38 changed files with 106 additions and 102 deletions
+3 -7
View File
@@ -9,18 +9,14 @@ import Footer from './views/Footer.vue';
const { const {
localeCache, isDark, loading, useSideMargin, isDark, loading, useSideMargin, telegramApp, isTelegram
telegramApp, isTelegram
} = useGlobalState() } = useGlobalState()
const { locale } = useI18n({});
const theme = computed(() => isDark.value ? darkTheme : null) const theme = computed(() => isDark.value ? darkTheme : null)
const localeConfig = computed(() => localeCache.value == 'zh' ? zhCN : null) const localeConfig = computed(() => locale.value == 'zh' ? zhCN : null)
const isMobile = useIsMobile() const isMobile = useIsMobile()
const showSideMargin = computed(() => !isMobile.value && useSideMargin.value); const showSideMargin = computed(() => !isMobile.value && useSideMargin.value);
const { locale } = useI18n({
useScope: 'global',
});
locale.value = localeCache.value;
onMounted(async () => { onMounted(async () => {
const token = import.meta.env.VITE_CF_WEB_ANALY_TOKEN; const token = import.meta.env.VITE_CF_WEB_ANALY_TOKEN;
+1 -4
View File
@@ -1,6 +1,5 @@
<script setup> <script setup>
import { watch, onMounted, ref, onBeforeUnmount } from "vue"; import { watch, onMounted, ref, onBeforeUnmount } from "vue";
import { useRouter } from "vue-router";
import { useMessage } from 'naive-ui' import { useMessage } from 'naive-ui'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../store' import { useGlobalState } from '../store'
@@ -10,7 +9,6 @@ import { processItem, getDownloadEmlUrl } from '../utils/email-parser'
const message = useMessage() const message = useMessage()
const isMobile = useIsMobile() const isMobile = useIsMobile()
const router = useRouter()
const props = defineProps({ const props = defineProps({
enableUserDeleteEmail: { enableUserDeleteEmail: {
@@ -41,7 +39,7 @@ const props = defineProps({
}) })
const { const {
localeCache, isDark, mailboxSplitSize, indexTab, isDark, mailboxSplitSize, indexTab,
useIframeShowMail, sendMailModel, preferShowTextMail useIframeShowMail, sendMailModel, preferShowTextMail
} = useGlobalState() } = useGlobalState()
const autoRefresh = ref(false) const autoRefresh = ref(false)
@@ -59,7 +57,6 @@ const curMail = ref(null);
const showTextMail = ref(preferShowTextMail.value) const showTextMail = ref(preferShowTextMail.value)
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
success: 'Success', success: 'Success',
+1 -2
View File
@@ -20,7 +20,7 @@ const props = defineProps({
}, },
}) })
const { localeCache, isDark, mailboxSplitSize } = useGlobalState() const { isDark, mailboxSplitSize } = useGlobalState()
const data = ref([]) const data = ref([])
const count = ref(0) const count = ref(0)
@@ -31,7 +31,6 @@ const curMail = ref(null);
const showCode = ref(false) const showCode = ref(false)
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
success: 'Success', success: 'Success',
+3 -4
View File
@@ -2,12 +2,11 @@
import { ref, watch, defineModel, onMounted } from "vue"; import { ref, watch, defineModel, onMounted } from "vue";
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../store' import { useGlobalState } from '../store'
const { localeCache, openSettings, isDark } = useGlobalState() const { openSettings, isDark } = useGlobalState()
const cfToken = defineModel('value') const cfToken = defineModel('value')
const { t } = useI18n({ const { locale, t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
refresh: 'Refresh' refresh: 'Refresh'
@@ -42,7 +41,7 @@ const checkCfTurnstile = async (remove) => {
"#cf-turnstile", "#cf-turnstile",
{ {
sitekey: openSettings.value.cfTurnstileSiteKey, sitekey: openSettings.value.cfTurnstileSiteKey,
language: localeCache.value == 'zh' ? 'zh-CN' : 'en-US', language: locale.value == 'zh' ? 'zh-CN' : 'en-US',
theme: isDark.value ? 'dark' : 'light', theme: isDark.value ? 'dark' : 'light',
callback: function (token) { callback: function (token) {
cfToken.value = token; cfToken.value = token;
+10
View File
@@ -17,6 +17,16 @@ const i18n = createI18n({
messages: {} messages: {}
} }
}) })
router.beforeEach((to, from) => {
if (to.params.lang) {
i18n.global.locale.value = to.params.lang
} else {
i18n.global.locale.value = 'zh'
}
});
const head = createHead() const head = createHead()
const app = createApp(App) const app = createApp(App)
app.use(i18n) app.use(i18n)
+10
View File
@@ -1,26 +1,36 @@
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
import Index from '../views/Index.vue' import Index from '../views/Index.vue'
import User from '../views/User.vue' import User from '../views/User.vue'
import { useGlobalState } from '../store'
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHistory(),
routes: [ routes: [
{ {
path: '/', path: '/',
alias: "/:lang/",
component: Index component: Index
}, },
{ {
path: '/user', path: '/user',
alias: "/:lang/user",
component: User component: User
}, },
{ {
path: '/admin', path: '/admin',
alias: "/:lang/admin",
component: () => import('../views/Admin.vue') component: () => import('../views/Admin.vue')
}, },
{ {
path: '/telegram_mail', path: '/telegram_mail',
alias: "/:lang/telegram_mail",
component: () => import('../views/telegram/Mail.vue') component: () => import('../views/telegram/Mail.vue')
}, },
{
name: 'not-found',
path: '/:pathMatch(.*)*',
redirect: '/'
}
] ]
}) })
-2
View File
@@ -45,7 +45,6 @@ export const useGlobalState = createGlobalState(
const auth = useStorage('auth', ''); const auth = useStorage('auth', '');
const adminAuth = useStorage('adminAuth', ''); const adminAuth = useStorage('adminAuth', '');
const jwt = useStorage('jwt', ''); const jwt = useStorage('jwt', '');
const localeCache = useStorage('locale', 'zh');
const adminTab = ref("account"); const adminTab = ref("account");
const adminMailTabAddress = ref(""); const adminMailTabAddress = ref("");
const adminSendBoxTabAddress = ref(""); const adminSendBoxTabAddress = ref("");
@@ -82,7 +81,6 @@ export const useGlobalState = createGlobalState(
showAddressCredential, showAddressCredential,
auth, auth,
jwt, jwt,
localeCache,
adminAuth, adminAuth,
showAdminAuth, showAdminAuth,
adminTab, adminTab,
@@ -1,6 +1,13 @@
export const hashPassword = async (password) => { export const hashPassword = async (password: string) => {
// user crypto to hash password // user crypto to hash password
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(password)); const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(password));
const hashArray = Array.from(new Uint8Array(digest)); const hashArray = Array.from(new Uint8Array(digest));
return hashArray.map(byte => byte.toString(16).padStart(2, '0')).join(''); return hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
} }
export const getRouterPathWithLang = (path: string, lang: string) => {
if (!lang || lang === 'zh') {
return path;
}
return `/${lang}${path}`;
}
+1 -2
View File
@@ -21,7 +21,7 @@ import Telegram from './admin/Telegram.vue';
import Webhook from './admin/Webhook.vue'; import Webhook from './admin/Webhook.vue';
const { const {
localeCache, adminAuth, showAdminAuth, adminTab, loading, globalTabplacement adminAuth, showAdminAuth, adminTab, loading, globalTabplacement
} = useGlobalState() } = useGlobalState()
const message = useMessage() const message = useMessage()
@@ -34,7 +34,6 @@ const authFunc = async () => {
} }
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
accessHeader: 'Admin Password', accessHeader: 'Admin Password',
+1 -2
View File
@@ -1,11 +1,10 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../store' import { useGlobalState } from '../store'
const { localeCache, openSettings } = useGlobalState() const { openSettings } = useGlobalState()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
copyright: "Copyright" copyright: "Copyright"
+25 -12
View File
@@ -12,10 +12,12 @@ import { GithubAlt, Language, User, Home } from '@vicons/fa'
import { useGlobalState } from '../store' import { useGlobalState } from '../store'
import { api } from '../api' import { api } from '../api'
import { getRouterPathWithLang } from '../utils'
const message = useMessage() const message = useMessage()
const { const {
localeCache, toggleDark, isDark, isTelegram, toggleDark, isDark, isTelegram,
showAuth, adminAuth, auth, loading, openSettings showAuth, adminAuth, auth, loading, openSettings
} = useGlobalState() } = useGlobalState()
const route = useRoute() const route = useRoute()
@@ -37,13 +39,15 @@ const authFunc = async () => {
} }
} }
const changeLocale = (locale) => { const changeLocale = async (lang) => {
localeCache.value = locale; if (lang == 'zh') {
location.reload() await router.push(route.fullPath.replace('/en', ''));
} else {
await router.push(`/${lang}${route.fullPath}`);
}
} }
const { t } = useI18n({ const { locale, t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
title: 'Cloudflare Temp Email', title: 'Cloudflare Temp Email',
@@ -80,7 +84,10 @@ const menuOptions = computed(() => [
size: "small", size: "small",
type: menuValue.value == "home" ? "primary" : "default", type: menuValue.value == "home" ? "primary" : "default",
style: "width: 100%", style: "width: 100%",
onClick: async () => { await router.push('/'); showMobileMenu.value = false; } onClick: async () => {
await router.push(getRouterPathWithLang('/', locale.value));
showMobileMenu.value = false;
}
}, },
{ {
default: () => t('home'), default: () => t('home'),
@@ -96,7 +103,10 @@ const menuOptions = computed(() => [
size: "small", size: "small",
type: menuValue.value == "user" ? "primary" : "default", type: menuValue.value == "user" ? "primary" : "default",
style: "width: 100%", style: "width: 100%",
onClick: async () => { await router.push("/user"); showMobileMenu.value = false; } onClick: async () => {
await router.push(getRouterPathWithLang("/user", locale.value));
showMobileMenu.value = false;
}
}, },
{ {
default: () => t('user'), default: () => t('user'),
@@ -114,7 +124,10 @@ const menuOptions = computed(() => [
size: "small", size: "small",
type: menuValue.value == "admin" ? "primary" : "default", type: menuValue.value == "admin" ? "primary" : "default",
style: "width: 100%", style: "width: 100%",
onClick: async () => { await router.push('/admin'); showMobileMenu.value = false; } onClick: async () => {
await router.push(getRouterPathWithLang('/admin', locale.value));
showMobileMenu.value = false;
}
}, },
{ {
default: () => "Admin", default: () => "Admin",
@@ -149,13 +162,13 @@ const menuOptions = computed(() => [
text: true, text: true,
size: "small", size: "small",
style: "width: 100%", style: "width: 100%",
onClick: () => { onClick: async () => {
localeCache.value == 'zh' ? changeLocale('en') : changeLocale('zh'); locale.value == 'zh' ? await changeLocale('en') : await changeLocale('zh');
showMobileMenu.value = false; showMobileMenu.value = false;
} }
}, },
{ {
default: () => localeCache.value == 'zh' ? "English" : "中文", default: () => locale.value == 'zh' ? "English" : "中文",
icon: () => h( icon: () => h(
NIcon, { component: Language } NIcon, { component: Language }
) )
+1 -2
View File
@@ -14,10 +14,9 @@ import WenHook from './index/Webhook.vue';
import About from './common/About.vue'; import About from './common/About.vue';
const SendMail = defineAsyncComponent(() => import('./index/SendMail.vue')); const SendMail = defineAsyncComponent(() => import('./index/SendMail.vue'));
const { localeCache, settings, openSettings, indexTab, globalTabplacement } = useGlobalState() const { settings, openSettings, indexTab, globalTabplacement } = useGlobalState()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
mailbox: 'Mail Box', mailbox: 'Mail Box',
+1 -2
View File
@@ -9,11 +9,10 @@ import UserBar from './user/UserBar.vue';
import BindAddress from './user/BindAddress.vue'; import BindAddress from './user/BindAddress.vue';
const { const {
localeCache, userTab, globalTabplacement, userSettings userTab, globalTabplacement, userSettings
} = useGlobalState() } = useGlobalState()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
address_management: 'Address Management', address_management: 'Address Management',
+1 -2
View File
@@ -9,13 +9,12 @@ import { NButton, NMenu } from 'naive-ui';
import { MenuFilled } from '@vicons/material' import { MenuFilled } from '@vicons/material'
const { const {
localeCache, adminAuth, showAdminAuth, loading, adminAuth, showAdminAuth, loading,
adminTab, adminMailTabAddress, adminSendBoxTabAddress adminTab, adminMailTabAddress, adminSendBoxTabAddress
} = useGlobalState() } = useGlobalState()
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
name: 'Name', name: 'Name',
+1 -2
View File
@@ -5,11 +5,10 @@ import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
const { localeCache, loading } = useGlobalState() const { loading } = useGlobalState()
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
save: 'Save', save: 'Save',
+1 -2
View File
@@ -6,12 +6,11 @@ import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
const { const {
localeCache, loading, openSettings, loading, openSettings,
} = useGlobalState() } = useGlobalState()
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
address: 'Address', address: 'Address',
+1 -2
View File
@@ -7,12 +7,11 @@ import { api } from '../../api'
import MailBox from '../../components/MailBox.vue'; import MailBox from '../../components/MailBox.vue';
const { const {
localeCache, adminAuth, showAdminAuth, adminAuth, showAdminAuth,
adminMailTabAddress adminMailTabAddress
} = useGlobalState() } = useGlobalState()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
addressQueryTip: 'Leave blank to query all addresses', addressQueryTip: 'Leave blank to query all addresses',
+1 -2
View File
@@ -6,7 +6,7 @@ import { CleaningServicesFilled } from '@vicons/material'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
const { localeCache, adminAuth, showAdminAuth } = useGlobalState() const { adminAuth, showAdminAuth } = useGlobalState()
const message = useMessage() const message = useMessage()
const cleanupModel = ref({ const cleanupModel = ref({
enableMailsAutoCleanup: false, enableMailsAutoCleanup: false,
@@ -20,7 +20,6 @@ const cleanupModel = ref({
}) })
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
tip: 'Please input the cleanup days', tip: 'Please input the cleanup days',
+1 -2
View File
@@ -5,10 +5,9 @@ import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
import SendBox from '../../components/SendBox.vue'; import SendBox from '../../components/SendBox.vue';
const { localeCache, adminSendBoxTabAddress } = useGlobalState() const { adminSendBoxTabAddress } = useGlobalState()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
query: 'Query', query: 'Query',
+1 -2
View File
@@ -5,11 +5,10 @@ import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
const { localeCache, loading } = useGlobalState() const { loading } = useGlobalState()
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
address: 'Address', address: 'Address',
+1 -2
View File
@@ -7,11 +7,10 @@ import { SendOutlined } from '@vicons/material'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
const { localeCache, adminAuth } = useGlobalState() const { adminAuth } = useGlobalState()
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
userCount: 'Account Count', userCount: 'Account Count',
-3
View File
@@ -6,13 +6,10 @@ import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
// @ts-ignore // @ts-ignore
import { api } from '../../api' import { api } from '../../api'
const { localeCache } = useGlobalState()
// @ts-ignore // @ts-ignore
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
init: 'Init', init: 'Init',
+1 -2
View File
@@ -8,11 +8,10 @@ import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
import { hashPassword } from '../../utils'; import { hashPassword } from '../../utils';
const { localeCache, loading } = useGlobalState() const { loading } = useGlobalState()
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
success: 'Success', success: 'Success',
+1 -2
View File
@@ -5,11 +5,10 @@ import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
const { localeCache, loading } = useGlobalState() const { loading } = useGlobalState()
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
save: 'Save', save: 'Save',
-3
View File
@@ -6,13 +6,10 @@ import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
// @ts-ignore // @ts-ignore
import { api } from '../../api' import { api } from '../../api'
const { localeCache } = useGlobalState()
// @ts-ignore // @ts-ignore
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
successTip: 'Success', successTip: 'Success',
+1 -2
View File
@@ -1,10 +1,9 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
const { localeCache, openSettings } = useGlobalState() const { openSettings } = useGlobalState()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
adminContact: 'If you need help, please contact the administrator ({msg})', adminContact: 'If you need help, please contact the administrator ({msg})',
+1 -2
View File
@@ -5,13 +5,12 @@ import { useIsMobile } from '../../utils/composables'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
const { const {
localeCache, mailboxSplitSize, useIframeShowMail, preferShowTextMail, mailboxSplitSize, useIframeShowMail, preferShowTextMail,
globalTabplacement, useSideMargin globalTabplacement, useSideMargin
} = useGlobalState() } = useGlobalState()
const isMobile = useIsMobile() const isMobile = useIsMobile()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
mailboxSplitSize: 'Mailbox Split Size', mailboxSplitSize: 'Mailbox Split Size',
+5 -5
View File
@@ -9,6 +9,7 @@ import Turnstile from '../../components/Turnstile.vue'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
import { getRouterPathWithLang } from '../../utils'
const props = defineProps({ const props = defineProps({
bindUserAddress: { bindUserAddress: {
@@ -36,7 +37,7 @@ const message = useMessage()
const router = useRouter() const router = useRouter()
const { const {
jwt, localeCache, loading, openSettings, jwt, loading, openSettings,
showAddressCredential, userSettings showAddressCredential, userSettings
} = useGlobalState() } = useGlobalState()
@@ -59,14 +60,13 @@ const login = async () => {
} catch (error) { } catch (error) {
message.error(`${t('bindUserAddressError')}: ${error.message}`); message.error(`${t('bindUserAddressError')}: ${error.message}`);
} }
await router.push("/"); await router.push(getRouterPathWithLang("/", locale.value));
} catch (error) { } catch (error) {
message.error(error.message || "error"); message.error(error.message || "error");
} }
} }
const { t } = useI18n({ const { locale, t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
login: 'Login', login: 'Login',
@@ -128,7 +128,7 @@ const newEmail = async () => {
); );
jwt.value = res["jwt"]; jwt.value = res["jwt"];
await api.getSettings(); await api.getSettings();
await router.push("/"); await router.push(getRouterPathWithLang("/", locale.value));
showAddressCredential.value = true; showAddressCredential.value = true;
try { try {
await props.bindUserAddress(); await props.bindUserAddress();
+5 -5
View File
@@ -6,17 +6,17 @@ import { useRouter } from 'vue-router'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
import Appearance from '../common/Appearance.vue' import Appearance from '../common/Appearance.vue'
import { getRouterPathWithLang } from '../../utils'
const { const {
jwt, localeCache, settings, showAddressCredential, loading jwt, settings, showAddressCredential, loading
} = useGlobalState() } = useGlobalState()
const router = useRouter() const router = useRouter()
const message = useMessage() const message = useMessage()
const showLogout = ref(false) const showLogout = ref(false)
const showDelteAccount = ref(false) const showDelteAccount = ref(false)
const { t } = useI18n({ const { locale, t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
logout: "Logout", logout: "Logout",
@@ -39,7 +39,7 @@ const { t } = useI18n({
const logout = async () => { const logout = async () => {
jwt.value = ''; jwt.value = '';
await router.push('/') await router.push(getRouterPathWithLang("/", locale.value))
location.reload() location.reload()
} }
@@ -49,7 +49,7 @@ const deleteAccount = async () => {
method: 'DELETE' method: 'DELETE'
}); });
jwt.value = ''; jwt.value = '';
await router.push('/') await router.push(getRouterPathWithLang("/", locale.value))
location.reload() location.reload()
} catch (error) { } catch (error) {
message.error(error.message || "error"); message.error(error.message || "error");
+8 -4
View File
@@ -11,18 +11,18 @@ import Login from '../common/Login.vue'
import AddressManagement from '../user/AddressManagement.vue' import AddressManagement from '../user/AddressManagement.vue'
import TelegramAddress from './TelegramAddress.vue' import TelegramAddress from './TelegramAddress.vue'
import LocalAddress from './LocalAddress.vue' import LocalAddress from './LocalAddress.vue'
import { getRouterPathWithLang } from '../../utils'
const { toClipboard } = useClipboard() const { toClipboard } = useClipboard()
const message = useMessage() const message = useMessage()
const router = useRouter() const router = useRouter()
const { const {
jwt, localeCache, settings, showAddressCredential, userJwt, jwt, settings, showAddressCredential, userJwt,
isTelegram isTelegram
} = useGlobalState() } = useGlobalState()
const { t } = useI18n({ const { locale, t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
addressManage: 'Address Manage', addressManage: 'Address Manage',
@@ -62,6 +62,10 @@ const copy = async () => {
} }
} }
const onUserLogin = async () => {
await router.push(getRouterPathWithLang("/user", locale.value))
}
onMounted(async () => { onMounted(async () => {
await api.getSettings(); await api.getSettings();
}); });
@@ -104,7 +108,7 @@ onMounted(async () => {
</n-alert> </n-alert>
<Login /> <Login />
<n-divider /> <n-divider />
<n-button @click="router.push('/user')" type="primary" block secondary strong> <n-button @click="onUserLogin" type="primary" block secondary strong>
<template #icon> <template #icon>
<n-icon :component="User" /> <n-icon :component="User" />
</template> </template>
+1 -2
View File
@@ -9,12 +9,11 @@ import { useGlobalState } from '../../store'
// @ts-ignore // @ts-ignore
import Login from '../common/Login.vue'; import Login from '../common/Login.vue';
const { localeCache, jwt } = useGlobalState() const { jwt } = useGlobalState()
// @ts-ignore // @ts-ignore
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
tip: 'These addresses are stored in your browser, maybe loss if you clear the browser cache.', tip: 'These addresses are stored in your browser, maybe loss if you clear the browser cache.',
+1 -2
View File
@@ -10,12 +10,11 @@ import { api } from '../../api'
// @ts-ignore // @ts-ignore
import Login from '../common/Login.vue'; import Login from '../common/Login.vue';
const { localeCache, jwt, telegramApp } = useGlobalState() const { jwt, telegramApp } = useGlobalState()
// @ts-ignore // @ts-ignore
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
success: 'success', success: 'success',
+1 -2
View File
@@ -7,12 +7,11 @@ import { useGlobalState } from '../../store'
// @ts-ignore // @ts-ignore
import { api } from '../../api' import { api } from '../../api'
const { localeCache, settings } = useGlobalState() const { settings } = useGlobalState()
// @ts-ignore // @ts-ignore
const message = useMessage() const message = useMessage()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
successTip: 'Success', successTip: 'Success',
@@ -6,13 +6,13 @@ import { NBadge, NPopconfirm, NButton } from 'naive-ui'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
import { getRouterPathWithLang } from '../../utils'
const { localeCache, jwt } = useGlobalState() const { jwt } = useGlobalState()
const message = useMessage() const message = useMessage()
const router = useRouter() const router = useRouter()
const { t } = useI18n({ const { locale, t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
success: 'success', success: 'success',
@@ -48,7 +48,7 @@ const changeMailAddress = async (address_id) => {
return; return;
} }
jwt.value = res.jwt; jwt.value = res.jwt;
await router.push('/'); await router.push(getRouterPathWithLang("/", locale.value))
location.reload(); location.reload();
} catch (error) { } catch (error) {
console.log(error) console.log(error)
+1 -2
View File
@@ -6,10 +6,9 @@ import { useRouter } from 'vue-router'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import Login from '../common/Login.vue' import Login from '../common/Login.vue'
const { userJwt, localeCache, userSettings, } = useGlobalState() const { userJwt, userSettings, } = useGlobalState()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
logout: 'Logout', logout: 'Logout',
+1 -2
View File
@@ -11,11 +11,10 @@ const message = useMessage()
const router = useRouter() const router = useRouter()
const { const {
localeCache, userSettings, userJwt, userOpenSettings userSettings, userJwt, userOpenSettings
} = useGlobalState() } = useGlobalState()
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
currentUser: 'Current Login User', currentUser: 'Current Login User',
+1 -2
View File
@@ -10,12 +10,11 @@ import { hashPassword } from '../../utils';
import Turnstile from '../../components/Turnstile.vue'; import Turnstile from '../../components/Turnstile.vue';
const { userJwt, localeCache, userTab, userOpenSettings } = useGlobalState() const { userJwt, userTab, userOpenSettings } = useGlobalState()
const message = useMessage(); const message = useMessage();
const router = useRouter(); const router = useRouter();
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
login: 'Login', login: 'Login',
+1 -2
View File
@@ -6,14 +6,13 @@ import { useRouter } from 'vue-router'
import { useGlobalState } from '../../store' import { useGlobalState } from '../../store'
import { api } from '../../api' import { api } from '../../api'
const { userJwt, localeCache, userSettings, } = useGlobalState() const { userJwt, userSettings, } = useGlobalState()
const router = useRouter() const router = useRouter()
const message = useMessage() const message = useMessage()
const showLogout = ref(false) const showLogout = ref(false)
const { t } = useI18n({ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: { messages: {
en: { en: {
logout: 'Logout', logout: 'Logout',