DeviceInfo_Item.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. StartCoroutine(HttpTool.Instance.SendHttp(HttpActionLang.bladeServer, jsondata, BladeServerCallBack));
  49. // HttpLangChaoTool.Instance.Post(HttpLangChaoAction.bladeServer, jsondata, BladeServerCallBack);
  50. // item.gameObject.SetActive(false);
  51. }
  52. private void SettingNull()
  53. {
  54. DetailsBtn.interactable = false;
  55. transform.GetComponent<Image>().enabled = false;
  56. for (int i = 0; i < transform.childCount; i++)
  57. {
  58. transform.GetChild(i).gameObject.SetActive(false);
  59. }
  60. }
  61. private void BladeServerCallBack(string msg)
  62. {
  63. Debug.Log(msg);
  64. JObject json = JObject.Parse(msg);
  65. if (json["code"].ToString() == "200")
  66. {
  67. string data = json["data"][0].ToString();
  68. //Debug.Log(data);
  69. this.DeviceParameter = JsonConvert.DeserializeObject<DeviceParameters>(data);
  70. Debug.Log(JsonConvert.SerializeObject(this.DeviceParameter));
  71. this.SendCommand(new DeviceDetailsUpdataDataCommand(DeviceParameter, currentPos, item)); // 触发事件,打开面板,更新数据
  72. }
  73. else
  74. {
  75. Debug.LogError(" 请求刀片机详情参数出错 !!! " + HttpActionLang.bladeServer);
  76. }
  77. }
  78. private void OnEnable()
  79. {
  80. if (mQueueSystem == null)
  81. mQueueSystem = this.GetService<IQueueSystem>();
  82. mQueueSystem.Add(gameObject);
  83. }
  84. private void OnDestroy()
  85. {
  86. mQueueSystem.Remove(gameObject);
  87. }
  88. }
  89. }