160 lines
6.0 KiB
C#
160 lines
6.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Networking;
|
|
using System;
|
|
using DataModel.Model;
|
|
using LitJson;
|
|
|
|
public class LoginPanel : MonoBehaviour
|
|
{
|
|
public InputField zhanghao;
|
|
public InputField mima;
|
|
public Button quedingbtn;
|
|
public Canvas canvas;
|
|
public Button settingBtn;
|
|
public Button clearBtn;
|
|
public Button exitBtn;
|
|
public Button anchorSettingBtn;
|
|
|
|
public static LoginPanel instance;
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
string zh=PlayerPrefs.GetString("HJZhangHu", "");
|
|
string password=PlayerPrefs.GetString("HJMiMa", "");
|
|
zhanghao.text = zh;
|
|
mima.text = password;
|
|
clearBtn.onClick.AddListener(() =>
|
|
{
|
|
zhanghao.text = "";
|
|
mima.text = "";
|
|
});
|
|
|
|
quedingbtn.onClick.AddListener(() =>
|
|
{
|
|
if (!string.IsNullOrEmpty(zhanghao.text) || !string.IsNullOrEmpty(mima.text))
|
|
{
|
|
Login(zhanghao.text, mima.text);
|
|
}
|
|
});
|
|
|
|
settingBtn.onClick.AddListener(()=>
|
|
{
|
|
IPsettingPanel.instance.Show();
|
|
});
|
|
|
|
exitBtn.onClick.AddListener(()=>
|
|
{
|
|
Application.Quit();
|
|
});
|
|
|
|
anchorSettingBtn.onClick.AddListener(() =>
|
|
{
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene("GetAnchor");
|
|
});
|
|
}
|
|
|
|
private void Login(string account, string password)
|
|
{
|
|
AuthReq user = new AuthReq();
|
|
|
|
user.passWord = password;
|
|
user.sysId = "5";
|
|
user.userCode = "001";
|
|
user.userName = account;
|
|
|
|
User tmpuser = new User();
|
|
|
|
//172.16.1.92:8089
|
|
|
|
StartCoroutine(MyNetMQClient.InvokeWebPostByUploadhandler("http://"+MyNetMQClient.userIP+":8089/api/auth", JsonMapper.ToJson(user), (ok,result) =>
|
|
{
|
|
if (ok)
|
|
{
|
|
JsonData jd = JsonMapper.ToObject(result);
|
|
if (jd["success"].ValueAsBoolean())
|
|
{
|
|
sys_user tmp = new sys_user();
|
|
//在这里取数据
|
|
tmp.user_name = jd["value"]["userInfo"]["userName"].ToString();
|
|
if (jd["value"]["userInfo"]["userCode"] != null)
|
|
tmp.user_code = jd["value"]["userInfo"]["userCode"].ToString();
|
|
tmp.user_id = int.Parse(jd["value"]["userInfo"]["userId"].ToString());
|
|
if (jd["value"]["userInfo"]["deptId"] != null)
|
|
tmp.dept_id = int.Parse(jd["value"]["userInfo"]["deptId"].ToString());
|
|
if (jd["value"]["userInfo"]["jobId"] != null)
|
|
tmp.job_id = int.Parse(jd["value"]["userInfo"]["jobId"].ToString());
|
|
tmp.nickName = jd["value"]["userInfo"]["nickName"].ToString();
|
|
if (jd["value"]["userInfo"]["avatar"] != null)
|
|
tmp.avatar = jd["value"]["userInfo"]["avatar"].ToString();
|
|
if (jd["value"]["userInfo"]["certificateNumber"] != null)
|
|
tmp.introduce = jd["value"]["userInfo"]["certificateNumber"].ToString();
|
|
|
|
|
|
tmpuser.user = tmp;
|
|
//获取角色
|
|
StartCoroutine(MyNetMQClient.InvokeWebPostByUploadhandler("http://"+MyNetMQClient.userIP+":8087/role/queryRoleByUserId", JsonMapper.ToJson(new { userId = tmp.user_id.ToString() }), (ok2,result2) =>
|
|
{
|
|
if (ok2)
|
|
{
|
|
JsonData jd2 = JsonMapper.ToObject(result2);
|
|
if (jd2["success"].ValueAsBoolean())
|
|
{
|
|
foreach (JsonData item in jd2["value"])
|
|
{
|
|
string tmpcode=item["roleCode"].ToString();
|
|
|
|
UserType ut;
|
|
if(Enum.TryParse<UserType>(tmpcode, out ut))
|
|
{
|
|
tmpuser.userType.Add(ut);
|
|
Debug.Log("角色:" + tmpcode);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("未找到此角色:" + tmpcode);
|
|
}
|
|
|
|
}
|
|
|
|
//登录成功
|
|
LoadManage.Instance.me = tmpuser;
|
|
PlayerPrefs.SetString("HJZhangHu", account);
|
|
PlayerPrefs.SetString("HJMiMa", password);
|
|
|
|
if (LoadManage.Instance.systemMode == SystemMode.PC)
|
|
{
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene("MainSencePC");
|
|
}
|
|
else if (LoadManage.Instance.systemMode == SystemMode.MR)
|
|
{
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene("MainSenceMR");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessagePanel.ShowMessage(jd2["msg"].ToString(), canvas.transform, null);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessagePanel.ShowMessage(result2, canvas.transform, null);
|
|
}
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
MessagePanel.ShowMessage(jd["msg"].ToString(), canvas.transform, null);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessagePanel.ShowMessage(result, canvas.transform, null);
|
|
}
|
|
}));
|
|
}
|
|
}
|