81 lines
2.1 KiB
C#
81 lines
2.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 使用记录列表项组件
|
|
/// </summary>
|
|
public class UseLogItem : ScrollableListItem
|
|
{
|
|
[Header("日志信息显示")]
|
|
public TextMeshProUGUI IndexText;
|
|
public TextMeshProUGUI OperationContentText;
|
|
public TextMeshProUGUI TimeText;
|
|
public TextMeshProUGUI AccountText;
|
|
|
|
private UseLogEvent _logEvent;
|
|
private int _index;
|
|
|
|
/// <summary>
|
|
/// 初始化日志项
|
|
/// </summary>
|
|
/// <param name="logEvent">日志事件</param>
|
|
/// <param name="index">序号</param>
|
|
public void Initialize(UseLogEvent logEvent, int index)
|
|
{
|
|
_logEvent = logEvent;
|
|
_index = index;
|
|
UpdateDisplay();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化新版本日志项
|
|
/// </summary>
|
|
/// <param name="userLogEvent">用户日志事件</param>
|
|
/// <param name="index">序号</param>
|
|
public void Initialize(UserLogEvent userLogEvent, int index)
|
|
{
|
|
// 将新版本日志转换为旧版本格式以保持兼容性
|
|
_logEvent = new UseLogEvent
|
|
{
|
|
Id = userLogEvent.Id,
|
|
Account = userLogEvent.Username,
|
|
OperationContentText = $"{userLogEvent.Operation}: {userLogEvent.OperationDetails ?? ""}",
|
|
Time = userLogEvent.Timestamp
|
|
};
|
|
_index = index;
|
|
UpdateDisplay();
|
|
}
|
|
|
|
private void UpdateDisplay()
|
|
{
|
|
if (_logEvent == null) return;
|
|
|
|
if (IndexText != null)
|
|
{
|
|
IndexText.text = _index.ToString();
|
|
}
|
|
|
|
if (OperationContentText != null)
|
|
{
|
|
OperationContentText.text = _logEvent.OperationContentText ?? "未知操作";
|
|
}
|
|
|
|
if (TimeText != null)
|
|
{
|
|
TimeText.text = _logEvent.Time.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
|
|
if (AccountText != null)
|
|
{
|
|
AccountText.text = _logEvent.Account ?? "未知用户";
|
|
}
|
|
}
|
|
|
|
protected override void UpdateUI()
|
|
{
|
|
UpdateDisplay();
|
|
}
|
|
} |