consumer模块完成度95%,准备部署消费者端测试

This commit is contained in:
cyh666666
2026-03-05 08:45:00 +08:00
parent cceb556c62
commit 7f7f723d93
1043 changed files with 53958 additions and 3445 deletions

View File

@@ -369,70 +369,6 @@ export class AkReq {
};
}
// 新增:支持类型转换的请求方法
static async requestAs<T = any>(options : AkReqOptions, skipRefresh ?: boolean) : Promise<AkReqResponse<T|Array<T>>> {
const response = await this.request(options, skipRefresh);
// 如果原始 data 是 null直接返回 null
// if (response.data == null) {
// return {
// status: response.status,
// data: null,
// headers: response.headers,
// error: response.error,
// total: response.total,
// page: response.page,
// limit: response.limit,
// hasmore: response.hasmore,
// origin: response.origin
// } as AkReqResponse<T|Array<T>>;
// }
// 尝试类型转换
let convertedData: T | null = null;
try {
// #ifdef APP-ANDROID
if (response.data instanceof UTSJSONObject) {
convertedData = response.data.parse<T>();
} else if (Array.isArray(response.data)) {
const convertedArray: Array<any> = [];
const dataArray = response.data;
for (let i = 0; i < dataArray.length; i++) {
const item = dataArray[i];
if (item instanceof UTSJSONObject) {
const parsed = item.parse<T>();
if (parsed != null) {
convertedArray.push(parsed);
}
} else {
convertedArray.push(item);
}
}
convertedData = convertedArray as T;
}
// #endif
// #ifndef APP-ANDROID
convertedData = response.data as T;
// #endif
} catch (e) {
console.warn('类型转换失败,使用原始 UTSJSONObject:', e);
// 转换失败时,返回原始 UTSJSONObject
convertedData = response.data as T;
}
const aaa = {
status: response.status,
data: convertedData!!,
headers: response.headers,
error: response.error,
total: response.total,
page: response.page,
limit: response.limit,
hasmore: response.hasmore,
origin: response.origin
} ;
return aaa
}
}
export default AkReq;