iT邦幫忙

2023 iThome 鐵人賽

DAY 19
0
SideProject30

Electron Angular軟體架構與簡易功能實作學習路程實記系列 第 19

Day 19- 功能開發-4-使用者文章列表-1

  • 分享至 

  • xImage
  •  

文章物件

export interface Article {
  IdArticle: number;
  Title: string;
  ArticleType: string;
  Position: string;
  Description: string;
  PlayedTime: Date;
  CreatedTime: Date;
}

文章列表UI初步設計

<div class="container">
  <div>
    <div class="flex justify-content-end">
      <h2>Hi {{userName}} </h2>

      <p-button label="登出" icon="pi pi-sign-out" styleClass="p-button-secondary p-button-sm m-2" (click)="loginOut()"></p-button>
    </div>
    <div class="flex justify-content-center p-1">
      <h1>文章列表</h1>
    </div>
    <div class="flex justify-content-start p-1">
          <span class="p-input-icon-left p-1">
              <i class="pi pi-search"></i>
              <input type="text" pInputText [(ngModel)]="searchValue" style="width: 300px"/>
          </span>
      <p-button label="新增" icon="pi pi-plus" styleClass="p-button-success p-button-sm m-2" (click)="addArticle()"></p-button>
    </div>
    <div class="flex justify-content-center p-1">
      <div class="card">
        <p-toast></p-toast>
        <p-table [value]="articles" selectionMode="single" [(selection)]="selectedArticle" dataKey="IdArticle"
                 (onRowSelect)="onRowSelect($event)" styleClass="p-datatable-gridlines p-datatable-sm" >
          <ng-template pTemplate="header">
            <tr>
              <th>項次</th>
              <th>標題</th>
              <th>地點</th>
              <th>類型</th>
              <th>旅遊日期</th>
              <th>建立時間</th>
              <th>編輯</th>
              <th>刪除</th>
            </tr>
          </ng-template>
          <ng-template pTemplate="body" let-article>
            <tr [pSelectableRow]="article">
              <td>{{article?.IdArticle}}</td>
              <td>{{article?.Title}}</td>
              <td>{{article?.Position}}</td>
              <td>{{article?.ArticleType}}</td>
              <td>{{article?.PlayedTime | date}}</td>
              <td>{{article?.CreatedTime | date}}</td>
              <td><p-button label="編輯" icon="pi pi-pencil" styleClass="p-button-warning p-button-sm m-2" (click)="editArticle(article)"></p-button></td>
              <td><p-button label="刪除" icon="pi pi-trash" styleClass="p-button-danger p-button-sm m-2" (click)="deleteArticle(article)"></p-button></td>
            </tr>
          </ng-template>
        </p-table>
      </div>
    </div>
  </div>
</div>

文章列表UI功能開發

export class ArticleListComponent implements OnInit{
  searchValue: string | undefined;
  articles!: Article[];
  selectedArticle!: Article;
  article: Article | undefined;
  userName!: string;

  constructor(private articleListService:ArticleListService,private router: Router) { }
	onRowSelect($event: TableRowSelectEvent) {

  }

  editArticle(article: any) {

  }

  deleteArticle(article: any) {

  }

  loginOut() {

  }

  addArticle() {

  }
}

結果顯示

https://ithelp.ithome.com.tw/upload/images/20231004/20124238Lc1aK4f8PT.png

小結

本次先完成文章列表基本框架layout後續補上功能與調整細節.


上一篇
Day 18- 功能開發-2-使用者資料建立測試-2
下一篇
Day 20- 功能開發-5-使用者文章
系列文
Electron Angular軟體架構與簡易功能實作學習路程實記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言