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"; const { ccclass, property } = _decorator; /** * 修改密码页面 * 预制体位于 resources/loginPanel/NewPasswordPanel */ @ccclass("NewPasswordPanel") export class NewPasswordPanel extends li_BaseView { private _nodeTab: any = {}; // 用于存储从安全验证页面传递过来的邮箱和验证码信息 private _email: string = ""; private _verificationCode: string = ""; /** * 组件初始化时调用 */ onLoadCT(): void { // 解析节点,将子节点存储到 _nodeTab 中 Utils.parseNode(this.node, this._nodeTab); // 初始化UI this.initUI(); // 注册事件监听 this.registerListener(); } /** * 打开界面时传入的数据 */ openUIData(data: any): void { if (data) { this._email = data.email || ""; this._verificationCode = data.code || ""; } } /** * 初始化UI */ private initUI(): void { // 清空输入框 const password1Input = this._nodeTab.Password1Input?.getComponent(EditBox); const password2Input = this._nodeTab.Password2Input?.getComponent(EditBox); if (password1Input) { password1Input.string = ""; } if (password2Input) { password2Input.string = ""; } } /** * 注册事件监听 */ private registerListener(): void { // 绑定确定按钮点击事件 if (this._nodeTab.ConfirmBtn) { GButton.BandClick(this._nodeTab.ConfirmBtn, this.onClickConfirm, this); } // 绑定关闭按钮点击事件 if (this._nodeTab.CloseBtn) { GButton.BandClick(this._nodeTab.CloseBtn, this.onClickClose, this); } } /** * 点击确定按钮 */ private onClickConfirm(): void { // 获取两个密码输入框 const password1Input = this._nodeTab.Password1Input?.getComponent(EditBox); const password2Input = this._nodeTab.Password2Input?.getComponent(EditBox); if (!password1Input || !password2Input) { console.error("未找到密码输入框"); return; } const password1 = password1Input.string.trim(); const password2 = password2Input.string.trim(); // 验证输入 if (!password1) { console.log("请输入新密码"); // TODO: 显示提示信息 return; } if (!password2) { console.log("请再次输入新密码"); // TODO: 显示提示信息 return; } if (password1.length < 6) { console.log("密码长度不能少于6位"); // TODO: 显示提示信息 return; } if (password1 !== password2) { console.log("两次输入的密码不一致"); // TODO: 显示提示信息 return; } // TODO: 调用后端接口修改密码 console.log("修改密码:", password1); this.requestChangePassword(password1); } /** * 调用后端修改密码接口 */ private requestChangePassword(newPassword: string): void { // TODO: 实现后端修改密码接口调用 // 示例: // const data = { // email: this._email, // code: this._verificationCode, // newPassword: newPassword // }; // NetworkManager.request('/api/changePassword', data, (response) => { // if (response.success) { // // 修改密码成功 // console.log('密码修改成功'); // // TODO: 显示成功提示 // // 关闭当前界面 // this.close(); // // 可以选择跳转回登录页面 // // ViewManager.I.openMainView('loginPanel/LoginPanel'); // } else { // // 修改密码失败,显示错误信息 // console.error('密码修改失败:', response.message); // // TODO: 显示错误提示 // } // }); console.log("TODO: 实现修改密码接口调用"); console.log("邮箱:", this._email); console.log("验证码:", this._verificationCode); console.log("新密码:", newPassword); } /** * 点击关闭按钮 */ private onClickClose(): void { // 关闭当前界面 this.close(); } }