feat: 添加通知功能,集成模拟数据并更新通知视图
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user