DeviceInfo_Item.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Blue;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using TMPro;
  7. namespace GHZLangChao
  8. {
  9. public class DeviceInfo_Item : AbstractController
  10. {
  11. private DeviceParameters DeviceParameter;
  12. public Transform currentPos;
  13. public DataItem item;
  14. public TMP_Text deviceName;
  15. public TMP_Text type;
  16. public TMP_Text model;
  17. public TMP_Text ip;
  18. [SerializeField] private Button DetailsBtn;
  19. private IQueueSystem mQueueSystem;
  20. private void Start()
  21. {
  22. DetailsBtn.onClick.AddListener(ClickDetails);
  23. }
  24. int i;
  25. public void Init(DeviceParameters DeviceParameter, int i, DataItem item)
  26. {
  27. this.DeviceParameter = DeviceParameter;
  28. this.i = i;
  29. this.item = item;
  30. deviceName.text = DeviceParameter.cabinetNumber;
  31. type.text = DeviceParameter.deviceType;
  32. model.text = DeviceParameter.deviceBrand;
  33. ip.text = DeviceParameter.managementIP;
  34. }
  35. public void InitNull()
  36. {
  37. SettingNull();
  38. }
  39. private void ClickDetails()
  40. {
  41. // DeviceParameter.deviceModel = "NetView400" + i;
  42. // Vector3 currentPos = transform.position; // 为了将详情面板移动到面前
  43. // 从后台获取UI详情
  44. JObject data = new JObject();
  45. data["cabinetNumber"] = DeviceParameter.cabinetNumber;
  46. data["u"] = DeviceParameter.u;
  47. string jsondata = JsonConvert.SerializeObject(data);
  48. HttpLangChaoTool.Instance.Post(HttpLangChaoAction.bladeServer, jsondata, BladeServerCallBack);
  49. // item.gameObject.SetActive(false);
  50. }
  51. private void SettingNull()
  52. {
  53. DetailsBtn.interactable = false;
  54. transform.GetComponent<Image>().enabled = false;
  55. for (int i = 0; i < transform.childCount; i++)
  56. {
  57. transform.GetChild(i).gameObject.SetActive(false);
  58. }
  59. }
  60. private void BladeServerCallBack(string msg)
  61. {
  62. Debug.Log(msg);
  63. JObject json = JObject.Parse(msg);
  64. if (json["code"].ToString() == "200")
  65. {
  66. string data = json["data"][0].ToString();
  67. //Debug.Log(data);
  68. this.DeviceParameter = JsonConvert.DeserializeObject<DeviceParameters>(data);
  69. Debug.Log(JsonConvert.SerializeObject(this.DeviceParameter));
  70. this.SendCommand(new DeviceDetailsUpdataDataCommand(DeviceParameter, currentPos, item)); // 触发事件,打开面板,更新数据
  71. }
  72. else
  73. {
  74. Debug.LogError(" 请求刀片机详情参数出错 !!! " + HttpLangChaoAction.bladeServer);
  75. }
  76. }
  77. private void OnEnable()
  78. {
  79. if (mQueueSystem == null)
  80. mQueueSystem = this.GetService<IQueueSystem>();
  81. mQueueSystem.Add(gameObject);
  82. }
  83. private void OnDestroy()
  84. {
  85. mQueueSystem.Remove(gameObject);
  86. }
  87. }
  88. }