|
@@ -88,25 +88,30 @@ export class CloudQuery {
|
|
|
this.className = className;
|
|
this.className = className;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- include(...fileds:string[]) {
|
|
|
|
|
- this.queryParams["include"] = fileds;
|
|
|
|
|
|
|
+ include(...fields: string[]) {
|
|
|
|
|
+ this.queryParams["include"] = fields;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
greaterThan(key: string, value: any) {
|
|
greaterThan(key: string, value: any) {
|
|
|
|
|
+ if (!this.queryParams["where"]) this.queryParams["where"] = {};
|
|
|
if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
this.queryParams["where"][key]["$gt"] = value;
|
|
this.queryParams["where"][key]["$gt"] = value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
greaterThanAndEqualTo(key: string, value: any) {
|
|
greaterThanAndEqualTo(key: string, value: any) {
|
|
|
|
|
+ if (!this.queryParams["where"]) this.queryParams["where"] = {};
|
|
|
if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
this.queryParams["where"][key]["$gte"] = value;
|
|
this.queryParams["where"][key]["$gte"] = value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
lessThan(key: string, value: any) {
|
|
lessThan(key: string, value: any) {
|
|
|
|
|
+ if (!this.queryParams["where"]) this.queryParams["where"] = {};
|
|
|
if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
this.queryParams["where"][key]["$lt"] = value;
|
|
this.queryParams["where"][key]["$lt"] = value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
lessThanAndEqualTo(key: string, value: any) {
|
|
lessThanAndEqualTo(key: string, value: any) {
|
|
|
|
|
+ if (!this.queryParams["where"]) this.queryParams["where"] = {};
|
|
|
if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
this.queryParams["where"][key]["$lte"] = value;
|
|
this.queryParams["where"][key]["$lte"] = value;
|
|
|
}
|
|
}
|
|
@@ -134,24 +139,23 @@ export class CloudQuery {
|
|
|
return json || {};
|
|
return json || {};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async find():Promise<Array<CloudObject>> {
|
|
|
|
|
|
|
+ async find(): Promise<Array<CloudObject>> {
|
|
|
let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
|
|
let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
|
|
|
|
|
|
|
|
- let queryStr = ``
|
|
|
|
|
- Object.keys(this.queryParams).forEach(key=>{
|
|
|
|
|
|
|
+ // 构建查询字符串
|
|
|
|
|
+ let queryStr = '';
|
|
|
|
|
+ Object.keys(this.queryParams).forEach(key => {
|
|
|
let paramStr = JSON.stringify(this.queryParams[key]);
|
|
let paramStr = JSON.stringify(this.queryParams[key]);
|
|
|
- if(key=="include"){
|
|
|
|
|
- paramStr = this.queryParams[key]?.join(",")
|
|
|
|
|
|
|
+ if (key === "include") {
|
|
|
|
|
+ paramStr = this.queryParams[key]?.join(","); // 将数组转换为逗号分隔字符串
|
|
|
}
|
|
}
|
|
|
- if(queryStr) {
|
|
|
|
|
- url += `${key}=${paramStr}`;
|
|
|
|
|
- }else{
|
|
|
|
|
|
|
+ // 添加查询参数到 URL
|
|
|
|
|
+ if (queryStr) {
|
|
|
url += `&${key}=${paramStr}`;
|
|
url += `&${key}=${paramStr}`;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ url += `${key}=${paramStr}`;
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
- // if (Object.keys(this.queryParams["where"]).length) {
|
|
|
|
|
-
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
const response = await fetch(url, {
|
|
const response = await fetch(url, {
|
|
|
headers: {
|
|
headers: {
|
|
@@ -165,12 +169,14 @@ export class CloudQuery {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const json = await response?.json();
|
|
const json = await response?.json();
|
|
|
- let list = json?.results || []
|
|
|
|
|
- let objList = list.map((item:any)=>this.dataToObj(item))
|
|
|
|
|
|
|
+ console.log(json); // 检查 API 返回的数据结构
|
|
|
|
|
+ let list = json?.results || [];
|
|
|
|
|
+ let objList = list.map((item: any) => this.dataToObj(item));
|
|
|
return objList || [];
|
|
return objList || [];
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
async first() {
|
|
async first() {
|
|
|
let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
|
|
let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
|
|
|
|
|
|
|
@@ -193,13 +199,13 @@ export class CloudQuery {
|
|
|
const json = await response?.json();
|
|
const json = await response?.json();
|
|
|
const exists = json?.results?.[0] || null;
|
|
const exists = json?.results?.[0] || null;
|
|
|
if (exists) {
|
|
if (exists) {
|
|
|
- let existsObject = this.dataToObj(exists)
|
|
|
|
|
|
|
+ let existsObject = this.dataToObj(exists);
|
|
|
return existsObject;
|
|
return existsObject;
|
|
|
}
|
|
}
|
|
|
- return null
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- dataToObj(exists:any):CloudObject{
|
|
|
|
|
|
|
+ dataToObj(exists: any): CloudObject {
|
|
|
let existsObject = new CloudObject(this.className);
|
|
let existsObject = new CloudObject(this.className);
|
|
|
existsObject.set(exists);
|
|
existsObject.set(exists);
|
|
|
existsObject.id = exists.objectId;
|
|
existsObject.id = exists.objectId;
|