2026-06-08 08:55:10 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Kill.Managers;
|
|
|
|
|
|
using Kill.Network;
|
|
|
|
|
|
using Kill.UI.Components;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
namespace Kill.UI.Pages
|
|
|
|
|
|
{
|
|
|
|
|
|
public class CheckPasswordPage : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
class PasswordRequest
|
|
|
|
|
|
{
|
|
|
|
|
|
public string password;
|
|
|
|
|
|
}
|
|
|
|
|
|
public InputField passwordInput;
|
|
|
|
|
|
public Text errorText;
|
|
|
|
|
|
public GameObject plane;
|
2026-09-20 14:04:59 +08:00
|
|
|
|
|
|
|
|
|
|
// 未设置密码时的引导分支(仅在 passwordInput 等组件未挂时强制进入;正常面板同时具备输入与引导能力)
|
|
|
|
|
|
[Header("未设密码引导")]
|
|
|
|
|
|
public GameObject passwordCheckPanel; // 密码输入区域容器(含 InputField / 确认按钮等)
|
|
|
|
|
|
public GameObject passwordGuidePanel; // "引导去设置密码"提示区域容器
|
|
|
|
|
|
public Button setupPasswordBtn; // "立即设置密码" 按钮
|
|
|
|
|
|
public Button remindLaterBtn; // "稍后再说" 按钮
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (setupPasswordBtn != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
setupPasswordBtn.onClick.RemoveAllListeners();
|
|
|
|
|
|
setupPasswordBtn.onClick.AddListener(OnSetupPasswordClick);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (remindLaterBtn != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
remindLaterBtn.onClick.RemoveAllListeners();
|
|
|
|
|
|
remindLaterBtn.onClick.AddListener(OnRemindLaterClick);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-03 14:41:12 +08:00
|
|
|
|
public void OnEnable()
|
|
|
|
|
|
{
|
2026-09-20 14:04:59 +08:00
|
|
|
|
UIManager.Instance.RegisterBackAction(OnBack);
|
2026-07-03 14:41:12 +08:00
|
|
|
|
errorText.text="";
|
2026-09-20 14:04:59 +08:00
|
|
|
|
// 检测当前账号是否已设置过密码,决定显示密码输入面板还是引导面板
|
|
|
|
|
|
RefreshByPasswordState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据 userInfo 的密码标记切换显示:
|
|
|
|
|
|
/// 未设密码 → 始终显示引导面板(不显示密码输入框,避免用户输什么都是错的)
|
|
|
|
|
|
/// 已设密码 → 显示密码输入面板
|
|
|
|
|
|
/// 简单策略:未设密码时,每次 LockButtonPlane 激活都弹引导,不再用本地日期去重
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void RefreshByPasswordState()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool hasPassword = DataManager.Instance != null && DataManager.Instance.HasAnyPassword();
|
|
|
|
|
|
|
|
|
|
|
|
if (passwordGuidePanel != null) passwordGuidePanel.SetActive(!hasPassword);
|
|
|
|
|
|
if (passwordCheckPanel != null) passwordCheckPanel.SetActive(hasPassword);
|
2026-07-03 14:41:12 +08:00
|
|
|
|
}
|
2026-06-08 08:55:10 +08:00
|
|
|
|
public async void OnConfirm()
|
|
|
|
|
|
{
|
2026-07-03 14:41:12 +08:00
|
|
|
|
errorText.text="";
|
2026-06-08 08:55:10 +08:00
|
|
|
|
LoadingUI.Show();
|
2026-09-01 09:25:48 +08:00
|
|
|
|
try
|
2026-06-08 08:55:10 +08:00
|
|
|
|
{
|
2026-09-01 09:25:48 +08:00
|
|
|
|
string password = passwordInput != null ? passwordInput.text : "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(password))
|
|
|
|
|
|
{
|
|
|
|
|
|
errorText.text = LanguageManager.Instance.GetLanguage("home_password_check_failed");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
PasswordRequest requestData=new PasswordRequest
|
|
|
|
|
|
{
|
|
|
|
|
|
password=passwordInput.text
|
|
|
|
|
|
};
|
2026-06-08 08:55:10 +08:00
|
|
|
|
|
2026-09-01 09:25:48 +08:00
|
|
|
|
var response = await NetworkCtrl.Instance.Post<LoginResponse>("/api/v1/auth/password/verify", requestData);
|
2026-06-08 08:55:10 +08:00
|
|
|
|
|
2026-09-01 09:25:48 +08:00
|
|
|
|
if (response != null && response.Data != null && response.Data.code == 200)
|
|
|
|
|
|
{
|
|
|
|
|
|
plane.SetActive(false);
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
errorText.text="";
|
|
|
|
|
|
passwordInput.text="";
|
2026-09-17 08:41:18 +08:00
|
|
|
|
// 解锁成功,记录解锁时间(自动锁定倒计时起点)
|
|
|
|
|
|
DataManager.Instance.RecordUnlock();
|
2026-09-01 09:25:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
errorText.text = LanguageManager.Instance.GetLanguage("home_password_check_failed");
|
|
|
|
|
|
passwordInput.text="";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.Exception ex)
|
2026-06-08 08:55:10 +08:00
|
|
|
|
{
|
2026-09-01 09:25:48 +08:00
|
|
|
|
Debug.LogError($"[CheckPasswordPage] 校验密码异常: {ex.Message}");
|
|
|
|
|
|
errorText.text = LanguageManager.Instance.GetLanguage("home_password_check_failed");
|
|
|
|
|
|
if (passwordInput != null) passwordInput.text = "";
|
2026-06-08 08:55:10 +08:00
|
|
|
|
}
|
2026-09-01 09:25:48 +08:00
|
|
|
|
finally
|
2026-06-08 08:55:10 +08:00
|
|
|
|
{
|
2026-09-01 09:25:48 +08:00
|
|
|
|
// 无论成功/失败/异常都关闭 Loading,避免一直挂着
|
|
|
|
|
|
LoadingUI.Hide();
|
2026-06-08 08:55:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-20 14:04:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 引导面板 - 立即设置密码
|
|
|
|
|
|
/// 关闭当前 LockButtonPlane 并打开个人中心的 设置密码 流程
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void OnSetupPasswordClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
OnSetPassword();
|
|
|
|
|
|
}
|
|
|
|
|
|
public SelfVerificationCodePanel verificationCodePanelPrefab;
|
|
|
|
|
|
public SelfSetPasswordPanel setPasswordPanelPrefab;
|
|
|
|
|
|
SelfVerificationCodePanel verificationCodePanel;
|
|
|
|
|
|
public void OnSetPassword()
|
|
|
|
|
|
{
|
|
|
|
|
|
verificationCodePanel = Instantiate(verificationCodePanelPrefab, transform);
|
|
|
|
|
|
verificationCodePanel.Init(OnSureVerificationCode, OnBack);
|
|
|
|
|
|
}
|
|
|
|
|
|
SelfSetPasswordPanel setPasswordPanel;
|
|
|
|
|
|
public void OnSureVerificationCode()
|
|
|
|
|
|
{
|
|
|
|
|
|
Destroy(verificationCodePanel.gameObject);
|
|
|
|
|
|
setPasswordPanel = Instantiate(setPasswordPanelPrefab, transform);
|
|
|
|
|
|
setPasswordPanel.Init(OnSetPasswordSuccess);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OnSetPasswordSuccess()
|
|
|
|
|
|
{
|
|
|
|
|
|
Destroy(setPasswordPanel.gameObject);
|
|
|
|
|
|
plane.SetActive(false);
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
// 解锁成功,记录解锁时间(自动锁定倒计时起点)
|
|
|
|
|
|
DataManager.Instance.RecordUnlock();
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 引导面板 - 稍后再说
|
|
|
|
|
|
/// 仅关闭 LockButtonPlane,下次再激活时仍会再次弹出引导面板(未设密码时每次都提示)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void OnRemindLaterClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
}
|
2026-06-08 08:55:10 +08:00
|
|
|
|
|
2026-09-20 14:04:59 +08:00
|
|
|
|
public void OnBack()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.RegisterBackAction(null);
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
}
|
2026-06-08 08:55:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|