|
@@ -1,10 +1,16 @@
|
|
|
-import { remove } from 'ionicons/icons';
|
|
|
-
|
|
|
+/**
|
|
|
+ * @desc 查找数据库
|
|
|
+ * @param {string} className:数据库中表的名称
|
|
|
+ */
|
|
|
export class CloudQuery {
|
|
|
className = '';
|
|
|
constructor(className: string) {
|
|
|
this.className = className;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc 获取数据表中的所有信息,配合CloudQuery()使用
|
|
|
+ */
|
|
|
async getAll() {
|
|
|
let response = await fetch(
|
|
|
'http://1.94.237.145:1338/parsecyx/classes/' + this.className,
|
|
@@ -32,9 +38,16 @@ export class CloudQuery {
|
|
|
return json || [];
|
|
|
}
|
|
|
|
|
|
- async getBy(id: string) {
|
|
|
+ /**
|
|
|
+ * @desc 获取数据表中单个信息,配合CloudQuery()使用
|
|
|
+ * @param {string} objectId:数据库中表的名称
|
|
|
+ */
|
|
|
+ async getBy(objectId: string) {
|
|
|
let response = await fetch(
|
|
|
- 'http://1.94.237.145:1338/parsecyx/classes/' + this.className + '/' + id,
|
|
|
+ 'http://1.94.237.145:1338/parsecyx/classes/' +
|
|
|
+ this.className +
|
|
|
+ '/' +
|
|
|
+ objectId,
|
|
|
{
|
|
|
headers: {
|
|
|
accept: '*/*',
|
|
@@ -61,6 +74,53 @@ export class CloudQuery {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// fetch('http://1.94.237.145:1338/parsecyx/classes/News', {
|
|
|
+// headers: {
|
|
|
+// accept: '*/*',
|
|
|
+// 'accept-language':
|
|
|
+// 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,zh-TW;q=0.5,ja;q=0.4',
|
|
|
+// 'content-type': 'text/plain',
|
|
|
+// },
|
|
|
+// referrer: 'http://127.0.0.1:4040/',
|
|
|
+// referrerPolicy: 'strict-origin-when-cross-origin',
|
|
|
+// body: '{"theme":"SDSS","title":"ASDF","_ApplicationId":"cyx","_ClientVersion":"js3.4.2","_MasterKey":"cyxmk","_InstallationId":"111053ea-8bfc-4dfc-8818-df34dd45d6b0"}',
|
|
|
+// method: 'POST',
|
|
|
+// mode: 'cors',
|
|
|
+// credentials: 'omit',
|
|
|
+// });
|
|
|
+
|
|
|
+export class CloudNews {
|
|
|
+ objectId: string = '';
|
|
|
+ sessionToken: string = '';
|
|
|
+ data: any = {};
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ let userCacheStr = localStorage.getItem('userData');
|
|
|
+ if (userCacheStr) {
|
|
|
+ let userData = JSON.parse(userCacheStr);
|
|
|
+ // 设置用户信息
|
|
|
+ this.objectId = userData?.objectId;
|
|
|
+ this.sessionToken = userData?.sessionToken;
|
|
|
+ this.data = userData; // 保存用户数据
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async add(newsData: any) {
|
|
|
+ let url = 'http://1.94.237.145:1338/parsecyx/classes/News';
|
|
|
+ const response = await fetch(url, {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ accept: '*/*',
|
|
|
+ 'X-Parse-Application-Id': 'cyx',
|
|
|
+ 'content-type': 'text/plain',
|
|
|
+ },
|
|
|
+ body: JSON.stringify(newsData),
|
|
|
+ });
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 示例
|
|
|
// fetch("http://1.94.237.145:1338/parsecyx/classes/_User?", {
|
|
|
// headers: {
|
|
|
// accept: "*/*",
|
|
@@ -78,15 +138,35 @@ export class CloudQuery {
|
|
|
// credentials: "omit",
|
|
|
// });
|
|
|
|
|
|
-// user操作
|
|
|
+/**
|
|
|
+ * @desc 对_User表操作,不用传参
|
|
|
+ */
|
|
|
export class CloudUser {
|
|
|
- constructor() {}
|
|
|
-
|
|
|
objectId: string = '';
|
|
|
sessionToken: string = '';
|
|
|
data: any = {};
|
|
|
|
|
|
- // 获取当前用户信息
|
|
|
+ constructor() {
|
|
|
+ let userCacheStr = localStorage.getItem('userData');
|
|
|
+ if (userCacheStr) {
|
|
|
+ let userData = JSON.parse(userCacheStr);
|
|
|
+ this.objectId = userData?.objectId;
|
|
|
+ this.sessionToken = userData?.sessionToken;
|
|
|
+ this.data = userData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ toPointer() {
|
|
|
+ return {
|
|
|
+ __type: 'Pointer',
|
|
|
+ className: '_User',
|
|
|
+ objectId: this.objectId,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc 获取当前用户信息
|
|
|
+ */
|
|
|
async current() {
|
|
|
let userCache = localStorage.getItem('userData');
|
|
|
if (userCache) {
|
|
@@ -96,7 +176,9 @@ export class CloudUser {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 用户登录
|
|
|
+ /**
|
|
|
+ * @desc 用户登录函数
|
|
|
+ */
|
|
|
async login(username: string, password: string): Promise<CloudUser | null> {
|
|
|
let url = `http://1.94.237.145:1338/parsecyx/login`;
|
|
|
const response = await fetch(url, {
|
|
@@ -120,7 +202,9 @@ export class CloudUser {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- // 用户登出
|
|
|
+ /**
|
|
|
+ * @desc 用户登出函数
|
|
|
+ */
|
|
|
async logout(): Promise<boolean> {
|
|
|
let url = 'http://1.94.237.145:1338/parsecyx/logout';
|
|
|
const response = await fetch(url, {
|
|
@@ -137,7 +221,9 @@ export class CloudUser {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- // 用户注册
|
|
|
+ /**
|
|
|
+ * @desc 用户注册
|
|
|
+ */
|
|
|
async register(username: string, password: string) {
|
|
|
let url = 'http://1.94.237.145:1338/parsecyx/users';
|
|
|
let response = await fetch(url, {
|
|
@@ -155,10 +241,10 @@ export class CloudUser {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- // 修改用户信息
|
|
|
+ /**
|
|
|
+ * @desc 修改用户信息
|
|
|
+ */
|
|
|
async update(userChangeInfo: any) {
|
|
|
- console.log(userChangeInfo);
|
|
|
-
|
|
|
this.current();
|
|
|
let url =
|
|
|
`http://1.94.237.145:1338/parsecyx/classes/_User/` + this.objectId;
|
|
@@ -178,20 +264,5 @@ export class CloudUser {
|
|
|
return this;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// fetch('http://1.94.237.145:1338/parsecyx/classes/_User/WBhghn8NuZ', {
|
|
|
-// headers: {
|
|
|
-// accept: '*/*',
|
|
|
-// 'accept-language':
|
|
|
-// 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,zh-TW;q=0.5,ja;q=0.4',
|
|
|
-// 'content-type': 'text/plain',
|
|
|
-// },
|
|
|
-// referrer: 'http://127.0.0.1:4040/',
|
|
|
-// referrerPolicy: 'strict-origin-when-cross-origin',
|
|
|
-// body: '{"phoneNumber":"12345","_method":"PUT","_ApplicationId":"cyx","_ClientVersion":"js3.4.2","_MasterKey":"cyxmk","_InstallationId":"111053ea-8bfc-4dfc-8818-df34dd45d6b0"}',
|
|
|
-// method: 'POST',
|
|
|
-// mode: 'cors',
|
|
|
-// credentials: 'omit',
|
|
|
-// });
|
|
|
// module.exports.Query = Query;
|
|
|
// module.exports.CloudUser = CloudUser;
|