浏览代码

update:cummunity

yt 3 月之前
父节点
当前提交
f37749ce1a

+ 19 - 4
tailor-app/myapp/src/app/community/community.page.ts

@@ -1,11 +1,13 @@
 import { Component, OnInit } from '@angular/core';
-import { IonAvatar, IonButton, IonCard, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonHeader, IonIcon, IonInput, IonItem, IonList, IonTitle, IonToolbar } from '@ionic/angular/standalone';
+import { IonAvatar, IonButton, IonCard, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonHeader, IonIcon, IonInput, IonItem, IonList, IonTitle, IonToolbar, ModalController } from '@ionic/angular/standalone';
 import { FormsModule } from '@angular/forms';
 import { CommonModule } from '@angular/common';
 import { NavigationExtras, Router } from '@angular/router';
 import { PostService } from '../post.service'; // 导入服务
 import { IonButtons } from '@ionic/angular/standalone';
 import { IonCardContent } from '@ionic/angular/standalone';
+import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
+import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
 
 @Component({
   selector: 'app-community',
@@ -19,7 +21,10 @@ import { IonCardContent } from '@ionic/angular/standalone';
 export class CommunityPage implements OnInit {
   posts: { id: number; username: string; date: Date; text: string; imageUrl?: string; avatarUrl?: string }[] = [];
 
-  constructor(private router: Router,private postService: PostService) {
+  constructor(private router: Router,private postService: PostService,
+    private modalCtrl: ModalController,
+
+  ) {
   }
 
   ngOnInit() {
@@ -41,9 +46,19 @@ export class CommunityPage implements OnInit {
   // }
   viewPost(postId: number) {
     // 直接导航到动态详情页面
-    this.router.navigate(['/tabs/post-page', postId]);
+    this.router.navigate(['/post-page', postId]);
   }
-  sharePost() {
+  async sharePost() {
+    let currentUser = new CloudUser();
+
+    if (!currentUser?.id) {
+      console.log("用户未登录,请登录后重试");
+      let user = await openUserLoginModal(this.modalCtrl);
+      if (!user?.id) {
+        return
+      }
+      currentUser = user;
+    }
     this.router.navigate(['/tabs/share-page']); // 导航到分享动态页面
   }
 }

+ 10 - 1
tailor-app/myapp/src/app/me/me.page.ts

@@ -50,7 +50,16 @@ export class MePage implements OnInit {
     this.currentUser?.logout();
   }
   
-  customizations(){
+  async customizations(){
+    let currentUser = new CloudUser();
+    if (!currentUser?.id) {
+      console.log("用户未登录,请登录后重试");
+      let user = await openUserLoginModal(this.modalCtrl);
+      if (!user?.id) {
+        return
+      }
+      currentUser = user;
+    }
     this.router.navigate(['tabs/customization'])
   }
   favorites(){

+ 1 - 1
tailor-app/myapp/src/app/post-page/post-page.component.ts

@@ -32,7 +32,7 @@ export class PostPageComponent  implements OnInit {
      // 使用 route.params 订阅参数变化
       // 获取动态 ID
       this.route.params.subscribe(params => {
-        const postId = Number(params['postId']); // 获取动态 ID
+        const postId = Number(params['id']); // 获取动态 ID
         if (!isNaN(postId)) {
           this.post = this.postService.getPostById(postId); // 根据 ID 获取动态内容
         } else {