未来全栈 2 месяцев назад
Родитель
Сommit
9e954a2984

+ 4 - 0
src/app/app-routing.module.ts

@@ -13,6 +13,10 @@ const routes: Routes = [
   {
     path: 'comments',
     loadChildren: () => import('./comments/comments.module').then( m => m.CommentsPageModule)
+  },
+  {
+    path: 'comment-modal',
+    loadChildren: () => import('./comment-modal/comment-modal.module').then( m => m.CommentModalPageModule)
   }
 ];
 @NgModule({

+ 17 - 0
src/app/comment-modal/comment-modal-routing.module.ts

@@ -0,0 +1,17 @@
+import { NgModule } from '@angular/core';
+import { Routes, RouterModule } from '@angular/router';
+
+import { CommentModalPage } from './comment-modal.page';
+
+const routes: Routes = [
+  {
+    path: '',
+    component: CommentModalPage
+  }
+];
+
+@NgModule({
+  imports: [RouterModule.forChild(routes)],
+  exports: [RouterModule],
+})
+export class CommentModalPageRoutingModule {}

+ 20 - 0
src/app/comment-modal/comment-modal.module.ts

@@ -0,0 +1,20 @@
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { FormsModule } from '@angular/forms';
+
+import { IonicModule } from '@ionic/angular';
+
+import { CommentModalPageRoutingModule } from './comment-modal-routing.module';
+
+import { CommentModalPage } from './comment-modal.page';
+
+@NgModule({
+  imports: [
+    CommonModule,
+    FormsModule,
+    IonicModule,
+    CommentModalPageRoutingModule
+  ],
+  declarations: [CommentModalPage]
+})
+export class CommentModalPageModule {}

+ 15 - 0
src/app/comment-modal/comment-modal.page.html

@@ -0,0 +1,15 @@
+<!-- <ion-header>
+  <ion-toolbar>
+    <ion-title></ion-title>
+  </ion-toolbar>
+</ion-header> -->
+
+<ion-content>
+  <!-- 输入框内容 -->
+  <ion-footer>
+    <ion-toolbar>
+      <ion-input placeholder="输入评论..." clearInput></ion-input>
+      <ion-button slot="end" color="primary">发送</ion-button>
+    </ion-toolbar>
+  </ion-footer>
+</ion-content>

+ 0 - 0
src/app/comment-modal/comment-modal.page.scss


+ 17 - 0
src/app/comment-modal/comment-modal.page.spec.ts

@@ -0,0 +1,17 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { CommentModalPage } from './comment-modal.page';
+
+describe('CommentModalPage', () => {
+  let component: CommentModalPage;
+  let fixture: ComponentFixture<CommentModalPage>;
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(CommentModalPage);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 15 - 0
src/app/comment-modal/comment-modal.page.ts

@@ -0,0 +1,15 @@
+import { Component, OnInit } from '@angular/core';
+
+@Component({
+  selector: 'app-comment-modal',
+  templateUrl: './comment-modal.page.html',
+  styleUrls: ['./comment-modal.page.scss'],
+})
+export class CommentModalPage implements OnInit {
+
+  constructor() { }
+
+  ngOnInit() {
+  }
+
+}

+ 10 - 18
src/app/comments/comments.page.html

@@ -38,26 +38,18 @@
         <span class="username">评论者1</span>
       </div>
       <div class="content">
-        <p>评论内容</p>
+        <p>评论内容...</p>
       </div>
-      <!-- 点赞 -->
-      <ion-button (click)="likeComment()" [color]="isLiked ? 'danger' : 'primary'" class="like-button">
-        <ion-icon slot="icon-only" [name]="isLiked ? 'thumbs-up' : 'thumbs-up-outline'"></ion-icon>
-      </ion-button>
-    </div>
-
-    <div class="comment">
-      <div class="user-info">
-        <img src="https://tse3-mm.cn.bing.net/th/id/OIP-C.QGUz1-tWsQhwsa3F6i9nGAHaHa?w=268&h=201&c=7&r=0&o=5&dpr=1.3&pid=1.7" class="avatar">
-        <span class="username">评论者2</span>
-      </div>
-      <div class="content">
-        <p>评论内容</p>
+      <div class="actions">
+        <ion-button size="small" color="primary">
+          <ion-icon name="thumbs-up"></ion-icon>
+          <!-- 点赞 -->
+        </ion-button>
+        <ion-button size="small" color="primary" (click)="openCommentPopover($event)">
+          <ion-icon name="chatbox-ellipses-outline"></ion-icon>
+          <!-- 评论 -->
+        </ion-button>
       </div>
-      <!-- 点赞 -->
-      <ion-button (click)="likeComment()" [color]="isLiked ? 'danger' : 'primary'" class="like-button">
-        <ion-icon slot="icon-only" [name]="isLiked ? 'thumbs-up' : 'thumbs-up-outline'"></ion-icon>
-      </ion-button>
     </div>
     <!-- 可以继续添加更多评论 -->
   </div>

+ 1 - 6
src/app/comments/comments.page.scss

@@ -31,9 +31,4 @@
     align-items: center;
     justify-content: space-between;
     border-bottom: 1px solid #ccc;
-}
-
-.like-button {
-    bottom: 20px;
-    right: 20px;
-  }
+}

+ 13 - 16
src/app/comments/comments.page.ts

@@ -1,5 +1,6 @@
 import { Component, OnInit } from '@angular/core';
-
+import { PopoverController } from '@ionic/angular';
+import { CommentModalPage } from 'src/app/comment-modal/comment-modal.page';
 @Component({
   selector: 'app-comments',
   templateUrl: './comments.page.html',
@@ -7,22 +8,18 @@ import { Component, OnInit } from '@angular/core';
 })
 export class CommentsPage implements OnInit {
 
-  constructor() { }
+  constructor(private popoverController: PopoverController) { }
 
-  ngOnInit() {
+  async openCommentPopover(ev: any) {
+    const popover = await this.popoverController.create({
+      component: CommentModalPage,
+      event: ev,
+      translucent: true,
+      cssClass: 'comment-popover'
+    });
+    return await popover.present();
   }
+  ngOnInit() { }
 
-  isLiked: boolean = false;
-  likeCount: number = 0;
-
-  likeComment() {
-    if (!this.isLiked) {
-      this.likeCount++;
-      this.isLiked = true;
-    } else {
-      this.likeCount--;
-      this.isLiked = false;
-    }
-  }
 
-}
+}