|
|
@@ -1,6 +1,6 @@
|
|
|
import { Input, OnInit } from '@angular/core';
|
|
|
import { Component } from '@angular/core';
|
|
|
-import { IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonButton, IonCardHeader, IonCardTitle, IonCardSubtitle, ModalController, IonInput, IonItem, IonSegment, IonSegmentButton, IonLabel } from '@ionic/angular/standalone';
|
|
|
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonButton, IonCardHeader, IonCardTitle, IonCardSubtitle, ModalController, IonInput, IonItem, IonSegment, IonSegmentButton, IonLabel, AlertController } from '@ionic/angular/standalone';
|
|
|
import { CloudUser } from '../../ncloud';
|
|
|
|
|
|
@Component({
|
|
|
@@ -10,80 +10,110 @@ import { CloudUser } from '../../ncloud';
|
|
|
standalone: true,
|
|
|
imports: [
|
|
|
IonHeader, IonToolbar, IonTitle, IonContent,
|
|
|
- IonCard,IonCardContent,IonButton,IonCardHeader,IonCardTitle,IonCardSubtitle,
|
|
|
- IonInput,IonItem,
|
|
|
- IonSegment,IonSegmentButton,IonLabel
|
|
|
+ IonCard, IonCardContent, IonButton, IonCardHeader, IonCardTitle, IonCardSubtitle,
|
|
|
+ IonInput, IonItem, IonSegment, IonSegmentButton, IonLabel
|
|
|
],
|
|
|
})
|
|
|
-export class ModalUserLoginComponent implements OnInit {
|
|
|
+export class ModalUserLoginComponent implements OnInit {
|
|
|
@Input()
|
|
|
- type:"login"|"signup" = "login"
|
|
|
- typeChange(ev:any){
|
|
|
+ type: "login"|"signup" = "login"
|
|
|
+
|
|
|
+ typeChange(ev: any) {
|
|
|
this.type = ev?.detail?.value || ev?.value || 'login'
|
|
|
}
|
|
|
- username:string = ""
|
|
|
- usernameChange(ev:any){
|
|
|
- console.log(ev)
|
|
|
+
|
|
|
+ username: string = ""
|
|
|
+ usernameChange(ev: any) {
|
|
|
this.username = ev?.detail?.value
|
|
|
}
|
|
|
- password:string = ""
|
|
|
- passwordChange(ev:any){
|
|
|
+
|
|
|
+ password: string = ""
|
|
|
+ passwordChange(ev: any) {
|
|
|
this.password = ev?.detail?.value
|
|
|
}
|
|
|
- password2:string = ""
|
|
|
- password2Change(ev:any){
|
|
|
+
|
|
|
+ password2: string = ""
|
|
|
+ password2Change(ev: any) {
|
|
|
this.password2 = ev?.detail?.value
|
|
|
}
|
|
|
- constructor(private modalCtrl:ModalController) {
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private modalCtrl: ModalController,
|
|
|
+ private alertCtrl: AlertController
|
|
|
+ ) {
|
|
|
console.log(this.type)
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
ngOnInit() {}
|
|
|
|
|
|
- async login(){
|
|
|
- if(!this.username || !this.password){
|
|
|
- console.log("请输入完整")
|
|
|
- return
|
|
|
+ async showAlert(header: string, message: string) {
|
|
|
+ const alert = await this.alertCtrl.create({
|
|
|
+ header,
|
|
|
+ message,
|
|
|
+ buttons: ['确定']
|
|
|
+ });
|
|
|
+ await alert.present();
|
|
|
+ }
|
|
|
+
|
|
|
+ async login() {
|
|
|
+ if (!this.username || !this.password) {
|
|
|
+ await this.showAlert('提示', '请输入完整的用户名和密码');
|
|
|
+ return;
|
|
|
}
|
|
|
- let user:any = new CloudUser();
|
|
|
- user = await user.login(this.username,this.password);
|
|
|
- if(user?.id){
|
|
|
- this.modalCtrl.dismiss(user,"confirm") //
|
|
|
- console.log("登录成功")
|
|
|
- }else{
|
|
|
- console.log("登录失败")
|
|
|
+
|
|
|
+ let user: any = new CloudUser();
|
|
|
+ try {
|
|
|
+ user = await user.login(this.username, this.password);
|
|
|
+ if (user?.id) {
|
|
|
+ this.modalCtrl.dismiss(user, "confirm");
|
|
|
+ console.log("登录成功");
|
|
|
+ } else {
|
|
|
+ await this.showAlert('登录失败', '用户名或密码错误');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ await this.showAlert('错误', '登录过程中发生错误,请稍后重试');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async signup(){
|
|
|
- if(!this.username || !this.password || !this.password2){
|
|
|
- console.log("请输入完整")
|
|
|
- return
|
|
|
+ async signup() {
|
|
|
+ if (!this.username || !this.password || !this.password2) {
|
|
|
+ await this.showAlert('提示', '请填写完整的注册信息');
|
|
|
+ return;
|
|
|
}
|
|
|
- if(this.password!=this.password2){
|
|
|
- console.log("两次密码不符,请修改")
|
|
|
- return
|
|
|
+
|
|
|
+ if (this.password != this.password2) {
|
|
|
+ await this.showAlert('提示', '两次输入的密码不一致,请重新输入');
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- let user:any = new CloudUser();
|
|
|
- user = await user.signUp(this.username,this.password);
|
|
|
- if(user){
|
|
|
- this.type = "login"
|
|
|
- console.log("注册成功请登录")
|
|
|
+ try {
|
|
|
+ let user: any = new CloudUser();
|
|
|
+ user = await user.signUp(this.username, this.password);
|
|
|
+ if (user) {
|
|
|
+ await this.showAlert('成功', '注册成功,请登录');
|
|
|
+ this.type = "login";
|
|
|
+ console.log("注册成功请登录");
|
|
|
+ } else {
|
|
|
+ await this.showAlert('注册失败', '注册失败,请稍后重试');
|
|
|
+ }
|
|
|
+ } catch (error: any) {
|
|
|
+ let message = '注册过程中发生错误,请稍后重试';
|
|
|
+ if (error.code === 202) {
|
|
|
+ message = '用户名已存在,请更换用户名';
|
|
|
+ }
|
|
|
+ await this.showAlert('错误', message);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-export async function openUserLoginModal(modalCtrl:ModalController,type:"login"|"signup"="login"):Promise<CloudUser|null>{
|
|
|
+export async function openUserLoginModal(modalCtrl: ModalController, type: "login"|"signup" = "login"): Promise<CloudUser|null> {
|
|
|
const modal = await modalCtrl.create({
|
|
|
component: ModalUserLoginComponent,
|
|
|
- componentProps:{
|
|
|
- type:type
|
|
|
+ componentProps: {
|
|
|
+ type: type
|
|
|
},
|
|
|
- breakpoints:[0.5,0.7],
|
|
|
- initialBreakpoint:0.5
|
|
|
+ breakpoints: [0.5, 0.7],
|
|
|
+ initialBreakpoint: 0.5
|
|
|
});
|
|
|
modal.present();
|
|
|
|
|
|
@@ -92,5 +122,5 @@ export async function openUserLoginModal(modalCtrl:ModalController,type:"login"|
|
|
|
if (role === 'confirm') {
|
|
|
return data;
|
|
|
}
|
|
|
- return null
|
|
|
+ return null;
|
|
|
}
|