|
@@ -1,7 +1,7 @@
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
import { AlertController, NavController } from '@ionic/angular';
|
|
|
import * as Parse from "parse"
|
|
|
-// 引用Router服务
|
|
|
+
|
|
|
@Component({
|
|
|
selector: 'app-login',
|
|
|
templateUrl: './login.page.html',
|
|
@@ -9,70 +9,67 @@ import * as Parse from "parse"
|
|
|
})
|
|
|
export class LoginPage implements OnInit {
|
|
|
|
|
|
- username:string = ""
|
|
|
- password:string = ""
|
|
|
+ username: string = ""
|
|
|
+ password: string = ""
|
|
|
+
|
|
|
constructor(
|
|
|
- // 新增:Router服务,用于路由跳转
|
|
|
- private navCtrl:NavController,
|
|
|
- private alertController:AlertController
|
|
|
+ private navCtrl: NavController,
|
|
|
+ private alertController: AlertController
|
|
|
) { }
|
|
|
|
|
|
- ngOnInit() {
|
|
|
- }
|
|
|
+ ngOnInit() { }
|
|
|
|
|
|
- async login(){
|
|
|
- let user
|
|
|
+ async login() {
|
|
|
+ let user;
|
|
|
try {
|
|
|
- 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 = "必须输入账号或邮箱"
|
|
|
+ user = await Parse.User.logIn(this.username, this.password);
|
|
|
+ } catch (error: any) {
|
|
|
+ let message: string = "";
|
|
|
+ if (error?.message.indexOf("is required") > -1) {
|
|
|
+ message = "必须输入账号或邮箱";
|
|
|
}
|
|
|
- if(error?.message.indexOf("Invalid username")>-1){
|
|
|
- message = "账号或密码错误,请检查"
|
|
|
+ if (error?.message.indexOf("Invalid username") > -1) {
|
|
|
+ message = "账号或密码错误,请检查";
|
|
|
}
|
|
|
this.presentAlert({
|
|
|
- header:"登录失败",
|
|
|
- subHeader:"状态码:"+error.code,
|
|
|
- message:message || error.message
|
|
|
- })
|
|
|
+ header: "登录失败",
|
|
|
+ subHeader: "状态码:" + error.code,
|
|
|
+ message: message || error.message
|
|
|
+ });
|
|
|
}
|
|
|
- console.log(user)
|
|
|
- if(user?.id){
|
|
|
- this.navCtrl.back()
|
|
|
+ console.log(user);
|
|
|
+ if (user?.id) {
|
|
|
+ this.navCtrl.navigateForward('/tabs/tab3'); // 修改这里
|
|
|
}
|
|
|
}
|
|
|
- async register(){
|
|
|
- let user = new Parse.User()
|
|
|
- user.set("username",this.username)
|
|
|
- user.set("password",this.password)
|
|
|
+
|
|
|
+ async register() {
|
|
|
+ let user = new Parse.User();
|
|
|
+ user.set("username", this.username);
|
|
|
+ user.set("password", this.password);
|
|
|
try {
|
|
|
- let result = await user.signUp();
|
|
|
- console.log(result)
|
|
|
- if(result?.id){
|
|
|
- this.navCtrl.back()
|
|
|
- }
|
|
|
- // Hooray! Let them use the app now.
|
|
|
- } catch (error:any) {
|
|
|
- // 新增提示词详情,根据Parse.User.signUp方法返回的不同英文提示词,增加对应的中文内容转换
|
|
|
- let message:string = ""
|
|
|
- if(error?.message.indexOf("already exists")>-1){
|
|
|
- message = "该账号已存在请修改后重试"
|
|
|
- }
|
|
|
- if(error?.message.indexOf("empty")>-1){
|
|
|
- message = "账号不能为空请输入后重试"
|
|
|
- }
|
|
|
- this.presentAlert({
|
|
|
- header:"注册失败",
|
|
|
- subHeader:"状态码:"+error.code,
|
|
|
- message:message || error.message
|
|
|
- })
|
|
|
+ let result = await user.signUp();
|
|
|
+ console.log(result);
|
|
|
+ if (result?.id) {
|
|
|
+ this.navCtrl.navigateForward('/tabs/tab3'); // 修改这里
|
|
|
+ }
|
|
|
+ } catch (error: any) {
|
|
|
+ let message: string = "";
|
|
|
+ if (error?.message.indexOf("already exists") > -1) {
|
|
|
+ message = "该账号已存在请修改后重试";
|
|
|
+ }
|
|
|
+ if (error?.message.indexOf("empty") > -1) {
|
|
|
+ message = "账号不能为空请输入后重试";
|
|
|
+ }
|
|
|
+ this.presentAlert({
|
|
|
+ header: "注册失败",
|
|
|
+ subHeader: "状态码:" + error.code,
|
|
|
+ message: message || error.message
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async presentAlert(options:{header:string,subHeader:string,message:string}) {
|
|
|
+ async presentAlert(options: { header: string, subHeader: string, message: string }) {
|
|
|
const alert = await this.alertController.create({
|
|
|
header: options?.header,
|
|
|
subHeader: options?.subHeader,
|
|
@@ -83,11 +80,7 @@ export class LoginPage implements OnInit {
|
|
|
await alert.present();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 返回上级页面函数
|
|
|
- * @desc
|
|
|
- */
|
|
|
- back(){
|
|
|
- this.navCtrl.back()
|
|
|
+ back() {
|
|
|
+ this.navCtrl.back();
|
|
|
}
|
|
|
}
|