169 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			169 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C#
		
	
	
	
| using Components;
 | ||
| using Data;
 | ||
| using MobileTerminal;
 | ||
| using Newtonsoft.Json;
 | ||
| using Newtonsoft.Json.Linq;
 | ||
| using System.Collections;
 | ||
| using System.Collections.Generic;
 | ||
| using UnityEngine;
 | ||
| using UnityEngine.UI;
 | ||
| //============================================================
 | ||
| //支持中文,文件使用UTF-8编码
 | ||
| //@author	#AUTHOR#
 | ||
| //@create	#CREATEDATE#
 | ||
| //@company	#COMPANY#
 | ||
| //
 | ||
| //@description:
 | ||
| //============================================================
 | ||
| 
 | ||
| public class MobileTerminalController : MonoBehaviour
 | ||
| {
 | ||
|     public string userViewUrl;
 | ||
|     public string tabelViewUrl;
 | ||
|     public InputField number;
 | ||
|     /// <summary>
 | ||
|     /// 表记数据
 | ||
|     /// </summary>
 | ||
|     public Button outsideBtn;
 | ||
|     /// <summary>
 | ||
|     /// 用户数据
 | ||
|     /// </summary>
 | ||
|     public Button electricitBtn;
 | ||
|     public Button backBtn;
 | ||
| 
 | ||
|     public GameObject tapView;
 | ||
|     public GameObject userView;
 | ||
| 
 | ||
|     public Transform userContent;
 | ||
|     public Transform tapContent;
 | ||
|     public MobileTerminalTipsItem itemPrfab;
 | ||
|     [HideInInspector]
 | ||
|     public UserViewData mData = new UserViewData();
 | ||
|     [HideInInspector]
 | ||
|     public TableViewData tData = new TableViewData();
 | ||
|     public JObject jbsx;
 | ||
|     public JObject jbxx;
 | ||
|     public List<JObject> jlzzxx = new List<JObject>();
 | ||
| 
 | ||
|     public bool isOnLoad = false;
 | ||
| 
 | ||
|     // Use this for initialization
 | ||
|     private void Start()
 | ||
|     {
 | ||
|         outsideBtn.onClick.AddListener(OnOutsideView);
 | ||
|         electricitBtn.onClick.AddListener(OnElectricitView);
 | ||
|         backBtn.onClick.AddListener(OnBack);
 | ||
|         SwitchView(-1);
 | ||
|     }
 | ||
| 
 | ||
|     public async void OnUser()
 | ||
|     {
 | ||
|         if (userContent.childCount > 0)
 | ||
|         {
 | ||
|             for (int i = 0; i < userContent.childCount; i++)
 | ||
|             {
 | ||
|                 Destroy(userContent.GetChild(i).gameObject);
 | ||
|             }
 | ||
|         }
 | ||
|         isOnLoad = true;
 | ||
|         string url = userViewUrl + number.text;
 | ||
|         mData = await AsyncWebReq.Get<UserViewData>(url);
 | ||
|         for (int i = 0; i < mData.data.Count; i++)
 | ||
|         {
 | ||
|             MobileTerminalTipsItem itemTip = Instantiate(itemPrfab, userContent);
 | ||
|             itemTip.SetValue(mData.data[i]);
 | ||
|         }
 | ||
|         //string jsonData = JsonConvert.SerializeObject(mData);
 | ||
|         //AsyncWebReq.SetValue(jsonData, out jbsx, out jbxx, out jlzzxx);
 | ||
| 
 | ||
|         //foreach (var item in jbsx)
 | ||
|         //{
 | ||
|         //    MobileTerminalTipsItem itemTip = Instantiate(itemPrfab, userContent);
 | ||
|         //    string info = item.Key + ":     " + item.Value;
 | ||
|         //    itemTip.SetValue(info);
 | ||
|         //}
 | ||
| 
 | ||
|         //foreach (var item in jbxx)
 | ||
|         //{
 | ||
|         //    MobileTerminalTipsItem itemTip = Instantiate(itemPrfab, userContent);
 | ||
|         //    string info = item.Key + ":     " + item.Value;
 | ||
|         //    itemTip.SetValue(info);
 | ||
|         //}
 | ||
| 
 | ||
|         //for (int i = 0; i < jlzzxx.Count; i++)
 | ||
|         //{
 | ||
|         //    foreach (var item in jlzzxx[i])
 | ||
|         //    {
 | ||
|         //        MobileTerminalTipsItem itemTip = Instantiate(itemPrfab, userContent);
 | ||
|         //        string info = item.Key + ":     " + item.Value;
 | ||
|         //        itemTip.SetValue(info);
 | ||
|         //    }
 | ||
|         //}
 | ||
|         SwitchView(0);
 | ||
|         isOnLoad = false;
 | ||
|     }
 | ||
| 
 | ||
|     public async void OnTable()
 | ||
|     {
 | ||
|         if (tapContent.childCount > 0)
 | ||
|         {
 | ||
|             for (int i = 0; i < tapContent.childCount; i++)
 | ||
|             {
 | ||
|                 Destroy(tapContent.GetChild(i).gameObject);
 | ||
|             }
 | ||
|         }
 | ||
|         isOnLoad = true;
 | ||
|         string url = tabelViewUrl + number.text;
 | ||
|         tData = await AsyncWebReq.Get<TableViewData>(url);
 | ||
|         for (int i = 0; i < tData.data.Count; i++)
 | ||
|         {
 | ||
|             MobileTerminalTipsItem itemTip = Instantiate(itemPrfab, tapContent);
 | ||
|             itemTip.SetValue(tData.data[i]);
 | ||
|         }
 | ||
|         SwitchView(1);
 | ||
|         isOnLoad = false;
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
|     /// <summary>
 | ||
|     /// 用户数据
 | ||
|     /// </summary>
 | ||
|     public void OnElectricitView()
 | ||
|     {
 | ||
|         if (isOnLoad) return;
 | ||
|         if (number.text == "") return;
 | ||
|         OnUser();
 | ||
| 
 | ||
|     }
 | ||
|     /// <summary>
 | ||
|     /// 表记数据
 | ||
|     /// </summary>
 | ||
|     public void OnOutsideView()
 | ||
|     {
 | ||
|         if (isOnLoad) return;
 | ||
|         if (number.text == "") return;
 | ||
|         OnTable();
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
|     public void SwitchView(int index)
 | ||
|     {
 | ||
|         userView.SetActive(index == 0);
 | ||
|         tapView.SetActive(index == 1);
 | ||
|         if (index == 0 || index == 1)
 | ||
|         {
 | ||
|             backBtn.gameObject.SetActive(true);
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|             backBtn.gameObject.SetActive(false);
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
|     public void OnBack()
 | ||
|     {
 | ||
|         SwitchView(-1);
 | ||
|     }
 | ||
| }
 |