123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import { Component, OnInit } from '@angular/core';
- import { IonAvatar,
- IonText,
- IonButton,
- IonIcon,
- IonCard,
- IonList,
- IonItem,
- IonLabel,
- IonBadge,
- IonContent,
- IonInput,
- AlertController,
- ModalController } from '@ionic/angular/standalone';
- import { ModalUserEditComponent } from '../modal-user-edit/modal-user-edit.component';
- import { FormsModule } from '@angular/forms';
- import { CloudUser } from 'src/lib/ncloud';
- import { ModalUserRegisterComponent } from '../modal-user-register/modal-user-register.component';
- @Component({
- selector: 'app-page-mine',
- templateUrl: './page-mine.component.html',
- styleUrls: ['./page-mine.component.scss'],
- standalone: true,
- imports: [
- IonContent,
- IonAvatar,
- IonText,
- IonButton,
- IonIcon,
- IonCard,
- IonList,
- IonItem,
- IonLabel,
- IonBadge,
- IonInput,
- FormsModule
- ]
- })
- export class PageMineComponent implements OnInit {
- currentUser: CloudUser | undefined;
- username: string = '';
- password: string = '';
- constructor(
- private modalCtrl: ModalController,
- private alertCtrl: AlertController
- ) {
- this.currentUser = new CloudUser();
- }
- async edit() {
- const modal = await this.modalCtrl.create({
- component: ModalUserEditComponent,
- });
- modal.present();
- const { data, role } = await modal.onWillDismiss();
- }
- async login() {
- if (!this.username || !this.password) {
- const alert = await this.alertCtrl.create({
- header: '错误',
- message: '请输入用户名和密码',
- buttons: ['确定']
- });
- await alert.present();
- return;
- }
- try {
- let user: any = new CloudUser();
- user = await user?.login(this.username, this.password);
- if (user?.id) {
- this.currentUser = user;
- } else {
- const alert = await this.alertCtrl.create({
- header: '登录失败',
- message: '用户名或密码错误',
- buttons: ['确定']
- });
- await alert.present();
- }
- } catch (error) {
- const alert = await this.alertCtrl.create({
- header: '登录错误',
- message: '登录过程中发生错误,请重试',
- buttons: ['确定']
- });
- await alert.present();
- }
- }
- async openRegisterModal() {
- const modal = await this.modalCtrl.create({
- component: ModalUserRegisterComponent
- });
- await modal.present();
- const { data, role } = await modal.onWillDismiss();
- if (role === 'success') {
- this.currentUser = data.user;
- }
- }
- logout() {
- this.currentUser?.logout();
- this.currentUser = undefined;
- this.username = '';
- this.password = '';
- }
- ngOnInit() {}
- }
|