|
|
@@ -1,5 +1,4 @@
|
|
|
-
|
|
|
-//CloudObject.ts
|
|
|
+// CloudObject.ts
|
|
|
export class CloudObject {
|
|
|
className: string;
|
|
|
id: string | null = null;
|
|
|
@@ -30,7 +29,7 @@ export class CloudObject {
|
|
|
|
|
|
async save() {
|
|
|
let method = "POST";
|
|
|
- let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}`;
|
|
|
+ let url = `https://dev.fmode.cn/parse/classes/${this.className}`;
|
|
|
|
|
|
// 更新
|
|
|
if (this.id) {
|
|
|
@@ -62,7 +61,7 @@ export class CloudObject {
|
|
|
|
|
|
async destroy() {
|
|
|
if (!this.id) return;
|
|
|
- const response = await fetch(`http://dev.fmode.cn:1337/parse/classes/${this.className}/${this.id}`, {
|
|
|
+ const response = await fetch(`https://dev.fmode.cn/parse/classes/${this.className}/${this.id}`, {
|
|
|
headers: {
|
|
|
"x-parse-application-id": "dev"
|
|
|
},
|
|
|
@@ -83,38 +82,41 @@ export class CloudObject {
|
|
|
// CloudQuery.ts
|
|
|
export class CloudQuery {
|
|
|
className: string;
|
|
|
- whereOptions: Record<string, any> = {};
|
|
|
+ queryParams: Record<string, any> = {};
|
|
|
|
|
|
constructor(className: string) {
|
|
|
this.className = className;
|
|
|
}
|
|
|
|
|
|
+ include(...fileds:string[]) {
|
|
|
+ this.queryParams["include"] = fileds;
|
|
|
+ }
|
|
|
greaterThan(key: string, value: any) {
|
|
|
- if (!this.whereOptions[key]) this.whereOptions[key] = {};
|
|
|
- this.whereOptions[key]["$gt"] = value;
|
|
|
+ if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
+ this.queryParams["where"][key]["$gt"] = value;
|
|
|
}
|
|
|
|
|
|
greaterThanAndEqualTo(key: string, value: any) {
|
|
|
- if (!this.whereOptions[key]) this.whereOptions[key] = {};
|
|
|
- this.whereOptions[key]["$gte"] = value;
|
|
|
+ if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
+ this.queryParams["where"][key]["$gte"] = value;
|
|
|
}
|
|
|
|
|
|
lessThan(key: string, value: any) {
|
|
|
- if (!this.whereOptions[key]) this.whereOptions[key] = {};
|
|
|
- this.whereOptions[key]["$lt"] = value;
|
|
|
+ if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
+ this.queryParams["where"][key]["$lt"] = value;
|
|
|
}
|
|
|
|
|
|
lessThanAndEqualTo(key: string, value: any) {
|
|
|
- if (!this.whereOptions[key]) this.whereOptions[key] = {};
|
|
|
- this.whereOptions[key]["$lte"] = value;
|
|
|
+ if (!this.queryParams["where"][key]) this.queryParams["where"][key] = {};
|
|
|
+ this.queryParams["where"][key]["$lte"] = value;
|
|
|
}
|
|
|
|
|
|
equalTo(key: string, value: any) {
|
|
|
- this.whereOptions[key] = value;
|
|
|
+ this.queryParams["where"][key] = value;
|
|
|
}
|
|
|
|
|
|
async get(id: string) {
|
|
|
- const url = `http://dev.fmode.cn:1337/parse/classes/${this.className}/${id}?`;
|
|
|
+ const url = `https://dev.fmode.cn/parse/classes/${this.className}/${id}?`;
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
headers: {
|
|
|
@@ -132,12 +134,23 @@ export class CloudQuery {
|
|
|
}
|
|
|
|
|
|
async find() {
|
|
|
- let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
|
|
|
+ let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
|
|
|
|
|
|
- if (Object.keys(this.whereOptions).length) {
|
|
|
- const whereStr = JSON.stringify(this.whereOptions);
|
|
|
- url += `where=${whereStr}`;
|
|
|
- }
|
|
|
+ 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) {
|
|
|
+
|
|
|
+ // }
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
headers: {
|
|
|
@@ -157,10 +170,10 @@ export class CloudQuery {
|
|
|
}
|
|
|
|
|
|
async first() {
|
|
|
- let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
|
|
|
+ let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
|
|
|
|
|
|
- if (Object.keys(this.whereOptions).length) {
|
|
|
- const whereStr = JSON.stringify(this.whereOptions);
|
|
|
+ if (Object.keys(this.queryParams["where"]).length) {
|
|
|
+ const whereStr = JSON.stringify(this.queryParams["where"]);
|
|
|
url += `where=${whereStr}`;
|
|
|
}
|
|
|
|
|
|
@@ -197,9 +210,9 @@ export class CloudQuery {
|
|
|
// CloudUser.ts
|
|
|
export class CloudUser extends CloudObject {
|
|
|
constructor() {
|
|
|
- super("Users"); // 用户类在Parse中是"Users"
|
|
|
+ super("_User"); // 假设用户类在Parse中是"_User"
|
|
|
// 读取用户缓存信息
|
|
|
- let userCacheStr = localStorage.getItem("NCloud/dev/Users")
|
|
|
+ let userCacheStr = localStorage.getItem("NCloud/dev/User")
|
|
|
if(userCacheStr){
|
|
|
let userData = JSON.parse(userCacheStr)
|
|
|
// 设置用户信息
|
|
|
@@ -210,7 +223,6 @@ export class CloudUser extends CloudObject {
|
|
|
}
|
|
|
|
|
|
sessionToken:string|null = ""
|
|
|
-
|
|
|
/** 获取当前用户信息 */
|
|
|
async current() {
|
|
|
if (!this.sessionToken) {
|
|
|
@@ -218,7 +230,7 @@ export class CloudUser extends CloudObject {
|
|
|
return null;
|
|
|
}
|
|
|
return this;
|
|
|
- // const response = await fetch(`http://dev.fmode.cn:1337/parse/users/me`, {
|
|
|
+ // const response = await fetch(`https://dev.fmode.cn/parse/users/me`, {
|
|
|
// headers: {
|
|
|
// "x-parse-application-id": "dev",
|
|
|
// "x-parse-session-token": this.sessionToken // 使用sessionToken进行身份验证
|
|
|
@@ -236,7 +248,7 @@ export class CloudUser extends CloudObject {
|
|
|
|
|
|
/** 登录 */
|
|
|
async login(username: string, password: string):Promise<CloudUser|null> {
|
|
|
- const response = await fetch(`http://dev.fmode.cn:1337/parse/login`, {
|
|
|
+ const response = await fetch(`https://dev.fmode.cn/parse/login`, {
|
|
|
headers: {
|
|
|
"x-parse-application-id": "dev",
|
|
|
"Content-Type": "application/json"
|
|
|
@@ -268,7 +280,7 @@ export class CloudUser extends CloudObject {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const response = await fetch(`http://dev.fmode.cn:1337/parse/logout`, {
|
|
|
+ const response = await fetch(`https://dev.fmode.cn/parse/logout`, {
|
|
|
headers: {
|
|
|
"x-parse-application-id": "dev",
|
|
|
"x-parse-session-token": this.sessionToken
|
|
|
@@ -298,7 +310,7 @@ export class CloudUser extends CloudObject {
|
|
|
...additionalData // 合并额外的用户数据
|
|
|
};
|
|
|
|
|
|
- const response = await fetch(`http://dev.fmode.cn:1337/parse/users`, {
|
|
|
+ const response = await fetch(`https://dev.fmode.cn/parse/users`, {
|
|
|
headers: {
|
|
|
"x-parse-application-id": "dev",
|
|
|
"Content-Type": "application/json"
|