“虞渠成” 1500451aa8 feat: 添加账号注销功能,优化登录注册流程
1.  新增账号注销全流程功能,包括注销页面、验证码校验和注销接口调用
2.  优化邮箱注册校验逻辑,区分已设置密码和未设置密码的账号
3.  重构个人页面登出逻辑,统一登出处理流程
4.  更新多语言文案,补充注销相关提示文本
5.  调整个人信息页面布局,添加注销账号入口
2026-09-21 15:55:13 +08:00

125 lines
4.2 KiB
C#

using Kill.Managers;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Serialization;
using Kill.Utils;
using Kill.UI.Components;
using Kill.Network;
namespace Kill.UI.Pages
{
/// <summary>
/// 登录页面
/// </summary>
public class LoginPanel : LoginSubPageBase
{
[Header("输入组件")]
public InputField emailInput;
public Toggle privacyToggle;
[Header("显示组件")]
public Text errorText;
[Header("按钮")]
public Button loginBtn;
public Button toRegisterBtn;
[FormerlySerializedAs("thirdPartyLoginBtn")]
public Button googleLoginBtn;
public Button appleLoginBtn;
public Button privacyLinkBtn;
protected override void OnInitialize()
{
// 绑定按钮事件
if (loginBtn != null)
loginBtn.onClick.AddListener(OnLoginClick);
if (toRegisterBtn != null)
toRegisterBtn.onClick.AddListener(() => ShowPage(LoginPageCtrl.SubPageType.Register));
if (googleLoginBtn != null)
{
googleLoginBtn.onClick.AddListener(() => LoginPageCtrl.Instance.OnGoogleLogin());
#if UNITY_ANDROID
googleLoginBtn.gameObject.SetActive(true);
#else
googleLoginBtn.gameObject.SetActive(false);
#endif
}
if (appleLoginBtn != null)
{
appleLoginBtn.onClick.AddListener(() => LoginPageCtrl.Instance.OnAppleLogin());
#if UNITY_IOS
appleLoginBtn.gameObject.SetActive(true);
#else
appleLoginBtn.gameObject.SetActive(false);
#endif
}
if (privacyLinkBtn != null)
privacyLinkBtn.onClick.AddListener(() => LoginPageCtrl.Instance.ShowPrivacyAgreementPlane());
}
protected override void OnShow()
{
// 页面显示时初始化隐私协议链接的显示状态
privacyToggle.isOn = true;
errorText.text = "";
emailInput.text = "";
}
private async void OnLoginClick()
{
string email = emailInput != null ? emailInput.text : "";
if (string.IsNullOrEmpty(email) || !ValidationUtils.IsValidEmailStrict(email))
{
errorText.text = LanguageManager.Instance.GetLanguage("100006");
return;
}
if (!privacyToggle.isOn)
{
LoginPageCtrl.Instance.ShowPrivacyAgreementTip(() =>
{
privacyToggle.isOn = true;
OnLoginClick();
});
return;
}
// 保存邮箱到登录控制器
LoginPageCtrl.Instance.SetCurrentEmail(email);
// 验证邮箱是否已注册
await LoginPageCtrl.Instance.CheckEmailRegistered(email,
onSuccess: (registered, passwordSet) =>
{
if (!registered)
{
errorText.text = LanguageManager.Instance.GetLanguage("100035");
return;
}
if (passwordSet)
{
// 已注册且已设置密码,走密码登录
ShowPage(LoginPageCtrl.SubPageType.LoginPassword);
}
else
{
// 已注册但未设置密码(如通过苹果登录创建的账号),
// 走 验证码 + 设置密码 流程,不进入密码输入页
var verifyPanel = GetSubPage(LoginPageCtrl.SubPageType.VerificationCode) as VerificationCodePanel;
if (verifyPanel != null)
{
verifyPanel.SetSceneType(VerificationCodePanel.CodeSceneType.ResetPassword);
}
ShowPage(LoginPageCtrl.SubPageType.VerificationCode);
}
},
onError: (code, message) =>
{
errorText.text = message;
}
);
}
}
}