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

181 lines
6.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Kill.Managers;
using UnityEngine.UI;
using Kill.Network;
using System.Threading.Tasks;
using Kill.UI.Components;
namespace Kill.UI.Pages
{
public class SelfInfoPage : MonoBehaviour
{
UserInfo userInfo;
public RawImage avatarImage;
public Text nicknameText;
public RenamePage renamePagePrefab;
public Button renameButton;
public Button backButton;
public SelfVerificationCodePanel verificationCodePanelPrefab;
public SelfSetPasswordPanel setPasswordPanelPrefab;
public SelectCountry selectCountryPrefab;
public Text countryText;
public Button selectCountryButton;
List<string> passwordSetKeys = new List<string> { "100200", "100201" };
/// <summary>
/// 0设置 1修改
/// </summary>
List<string> passwordSet;
/// <summary>
/// <summary>
/// 0简单密码 1复杂密码
/// </summary>
public Button resetPassword;
/// <summary>
/// 注销账号入口
/// </summary>
public Button cancelAccountButton;
public SelfCancelAccountPage cancelAccountPagePrefab;
public async Task Init(UserInfo userInfo)
{
this.userInfo = userInfo;
UIManager.Instance.RegisterBackAction(OnBack);
backButton.onClick.RemoveAllListeners();
backButton.onClick.AddListener(OnBack);
resetPassword.onClick.RemoveAllListeners();
resetPassword.onClick.AddListener(OnSetPassword);
// 注销账号入口
if (cancelAccountButton != null)
{
cancelAccountButton.onClick.RemoveAllListeners();
cancelAccountButton.onClick.AddListener(OnCancelAccount);
}
renameButton.onClick.RemoveAllListeners();
renameButton.onClick.AddListener(() =>
{
RenamePage renamePage = Instantiate(renamePagePrefab, transform);
renamePage.Init(userInfo.username, CloseRenamePage, 1);
});
// 在这里初始化个人信息页面,显示用户信息
if (avatarImage != null)
{
// 设置头像
if (userInfo.avatar != null)
{
avatarImage.gameObject.SetActive(true);
await NetworkCtrl.Instance.LoadImageToUIRawImageAsync(userInfo.avatar, avatarImage);
avatarImage.transform.parent.GetComponent<Mask>().showMaskGraphic = false;
}
}
if (nicknameText != null)
{
nicknameText.text = userInfo.username;
}
// 国家展示与选择
if (countryText != null)
UpdateCountryDisplay(userInfo.country_code);
if (selectCountryButton != null)
{
selectCountryButton.onClick.RemoveAllListeners();
selectCountryButton.onClick.AddListener(OnSelectCountry);
}
}
/// <summary>
/// 更新国家显示文本
/// </summary>
private void UpdateCountryDisplay(string code)
{
if (string.IsNullOrEmpty(code))
{
countryText.text = "";
return;
}
var country = LanguageManager.Instance.countryList.Find(c => c.code == code);
bool isZh = LanguageManager.Instance.languageType == LanguageManager.LanguageType.Chinese;
countryText.text = country.code != null ? (isZh ? country.name_zh : country.name_en) : code;
}
/// <summary>
/// 选择国家
/// </summary>
private void OnSelectCountry()
{
var selectCountry = Instantiate(selectCountryPrefab, transform);
selectCountry.Init(userInfo.country_code);
selectCountry.onConfirm = (code) =>
{
if (code != null)
{
userInfo.country_code = code;
UpdateCountryDisplay(code);
}
Destroy(selectCountry.gameObject);
UIManager.Instance.RegisterBackAction(OnBack);
};
}
public void InitLanguageText()
{
passwordSet = new List<string>();
}
public void CloseRenamePage(string newNickname)
{
if (nicknameText != null)
{
nicknameText.text = newNickname;
}
DataManager.Instance.userInfo.username = newNickname;
UIManager.Instance.RegisterBackAction(OnBack);
}
SelfVerificationCodePanel verificationCodePanel;
public void OnSetPassword()
{
verificationCodePanel = Instantiate(verificationCodePanelPrefab, transform);
verificationCodePanel.Init(OnSureVerificationCode, OnBack);
}
SelfCancelAccountPage cancelAccountPage;
/// <summary>
/// 打开注销账号页面
/// </summary>
public void OnCancelAccount()
{
if (cancelAccountPagePrefab == null)
return;
cancelAccountPage = Instantiate(cancelAccountPagePrefab, transform);
cancelAccountPage.Init(OnCancelAccountBack);
cancelAccountPage.gameObject.SetActive(true);
}
void OnCancelAccountBack()
{
UIManager.Instance.RegisterBackAction(OnBack);
}
SelfSetPasswordPanel setPasswordPanel;
public void OnSureVerificationCode()
{
Destroy(verificationCodePanel.gameObject);
setPasswordPanel = Instantiate(setPasswordPanelPrefab, transform);
setPasswordPanel.Init(OnSetPasswordSuccess);
}
public void OnSetPasswordSuccess()
{
Destroy(setPasswordPanel.gameObject);
GetComponentInParent<SelfPage>().OnSignOut();
}
public void OnBack()
{
UIManager.Instance.RegisterBackAction(GetComponentInParent<SelfPage>().OnBack);
GetComponentInParent<SelfPage>().RefreshAsync();
Destroy(gameObject);
}
}
}