1. 新增账号注销全流程功能,包括注销页面、验证码校验和注销接口调用 2. 优化邮箱注册校验逻辑,区分已设置密码和未设置密码的账号 3. 重构个人页面登出逻辑,统一登出处理流程 4. 更新多语言文案,补充注销相关提示文本 5. 调整个人信息页面布局,添加注销账号入口
167 lines
5.6 KiB
C#
167 lines
5.6 KiB
C#
using System;
|
||
using System.Threading.Tasks;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Kill.Managers;
|
||
using Kill.Network;
|
||
using Kill.UI.Components;
|
||
|
||
namespace Kill.UI.Pages
|
||
{
|
||
/// <summary>
|
||
/// 注销账号页面(提示确认 -> 验证码(复用SelfVerificationCodePanel) -> 最终确认)
|
||
/// 在 SelfInfoPage 中通过 cancelAccountPagePrefab 实例化,Init 传入返回回调
|
||
/// </summary>
|
||
public class SelfCancelAccountPage : MonoBehaviour
|
||
{
|
||
[Header("提示界面1(提示确认)")]
|
||
public GameObject stepConfirm;
|
||
public Button confirmNextBtn; // 确认,进入验证码
|
||
public Button step1CancelBtn; // 取消,关闭页面
|
||
|
||
[Header("验证码页(复用 SelfVerificationCodePanel)")]
|
||
public SelfVerificationCodePanel verificationCodePanelPrefab;
|
||
|
||
[Header("提示界面2(最终确认)")]
|
||
public GameObject stepFinal;
|
||
public Button finalConfirmBtn; // 确认注销
|
||
public Button step3BackBtn; // 返回
|
||
|
||
private Action onBackCallback;
|
||
private string verifyCode; // 校验通过的验证码
|
||
private bool isSubmitting = false;
|
||
private SelfVerificationCodePanel verificationCodePanel;
|
||
|
||
public void Init(Action onBack)
|
||
{
|
||
onBackCallback = onBack;
|
||
UIManager.Instance.RegisterBackAction(OnBack);
|
||
|
||
// 提示界面1
|
||
if (confirmNextBtn != null)
|
||
{
|
||
confirmNextBtn.onClick.RemoveAllListeners();
|
||
confirmNextBtn.onClick.AddListener(OnConfirmNext);
|
||
}
|
||
if (step1CancelBtn != null)
|
||
{
|
||
step1CancelBtn.onClick.RemoveAllListeners();
|
||
step1CancelBtn.onClick.AddListener(OnBack);
|
||
}
|
||
|
||
// 提示界面2
|
||
if (finalConfirmBtn != null)
|
||
{
|
||
finalConfirmBtn.onClick.RemoveAllListeners();
|
||
finalConfirmBtn.onClick.AddListener(OnFinalConfirm);
|
||
}
|
||
if (step3BackBtn != null)
|
||
{
|
||
step3BackBtn.onClick.RemoveAllListeners();
|
||
step3BackBtn.onClick.AddListener(OnBack);
|
||
}
|
||
|
||
// 默认显示提示界面1
|
||
ShowStep(stepConfirm);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 切换显示步骤
|
||
/// </summary>
|
||
private void ShowStep(GameObject step)
|
||
{
|
||
if (stepConfirm != null) stepConfirm.SetActive(step == stepConfirm);
|
||
if (stepFinal != null) stepFinal.SetActive(step == stepFinal);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提示界面1确认,打开验证码面板(注销场景)
|
||
/// </summary>
|
||
private void OnConfirmNext()
|
||
{
|
||
stepConfirm.SetActive(false);
|
||
if (verificationCodePanelPrefab == null)
|
||
return;
|
||
verificationCodePanel = Instantiate(verificationCodePanelPrefab, transform);
|
||
verificationCodePanel.gameObject.SetActive(true);
|
||
verificationCodePanel.Init(OnVerifySuccess, OnBack, SelfVerificationCodePanel.VerificationScene.CancelAccount);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 验证码校验成功,进入最终确认
|
||
/// </summary>
|
||
private void OnVerifySuccess()
|
||
{
|
||
verifyCode = verificationCodePanel != null ? verificationCodePanel.VerifiedCode : "";
|
||
if (verificationCodePanel != null)
|
||
{
|
||
Destroy(verificationCodePanel.gameObject);
|
||
verificationCodePanel = null;
|
||
}
|
||
ShowStep(stepFinal);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提示界面2最终确认,执行注销
|
||
/// </summary>
|
||
private async void OnFinalConfirm()
|
||
{
|
||
if (isSubmitting)
|
||
return;
|
||
isSubmitting = true;
|
||
LoadingUI.Show();
|
||
|
||
var requestData = new CancelAccountRequest
|
||
{
|
||
email = DataManager.Instance.userInfo.email,
|
||
code = verifyCode
|
||
};
|
||
|
||
try
|
||
{
|
||
var response = await NetworkCtrl.Instance.Post<NoDataResponse>("/api/v1/user/cancel", requestData);
|
||
LoadingUI.Hide();
|
||
|
||
ResponseCodeHandler.HandleResponse(response,
|
||
onSuccess: (data) =>
|
||
{
|
||
isSubmitting = false;
|
||
DataManager.Instance.ClearInfo();
|
||
UIManager.Instance.OpenMainPage(UIManager.PageName.loginPage);
|
||
},
|
||
onError: (code, message) =>
|
||
{
|
||
isSubmitting = false;
|
||
// 验证码错误或已过期
|
||
if (code == 603)
|
||
{
|
||
ToastUI.Show("100342");
|
||
}
|
||
// 其他原因注销失败
|
||
else
|
||
{
|
||
ToastUI.Show("100343");
|
||
}
|
||
// 回到注销账号页最初状态(提示界面1)
|
||
verifyCode = "";
|
||
ShowStep(stepConfirm);
|
||
}
|
||
);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LoadingUI.Hide();
|
||
isSubmitting = false;
|
||
Debug.LogError("注销账号异常: " + ex.Message);
|
||
ToastUI.ShowText(ex.Message);
|
||
}
|
||
}
|
||
|
||
public void OnBack()
|
||
{
|
||
UIManager.Instance.RegisterBackAction(onBackCallback);
|
||
Destroy(gameObject);
|
||
}
|
||
}
|
||
}
|