feat: 更新 @riwa/api-types 依赖地址,优化语言加载逻辑
This commit is contained in:
@@ -2,6 +2,7 @@ import type { App } from "@riwa/api-types";
|
||||
import type { WatchSource } from "vue";
|
||||
import { treaty } from "@elysiajs/eden";
|
||||
import { toastController } from "@ionic/vue";
|
||||
import { i18n } from "@/locales";
|
||||
|
||||
const client = treaty<App>(window.location.origin, {
|
||||
fetch: {
|
||||
@@ -54,7 +55,9 @@ export function safeClient<T, E>(
|
||||
if (res.error && res.status === 418) {
|
||||
if (!options.silent) {
|
||||
const toast = await toastController.create({
|
||||
message: (res.error as any).value.message,
|
||||
message: i18n.global.t((res.error as any).value.code, {
|
||||
...(res.error as any).value.context,
|
||||
}),
|
||||
duration: 3000,
|
||||
position: "bottom",
|
||||
color: "danger",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Locale } from "vue-i18n";
|
||||
import { client, safeClient } from "@/api";
|
||||
|
||||
export interface Language {
|
||||
code: Locale;
|
||||
@@ -10,7 +11,7 @@ export interface Language {
|
||||
* 语言管理组合式函数
|
||||
*/
|
||||
export function useLanguage() {
|
||||
const { locale, availableLocales } = useI18n();
|
||||
const { locale, availableLocales, mergeLocaleMessage } = useI18n();
|
||||
const language = useStorage<Locale>("app-language", locale.value);
|
||||
|
||||
// 可用的语言列表
|
||||
@@ -38,6 +39,13 @@ export function useLanguage() {
|
||||
function setLanguage(langCode: Locale) {
|
||||
locale.value = langCode;
|
||||
language.value = langCode;
|
||||
loadRemoteLanguage();
|
||||
}
|
||||
|
||||
function loadRemoteLanguage() {
|
||||
safeClient(client.api.error_messages({ lang: language.value }).get()).then((res) => {
|
||||
mergeLocaleMessage(locale.value, res.data.value);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +54,7 @@ export function useLanguage() {
|
||||
function loadSavedLanguage() {
|
||||
if (language.value && availableLocales.includes(language.value)) {
|
||||
locale.value = language.value;
|
||||
loadRemoteLanguage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { authClient, modelControllerLogin, modelControllerSignup } from "@/auth"
|
||||
|
||||
const page = useTemplateRef<PageInstance>("page");
|
||||
const { user } = useAuth();
|
||||
const tradingViewContainer = useTemplateRef<HTMLElement>("tradingViewContainer");
|
||||
|
||||
async function openSignin() {
|
||||
const modal = await modelControllerLogin(page.value?.$el);
|
||||
@@ -15,6 +16,19 @@ async function openSignup() {
|
||||
async function handleLogout() {
|
||||
await authClient.signOut();
|
||||
}
|
||||
|
||||
useTradingView(tradingViewContainer, {
|
||||
data: [
|
||||
// 随机k线图数据
|
||||
{ time: "2023-10-01", open: 100, high: 110, low: 90, close: 105 },
|
||||
{ time: "2023-10-02", open: 105, high: 115, low: 95, close: 100 },
|
||||
{ time: "2023-10-03", open: 100, high: 120, low: 80, close: 110 },
|
||||
{ time: "2023-10-04", open: 110, high: 130, low: 100, close: 120 },
|
||||
{ time: "2023-10-05", open: 120, high: 140, low: 110, close: 130 },
|
||||
{ time: "2023-10-06", open: 130, high: 150, low: 120, close: 140 },
|
||||
{ time: "2023-10-07", open: 140, high: 160, low: 130, close: 150 },
|
||||
],
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -34,7 +48,7 @@ async function handleLogout() {
|
||||
<IonButton @click="handleLogout">
|
||||
Log out
|
||||
</IonButton>
|
||||
|
||||
<div ref="tradingViewContainer" />
|
||||
{{ user }}
|
||||
</IonContent>
|
||||
</IonPage>
|
||||
|
||||
Reference in New Issue
Block a user