123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- class ParseObject{
- className
- id
- serverURL = "https://web2023.fmode.cn/parse"
- data = {}
- toJSON(){
- return this.data
- }
- constructor(className){
- this.className = className
- }
- async get(id){
- let response = await fetch(this.serverURL+"/classes/"+this.className+"/"+id, {
- "headers": {
- "x-parse-application-id": "dev"
- },
- "body": null,
- "method": "GET",
- "mode": "cors",
- "credentials": "omit"
- });
- if(response?.status=="200"){
- let json = await response.json()
- this.id = json?.objectId;
- delete json.objectId
- delete json.createdAt
- delete json.updatedAt
- this.data = json;
- return this
- }else{
- return []
- }
- }
- async findAll(){
- let response = await fetch(this.serverURL+"/classes/"+this.className, {
- "headers": {
- "x-parse-application-id": "dev"
- },
- "body": null,
- "method": "GET",
- "mode": "cors",
- "credentials": "omit"
- });
- console.log(response)
- return []
- if(response?.status=="200"){
- let json = await response.json()
- // console.log(json)
- return json?.results || []
- }else{
- return []
- }
- }
- set(data){
- this.data = data
- }
- async save(){
- let body = JSON.stringify(this.data)
- let url = this.serverURL+"/classes/"+this.className // 创建URL
- let method = "POST"
- if(this.id){
- url = url + "/" + this.id // 更新URL
- method = "PUT"
- }
- console.log(url,method,body)
- let response = await fetch(url, {
- "headers": {
- // "content-type": "text/plain;charset=UTF-8",
- "x-parse-application-id": "dev"
- },
- "body": body,
- "method": method,
- "mode": "cors",
- "credentials": "omit"
- });
- console.log(body)
- let text = await response?.text();
- console.log(text)
- let json = await response?.json();
- if(json?.objectId){
- console.log(json)
- this.id = json?.objectId
- return this
- }else{
- return null
- }
- }
- async delete(){
- let response = await fetch(this.serverURL+"/classes/"+this.className+"/"+id, {
- "headers": {
- "x-parse-application-id": "dev"
- },
- "body": null,
- "method": "DELETE",
- "mode": "cors",
- "credentials": "omit"
- });
- if(response?.status=="200"){
- let json = await response.json()
- return json
- }else{
- return []
- }
- }
- }
- module.exports.ParseObject = ParseObject
- class ParseQuery{
-
- }
|