consumer模块完成度95%,准备部署消费者端测试
This commit is contained in:
@@ -442,41 +442,24 @@ export class AkSupaQueryBuilder {
|
||||
if (res["data"] == null) res["data"] = {};
|
||||
return res;
|
||||
} // 新增:支持类型转换的执行方法
|
||||
async executeAs<T = any>() : Promise<AkReqResponse<T | Array<T>>> {
|
||||
async executeAs<T>() : Promise<AkReqResponse<T>> {
|
||||
const result = await this.execute();
|
||||
|
||||
// 如果原始 data 是 null,直接返回 null
|
||||
if (result.data == null) {
|
||||
const aaa = {
|
||||
status: result.status,
|
||||
data: null,
|
||||
headers: result.headers,
|
||||
error: result.error,
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
limit: result.limit,
|
||||
hasmore: result.hasmore,
|
||||
origin: result.origin
|
||||
}
|
||||
return aaa;
|
||||
return result as AkReqResponse<T>;
|
||||
}
|
||||
|
||||
// 尝试类型转换
|
||||
let convertedData : T | Array<T> | null = null;
|
||||
let convertedData : any | null = null;
|
||||
|
||||
try {
|
||||
if (Array.isArray(result.data)) {
|
||||
// 处理数组数据
|
||||
const dataArray = result.data;
|
||||
const convertedArray : Array<T> = [];
|
||||
//console.log(convertedArray)
|
||||
const convertedArray : Array<any> = [];
|
||||
for (let i = 0; i < dataArray.length; i++) {
|
||||
const item = dataArray[i];
|
||||
if (item instanceof UTSJSONObject) {
|
||||
// #ifdef APP-ANDROID
|
||||
// //console.log(item)
|
||||
const parsed = item.parse<T>();
|
||||
// //console.log('ak parsed')
|
||||
// #endif
|
||||
// #ifndef APP-ANDROID
|
||||
const parsed = item as T;
|
||||
@@ -485,10 +468,9 @@ export class AkSupaQueryBuilder {
|
||||
convertedArray.push(parsed);
|
||||
} else {
|
||||
console.warn('转换失败,使用原始对象:', item);
|
||||
convertedArray.push(item as T);
|
||||
convertedArray.push(item);
|
||||
}
|
||||
} else {
|
||||
// 将普通对象转换为 UTSJSONObject 后再 parse
|
||||
const jsonObj = new UTSJSONObject(item);
|
||||
// #ifdef APP-ANDROID
|
||||
const parsed = jsonObj.parse<T>();
|
||||
@@ -501,15 +483,14 @@ export class AkSupaQueryBuilder {
|
||||
}
|
||||
else {
|
||||
console.warn('转换失败,使用原始对象:', item);
|
||||
convertedArray.push(item as T);
|
||||
convertedArray.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
convertedData = convertedArray;
|
||||
|
||||
} else {
|
||||
// 处理单个对象
|
||||
const convertedArray : Array<T> = [];
|
||||
const convertedArray : Array<any> = [];
|
||||
if (result.data instanceof UTSJSONObject) {
|
||||
const parsed = result.data.parse<T>();
|
||||
|
||||
@@ -534,23 +515,10 @@ export class AkSupaQueryBuilder {
|
||||
} catch (e) {
|
||||
console.warn('数据类型转换失败,使用原始数据:', e);
|
||||
console.log(result.data)
|
||||
// 转换失败时,使用原始数据
|
||||
convertedData = result.data as T | Array<T>;
|
||||
convertedData = result.data as any;
|
||||
}
|
||||
result.data = convertedData
|
||||
const aaa = result as AkReqResponse<T | Array<T>
|
||||
// const aaa = {
|
||||
// status: result.status,
|
||||
// data: convertedData,
|
||||
// headers: result.headers,
|
||||
// error: result.error,
|
||||
// total: result.total,
|
||||
// page: result.page,
|
||||
// limit: result.limit,
|
||||
// hasmore: result.hasmore,
|
||||
// origin: result.origin
|
||||
// }
|
||||
return aaa;
|
||||
return result as AkReqResponse<T>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user