97 lines
2.6 KiB
C#
97 lines
2.6 KiB
C#
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
|
|
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using FairyGUI;
|
|
using NBC;
|
|
|
|
namespace NBF
|
|
{
|
|
public partial class VideoListPage : GComponent
|
|
{
|
|
public const int PageSize = 20;
|
|
private readonly List<VideoRetData> Videos = new List<VideoRetData>();
|
|
private GComponent _footer;
|
|
private Controller _controller;
|
|
public int Page = 0;
|
|
|
|
private void OnInited()
|
|
{
|
|
List.itemRenderer = RenderListItem1;
|
|
List.SetVirtual();
|
|
List.scrollPane.onPullUpRelease.Add(OnPullUpToRefresh);
|
|
_footer = (GComponent)List.scrollPane.footer;
|
|
_controller = _footer.GetController("style");
|
|
}
|
|
|
|
private void SetList()
|
|
{
|
|
List.numItems = Videos.Count;
|
|
}
|
|
|
|
void RenderListItem1(int index, GObject obj)
|
|
{
|
|
if (obj is VideoEditorItem item)
|
|
{
|
|
|
|
}
|
|
// GButton item = obj.asButton;
|
|
// item.title = "Item " + (_list1.numItems - index - 1);
|
|
}
|
|
|
|
void OnPullUpToRefresh()
|
|
{
|
|
_controller.selectedIndex = 1;
|
|
List.scrollPane.LockFooter(_footer.sourceHeight);
|
|
|
|
GetList(Page + 1);
|
|
// //Simulate a async resquest
|
|
// Timers.inst.Add(2, 1, (object param) =>
|
|
// {
|
|
// List.numItems += 5;
|
|
//
|
|
// //Refresh completed
|
|
// _controller.selectedIndex = 0;
|
|
// List.scrollPane.LockFooter(0);
|
|
// });
|
|
}
|
|
|
|
|
|
#region 数据
|
|
|
|
private void GetList(int page)
|
|
{
|
|
if (page < 1) return;
|
|
|
|
var dic = new Dictionary<string, string>
|
|
{
|
|
{ "page", page.ToString() },
|
|
{ "PageSize", PageSize.ToString() }
|
|
};
|
|
Net.Instance.Send("/api/list", dic, ParseVideo);
|
|
}
|
|
|
|
private void ParseVideo(HttpResult httpResult)
|
|
{
|
|
_controller.selectedIndex = 0;
|
|
List.scrollPane.LockFooter(0);
|
|
if (httpResult.Code == 0)
|
|
{
|
|
var retData = httpResult.Data.ToObject<PageListData<VideoRetData>>();
|
|
if (retData != null)
|
|
{
|
|
if (retData.List.Count > 0)
|
|
{
|
|
Videos.AddRange(retData.List);
|
|
}
|
|
|
|
Page = retData.Page;
|
|
}
|
|
}
|
|
|
|
SetList();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |