killapp/Assets/Scripts/UI/Pages/HomePage/CheckPasswordPage.cs

74 lines
2.4 KiB
C#
Raw Normal View History

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;
public void OnEnable()
{
errorText.text="";
}
2026-06-08 08:55:10 +08:00
public async void OnConfirm()
{
errorText.text="";
2026-06-08 08:55:10 +08:00
LoadingUI.Show();
try
2026-06-08 08:55:10 +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
var response = await NetworkCtrl.Instance.Post<LoginResponse>("/api/v1/auth/password/verify", requestData);
2026-06-08 08:55:10 +08:00
if (response != null && response.Data != null && response.Data.code == 200)
{
plane.SetActive(false);
gameObject.SetActive(false);
errorText.text="";
passwordInput.text="";
UIManager.Instance.isFirstTime=false;
// 解锁成功,记录解锁时间(自动锁定倒计时起点)
DataManager.Instance.RecordUnlock();
}
else
{
errorText.text = LanguageManager.Instance.GetLanguage("home_password_check_failed");
passwordInput.text="";
}
}
catch (System.Exception ex)
2026-06-08 08:55:10 +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
}
finally
2026-06-08 08:55:10 +08:00
{
// 无论成功/失败/异常都关闭 Loading避免一直挂着
LoadingUI.Hide();
2026-06-08 08:55:10 +08:00
}
}
}
}