64 lines
1.6 KiB
C#
64 lines
1.6 KiB
C#
using Adam;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
//============================================================
|
||
//支持中文,文件使用UTF-8编码
|
||
//@author #AUTHOR#
|
||
//@create #CREATEDATE#
|
||
//@company #COMPANY#
|
||
//
|
||
//@description:
|
||
//============================================================
|
||
|
||
public class LoginController : MonoBehaviour
|
||
{
|
||
//public string url;
|
||
public string loginUrl;
|
||
public InputField user;
|
||
public InputField password;
|
||
public Text errorInfo;
|
||
public Button loginBtn;
|
||
public GameObject modelChangePlane;
|
||
// Use this for initialization
|
||
private void Start()
|
||
{
|
||
//var res = await AsyncWebReq.Get<LineLossData>(url);
|
||
//Debug.Log(res == null);
|
||
loginBtn.onClick.AddListener(() =>
|
||
{
|
||
OnLogin();
|
||
});
|
||
}
|
||
|
||
|
||
public async void OnLogin()
|
||
{
|
||
if (string.IsNullOrEmpty(user.text) || string.IsNullOrEmpty(password.text))
|
||
{
|
||
StartCoroutine(WaitCloseErrorPlane("姓名和身份证不能为空"));
|
||
return;
|
||
}
|
||
|
||
LoginData msg = await AsyncWebReq.Post<LoginData>(loginUrl + "?login_name=" + user.text + "&login_card=" + password.text, null);
|
||
Debug.Log(msg.state);
|
||
if (msg.state == "Fail")
|
||
{
|
||
StartCoroutine(WaitCloseErrorPlane(msg.data[0].msg));
|
||
return;
|
||
}
|
||
modelChangePlane.SetActive(true);
|
||
}
|
||
|
||
IEnumerator WaitCloseErrorPlane(string msg)
|
||
{
|
||
errorInfo.text = msg;
|
||
yield return new WaitForSeconds(2f);
|
||
errorInfo.text = "";
|
||
}
|
||
}
|
||
|
||
|