123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- 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<AIDeviceAlarm> listAlarm;
- public Dictionary<GameObject, AIDeviceAlarmItem> dicAlarmItem;
- private bool isGetData = false;
- private void Start()
- {
- listAlarm = new List<AIDeviceAlarm>();
- dicAlarmItem = new Dictionary<GameObject, AIDeviceAlarmItem>();
- scrollRect = VerticalScroll.GetComponent<ScrollRect>();
- //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<List<AIDeviceAlarm>>(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<AIDeviceAlarm> listAlarmdata = new List<AIDeviceAlarm>();
- listAlarmdata = JsonConvert.DeserializeObject<List<AIDeviceAlarm>>(data["data"]["list"].ToJson());
- if (listAlarmdata.Count > 0)
- {
- listAlarm.AddRange(listAlarmdata);
- }
- }
- isHttp = false;
- });
- }
- }
- }
- public void DataUpdate(List<AIDeviceAlarm> 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>().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<AIDeviceAlarm> listAlarmdata = new List<AIDeviceAlarm>();
- listAlarmdata = JsonConvert.DeserializeObject<List<AIDeviceAlarm>>(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<AIDeviceAlarmItem>());
- dicAlarmItem[cell].DataUpdate(listAlarm[index]);
- }
- }
- }
|