Browse Source

fix:pinyin

xukang 3 months ago
parent
commit
756fc84949
1 changed files with 14 additions and 337 deletions
  1. 14 337
      TFPower-server/lib/ncloud.js

+ 14 - 337
TFPower-server/lib/ncloud.js

@@ -1,189 +1,5 @@
 
 
-<<<<<<< HEAD
-// class CloudObject{
-//     id
-//     className
-//     data = {}
-//     constructor(className){
-//         this.className = className
-//     }
-//     toPointer(){
-//         return {"__type":"Pointer","className":this.className,"objectId":this.id}
-//     }
-//     set(json){
-//         Object.keys(json).forEach(key=>{
-//             if(["objectId","id","createdAt","updatedAt","ACL"].indexOf(key)>-1){
-//                 return
-//             }
-//             this.data[key] = json[key]
-//         })
-//     }
-//     get(key){
-//         return this.data[key] || null
-//     }
-//     async save(){
-//         let method = "POST"
-//         let url = "http://dev.fmode.cn:1337/parse/classes/" + this.className
-//         // 更新
-//         if(this.id){
-//             url += "/"+this.id
-//             method = "PUT"
-//         } 
-//         let body = JSON.stringify(this.data)
-//         let response = await fetch(url, {
-//             "headers": {
-//               "content-type": "application/json;charset=UTF-8",
-//               "x-parse-application-id": "dev"
-//             },
-//             "body": body,
-//             "method": method,
-//             "mode": "cors",
-//             "credentials": "omit"
-//           });
-//           let result = await response?.json();
-//           if(result?.error){
-//             console.error(result?.error)
-//           }
-//           if(result?.objectId){this.id = result?.objectId}
-//           return this
-//     }
-//     async destory(){
-//         if(!this.id) return
-//         let response = await fetch("http://dev.fmode.cn:1337/parse/classes/Doctor/"+this.id, {
-//             "headers": {
-//               "x-parse-application-id": "dev"
-//             },
-//             "body": null,
-//             "method": "DELETE",
-//             "mode": "cors",
-//             "credentials": "omit"
-//           });
-//           let result = await response?.json();
-//           if(result){
-//             this.id = null
-//         }
-//         return true
-//     }
-// }
-
-// class CloudQuery{
-//     className
-//     constructor(className){
-//         this.className = className
-//     }
-
-//     whereOptions = {}
-//     greaterThan(key,value){
-//         if(!this.whereOptions[key]) this.whereOptions[key] = {}
-//         this.whereOptions[key]["$gt"] = value
-//     }
-//     greaterThanAndEqualTo(key,value){
-//         if(!this.whereOptions[key]) this.whereOptions[key] = {}
-//         this.whereOptions[key]["$gte"] = value
-//     }
-//     lessThan(key,value){
-//         if(!this.whereOptions[key]) this.whereOptions[key] = {}
-//         this.whereOptions[key]["$lt"] = value
-//     }
-//     lessThanAndEqualTo(key,value){
-//         if(!this.whereOptions[key]) this.whereOptions[key] = {}
-//         this.whereOptions[key]["$lte"] = value
-//     }
-//     equalTo(key,value){
-//         this.whereOptions[key] = value
-//     }
-
-//     async get(id){
-//         let url = "http://dev.fmode.cn:1337/parse/classes/"+this.className+"/"+id+"?"
-
-//         let response = await fetch(url, {
-//             "headers": {
-//             "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
-//             "x-parse-application-id": "dev"
-//             },
-//             "body": null,
-//             "method": "GET",
-//             "mode": "cors",
-//             "credentials": "omit"
-//         });
-//         let json = await response?.json();
-//         return json || {}
-//     }
-//     async find(){
-//         let url = "http://dev.fmode.cn:1337/parse/classes/"+this.className+"?"
-        
-//         if(Object.keys(this.whereOptions)?.length){
-//             let whereStr = JSON.stringify(this.whereOptions)
-//             url += `where=${whereStr}`
-//         }
-
-//         let response = await fetch(url, {
-//             "headers": {
-//             "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
-//             "x-parse-application-id": "dev"
-//             },
-//             "body": null,
-//             "method": "GET",
-//             "mode": "cors",
-//             "credentials": "omit"
-//         });
-//         let json = await response?.json();
-//         return json?.results || []
-//     }
-//     async first(){
-//         let url = "http://dev.fmode.cn:1337/parse/classes/"+this.className+"?"
-        
-//         if(Object.keys(this.whereOptions)?.length){
-//             let whereStr = JSON.stringify(this.whereOptions)
-//             url += `where=${whereStr}`
-//         }
-
-//         let response = await fetch(url, {
-//             "headers": {
-//             "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
-//             "x-parse-application-id": "dev"
-//             },
-//             "body": null,
-//             "method": "GET",
-//             "mode": "cors",
-//             "credentials": "omit"
-//         });
-//         let json = await response?.json();
-//         let exists = json?.results?.[0] || null
-//         if(exists){
-//             let existsObject = new CloudObject(this.className)
-//             existsObject.set(exists)
-//             existsObject.id = exists.objectId
-//             existsObject.createdAt = exists.createdAt
-//             existsObject.updatedAt = exists.updatedAt
-//             return existsObject
-//         }
-//     }
-// }
-
-// module.exports.CloudObject = CloudObject
-// module.exports.CloudQuery = CloudQuery
-
-class CloudObject{
-    id
-    ClassName
-    data={}
-    constructor(ClassName)
-    {
-        this.ClassName=ClassName
-    }
-
-    toPointer(){
-        return {"_type":"Pointer","ClassName":this.ClassName,"objectId":this.id}
-    }
-    // 界面给data传数据
-    set(json){
-        Object.keys(json).forEach(key=>{
-            if(["objectId","id","createdAt","updateAt","ACL"].indexOf(key)>-1)
-            {
-                return 
-=======
 class CloudObject {
     id
     className
@@ -198,50 +14,10 @@ class CloudObject {
         Object.keys(json).forEach(key => {
             if (["objectId", "id", "createdAt", "updatedAt", "ACL"].indexOf(key) > -1) {
                 return
->>>>>>> xk
             }
-            this.data[key]=json[key]
+            this.data[key] = json[key]
         })
     }
-<<<<<<< HEAD
-    // data返回数据给界面
-    get(){
-        return this.data[key] || null
-    }
-
-    // data数据传给数据库,
-    // 增数据 数据库生成id,给id赋值,返回整个对象
-    // 改数据 修改非id数据,返回整个对象
-    async save(){
-        let url="http://dev.fmode.cn:1337/parse/classes/" +this.ClassName
-        let method="POST"
-        if(this.id)
-        {
-            method="PUT"
-            url+="/"+this.id
-        }
-
-        let body=JSON.stringify(this.data)
-        let response=await fetch(url, {
-           "headers": {
-             "content-type": "application/json;charset=UTF-8",
-             "x-parse-application-id": "dev"
-           },
-           "body": body,
-           "method": method,
-           "mode": "cors",
-           "credentials": "omit"
-         });
-       let json= await response?.json();
-       if(json?.objectId){this.id=json?.objectId}
-       return this
-    }
-
-    // 通过数据库删除,再删除id里可能存在的数据
-    async destroy() {
-        if(!this.id)return 
-        let response=await fetch("http://dev.fmode.cn:1337/parse/classes/Post/"+this.id, {
-=======
     get(key) {
         return this.data[key] || null
     }
@@ -274,7 +50,6 @@ class CloudObject {
     async destory() {
         if (!this.id) return
         let response = await fetch("https://dev.fmode.cn/parse/classes/Doctor/" + this.id, {
->>>>>>> xk
             "headers": {
                 "x-parse-application-id": "dev"
             },
@@ -282,67 +57,15 @@ class CloudObject {
             "method": "DELETE",
             "mode": "cors",
             "credentials": "omit"
-<<<<<<< HEAD
-          });
-          let json=await response?.json()
-          if(json)this.id=null
-          return true;
-=======
         });
         let result = await response?.json();
         if (result) {
             this.id = null
         }
         return true
->>>>>>> xk
     }
 
 }
-class CloudQuery
-{
-    ClassName
-
-<<<<<<< HEAD
-    constructor(ClassName)
-    {
-        this.ClassName=ClassName
-    }
-    
-    whereOptions={}
-    equalTo(key,value)
-    {
-        this.whereOptions[key]=value
-    }
-
-    greaterThan(key,value)
-    {
-        if(!this.whereOptions[key])this.whereOptions[key]={}
-        this.whereOptions[key]["$gt"]=value
-    }
-    greaterThanAndEqualTo(key,value)
-    {
-        if(!this.whereOptions[key])this.whereOptions[key]={}
-        this.whereOptions[key]["$gte"]=value
-    }
-    lessThan(key,value)
-    {
-        if(!this.whereOptions[key])this.whereOptions[key]={}
-        this.whereOptions[key]["$lt"]=value
-    }
-    lessThanAndEqualTo(key,value)
-    {
-        if(!this.whereOptions[key])this.whereOptions[key]={}
-        this.whereOptions[key]["$lte"]=value
-    }
-
-    // 查询一个表中的特定id数据
-    async get(id)
-    {
-        let response=await fetch("http://dev.fmode.cn:1337/parse/classes/"+this.ClassName+"/"+id+"?", {
-            "headers": {
-              "if-none-match": "W/\"ab-2gNtNZqRYX93fdbIaSj6z5h571k\"",
-              "x-parse-application-id": "dev"
-=======
 class CloudQuery {
     className
     constructor(className) {
@@ -377,121 +100,75 @@ class CloudQuery {
             "headers": {
                 "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
                 "x-parse-application-id": "dev"
->>>>>>> xk
             },
-    
+
             "body": null,
             "method": "GET",
             "mode": "cors",
             "credentials": "omit"
-          });
-        let json=await response?.json();
+        });
+        let json = await response?.json();
         // console.log(json);
         return json || {}
     }
-<<<<<<< HEAD
- 
-    // 查询一个表中的所有数据,高级查询
-    async find(){
-        let url="http://dev.fmode.cn:1337/parse/classes/"+this.ClassName+"?"
-
-
-        if(Object.keys(this.whereOptions).length)
-        {
-            let whereStr=JSON.stringify(this.whereOptions)
-            url+=`where=${whereStr}`
-=======
     async find() {
         let url = "https://dev.fmode.cn/parse/classes/" + this.className + "?"
 
         if (Object.keys(this.whereOptions)?.length) {
             let whereStr = JSON.stringify(this.whereOptions)
             url += `where=${whereStr}`
->>>>>>> xk
         }
 
-        let response=await fetch(url, {
+        let response = await fetch(url, {
             "headers": {
-<<<<<<< HEAD
-              "if-none-match": "W/\"ab-2gNtNZqRYX93fdbIaSj6z5h571k\"",
-              "x-parse-application-id": "dev"
-=======
                 "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
                 "x-parse-application-id": "dev"
->>>>>>> xk
             },
 
             "body": null,
             "method": "GET",
             "mode": "cors",
             "credentials": "omit"
-          });
-        let json=await response?.json();
+        });
+        let json = await response?.json();
         // console.log(json);
         return json?.results || []
     }
-<<<<<<< HEAD
-    async first(){
-        let url="http://dev.fmode.cn:1337/parse/classes/"+this.ClassName+"?"
-
-
-        if(Object.keys(this.whereOptions).length)
-        {
-            let whereStr=JSON.stringify(this.whereOptions)
-            url+=`where=${whereStr}`
-=======
     async first() {
         let url = "https://dev.fmode.cn/parse/classes/" + this.className + "?"
 
         if (Object.keys(this.whereOptions)?.length) {
             let whereStr = JSON.stringify(this.whereOptions)
             url += `where=${whereStr}`
->>>>>>> xk
         }
 
-        let response=await fetch(url, {
+        let response = await fetch(url, {
             "headers": {
-<<<<<<< HEAD
-              "if-none-match": "W/\"ab-2gNtNZqRYX93fdbIaSj6z5h571k\"",
-              "x-parse-application-id": "dev"
-=======
                 "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
                 "x-parse-application-id": "dev"
->>>>>>> xk
             },
 
             "body": null,
             "method": "GET",
             "mode": "cors",
             "credentials": "omit"
-<<<<<<< HEAD
-          });
-        let json=await response?.json();
-        // console.log(json);
-        let exists=json?.results?.[0] || null
-        if(exists)
-        {
-            let existsObject=new CloudObject(this.ClassName)
-
-=======
         });
         let json = await response?.json();
         let exists = json?.results?.[0] || null
         if (exists) {
             let existsObject = new CloudObject(this.className)
->>>>>>> xk
             existsObject.set(exists)
-            existsObject.id=exists.objectId
-            existsObject.createdAt=exists.createdAt
-            existsObject.updatedAt=exists.updatedAt
+            existsObject.id = exists.objectId
+            existsObject.createdAt = exists.createdAt
+            existsObject.updatedAt = exists.updatedAt
             return existsObject
         }
-       
+
     }
 
 }
 
 
 
-module.exports.CloudObject=CloudObject
-module.exports.CloudQuery=CloudQuery
+module.exports.CloudObject = CloudObject
+module.exports.CloudQuery = CloudQuery