consumer模块完成度95%,优化安卓端界面和小程序测试
This commit is contained in:
@@ -116,12 +116,28 @@ export class AkSupaQueryBuilder {
|
||||
private _addCond(afield : string, op : string, value : any | null) : AkSupaQueryBuilder {
|
||||
//console.log('add cond:', op, afield, value)
|
||||
const field = encodeURIComponent(afield)!!
|
||||
// 将 null 转换为字符串 'null',避免构造对象时缺少 value 属性
|
||||
let safeValue = value;
|
||||
// 将值安全存储,避免安卓端类型转换问题
|
||||
let safeValue: any | null = value;
|
||||
if (value === null) {
|
||||
safeValue = 'null';
|
||||
} else if (Array.isArray(value)) {
|
||||
// 数组类型保持原样,用于 in 操作符
|
||||
safeValue = value;
|
||||
} else if (typeof value === 'number') {
|
||||
// 数字类型保持原样
|
||||
safeValue = value;
|
||||
} else if (typeof value === 'boolean') {
|
||||
// 布尔类型保持原样
|
||||
safeValue = value;
|
||||
} else if (typeof value !== 'string') {
|
||||
// 其他类型尝试转换为字符串
|
||||
try {
|
||||
safeValue = value.toString();
|
||||
} catch (e) {
|
||||
safeValue = '';
|
||||
}
|
||||
}
|
||||
this._conditions.push({ field, op, value: safeValue, logic: this._nextLogic });
|
||||
this._conditions.push({ field, op, value: safeValue ?? '', logic: this._nextLogic });
|
||||
//console.log(this._conditions)
|
||||
this._nextLogic = 'and';
|
||||
return this;
|
||||
@@ -209,6 +225,23 @@ export class AkSupaQueryBuilder {
|
||||
//console.log('设置 range:', from, 'to', to);
|
||||
return this;
|
||||
}
|
||||
|
||||
// 辅助函数:安全地将值转换为字符串
|
||||
private _valToStr(val: any): string {
|
||||
if (val == null) return '';
|
||||
try {
|
||||
// 尝试直接调用 toString
|
||||
return val.toString();
|
||||
} catch (e) {
|
||||
try {
|
||||
// 尝试 JSON 序列化
|
||||
return JSON.stringify(val);
|
||||
} catch (e2) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将 _conditions 强类型直接转换为 Supabase/PostgREST 查询字符串(不再用 UTSJSONObject 做中转)
|
||||
private _buildFilter() : string | null {
|
||||
if (this._conditions.length == 0 && (this._orString==null || this._orString == "")) {
|
||||
@@ -236,12 +269,13 @@ export class AkSupaQueryBuilder {
|
||||
const op = cond.op;
|
||||
const val = cond.value;
|
||||
if ((op == 'in' || op == 'not.in') && Array.isArray(val)) {
|
||||
params.push(`${k}=${op}.(${val.map(x => typeof x == 'object' ? encodeURIComponent(JSON.stringify(x)) : encodeURIComponent(x.toString())).join(',')})`);
|
||||
params.push(`${k}=${op}.(${val.map(x => this._valToStr(x)).map(x => encodeURIComponent(x)).join(',')})`);
|
||||
} else if ((op == 'is' || op == 'not.is') && (val == null || val == 'null')) {
|
||||
params.push(`${k}=${op}.null`);
|
||||
} else if (op == 'like' || op == 'ilike') {
|
||||
params.push(`${k}=${op}.${this._valToStr(val)}`);
|
||||
} else {
|
||||
const opvalstr: string = (typeof val == 'object') ? JSON.stringify(val) : (val as string);
|
||||
params.push(`${k}=${op}.${encodeURIComponent(opvalstr)}`);
|
||||
params.push(`${k}=${op}.${encodeURIComponent(this._valToStr(val))}`);
|
||||
}
|
||||
}
|
||||
// 处理 or 条件
|
||||
@@ -251,17 +285,21 @@ export class AkSupaQueryBuilder {
|
||||
const op = o.op;
|
||||
const val = o.value;
|
||||
if (op == "in" && Array.isArray(val)) {
|
||||
return `${k}.in.(${val.map(x => encodeURIComponent(x as string)).join(",")})`;
|
||||
return `${k}.in.(${val.map(x => encodeURIComponent(this._valToStr(x))).join(",")})`;
|
||||
}
|
||||
if (op == "is" && (val == null)) {
|
||||
return `${k}.is.null`;
|
||||
}
|
||||
return `${k}.${op}.${encodeURIComponent(val as string)}`;
|
||||
if (op == "like" || op == "ilike") {
|
||||
return `${k}.${op}.${this._valToStr(val)}`;
|
||||
}
|
||||
return `${k}.${op}.${encodeURIComponent(this._valToStr(val))}`;
|
||||
}).join(",");
|
||||
params.push(`or=(${orStr})`);
|
||||
}
|
||||
if (this._orString!=null && this._orString !== "") {
|
||||
params.push(`or=(${encodeURIComponent(this._orString!!)})`);
|
||||
console.log('[AkSupaQueryBuilder] or字符串:', this._orString)
|
||||
params.push(`or=(${this._orString!!})`);
|
||||
}
|
||||
return params.length > 0 ? params.join('&') : null;
|
||||
}
|
||||
@@ -316,7 +354,7 @@ export class AkSupaQueryBuilder {
|
||||
async execute() : Promise<AkReqResponse<any>> {
|
||||
//console.log('execute')
|
||||
const filter = this._buildFilter();
|
||||
//console.log('execute', filter)
|
||||
console.log('[AkSupaQueryBuilder] execute - 表:', this._table, 'filter:', filter)
|
||||
let res : any;
|
||||
switch (this._action) {
|
||||
case 'select': {
|
||||
|
||||
Reference in New Issue
Block a user