|
@@ -1,7 +1,7 @@
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
-import { Router } from '@angular/router';
|
|
|
-import { AlertController } from '@ionic/angular';
|
|
|
+import { AlertController, NavController } from '@ionic/angular';
|
|
|
import * as Parse from "parse"
|
|
|
+// 引用Router服务
|
|
|
@Component({
|
|
|
selector: 'app-login',
|
|
|
templateUrl: './login.page.html',
|
|
@@ -11,7 +11,11 @@ export class LoginPage implements OnInit {
|
|
|
|
|
|
username:string = ""
|
|
|
password:string = ""
|
|
|
- constructor(private router:Router,private alertController:AlertController) { }
|
|
|
+ constructor(
|
|
|
+ // 新增:Router服务,用于路由跳转
|
|
|
+ private navCtrl:NavController,
|
|
|
+ private alertController:AlertController
|
|
|
+ ) { }
|
|
|
|
|
|
ngOnInit() {
|
|
|
}
|
|
@@ -22,6 +26,7 @@ export class LoginPage implements OnInit {
|
|
|
user = await Parse.User.logIn(this.username,this.password)
|
|
|
} catch (error:any) {
|
|
|
let message:string = ""
|
|
|
+ // 新增提示词详情,根据Parse.User.login方法返回的不同英文提示词,增加对应的中文内容转换
|
|
|
if(error?.message.indexOf("is required")>-1){
|
|
|
message = "必须输入账号或邮箱"
|
|
|
}
|
|
@@ -36,7 +41,7 @@ export class LoginPage implements OnInit {
|
|
|
}
|
|
|
console.log(user)
|
|
|
if(user?.id){
|
|
|
- this.router.navigateByUrl("/tabs/tab3")
|
|
|
+ this.navCtrl.back()
|
|
|
}
|
|
|
}
|
|
|
async register(){
|
|
@@ -47,11 +52,11 @@ export class LoginPage implements OnInit {
|
|
|
let result = await user.signUp();
|
|
|
console.log(result)
|
|
|
if(result?.id){
|
|
|
- this.router.navigateByUrl("/tabs/tab3")
|
|
|
+ this.navCtrl.back()
|
|
|
}
|
|
|
// Hooray! Let them use the app now.
|
|
|
} catch (error:any) {
|
|
|
- // Show the error message somewhere and let the user try again.
|
|
|
+ // 新增提示词详情,根据Parse.User.signUp方法返回的不同英文提示词,增加对应的中文内容转换
|
|
|
let message:string = ""
|
|
|
if(error?.message.indexOf("already exists")>-1){
|
|
|
message = "该账号已存在请修改后重试"
|
|
@@ -77,4 +82,12 @@ export class LoginPage implements OnInit {
|
|
|
|
|
|
await alert.present();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回上级页面函数
|
|
|
+ * @desc
|
|
|
+ */
|
|
|
+ back(){
|
|
|
+ this.navCtrl.back()
|
|
|
+ }
|
|
|
}
|