This commit is contained in:
2026-07-07 02:22:31 +08:00
parent ff49b4207a
commit b25995eeff
100 changed files with 16546 additions and 66 deletions
+151 -5
View File
@@ -1,5 +1,6 @@
using Assets.Framework.Tool;
using Assets.MyGame.Scripts.Net;
using Assets.MyGame.Scripts.Net.APIRequest.Params;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
@@ -22,6 +23,23 @@ public class UserInfoPanel : SubUIBase
public TextMeshProUGUI tMPText_IP;
public TextMeshProUGUI tMPText_VIPLeave;
public TextMeshProUGUI tMPText_PhoneNumber;
[Header("换绑手机")]
public TextMeshProUGUI tMPText_OldPhoneNumber;
public TMP_InputField tMPText_NewPhoneNumber;
public TMP_InputField tMPText_NewPhoneNumberQueRen;
public TMP_InputField tMPText_YZM;
public Button btn_GetYZM; //先不写获取验证码
public Button btn_ChangePhoneNumber;
[Header("改名")]
public TMP_InputField tMPText_NewName;
public Button btn_ChangeName;
[Header("修改密码")]
public TextMeshProUGUI tMPText_PhoneNumberXGMM;
public TMP_InputField tMPText_NewPassword;
public TMP_InputField tMPText_NewPasswordQueRen;
public TMP_InputField tMPText_YZMXGMM;
public Button btn_GetYZMXGMM; //先不写获取验证码
public Button btn_ChangePassword;
[Header("预览")]
public Image img_ShowAvatar; // 预览头像(选中即更新)
public Image img_ShowAvatarK; // 预览头像框(选中即更新)
@@ -33,6 +51,8 @@ public class UserInfoPanel : SubUIBase
public Toggle prefab_AvatarItem; // 头像/头像框选项预制体(child0=Image, child2=选中对号)
GameManager gameManager => GameManager.Instance;
private List<Toggle> _avatarToggles = new List<Toggle>();
private List<Toggle> _avatarFrameToggles = new List<Toggle>();
@@ -47,6 +67,13 @@ public class UserInfoPanel : SubUIBase
gameManager.Logout();
});
btn_UseAvatar.onClick.AddListener(OnClickUseAvatar);
// 换绑手机
btn_ChangePhoneNumber.onClick.AddListener(OnClickChangePhone);
// 改名
btn_ChangeName.onClick.AddListener(OnClickChangeName);
// 修改密码
btn_ChangePassword.onClick.AddListener(OnClickChangePassword);
}
protected override void OnShow(object args = null)
@@ -92,6 +119,12 @@ public class UserInfoPanel : SubUIBase
tMPText_IP.text = gameManager.user.@static.lastLoginIp;
tMPText_VIPLeave.text = gameManager.user.assets.vipLevel.ToString();
tMPText_PhoneNumber.text = MaskPhone(gameManager.user.BaseInfo.mobile);
// 换绑手机 & 修改密码页面显示旧手机号
if (tMPText_OldPhoneNumber != null)
tMPText_OldPhoneNumber.text = MaskPhone(gameManager.user.BaseInfo.mobile);
if (tMPText_PhoneNumberXGMM != null)
tMPText_PhoneNumberXGMM.text = MaskPhone(gameManager.user.BaseInfo.mobile);
}
// ==================== 头像加载 ====================
@@ -322,15 +355,128 @@ public class UserInfoPanel : SubUIBase
}
}
// ==================== 换绑手机 ====================
private void OnClickChangePhone()
{
string oldPhone = gameManager.user.BaseInfo.mobile;
string newPhone = tMPText_NewPhoneNumber?.text?.Trim();
string newPhoneConfirm = tMPText_NewPhoneNumberQueRen?.text?.Trim();
string code = tMPText_YZM?.text?.Trim();
if (string.IsNullOrEmpty(newPhone))
{
UIManager.Instance.ShowBoardError("请输入新手机号");
return;
}
if (newPhone != newPhoneConfirm)
{
UIManager.Instance.ShowBoardError("两次输入的新手机号不一致");
return;
}
if (string.IsNullOrEmpty(code))
{
UIManager.Instance.ShowBoardError("请输入验证码");
return;
}
APIRequestList.BindMobile(newPhone, code, (result) =>
{
UIManager.Instance.ShowBoardError("手机号换绑成功");
// 刷新本地数据
gameManager.user.BaseInfo.mobile = newPhone;
tMPText_OldPhoneNumber.text = MaskPhone(newPhone);
tMPText_PhoneNumber.text = MaskPhone(newPhone);
tMPText_NewPhoneNumber.text = "";
tMPText_NewPhoneNumberQueRen.text = "";
tMPText_YZM.text = "";
});
}
private void OnClickChangeName()
{
// 检查是否有改名卡
var props = gameManager.user.props;
bool hasNameCard = false;
if (props != null)
{
foreach (var p in props)
{
if (p.count > 0 && (PropEnum)p.type == PropEnum.改名卡)
{
hasNameCard = true;
break;
}
}
}
if (!hasNameCard)
{
UIManager.Instance.ShowBoardError("没有改名卡");
return;
}
string newName = tMPText_NewName?.text?.Trim();
if (string.IsNullOrEmpty(newName))
{
UIManager.Instance.ShowBoardError("请输入新名字");
return;
}
APIRequestList.UpdateUserName(newName, (result) =>
{
UIManager.Instance.ShowBoardError("改名成功");
gameManager.user.BaseInfo.userName = newName;
tMPText_Name.text = newName;
tMPText_NewName.text = "";
gameManager.UpdataUserData(gameManager.user);
});
}
// ==================== 修改密码 ====================
private void OnClickChangePassword()
{
string mobile = gameManager.user.BaseInfo.mobile;
string newPwd = tMPText_NewPassword?.text?.Trim();
string newPwdConfirm = tMPText_NewPasswordQueRen?.text?.Trim();
string code = tMPText_YZMXGMM?.text?.Trim();
if (string.IsNullOrEmpty(newPwd))
{
UIManager.Instance.ShowBoardError("请输入新密码");
return;
}
if (newPwd != newPwdConfirm)
{
UIManager.Instance.ShowBoardError("两次输入的密码不一致");
return;
}
if (string.IsNullOrEmpty(code))
{
UIManager.Instance.ShowBoardError("请输入验证码");
return;
}
APIRequestList.ResetPassword(new ReSetPassWordParam
{
mobile = mobile,
password = newPwd,
code = code
}, (result) =>
{
UIManager.Instance.ShowBoardError("密码修改成功");
tMPText_NewPassword.text = "";
tMPText_NewPasswordQueRen.text = "";
tMPText_YZMXGMM.text = "";
});
}
// ==================== 工具 ====================
public static string MaskPhone(string phone)
{
if (string.IsNullOrEmpty(phone) || phone.Length <= 6)
if (string.IsNullOrEmpty(phone) || phone.Length < 7)
return phone;
int prefix = 3;
int suffix = 3;
int maskCount = phone.Length - prefix - suffix;
return phone.Substring(0, prefix) + new string('*', maskCount) + phone.Substring(phone.Length - suffix);
return phone.Substring(0, 3) + "****" + phone.Substring(phone.Length - 4);
}
}