Delancey 6 ماه پیش
والد
کامیت
2d32cbeeae

+ 1 - 1
travel-app/src/app/tab1/tab1.page.html

@@ -16,5 +16,5 @@
     </ion-toolbar>
   </ion-header>
 
-  <app-explore-container name="Tab 1 page"></app-explore-container>
+  <app-explore-container name="Tab 1 page" (click)="f()"></app-explore-container>
 </ion-content>

+ 8 - 2
travel-app/src/app/tab1/tab1.page.ts

@@ -1,5 +1,5 @@
 import { Component } from '@angular/core';
-import { IonHeader, IonToolbar, IonTitle, IonContent, IonSearchbar } from '@ionic/angular/standalone';
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonSearchbar,NavController } from '@ionic/angular/standalone';
 import { ExploreContainerComponent } from '../explore-container/explore-container.component';
 
 @Component({
@@ -11,6 +11,12 @@ import { ExploreContainerComponent } from '../explore-container/explore-containe
 })
 export class Tab1Page {
 
-  constructor() {}
+  constructor(private navCtrl:NavController) {
 
+  }
+
+  f(){
+this.navCtrl.navigateForward('tabs/Container');
+
+  }
 }

+ 2 - 2
travel-app/src/app/tab3/tab3.page.html

@@ -67,7 +67,7 @@
     <!-- 高级选项 -->
     <ion-item class="custom-gaoji" lines="none">
       <ion-label>高级选项</ion-label>
-      <ion-toggle slot="end">保存到相册</ion-toggle><br /><br />
+      <ion-toggle [(ngModel)]="saveToAlbum" slot="end">保存到相册</ion-toggle><br /><br />
   </ion-item>
 
   </form>
@@ -75,7 +75,7 @@
 
 
 <ion-footer>
-  <ion-button (click)="sendMessage()" expand="block" class="custom-button">
+  <ion-button type="submit" form="postForm" expand="block" class="custom-button" (click)="publishPost()">
     发布笔记
   </ion-button>
 </ion-footer>

+ 40 - 21
travel-app/src/app/tab3/tab3.page.ts

@@ -4,7 +4,7 @@ import { IonicModule } from '@ionic/angular';
 import { FormsModule } from '@angular/forms';
 import { addIcons } from 'ionicons';
 import { add,close,location,lockOpen} from 'ionicons/icons';
-
+import { CloudObject} from 'src/lib/ncloud';
 
 @Component({
   selector: 'app-tab3',
@@ -59,30 +59,49 @@ export class Tab3Page {
     this.selectedFiles = this.selectedFiles.filter(file => file !== fileToRemove); // 从数组中移除指定文件
   }
 
-  sendMessage() {}
+  sendMessage() {
+    
+  }
 
   publishPost() {
-    if (this.postTitle && this.postContent) {
-      // 这里可以将帖子数据发送到服务器
-      console.log('发布帖子:', {
-        title: this.postTitle,
-        content: this.postContent,
-        files: this.selectedFiles,
-        location: this.location, // 新增属性
-        isPublic: this.isPublic, // 新增属性
-        saveToAlbum: this.saveToAlbum, // 新增属性
-        visibility: this.visibility, // 将可见性信息包含在发布的数据中
-      });
-      // 清空表单
-      this.postTitle = '';
-      this.postContent = '';
-      this.selectedFiles = [];
-      this.location = ''; // 清空地点
-      this.isPublic = true; // 重置公开可见状态
-      this.saveToAlbum = false; // 重置保存到相册状态
-      this.visibility = 'none'; // 重置可见性
+    if (this.postTitle && this.postContent && this.location) {
+
+    // 创建一个新的CloudObject实例,类名为"TravelPost"
+    const post = new CloudObject('TravelPost');
+console.log(this.postTitle);
+    // 设置帖子的属性
+    post.set({
+      title: this.postTitle,
+      content: this.postContent,
+      location: this.location,
+      isPublic: this.isPublic,
+      saveToAlbum: this.saveToAlbum,
+      visibility: this.visibility
+    });
+
+    // 保存帖子到数据库
+    post.save().then(
+      () => {
+        console.log('Post created successfully:', post);
+        this.clearForm();
+      },
+      (error) => {
+        console.error('Failed to create post:', error);
+      }
+    );
     } else {
       console.log('标题和正文不能为空');
     }
   }
+  //清空表单
+  clearForm() {
+    this.postTitle = '';
+    this.postContent = '';
+    this.selectedFiles = [];
+    this.location = '';
+    this.isPublic = true;
+    this.saveToAlbum = false;
+    this.visibility = 'none';
+  }
+  
 }

+ 6 - 0
travel-app/src/app/tabs/tabs.routes.ts

@@ -26,6 +26,12 @@ export const routes: Routes = [
         loadComponent: () =>
           import('../tab4/tab4.page').then((m) => m.Tab4Page),
       },
+      {
+        path: 'Container',
+        loadComponent: () =>
+          import('../explore-container/explore-container.component').then((m) => m.ExploreContainerComponent),
+      },
+      
       {
         path: '',
         redirectTo: '/tabs/tab1',

+ 194 - 0
travel-app/src/lib/ncloud.ts

@@ -0,0 +1,194 @@
+// CloudObject.ts
+export class CloudObject {
+    className: string;
+    id: string | null = null;
+    createdAt:any;
+    updatedAt:any;
+    data: Record<string, any> = {};
+
+    constructor(className: string) {
+        this.className = className;
+    }
+
+    toPointer() {
+        return { "__type": "Pointer", "className": this.className, "objectId": this.id };
+    }
+
+    set(json: Record<string, any>) {
+        Object.keys(json).forEach(key => {
+            if (["objectId", "id", "createdAt", "updatedAt", "ACL"].indexOf(key) > -1) {
+                return;
+            }
+            this.data[key] = json[key];
+        });
+    }
+
+    get(key: string) {
+        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";
+        }
+
+        const body = JSON.stringify(this.data);
+        const 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"
+        });
+
+        const result = await response?.json();
+        if (result?.error) {
+            console.error(result?.error);
+        }
+        if (result?.objectId) {
+            this.id = result?.objectId;
+        }
+        return this;
+    }
+
+    async destroy() {
+        if (!this.id) return;
+        const response = await fetch(`http://dev.fmode.cn:1337/parse/classes/${this.className}/${this.id}`, {
+            headers: {
+                "x-parse-application-id": "dev"
+            },
+            body: null,
+            method: "DELETE",
+            mode: "cors",
+            credentials: "omit"
+        });
+
+        const result = await response?.json();
+        if (result) {
+            this.id = null;
+        }
+        return true;
+    }
+}
+
+// CloudQuery.ts
+export class CloudQuery {
+    className: string;
+    whereOptions: Record<string, any> = {};
+
+    constructor(className: string) {
+        this.className = className;
+    }
+
+    greaterThan(key: string, value: any) {
+        if (!this.whereOptions[key]) this.whereOptions[key] = {};
+        this.whereOptions[key]["$gt"] = value;
+    }
+
+    greaterThanAndEqualTo(key: string, value: any) {
+        if (!this.whereOptions[key]) this.whereOptions[key] = {};
+        this.whereOptions[key]["$gte"] = value;
+    }
+
+    lessThan(key: string, value: any) {
+        if (!this.whereOptions[key]) this.whereOptions[key] = {};
+        this.whereOptions[key]["$lt"] = value;
+    }
+
+    lessThanAndEqualTo(key: string, value: any) {
+        if (!this.whereOptions[key]) this.whereOptions[key] = {};
+        this.whereOptions[key]["$lte"] = value;
+    }
+
+    equalTo(key: string, value: any) {
+        this.whereOptions[key] = value;
+    }
+
+    async get(id: string) {
+        const url = `http://dev.fmode.cn:1337/parse/classes/${this.className}/${id}?`;
+
+        const response = await fetch(url, {
+            headers: {
+                "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
+                "x-parse-application-id": "dev"
+            },
+            body: null,
+            method: "GET",
+            mode: "cors",
+            credentials: "omit"
+        });
+
+        const 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) {
+            const whereStr = JSON.stringify(this.whereOptions);
+            url += `where=${whereStr}`;
+        }
+
+        const response = await fetch(url, {
+            headers: {
+                "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
+                "x-parse-application-id": "dev"
+            },
+            body: null,
+            method: "GET",
+            mode: "cors",
+            credentials: "omit"
+        });
+
+        const json = await response?.json();
+        let list = json?.results || []
+        let objList = list.map((item:any)=>this.dataToObj(item))
+        return objList || [];
+    }
+
+    async first() {
+        let url = `http://dev.fmode.cn:1337/parse/classes/${this.className}?`;
+
+        if (Object.keys(this.whereOptions).length) {
+            const whereStr = JSON.stringify(this.whereOptions);
+            url += `where=${whereStr}`;
+        }
+
+        const response = await fetch(url, {
+            headers: {
+                "if-none-match": "W/\"1f0-ghxH2EwTk6Blz0g89ivf2adBDKY\"",
+                "x-parse-application-id": "dev"
+            },
+            body: null,
+            method: "GET",
+            mode: "cors",
+            credentials: "omit"
+        });
+
+        const json = await response?.json();
+        const exists = json?.results?.[0] || null;
+        if (exists) {
+            let existsObject = this.dataToObj(exists)
+            return existsObject;
+        }
+        return null
+    }
+
+    dataToObj(exists:any):CloudObject{
+        let existsObject = new CloudObject(this.className);
+        existsObject.set(exists);
+        existsObject.id = exists.objectId;
+        existsObject.createdAt = exists.createdAt;
+        existsObject.updatedAt = exists.updatedAt;
+        return existsObject;
+    }
+}