feat: 更新 API 地址,添加分类组件,优化市场页面布局和功能

This commit is contained in:
2025-12-17 20:27:58 +07:00
parent f3b7931d78
commit 5b5fcf9d44
12 changed files with 198 additions and 56 deletions

View File

@@ -1,4 +1,5 @@
import type { App } from "@riwa/api-types";
import type { Awaitable } from "@vueuse/core";
import { treaty } from "@elysiajs/eden";
import { toastController } from "@ionic/vue";
@@ -13,10 +14,17 @@ export interface SafeClientOptions {
immediate?: boolean;
}
export async function safeClient<T, E>(
export interface SafeClientReturn<T, E> {
data: Ref<T | null>;
error: Ref<E | null>;
refresh: () => Promise<void>;
onFetchResponse: (callback: (data: T, error: E) => void) => void;
}
export function safeClient<T, E>(
requestPromise: () => Promise<{ data: T; error: E }>,
options: SafeClientOptions = {},
) {
): SafeClientReturn<T, E> & Promise<SafeClientReturn<T, E>> {
const { immediate = true } = options;
const data = ref<T | null>(null);
const error = ref<E | null>(null);
@@ -61,11 +69,20 @@ export async function safeClient<T, E>(
responseCallback = callback;
}
if (immediate) {
await execute();
}
const result: SafeClientReturn<T, E> = {
data: data as Ref<T | null>,
error: error as Ref<E | null>,
refresh: execute,
onFetchResponse,
};
return { data, error, refresh: execute, onFetchResponse };
// 创建一个 Promise 并在其上添加属性
const promise = immediate ? execute().then(() => result) : Promise.resolve(result);
// 将 result 的属性添加到 promise 上
Object.assign(promise, result);
return promise as SafeClientReturn<T, E> & Promise<SafeClientReturn<T, E>>;
}
export { client };