165 lines
4.0 KiB
TypeScript
165 lines
4.0 KiB
TypeScript
import { _decorator, EditBox } from "cc";
|
|||
|
|
import Utils from "../../../Main/Common/Utils";
|
||
|
|
import li_BaseView from "../../../Main/Common/li_BaseView";
|
||
|
|
import { GButton } from "../../../Main/Common/GButton";
|
||
|
|
import { ViewManager } from "../../../Main/Manager/ViewManager";
|
||
|
|
|
||
|
|
const { ccclass, property } = _decorator;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 登录页面
|
||
|
|
* 预制体位于 resources/loginPanel/LoginPanel
|
||
|
|
*/
|
||
|
|
@ccclass("LoginPanel")
|
||
|
|
export class LoginPanel extends li_BaseView {
|
||
|
|
private _nodeTab: any = {};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 组件初始化时调用
|
||
|
|
*/
|
||
|
|
onLoadCT(): void {
|
||
|
|
// 解析节点,将子节点存储到 _nodeTab 中
|
||
|
|
Utils.parseNode(this.node, this._nodeTab);
|
||
|
|
|
||
|
|
// 初始化UI
|
||
|
|
this.initUI();
|
||
|
|
|
||
|
|
// 注册事件监听
|
||
|
|
this.registerListener();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 初始化UI
|
||
|
|
*/
|
||
|
|
private initUI(): void {
|
||
|
|
// 这里可以初始化一些默认值
|
||
|
|
// 例如:清空输入框等
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 注册事件监听
|
||
|
|
*/
|
||
|
|
private registerListener(): void {
|
||
|
|
// 绑定登录按钮点击事件
|
||
|
|
if (this._nodeTab.LoginBtn) {
|
||
|
|
GButton.BandClick(this._nodeTab.LoginBtn, this.onClickLogin, this);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 绑定注册按钮点击事件
|
||
|
|
if (this._nodeTab.registerBtn) {
|
||
|
|
GButton.BandClick(this._nodeTab.registerBtn, this.onClickRegister, this);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 绑定忘记密码按钮点击事件
|
||
|
|
if (this._nodeTab.forgetPasswordBtn) {
|
||
|
|
GButton.BandClick(
|
||
|
|
this._nodeTab.forgetPasswordBtn,
|
||
|
|
this.onClickForgetPassword,
|
||
|
|
this
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 绑定关闭按钮点击事件
|
||
|
|
if (this._nodeTab.closeBtn) {
|
||
|
|
GButton.BandClick(this._nodeTab.closeBtn, this.onClickClose, this);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 点击登录按钮
|
||
|
|
*/
|
||
|
|
private onClickLogin(): void {
|
||
|
|
// 获取邮箱和密码输入框
|
||
|
|
const emailInput = this._nodeTab.EmailInput?.getComponent(EditBox);
|
||
|
|
const passwordInput = this._nodeTab.PasswordInput?.getComponent(EditBox);
|
||
|
|
|
||
|
|
if (!emailInput || !passwordInput) {
|
||
|
|
console.error("未找到邮箱或密码输入框");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const email = emailInput.string.trim();
|
||
|
|
const password = passwordInput.string.trim();
|
||
|
|
|
||
|
|
// 验证输入
|
||
|
|
if (!email) {
|
||
|
|
console.log("请输入邮箱");
|
||
|
|
// TODO: 显示提示信息
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!this.isValidEmail(email)) {
|
||
|
|
console.log("请输入有效的邮箱地址");
|
||
|
|
// TODO: 显示提示信息
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!password) {
|
||
|
|
console.log("请输入密码");
|
||
|
|
// TODO: 显示提示信息
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// TODO: 调用后端接口进行登录
|
||
|
|
console.log("登录:", email, password);
|
||
|
|
this.requestLogin(email, password);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 调用后端登录接口
|
||
|
|
*/
|
||
|
|
private requestLogin(email: string, password: string): void {
|
||
|
|
// TODO: 实现后端登录接口调用
|
||
|
|
// 示例:
|
||
|
|
// const loginData = {
|
||
|
|
// email: email,
|
||
|
|
// password: password
|
||
|
|
// };
|
||
|
|
// NetworkManager.request('/api/login', loginData, (response) => {
|
||
|
|
// if (response.success) {
|
||
|
|
// // 登录成功,保存token等信息
|
||
|
|
// // LoginData.I.token = response.token;
|
||
|
|
// // 关闭登录界面,跳转到主界面
|
||
|
|
// this.close();
|
||
|
|
// } else {
|
||
|
|
// // 登录失败,显示错误信息
|
||
|
|
// console.error('登录失败:', response.message);
|
||
|
|
// }
|
||
|
|
// });
|
||
|
|
|
||
|
|
console.log("TODO: 实现登录接口调用");
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 点击注册按钮
|
||
|
|
*/
|
||
|
|
private onClickRegister(): void {
|
||
|
|
// 打开注册页面
|
||
|
|
ViewManager.I.openMainView("loginPanel/RegisterPanel");
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 点击忘记密码按钮
|
||
|
|
*/
|
||
|
|
private onClickForgetPassword(): void {
|
||
|
|
// 打开安全验证页面
|
||
|
|
ViewManager.I.openMainView("loginPanel/SafeCheckPanel");
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 点击关闭按钮
|
||
|
|
*/
|
||
|
|
private onClickClose(): void {
|
||
|
|
// 关闭当前界面
|
||
|
|
this.close();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 验证邮箱格式
|
||
|
|
*/
|
||
|
|
private isValidEmail(email: string): boolean {
|
||
|
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||
|
|
return emailRegex.test(email);
|
||
|
|
}
|
||
|
|
}
|