iT邦幫忙

2023 iThome 鐵人賽

DAY 16
0

登入頁面UI

<div class="container">
    <div class="border-solid border-round border-500" style="width: 400px">
      <div class="flex justify-content-center p-1">
        <h1>隨身旅遊雜記</h1>
      </div>
      <div class="flex justify-content-center p-2">
        <img src="assets/icons/travelicon.png" alt="travel logo">
      </div>
      <div class="flex justify-content-center p-1">
        <label class="p-2" for="username">帳號:</label>
        <input class="p-2" style="width: 250px" pInputText id="username" type="text" [(ngModel)]="userId"/>
      </div>
      <div class="flex justify-content-center p-1">
        <label class="p-2" for="password">密碼:</label>
        <input class="p-2" pInputText id="password" type="password" style="width: 250px" [(ngModel)]="password"/>
      </div>
      <div class="flex justify-content-center">
        <p-button label="登入" styleClass="p-button-success" class="p-1" (onClick)="login()" )></p-button>
        <p-button label="清除" styleClass="p-button-success"  class="p-1" (onClick)="clean()"></p-button>
        <p-button label="測試頁面" class="p-1" routerLink="/test"></p-button>
      </div>
      <div class="flex justify-content-center">
        {{warningText}}
      </div>
    </div>
  </div>

功能開發

class LoginComponent {
  userId:  string | undefined
  password: string | undefined
  warningText: any;
  constructor(private userService: UserService) {
  }

  clean() {
    this.userId = '';
    this.password = '';
  }

  login() {
    if (this.userId == null || this.userId === '' || this.password == null || this.password === '') {
      this.warningText = 'Please enter your user ID. ';
      return;
    }
    this.userService.login(this.userId, this.password)
      .subscribe(
        (data: any) => {
        const result = JSON.stringify(data);
        console.log(result);
      },
        (error: any) => {
          console.log(error);
          this.warningText = 'Please enter your user ID. ';
        }
      );
  }
}
login(userId: string, password: string):any {
    this.http.post(this.loginUrl, {IdUser: userId, password: password});
  }

頁面呈現結果

https://ithelp.ithome.com.tw/upload/images/20231001/20124238ZgLGhBY3gJ.png


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

尚未有邦友留言

立即登入留言