using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
///
/// 使用记录列表项组件
///
public class UseLogItem : ScrollableListItem
{
[Header("日志信息显示")]
public TextMeshProUGUI IndexText;
public TextMeshProUGUI OperationContentText;
public TextMeshProUGUI TimeText;
public TextMeshProUGUI AccountText;
private UseLogEvent _logEvent;
private int _index;
///
/// 初始化日志项
///
/// 日志事件
/// 序号
public void Initialize(UseLogEvent logEvent, int index)
{
_logEvent = logEvent;
_index = index;
UpdateDisplay();
}
///
/// 初始化新版本日志项
///
/// 用户日志事件
/// 序号
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();
}
}