killapp/Assets/Scripts/UI/Pages/Safetylearning/SafetylearningPageCtrl.cs
“虞渠成” 5105f6fbfa feat: 新增安全学习页面退出提示功能
1. 新增多语言词条用于温馨提示和退出确认弹窗
2. 调整视频页面UI布局适配全屏显示
3. 优化蓝牙延迟返回逻辑避免重复跳转主页
4. 为安全学习页面添加返回确认弹窗逻辑
5. 为安全学习页面预制体绑定退出提示弹窗组件
2026-07-14 13:43:57 +08:00

154 lines
4.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Kill.Managers;
using Kill.Network;
using Kill.UI.Components;
using UnityEngine;
using UnityEngine.UI;
namespace Kill.UI.Pages
{
/// <summary>
/// 安全学习页面控制器 - 仅显示题目,不包含答题逻辑
/// </summary>
public class SafetylearningPageCtrl : MonoBehaviour
{
public static SafetylearningPageCtrl Instance { get; private set; }
/// <summary>
/// 0引导 1视屏学习 2测试 3完成
/// </summary>
public GameObject[] sonPages;
private GameObject nowPage;
public GameObject topUI;
// 题目数据
private List<QuestionInfo> questions = new List<QuestionInfo>();
private int currentQuestionIndex = 0;
public WindowTipCtrl backTip;
void Awake()
{
Instance = this;
}
void Start()
{
foreach (var page in sonPages)
{
page.SetActive(false);
}
nowPage = sonPages[0];
nowPage.SetActive(true);
topUI.SetActive(true);
// 加载题目
LoadQuestions();
UIManager.Instance.RegisterBackAction(BackAction);
}
/// <summary>
/// 从服务器加载全部题目
/// </summary>
public async void LoadQuestions()
{
LoadingUI.Show();
try
{
// 调用获取题目列表接口,获取全部题目
var response = await NetworkCtrl.Instance.Get<QuestionListResponse>("/api/v1/exam/questions");
LoadingUI.Hide();
ResponseCodeHandler.HandleResponse(response,
onSuccess: (data) =>
{
questions = data.data.list;
Debug.Log($"加载题目成功,共 {questions.Count} 道");
},
onError:(code,message)=>
{
Debug.LogError($"加载题目失败: {message}");
ToastUI.Show("100062");
}
);
}
catch (Exception ex)
{
LoadingUI.Hide();
Debug.LogError($"加载题目异常: {ex.Message}");
ToastUI.Show("100062");
}
}
/// <summary>
/// 完成考试
/// </summary>
public async void ExamCompletion()
{
LoadingUI.Show();
try
{
var response = await NetworkCtrl.Instance.Post<NoDataResponse>("/api/v1/exam/completion");
LoadingUI.Hide();
ResponseCodeHandler.HandleResponse(response,
onSuccess: (data) =>
{
DataManager.Instance.userInfo.exam_completed=true;
Debug.Log($"上传成功");
}
);
}
catch (Exception ex)
{
LoadingUI.Hide();
}
}
public void ShowVideoPage()
{
nowPage.SetActive(false);
nowPage = sonPages[1];
nowPage.SetActive(true);
string videoUrl="";
if (LanguageManager.Instance.languageType == LanguageManager.LanguageType.Chinese)
videoUrl = questions[0].videoUrl;
else
videoUrl = questions[0].videoUrlEn;
nowPage.GetComponent<SafetylearningVideoPage>().Init(videoUrl);
questions.RemoveAt(0);
}
public void ShowTestPage()
{
nowPage.SetActive(false);
nowPage = sonPages[2];
nowPage.SetActive(true);
nowPage.GetComponent<SafetylearningTestPage>().Init(questions);
}
public void ShowFinishPage()
{
ExamCompletion();
topUI.SetActive(false);
nowPage.SetActive(false);
nowPage = sonPages[3];
nowPage.SetActive(true);
}
public void BackToHomePage()
{
UIManager.Instance.OpenPage(UIManager.PageName.homePage,null,true);
}
public void ConnectDevice()
{
UIManager.Instance.OpenPage(UIManager.PageName.connectDevicePage,null,true);
}
public void BackAction()
{
backTip.Init(SureBack,()=>{backTip.gameObject.SetActive(false);});
backTip.gameObject.SetActive(true);
}
public void SureBack()
{
UIManager.Instance.OpenPage(UIManager.PageName.homePage,null,true);
}
}
}