ncloud.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <<<<<<< HEAD
  2. // class CloudObject{
  3. // id
  4. // className
  5. // data = {}
  6. // constructor(className){
  7. // this.className = className
  8. // }
  9. // toPointer(){
  10. // return {"__type":"Pointer","className":this.className,"objectId":this.id}
  11. // }
  12. // set(json){
  13. // Object.keys(json).forEach(key=>{
  14. // if(["objectId","id","createdAt","updatedAt","ACL"].indexOf(key)>-1){
  15. // return
  16. // }
  17. // this.data[key] = json[key]
  18. // })
  19. // }
  20. // get(key){
  21. // return this.data[key] || null
  22. // }
  23. // async save(){
  24. // let method = "POST"
  25. // let url = "http://dev.fmode.cn:1337/parse/classes/" + this.className
  26. // // 更新
  27. // if(this.id){
  28. // url += "/"+this.id
  29. // method = "PUT"
  30. // }
  31. // let body = JSON.stringify(this.data)
  32. // let response = await fetch(url, {
  33. // "headers": {
  34. // "content-type": "application/json;charset=UTF-8",
  35. // "x-parse-application-id": "dev"
  36. // },
  37. // "body": body,
  38. // "method": method,
  39. // "mode": "cors",
  40. // "credentials": "omit"
  41. // });
  42. // let result = await response?.json();
  43. // if(result?.error){
  44. // console.error(result?.error)
  45. // }
  46. // if(result?.objectId){this.id = result?.objectId}
  47. // return this
  48. // }
  49. // async destory(){
  50. // if(!this.id) return
  51. // let response = await fetch("http://dev.fmode.cn:1337/parse/classes/Doctor/"+this.id, {
  52. // "headers": {
  53. // "x-parse-application-id": "dev"
  54. // },
  55. // "body": null,
  56. // "method": "DELETE",
  57. // "mode": "cors",
  58. // "credentials": "omit"
  59. // });
  60. // let result = await response?.json();
  61. // if(result){
  62. // this.id = null
  63. // }
  64. // return true
  65. // }
  66. // }
  67. // class CloudQuery{
  68. // className
  69. // constructor(className){
  70. // this.className = className
  71. // }
  72. // whereOptions = {}
  73. // greaterThan(key,value){
  74. // if(!this.whereOptions[key]) this.whereOptions[key] = {}
  75. // this.whereOptions[key]["$gt"] = value
  76. // }
  77. // greaterThanAndEqualTo(key,value){
  78. // if(!this.whereOptions[key]) this.whereOptions[key] = {}
  79. // this.whereOptions[key]["$gte"] = value
  80. // }
  81. // lessThan(key,value){
  82. // if(!this.whereOptions[key]) this.whereOptions[key] = {}
  83. // this.whereOptions[key]["$lt"] = value
  84. // }
  85. // lessThanAndEqualTo(key,value){
  86. // if(!this.whereOptions[key]) this.whereOptions[key] = {}
  87. // this.whereOptions[key]["$lte"] = value
  88. // }
  89. // equalTo(key,value){
  90. // this.whereOptions[key] = value
  91. // }
  92. // async get(id){
  93. // let url = "http://dev.fmode.cn:1337/parse/classes/"+this.className+"/"+id+"?"
  94. // let response = await fetch(url, {
  95. // "headers": {
  96. // "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
  97. // "x-parse-application-id": "dev"
  98. // },
  99. // "body": null,
  100. // "method": "GET",
  101. // "mode": "cors",
  102. // "credentials": "omit"
  103. // });
  104. // let json = await response?.json();
  105. // return json || {}
  106. // }
  107. // async find(){
  108. // let url = "http://dev.fmode.cn:1337/parse/classes/"+this.className+"?"
  109. // if(Object.keys(this.whereOptions)?.length){
  110. // let whereStr = JSON.stringify(this.whereOptions)
  111. // url += `where=${whereStr}`
  112. // }
  113. // let response = await fetch(url, {
  114. // "headers": {
  115. // "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
  116. // "x-parse-application-id": "dev"
  117. // },
  118. // "body": null,
  119. // "method": "GET",
  120. // "mode": "cors",
  121. // "credentials": "omit"
  122. // });
  123. // let json = await response?.json();
  124. // return json?.results || []
  125. // }
  126. // async first(){
  127. // let url = "http://dev.fmode.cn:1337/parse/classes/"+this.className+"?"
  128. // if(Object.keys(this.whereOptions)?.length){
  129. // let whereStr = JSON.stringify(this.whereOptions)
  130. // url += `where=${whereStr}`
  131. // }
  132. // let response = await fetch(url, {
  133. // "headers": {
  134. // "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
  135. // "x-parse-application-id": "dev"
  136. // },
  137. // "body": null,
  138. // "method": "GET",
  139. // "mode": "cors",
  140. // "credentials": "omit"
  141. // });
  142. // let json = await response?.json();
  143. // let exists = json?.results?.[0] || null
  144. // if(exists){
  145. // let existsObject = new CloudObject(this.className)
  146. // existsObject.set(exists)
  147. // existsObject.id = exists.objectId
  148. // existsObject.createdAt = exists.createdAt
  149. // existsObject.updatedAt = exists.updatedAt
  150. // return existsObject
  151. // }
  152. // }
  153. // }
  154. // module.exports.CloudObject = CloudObject
  155. // module.exports.CloudQuery = CloudQuery
  156. class CloudObject{
  157. id
  158. ClassName
  159. data={}
  160. constructor(ClassName)
  161. {
  162. this.ClassName=ClassName
  163. }
  164. toPointer(){
  165. return {"_type":"Pointer","ClassName":this.ClassName,"objectId":this.id}
  166. }
  167. // 界面给data传数据
  168. set(json){
  169. Object.keys(json).forEach(key=>{
  170. if(["objectId","id","createdAt","updateAt","ACL"].indexOf(key)>-1)
  171. {
  172. return
  173. =======
  174. class CloudObject {
  175. id
  176. className
  177. data = {}
  178. constructor(className) {
  179. this.className = className
  180. }
  181. toPointer() {
  182. return { "__type": "Pointer", "className": this.className, "objectId": this.id }
  183. }
  184. set(json) {
  185. Object.keys(json).forEach(key => {
  186. if (["objectId", "id", "createdAt", "updatedAt", "ACL"].indexOf(key) > -1) {
  187. return
  188. >>>>>>> xk
  189. }
  190. this.data[key]=json[key]
  191. })
  192. }
  193. <<<<<<< HEAD
  194. // data返回数据给界面
  195. get(){
  196. return this.data[key] || null
  197. }
  198. // data数据传给数据库,
  199. // 增数据 数据库生成id,给id赋值,返回整个对象
  200. // 改数据 修改非id数据,返回整个对象
  201. async save(){
  202. let url="http://dev.fmode.cn:1337/parse/classes/" +this.ClassName
  203. let method="POST"
  204. if(this.id)
  205. {
  206. method="PUT"
  207. url+="/"+this.id
  208. }
  209. let body=JSON.stringify(this.data)
  210. let response=await fetch(url, {
  211. "headers": {
  212. "content-type": "application/json;charset=UTF-8",
  213. "x-parse-application-id": "dev"
  214. },
  215. "body": body,
  216. "method": method,
  217. "mode": "cors",
  218. "credentials": "omit"
  219. });
  220. let json= await response?.json();
  221. if(json?.objectId){this.id=json?.objectId}
  222. return this
  223. }
  224. // 通过数据库删除,再删除id里可能存在的数据
  225. async destroy() {
  226. if(!this.id)return
  227. let response=await fetch("http://dev.fmode.cn:1337/parse/classes/Post/"+this.id, {
  228. =======
  229. get(key) {
  230. return this.data[key] || null
  231. }
  232. async save() {
  233. let method = "POST"
  234. let url = "https://dev.fmode.cn/parse/classes/" + this.className
  235. // 更新
  236. if (this.id) {
  237. url += "/" + this.id
  238. method = "PUT"
  239. }
  240. let body = JSON.stringify(this.data)
  241. let response = await fetch(url, {
  242. "headers": {
  243. "content-type": "application/json;charset=UTF-8",
  244. "x-parse-application-id": "dev"
  245. },
  246. "body": body,
  247. "method": method,
  248. "mode": "cors",
  249. "credentials": "omit"
  250. });
  251. let result = await response?.json();
  252. if (result?.error) {
  253. console.error(result?.error)
  254. }
  255. if (result?.objectId) { this.id = result?.objectId }
  256. return this
  257. }
  258. async destory() {
  259. if (!this.id) return
  260. let response = await fetch("https://dev.fmode.cn/parse/classes/Doctor/" + this.id, {
  261. >>>>>>> xk
  262. "headers": {
  263. "x-parse-application-id": "dev"
  264. },
  265. "body": null,
  266. "method": "DELETE",
  267. "mode": "cors",
  268. "credentials": "omit"
  269. <<<<<<< HEAD
  270. });
  271. let json=await response?.json()
  272. if(json)this.id=null
  273. return true;
  274. =======
  275. });
  276. let result = await response?.json();
  277. if (result) {
  278. this.id = null
  279. }
  280. return true
  281. >>>>>>> xk
  282. }
  283. }
  284. class CloudQuery
  285. {
  286. ClassName
  287. <<<<<<< HEAD
  288. constructor(ClassName)
  289. {
  290. this.ClassName=ClassName
  291. }
  292. whereOptions={}
  293. equalTo(key,value)
  294. {
  295. this.whereOptions[key]=value
  296. }
  297. greaterThan(key,value)
  298. {
  299. if(!this.whereOptions[key])this.whereOptions[key]={}
  300. this.whereOptions[key]["$gt"]=value
  301. }
  302. greaterThanAndEqualTo(key,value)
  303. {
  304. if(!this.whereOptions[key])this.whereOptions[key]={}
  305. this.whereOptions[key]["$gte"]=value
  306. }
  307. lessThan(key,value)
  308. {
  309. if(!this.whereOptions[key])this.whereOptions[key]={}
  310. this.whereOptions[key]["$lt"]=value
  311. }
  312. lessThanAndEqualTo(key,value)
  313. {
  314. if(!this.whereOptions[key])this.whereOptions[key]={}
  315. this.whereOptions[key]["$lte"]=value
  316. }
  317. // 查询一个表中的特定id数据
  318. async get(id)
  319. {
  320. let response=await fetch("http://dev.fmode.cn:1337/parse/classes/"+this.ClassName+"/"+id+"?", {
  321. "headers": {
  322. "if-none-match": "W/\"ab-2gNtNZqRYX93fdbIaSj6z5h571k\"",
  323. "x-parse-application-id": "dev"
  324. =======
  325. class CloudQuery {
  326. className
  327. constructor(className) {
  328. this.className = className
  329. }
  330. whereOptions = {}
  331. greaterThan(key, value) {
  332. if (!this.whereOptions[key]) this.whereOptions[key] = {}
  333. this.whereOptions[key]["$gt"] = value
  334. }
  335. greaterThanAndEqualTo(key, value) {
  336. if (!this.whereOptions[key]) this.whereOptions[key] = {}
  337. this.whereOptions[key]["$gte"] = value
  338. }
  339. lessThan(key, value) {
  340. if (!this.whereOptions[key]) this.whereOptions[key] = {}
  341. this.whereOptions[key]["$lt"] = value
  342. }
  343. lessThanAndEqualTo(key, value) {
  344. if (!this.whereOptions[key]) this.whereOptions[key] = {}
  345. this.whereOptions[key]["$lte"] = value
  346. }
  347. equalTo(key, value) {
  348. this.whereOptions[key] = value
  349. }
  350. async get(id) {
  351. let url = "https://dev.fmode.cn/parse/classes/" + this.className + "/" + id + "?"
  352. let response = await fetch(url, {
  353. "headers": {
  354. "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
  355. "x-parse-application-id": "dev"
  356. >>>>>>> xk
  357. },
  358. "body": null,
  359. "method": "GET",
  360. "mode": "cors",
  361. "credentials": "omit"
  362. });
  363. let json=await response?.json();
  364. // console.log(json);
  365. return json || {}
  366. }
  367. <<<<<<< HEAD
  368. // 查询一个表中的所有数据,高级查询
  369. async find(){
  370. let url="http://dev.fmode.cn:1337/parse/classes/"+this.ClassName+"?"
  371. if(Object.keys(this.whereOptions).length)
  372. {
  373. let whereStr=JSON.stringify(this.whereOptions)
  374. url+=`where=${whereStr}`
  375. =======
  376. async find() {
  377. let url = "https://dev.fmode.cn/parse/classes/" + this.className + "?"
  378. if (Object.keys(this.whereOptions)?.length) {
  379. let whereStr = JSON.stringify(this.whereOptions)
  380. url += `where=${whereStr}`
  381. >>>>>>> xk
  382. }
  383. let response=await fetch(url, {
  384. "headers": {
  385. <<<<<<< HEAD
  386. "if-none-match": "W/\"ab-2gNtNZqRYX93fdbIaSj6z5h571k\"",
  387. "x-parse-application-id": "dev"
  388. =======
  389. "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
  390. "x-parse-application-id": "dev"
  391. >>>>>>> xk
  392. },
  393. "body": null,
  394. "method": "GET",
  395. "mode": "cors",
  396. "credentials": "omit"
  397. });
  398. let json=await response?.json();
  399. // console.log(json);
  400. return json?.results || []
  401. }
  402. <<<<<<< HEAD
  403. async first(){
  404. let url="http://dev.fmode.cn:1337/parse/classes/"+this.ClassName+"?"
  405. if(Object.keys(this.whereOptions).length)
  406. {
  407. let whereStr=JSON.stringify(this.whereOptions)
  408. url+=`where=${whereStr}`
  409. =======
  410. async first() {
  411. let url = "https://dev.fmode.cn/parse/classes/" + this.className + "?"
  412. if (Object.keys(this.whereOptions)?.length) {
  413. let whereStr = JSON.stringify(this.whereOptions)
  414. url += `where=${whereStr}`
  415. >>>>>>> xk
  416. }
  417. let response=await fetch(url, {
  418. "headers": {
  419. <<<<<<< HEAD
  420. "if-none-match": "W/\"ab-2gNtNZqRYX93fdbIaSj6z5h571k\"",
  421. "x-parse-application-id": "dev"
  422. =======
  423. "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
  424. "x-parse-application-id": "dev"
  425. >>>>>>> xk
  426. },
  427. "body": null,
  428. "method": "GET",
  429. "mode": "cors",
  430. "credentials": "omit"
  431. <<<<<<< HEAD
  432. });
  433. let json=await response?.json();
  434. // console.log(json);
  435. let exists=json?.results?.[0] || null
  436. if(exists)
  437. {
  438. let existsObject=new CloudObject(this.ClassName)
  439. =======
  440. });
  441. let json = await response?.json();
  442. let exists = json?.results?.[0] || null
  443. if (exists) {
  444. let existsObject = new CloudObject(this.className)
  445. >>>>>>> xk
  446. existsObject.set(exists)
  447. existsObject.id=exists.objectId
  448. existsObject.createdAt=exists.createdAt
  449. existsObject.updatedAt=exists.updatedAt
  450. return existsObject
  451. }
  452. }
  453. }
  454. module.exports.CloudObject=CloudObject
  455. module.exports.CloudQuery=CloudQuery