|
@@ -1,23 +1,58 @@
|
|
|
+/*export interface Pointer {
|
|
|
+ __type: string;
|
|
|
+ className: string;
|
|
|
+ objectId?: string; // 这里保持 objectId 作为可选字段
|
|
|
+ //QuestionnaireId?: string; // 自定义主键
|
|
|
+ //QuestionId?: string; // 自定义主键
|
|
|
+ //OptionId?: string; // 自定义主键
|
|
|
+ //_UserId?: string; // 自定义主键
|
|
|
+}
|
|
|
|
|
|
-// CloudObject.ts
|
|
|
export class CloudObject {
|
|
|
+ id: string | null = null; // 数据库生成的 objectId
|
|
|
className: string;
|
|
|
- id: string | null = null;
|
|
|
- createdAt: any;
|
|
|
- updatedAt: any;
|
|
|
+ createdAt: string | null = null;
|
|
|
+ updatedAt: string | null = null;
|
|
|
data: Record<string, any> = {};
|
|
|
|
|
|
+ // 新增的自定义主键
|
|
|
+ QuestionnaireId?: string;
|
|
|
+ QuestionId?: string;
|
|
|
+ OptionId?: string;
|
|
|
+ _UserId?: string;
|
|
|
+
|
|
|
constructor(className: string) {
|
|
|
this.className = className;
|
|
|
}
|
|
|
|
|
|
- toPointer() {
|
|
|
- return { "__type": "Pointer", "className": this.className, "objectId": this.id };
|
|
|
+ toPointer(): Pointer {
|
|
|
+ // 使用自定义主键生成指针
|
|
|
+ let pointer: Pointer = { "__type": "Pointer", "className": this.className };
|
|
|
+
|
|
|
+ // 根据类名设置相应的 ID
|
|
|
+ switch (this.className) {
|
|
|
+ case "Questionnaire":
|
|
|
+ pointer.objectId = this.QuestionnaireId || "";
|
|
|
+ break;
|
|
|
+ case "Question":
|
|
|
+ pointer.objectId = this.QuestionId || "";
|
|
|
+ break;
|
|
|
+ case "Option":
|
|
|
+ pointer.objectId = this.OptionId || "";
|
|
|
+ break;
|
|
|
+ case "_User":
|
|
|
+ pointer.objectId = this._UserId || "";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ pointer.objectId = this.id || ""; // 保持 objectId 作为后备
|
|
|
+ }
|
|
|
+
|
|
|
+ return pointer;
|
|
|
}
|
|
|
|
|
|
set(json: Record<string, any>) {
|
|
|
Object.keys(json).forEach(key => {
|
|
|
- if (["objectId", "id", "createdAt", "updatedAt"].indexOf(key) > -1) {
|
|
|
+ if (["objectId", "id", "createdAt", "updatedAt", "ACL"].includes(key)) {
|
|
|
return;
|
|
|
}
|
|
|
this.data[key] = json[key];
|
|
@@ -28,7 +63,7 @@ export class CloudObject {
|
|
|
return this.data[key] || null;
|
|
|
}
|
|
|
|
|
|
- async save() {
|
|
|
+ async save(): Promise<this> {
|
|
|
let method = "POST";
|
|
|
let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}`;
|
|
|
|
|
@@ -50,29 +85,27 @@ export class CloudObject {
|
|
|
credentials: "omit"
|
|
|
});
|
|
|
|
|
|
- const result = await response?.json();
|
|
|
+ const result = await response.json();
|
|
|
if (result?.error) {
|
|
|
- console.error(result?.error);
|
|
|
+ console.error(result.error);
|
|
|
}
|
|
|
if (result?.objectId) {
|
|
|
- this.id = result?.objectId;
|
|
|
+ this.id = result.objectId;
|
|
|
}
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- async destroy() {
|
|
|
- if (!this.id) return;
|
|
|
+ async destroy(): Promise<boolean> {
|
|
|
+ if (!this.id) return false;
|
|
|
const response = await fetch(`http://dev.fmode.cn:1337/parse/classes/${this.className}/${this.id}`, {
|
|
|
headers: {
|
|
|
"x-parse-application-id": "dev"
|
|
|
},
|
|
|
- body: null,
|
|
|
method: "DELETE",
|
|
|
mode: "cors",
|
|
|
credentials: "omit"
|
|
|
});
|
|
|
-
|
|
|
- const result = await response?.json();
|
|
|
+ const result = await response.json();
|
|
|
if (result) {
|
|
|
this.id = null;
|
|
|
}
|
|
@@ -80,300 +113,306 @@ export class CloudObject {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// CloudQuery.ts
|
|
|
export class CloudQuery {
|
|
|
className: string;
|
|
|
- queryParams: Record<string, any> = {};
|
|
|
+ whereOptions: Record<string, any> = {};
|
|
|
|
|
|
constructor(className: string) {
|
|
|
this.className = className;
|
|
|
}
|
|
|
|
|
|
- include(...fileds: string[]) {
|
|
|
- this.queryParams["include"] = fileds;
|
|
|
- }
|
|
|
greaterThan(key: string, value: any) {
|
|
|
- if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
- this.queryParams["where"][key]["$gt"] = value;
|
|
|
+ if (!this.whereOptions[key]) this.whereOptions[key] = {};
|
|
|
+ this.whereOptions[key]["$gt"] = value;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
greaterThanAndEqualTo(key: string, value: any) {
|
|
|
- if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
- this.queryParams["where"][key]["$gte"] = value;
|
|
|
+ if (!this.whereOptions[key]) this.whereOptions[key] = {};
|
|
|
+ this.whereOptions[key]["$gte"] = value;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
lessThan(key: string, value: any) {
|
|
|
- if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
- this.queryParams["where"][key]["$lt"] = value;
|
|
|
+ if (!this.whereOptions[key]) this.whereOptions[key] = {};
|
|
|
+ this.whereOptions[key]["$lt"] = value;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
lessThanAndEqualTo(key: string, value: any) {
|
|
|
- if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
- this.queryParams["where"][key]["$lte"] = value;
|
|
|
+ if (!this.whereOptions[key]) this.whereOptions[key] = {};
|
|
|
+ this.whereOptions[key]["$lte"] = value;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
equalTo(key: string, value: any) {
|
|
|
- this.queryParams["where"][key] = value;
|
|
|
+ this.whereOptions[key] = value;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
- async get(id: string) {
|
|
|
- const url = `http://dev.fmode.cn:1337/parse/classes/${this.className}/${id}?`;
|
|
|
-
|
|
|
+ async get(id: string): Promise<Record<string, any>> {
|
|
|
+ const url = `http://dev.fmode.cn:1337/parse/classes/${this.className}/${id}`;
|
|
|
const response = await fetch(url, {
|
|
|
headers: {
|
|
|
- "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
|
|
|
"x-parse-application-id": "dev"
|
|
|
},
|
|
|
- body: null,
|
|
|
method: "GET",
|
|
|
mode: "cors",
|
|
|
credentials: "omit"
|
|
|
});
|
|
|
-
|
|
|
- const json = await response?.json();
|
|
|
+ const json = await response.json();
|
|
|
return json || {};
|
|
|
}
|
|
|
|
|
|
- async find() {
|
|
|
+ async find(): Promise<CloudObject[]> {
|
|
|
let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
|
|
|
|
|
|
- let queryStr = ``
|
|
|
- Object.keys(this.queryParams).forEach(key => {
|
|
|
- let paramStr = JSON.stringify(this.queryParams[key]);
|
|
|
- if (key == "include") {
|
|
|
- paramStr = this.queryParams[key]?.join(",")
|
|
|
- }
|
|
|
- if (queryStr) {
|
|
|
- url += `${key}=${paramStr}`;
|
|
|
- } else {
|
|
|
- url += `&${key}=${paramStr}`;
|
|
|
- }
|
|
|
- })
|
|
|
- // if (Object.keys(this.queryParams["where"]).length) {
|
|
|
-
|
|
|
- // }
|
|
|
+ if (Object.keys(this.whereOptions).length) {
|
|
|
+ const whereStr = JSON.stringify(this.whereOptions);
|
|
|
+ url += `where=${encodeURIComponent(whereStr)}`;
|
|
|
+ }
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
headers: {
|
|
|
- "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
|
|
|
"x-parse-application-id": "dev"
|
|
|
},
|
|
|
- body: null,
|
|
|
method: "GET",
|
|
|
mode: "cors",
|
|
|
credentials: "omit"
|
|
|
});
|
|
|
-
|
|
|
- const json = await response?.json();
|
|
|
- let list = json?.results || []
|
|
|
- let objList = list.map((item: any) => this.dataToObj(item))
|
|
|
- return objList || [];
|
|
|
+ const json = await response.json();
|
|
|
+ return json?.results.map((item: any) => {
|
|
|
+ const cloudObject = new CloudObject(this.className);
|
|
|
+ cloudObject.set(item);
|
|
|
+ cloudObject.id = item.objectId;
|
|
|
+ cloudObject.createdAt = item.createdAt;
|
|
|
+ cloudObject.updatedAt = item.updatedAt;
|
|
|
+ return cloudObject;
|
|
|
+ }) || [];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- async first() {
|
|
|
+ async first(): Promise<CloudObject | null> {
|
|
|
let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
|
|
|
|
|
|
- if (Object.keys(this.queryParams["where"]).length) {
|
|
|
- const whereStr = JSON.stringify(this.queryParams["where"]);
|
|
|
- url += `where=${whereStr}`;
|
|
|
+ if (Object.keys(this.whereOptions).length) {
|
|
|
+ const whereStr = JSON.stringify(this.whereOptions);
|
|
|
+ url += `where=${encodeURIComponent(whereStr)}&limit=1`;
|
|
|
+ } else {
|
|
|
+ url += `limit=1`;
|
|
|
}
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
headers: {
|
|
|
- "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
|
|
|
"x-parse-application-id": "dev"
|
|
|
},
|
|
|
- body: null,
|
|
|
method: "GET",
|
|
|
mode: "cors",
|
|
|
credentials: "omit"
|
|
|
});
|
|
|
-
|
|
|
- const json = await response?.json();
|
|
|
+ const json = await response.json();
|
|
|
const exists = json?.results?.[0] || null;
|
|
|
if (exists) {
|
|
|
- let existsObject = this.dataToObj(exists)
|
|
|
- return existsObject;
|
|
|
+ const cloudObject = new CloudObject(this.className);
|
|
|
+ cloudObject.set(exists);
|
|
|
+ cloudObject.id = exists.objectId;
|
|
|
+ cloudObject.createdAt = exists.createdAt;
|
|
|
+ cloudObject.updatedAt = exists.updatedAt;
|
|
|
+ return cloudObject;
|
|
|
}
|
|
|
- return null
|
|
|
+ return null;
|
|
|
}
|
|
|
+}*/
|
|
|
+// CloudObject.ts
|
|
|
+export interface Pointer {
|
|
|
+ __type: string;
|
|
|
+ className: string;
|
|
|
+ objectId?: string; // 这里保持 objectId 作为可选字段
|
|
|
+}
|
|
|
+export class CloudObject {
|
|
|
+ id: string | null = null;
|
|
|
+ className: string;
|
|
|
+ data: Record<string, any> = {};
|
|
|
+ createdAt: string | null = null;
|
|
|
+ updatedAt: string | null = null;
|
|
|
|
|
|
- dataToObj(exists: any): CloudObject {
|
|
|
- let existsObject = new CloudObject(this.className);
|
|
|
- existsObject.set(exists);
|
|
|
- existsObject.id = exists.objectId;
|
|
|
- existsObject.createdAt = exists.createdAt;
|
|
|
- existsObject.updatedAt = exists.updatedAt;
|
|
|
- return existsObject;
|
|
|
+ constructor(className: string) {
|
|
|
+ this.className = className;
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-// CloudUser.ts
|
|
|
-export class CloudUser extends CloudObject {
|
|
|
- constructor() {
|
|
|
- super("_User"); // 假设用户类在Parse中是"_User"
|
|
|
- // 读取用户缓存信息
|
|
|
- let userCacheStr = localStorage.getItem("NCloud/dev/User")
|
|
|
- if (userCacheStr) {
|
|
|
- let userData = JSON.parse(userCacheStr)
|
|
|
- // 设置用户信息
|
|
|
- this.id = userData?.objectId;
|
|
|
- this.sessionToken = userData?.sessionToken;
|
|
|
- this.data = userData; // 保存用户数据
|
|
|
- }
|
|
|
+ toPointer() {
|
|
|
+ return { "__type": "Pointer", "className": this.className, "objectId": this.id };
|
|
|
}
|
|
|
|
|
|
- sessionToken: string | null = ""
|
|
|
- /** 获取当前用户信息 */
|
|
|
- async current() {
|
|
|
- if (!this.sessionToken) {
|
|
|
- console.error("用户未登录");
|
|
|
- return null;
|
|
|
- }
|
|
|
- return this;
|
|
|
- // const response = await fetch(`http://dev.fmode.cn:1337/parse/users/me`, {
|
|
|
- // headers: {
|
|
|
- // "x-parse-application-id": "dev",
|
|
|
- // "x-parse-session-token": this.sessionToken // 使用sessionToken进行身份验证
|
|
|
- // },
|
|
|
- // method: "GET"
|
|
|
- // });
|
|
|
-
|
|
|
- // const result = await response?.json();
|
|
|
- // if (result?.error) {
|
|
|
- // console.error(result?.error);
|
|
|
- // return null;
|
|
|
- // }
|
|
|
- // return result;
|
|
|
+ set(json: Record<string, any>) {
|
|
|
+ Object.keys(json).forEach(key => {
|
|
|
+ if (["objectId", "id", "createdAt", "updatedAt", "ACL"].includes(key)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.data[key] = json[key];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ get(key: string) {
|
|
|
+ return this.data[key] || null;
|
|
|
}
|
|
|
|
|
|
- /** 登录 */
|
|
|
- async login(username: string, password: string): Promise<CloudUser | null> {
|
|
|
- const response = await fetch(`http://dev.fmode.cn:1337/parse/login`, {
|
|
|
+ async save(): Promise<CloudObject> {
|
|
|
+ let method = "POST";
|
|
|
+ let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}`;
|
|
|
+
|
|
|
+ // 更新
|
|
|
+ if (this.id) {
|
|
|
+ url += `/${this.id}`;
|
|
|
+ method = "PUT";
|
|
|
+ }
|
|
|
+
|
|
|
+ const body = JSON.stringify(this.data);
|
|
|
+ const response = await fetch(url, {
|
|
|
headers: {
|
|
|
- "x-parse-application-id": "dev",
|
|
|
- "Content-Type": "application/json"
|
|
|
+ "Content-Type": "application/json;charset=UTF-8",
|
|
|
+ "x-parse-application-id": "dev"
|
|
|
},
|
|
|
- body: JSON.stringify({ username, password }),
|
|
|
- method: "POST"
|
|
|
+ body,
|
|
|
+ method,
|
|
|
+ mode: "cors",
|
|
|
+ credentials: "omit"
|
|
|
});
|
|
|
|
|
|
- const result = await response?.json();
|
|
|
+ const result = await response.json();
|
|
|
if (result?.error) {
|
|
|
- console.error(result?.error);
|
|
|
- return null;
|
|
|
+ console.error(result.error);
|
|
|
+ }
|
|
|
+ if (result?.objectId) {
|
|
|
+ this.id = result.objectId;
|
|
|
}
|
|
|
-
|
|
|
- // 设置用户信息
|
|
|
- this.id = result?.objectId;
|
|
|
- this.sessionToken = result?.sessionToken;
|
|
|
- this.data = result; // 保存用户数据
|
|
|
- // 缓存用户信息
|
|
|
- console.log(result)
|
|
|
- localStorage.setItem("NCloud/dev/User", JSON.stringify(result))
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- /** 登出 */
|
|
|
- async logout() {
|
|
|
- if (!this.sessionToken) {
|
|
|
- console.error("用户未登录");
|
|
|
- return;
|
|
|
- }
|
|
|
+ async destroy(): Promise<boolean> {
|
|
|
+ if (!this.id) return false;
|
|
|
|
|
|
- const response = await fetch(`http://dev.fmode.cn:1337/parse/logout`, {
|
|
|
+ const response = await fetch(`http://dev.fmode.cn:1337/parse/classes/${this.className}/${this.id}`, {
|
|
|
headers: {
|
|
|
- "x-parse-application-id": "dev",
|
|
|
- "x-parse-session-token": this.sessionToken
|
|
|
+ "x-parse-application-id": "dev"
|
|
|
},
|
|
|
- method: "POST"
|
|
|
+ method: "DELETE",
|
|
|
+ mode: "cors",
|
|
|
+ credentials: "omit"
|
|
|
});
|
|
|
|
|
|
const result = await response?.json();
|
|
|
- if (result?.error) {
|
|
|
- console.error(result?.error);
|
|
|
- return false;
|
|
|
+ if (result) {
|
|
|
+ this.id = null;
|
|
|
}
|
|
|
-
|
|
|
- // 清除用户信息
|
|
|
- localStorage.removeItem("NCloud/dev/User")
|
|
|
- this.id = null;
|
|
|
- this.sessionToken = null;
|
|
|
- this.data = {};
|
|
|
return true;
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+// CloudQuery.ts
|
|
|
+export class CloudQuery {
|
|
|
+ className: string;
|
|
|
+ whereOptions: Record<string, any> = {};
|
|
|
+
|
|
|
+ constructor(className: string) {
|
|
|
+ this.className = className;
|
|
|
+ }
|
|
|
|
|
|
- /** 注册 */
|
|
|
- async signUp(username: string, password: string, additionalData: Record<string, any> = {}) {
|
|
|
- const userData = {
|
|
|
- username,
|
|
|
- password,
|
|
|
- ...additionalData // 合并额外的用户数据
|
|
|
- };
|
|
|
+ greaterThan(key: string, value: any) {
|
|
|
+ this.whereOptions[key] = { "$gt": value };
|
|
|
+ }
|
|
|
|
|
|
- const response = await fetch(`http://dev.fmode.cn:1337/parse/users`, {
|
|
|
+ greaterThanAndEqualTo(key: string, value: any) {
|
|
|
+ this.whereOptions[key] = { "$gte": value };
|
|
|
+ }
|
|
|
+
|
|
|
+ lessThan(key: string, value: any) {
|
|
|
+ this.whereOptions[key] = { "$lt": value };
|
|
|
+ }
|
|
|
+
|
|
|
+ lessThanAndEqualTo(key: string, value: any) {
|
|
|
+ this.whereOptions[key] = { "$lte": value };
|
|
|
+ }
|
|
|
+
|
|
|
+ equalTo(key: string, value: any) {
|
|
|
+ this.whereOptions[key] = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ containedIn(key: string, valueArray: any[]) {
|
|
|
+ this.whereOptions[key] = { "$in": valueArray };
|
|
|
+ }
|
|
|
+
|
|
|
+ async get(id: string): Promise<Record<string, any>> {
|
|
|
+ const url = `http://dev.fmode.cn:1337/parse/classes/${this.className}/${id}?`;
|
|
|
+
|
|
|
+ const response = await fetch(url, {
|
|
|
headers: {
|
|
|
- "x-parse-application-id": "dev",
|
|
|
- "Content-Type": "application/json"
|
|
|
+ "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
|
|
|
+ "x-parse-application-id": "dev"
|
|
|
},
|
|
|
- body: JSON.stringify(userData),
|
|
|
- method: "POST"
|
|
|
+ method: "GET",
|
|
|
+ mode: "cors",
|
|
|
+ credentials: "omit"
|
|
|
});
|
|
|
|
|
|
- const result = await response?.json();
|
|
|
- if (result?.error) {
|
|
|
- console.error(result?.error);
|
|
|
- return null;
|
|
|
+ const json = await response.json();
|
|
|
+ return json || {};
|
|
|
+ }
|
|
|
+
|
|
|
+ async find(): Promise<CloudObject[]> {
|
|
|
+ let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
|
|
|
+
|
|
|
+ if (Object.keys(this.whereOptions).length) {
|
|
|
+ const whereStr = JSON.stringify(this.whereOptions);
|
|
|
+ url += `where=${encodeURIComponent(whereStr)}`;
|
|
|
}
|
|
|
|
|
|
- // 设置用户信息
|
|
|
- // 缓存用户信息
|
|
|
- console.log(result)
|
|
|
- localStorage.setItem("NCloud/dev/User", JSON.stringify(result))
|
|
|
- this.id = result?.objectId;
|
|
|
- this.sessionToken = result?.sessionToken;
|
|
|
- this.data = result; // 保存用户数据
|
|
|
- return this;
|
|
|
+ const response = await fetch(url, {
|
|
|
+ headers: {
|
|
|
+ "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2BDKY\"",
|
|
|
+ "x-parse-application-id": "dev"
|
|
|
+ },
|
|
|
+ method: "GET",
|
|
|
+ mode: "cors",
|
|
|
+ credentials: "omit"
|
|
|
+ });
|
|
|
+
|
|
|
+ const json = await response.json();
|
|
|
+ return json?.results.map((item: any) => {
|
|
|
+ const cloudObject = new CloudObject(this.className);
|
|
|
+ cloudObject.set(item);
|
|
|
+ cloudObject.id = item.objectId;
|
|
|
+ return cloudObject;
|
|
|
+ }) || [];
|
|
|
}
|
|
|
|
|
|
- override async save() {
|
|
|
- let method = "POST";
|
|
|
- let url = `http://dev.fmode.cn:1337/parse/users`;
|
|
|
+ async first(): Promise<CloudObject | null> {
|
|
|
+ let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
|
|
|
|
|
|
- // 更新用户信息
|
|
|
- if (this.id) {
|
|
|
- url += `/${this.id}`;
|
|
|
- method = "PUT";
|
|
|
+ if (Object.keys(this.whereOptions).length) {
|
|
|
+ const whereStr = JSON.stringify(this.whereOptions);
|
|
|
+ url += `where=${encodeURIComponent(whereStr)}`;
|
|
|
}
|
|
|
|
|
|
- let data: any = JSON.parse(JSON.stringify(this.data))
|
|
|
- delete data.createdAt
|
|
|
- delete data.updatedAt
|
|
|
- delete data.ACL
|
|
|
- delete data.objectId
|
|
|
- const body = JSON.stringify(data);
|
|
|
- let headersOptions: any = {
|
|
|
- "content-type": "application/json;charset=UTF-8",
|
|
|
- "x-parse-application-id": "dev",
|
|
|
- "x-parse-session-token": this.sessionToken, // 添加sessionToken以进行身份验证
|
|
|
- }
|
|
|
const response = await fetch(url, {
|
|
|
- headers: headersOptions,
|
|
|
- body: body,
|
|
|
- method: method,
|
|
|
+ headers: {
|
|
|
+ "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
|
|
|
+ "x-parse-application-id": "dev"
|
|
|
+ },
|
|
|
+ method: "GET",
|
|
|
mode: "cors",
|
|
|
credentials: "omit"
|
|
|
});
|
|
|
|
|
|
- const result = await response?.json();
|
|
|
- if (result?.error) {
|
|
|
- console.error(result?.error);
|
|
|
- }
|
|
|
- if (result?.objectId) {
|
|
|
- this.id = result?.objectId;
|
|
|
+ const json = await response.json();
|
|
|
+ const exists = json?.results?.[0] || null;
|
|
|
+ if (exists) {
|
|
|
+ const existsObject = new CloudObject(this.className);
|
|
|
+ existsObject.set(exists);
|
|
|
+ existsObject.id = exists.objectId;
|
|
|
+ existsObject.createdAt = exists.createdAt;
|
|
|
+ existsObject.updatedAt = exists.updatedAt;
|
|
|
+ return existsObject;
|
|
|
}
|
|
|
- localStorage.setItem("NCloud/dev/User", JSON.stringify(this.data))
|
|
|
- return this;
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|