using LitJson; using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DeviceAlarmControl : MonoBehaviour { public int ListCount = 10000; public RecycleView VerticalScroll; public ScrollRect scrollRect; public string deviceName; public List listAlarm; public Dictionary dicAlarmItem; private bool isGetData = false; private void Start() { listAlarm = new List(); dicAlarmItem = new Dictionary(); scrollRect = VerticalScroll.GetComponent(); //for (int i = 0; i < 20; i++) //{ // AIDeviceAlarm testData = new AIDeviceAlarm(); // testData.level = "中"; // testData.times = "2024-05-23 16:13"; // testData.deviceName = "温湿度传感器" + i.ToString(); // testData.describe = "设备离线"; // testData.duarationTimer = i.ToString() + "天0时59分56秒"; // listAlarm.Add(testData); //} //Debug.Log("DGJ==>TestData " +JsonConvert.SerializeObject(listAlarm)); JsonData data = new JsonData(); data["deviceClassification"] = ""; data["page"] = 1; data["limit"] = 20; PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/alarm/getalarmrecord", data.ToJson(), (msg) => { Debug.Log("DGJ ==> " + "/feature-tester/v1/AIot/alarm/getalarmrecord" + " " + msg); JsonData data = JsonMapper.ToObject(msg); if (data["code"].ToString() == "200") { string msgData = data["data"].ToString(); msgData = JsonConvert.SerializeObject(data["data"]["list"].ToJson()); Debug.Log(JsonConvert.SerializeObject(msgData)); // JsonData data2 = JsonMapper.ToObject(msgData); listAlarm = JsonConvert.DeserializeObject>(data["data"]["list"].ToJson()); ListCount = int.Parse(data["data"]["total"].ToString()); DataUpdate(listAlarm); } StartCoroutine(GetListAlarm()); }); } private IEnumerator GetListAlarm() { bool isHttp = false; while (listAlarm.Count < ListCount) { yield return new WaitForFixedUpdate(); if (!isHttp) { isHttp = true; JsonData data = new JsonData(); data["deviceClassification"] = ""; data["page"] = listAlarm.Count / 20 + 1; data["limit"] = 20; PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/alarm/getalarmrecord", data.ToJson(), (msg) => { Debug.Log("DGJ ==> " + "/feature-tester/v1/AIot/alarm/getalarmrecord" + " " + msg); JsonData data = JsonMapper.ToObject(msg); if (data["code"].ToString() == "200") { string msgData = data["data"]["list"].ToString(); List listAlarmdata = new List(); listAlarmdata = JsonConvert.DeserializeObject>(data["data"]["list"].ToJson()); if (listAlarmdata.Count > 0) { listAlarm.AddRange(listAlarmdata); } } isHttp = false; }); } } } public void DataUpdate(List listdata) { this.listAlarm = listdata; StartScrollView(); } public void StartScrollView() { VerticalScroll.Init(NormalCallBack); VerticalScroll.ShowList(ListCount); } private void NormalCallBack(GameObject cell, int index) { // cell.transform.Find("Text1").GetComponent().text = index.ToString(); Debug.Log("DGJ ==> Index" + index); if (isGetData) return; if (ListCount != listAlarm.Count && ((index + 1) >= listAlarm.Count)) { isGetData = true; // 请求添加 JsonData data = new JsonData(); data["deviceClassification"] = ""; data["page"] = listAlarm.Count / 20 + 1; data["limit"] = 20; PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/alarm/getalarmrecord", data.ToJson(), (msg) => { Debug.Log("DGJ ==> " + "/feature-tester/v1/AIot/alarm/getalarmrecord" + " " + msg); JsonData data = JsonMapper.ToObject(msg); if (data["code"].ToString() == "200") { string msgData = data["data"]["list"].ToString(); List listAlarmdata = new List(); listAlarmdata = JsonConvert.DeserializeObject>(data["data"]["list"].ToJson()); if (listAlarmdata.Count > 0) { listAlarm.AddRange(listAlarmdata); } } scrollRect.inertia = true; scrollRect.decelerationRate = 0.135f; }); scrollRect.inertia = false; scrollRect.decelerationRate = 0; return; } if (dicAlarmItem.ContainsKey(cell)) { dicAlarmItem[cell].DataUpdate(listAlarm[index]); } else { dicAlarmItem.Add(cell, cell.GetComponent()); dicAlarmItem[cell].DataUpdate(listAlarm[index]); } } }