feat: 添加通知功能,集成模拟数据并更新通知视图

This commit is contained in:
2025-12-27 01:30:37 +07:00
parent 6b7a2c7ef1
commit ee07f06d9e
8 changed files with 197 additions and 18 deletions

View File

@@ -3,6 +3,7 @@ import type { WatchSource } from "vue";
import { treaty } from "@elysiajs/eden";
import { toastController } from "@ionic/vue";
import { i18n } from "@/locales";
import { useMocks } from "@/mocks";
const client = treaty<App>(window.location.origin, {
fetch: {
@@ -121,4 +122,17 @@ export function safeClient<T, E>(
return promise as SafeClientReturn<T, E> & Promise<SafeClientReturn<T, E>>;
}
export function mockClient<T = any, E = any>(key: string): SafeClientReturn<T, E> & Promise<SafeClientReturn<T, E>> {
const requestPromise = async () => {
const mocks = useMocks();
const mockFn = mocks.get(key);
if (!mockFn) {
throw new Error(`Mock with key "${key}" not found.`);
}
const data = await mockFn();
return { data: data as T, error: null as E };
};
return safeClient<T, E>(requestPromise, { immediate: true });
}
export { client };