160 lines
5.3 KiB
C#
160 lines
5.3 KiB
C#
|
|
using Assets.Scripts;
|
|||
|
|
using Newtonsoft.Json.Linq;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
public class AppleInfoController : PFUIPanel
|
|||
|
|
{
|
|||
|
|
public Action afterClose = null;
|
|||
|
|
private SignForm signForm;
|
|||
|
|
private Dictionary<string, Selectable> signFormDict;
|
|||
|
|
public bool startCaptcha = false;
|
|||
|
|
|
|||
|
|
protected override void Awake()
|
|||
|
|
{
|
|||
|
|
UIManager.AddEvent(transform.Find("FormContainer-Sign/btnClose").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|||
|
|
{
|
|||
|
|
Close();
|
|||
|
|
//if (afterClose != null)
|
|||
|
|
//{
|
|||
|
|
// afterClose.Invoke();
|
|||
|
|
//}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
signForm = new SignForm()
|
|||
|
|
{
|
|||
|
|
email = transform.Find("FormContainer-Sign/FirstPage/Email").GetComponent<InputField>(),
|
|||
|
|
captcha = transform.Find("FormContainer-Sign/FirstPage/Captcha").GetComponent<InputField>(),
|
|||
|
|
password = transform.Find("FormContainer-Sign/FirstPage/Password").GetComponent<InputField>(),
|
|||
|
|
cpassword = transform.Find("FormContainer-Sign/FirstPage/CPassword").GetComponent<InputField>(),
|
|||
|
|
};
|
|||
|
|
signFormDict = new Dictionary<string, Selectable>
|
|||
|
|
{
|
|||
|
|
{ "Phone",signForm.email},
|
|||
|
|
{ "Captcha",signForm.captcha},
|
|||
|
|
{ "Pwd",signForm.password},
|
|||
|
|
{ "CPwd",signForm.cpassword},
|
|||
|
|
};
|
|||
|
|
signPage1 = transform.Find("FormContainer-Sign/FirstPage");
|
|||
|
|
UIManager.AddEvent(signPage1.Find("Captcha").Find("BtnGet").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|||
|
|
{
|
|||
|
|
GetCaptcha();
|
|||
|
|
});
|
|||
|
|
UIManager.AddEvent(signPage1.Find("next").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|||
|
|
{
|
|||
|
|
Submit();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private async void Submit()
|
|||
|
|
{
|
|||
|
|
if (signForm.password.text != signForm.cpassword.text)
|
|||
|
|
{
|
|||
|
|
Utils.SetValidate(signFormDict, JArray.FromObject(new object[]
|
|||
|
|
{
|
|||
|
|
new { Field="Pwd"},
|
|||
|
|
new { Field="CPwd"},
|
|||
|
|
}));
|
|||
|
|
Utils.showToast(gameObject, "Two password entries are inconsistent");//两次密码输入不一致
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
var res = await ConfigHelper.userApi.AppleCompleteInfo(signForm.email.text, signForm.captcha.text, signForm.password.text);
|
|||
|
|
if (res.result)
|
|||
|
|
{
|
|||
|
|
Utils.showToast(null, App.GetLocalString("Success"), type: 1);
|
|||
|
|
App.CurrentUser.Phone = signForm.email.text;
|
|||
|
|
if (afterClose != null)
|
|||
|
|
{
|
|||
|
|
afterClose.Invoke();
|
|||
|
|
}
|
|||
|
|
Close();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Utils.SetValidate(signFormDict, JArray.FromObject(res.data));
|
|||
|
|
Utils.showToast(null, res.errMsg);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
float timer = 1f;
|
|||
|
|
int time = 60;
|
|||
|
|
Transform signPage1;
|
|||
|
|
async void GetCaptcha()
|
|||
|
|
{
|
|||
|
|
var btn = signPage1.Find("Captcha").Find("BtnGet");
|
|||
|
|
btn.GetComponent<Button>().enabled = false;
|
|||
|
|
btn.GetComponent<Button>().interactable = false;
|
|||
|
|
var btnText = btn.Find("Text").GetComponent<Text>();
|
|||
|
|
var Email = signForm.email;
|
|||
|
|
var r = await ConfigHelper.userApi.GetCaptcha(Email.text);
|
|||
|
|
//Timer t = new Ti
|
|||
|
|
if (r.result)
|
|||
|
|
{
|
|||
|
|
//if (r.data.Value<bool>("isExist"))
|
|||
|
|
//{
|
|||
|
|
// signPage1.Find("Password").gameObject.SetActive(false);
|
|||
|
|
// signPage1.Find("CPassword").gameObject.SetActive(false);
|
|||
|
|
//}
|
|||
|
|
//else
|
|||
|
|
//{
|
|||
|
|
// signPage1.Find("Password").gameObject.SetActive(true);
|
|||
|
|
// signPage1.Find("CPassword").gameObject.SetActive(true);
|
|||
|
|
//}
|
|||
|
|
time = 60;
|
|||
|
|
btnText.text = $"Again({time})";
|
|||
|
|
btn.GetComponent<Button>().enabled = false;
|
|||
|
|
btn.GetComponent<Button>().interactable = false;
|
|||
|
|
startCaptcha = true;
|
|||
|
|
//timer.Interval = 1000;
|
|||
|
|
//timer.AutoReset = true;
|
|||
|
|
//timer.Elapsed += new ElapsedEventHandler(CaptchaTimerTick);
|
|||
|
|
//timer.Enabled = true;
|
|||
|
|
//btnGet.
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
btn.GetComponent<Button>().enabled = true;
|
|||
|
|
btn.GetComponent<Button>().interactable = true;
|
|||
|
|
Utils.showToast(gameObject, r.errMsg);
|
|||
|
|
Utils.SetValidate(signFormDict, r.errFieldMsg);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CaptchaTimerTick()
|
|||
|
|
{
|
|||
|
|
timer -= Time.deltaTime;
|
|||
|
|
if (timer <= 0)
|
|||
|
|
{
|
|||
|
|
var btn = signPage1.Find("Captcha").Find("BtnGet");
|
|||
|
|
var btnText = signPage1.Find("Captcha").Find("BtnGet").Find("Text").GetComponent<Text>();
|
|||
|
|
btnText.text = $"{App.GetLocalString("Again")}({time--})";
|
|||
|
|
if (time < 0)
|
|||
|
|
{
|
|||
|
|
btnText.text = App.GetLocalString("Get");
|
|||
|
|
btn.GetComponent<Button>().enabled = true;
|
|||
|
|
btn.GetComponent<Button>().interactable = true;
|
|||
|
|
startCaptcha = false;
|
|||
|
|
//timer.Stop();
|
|||
|
|
}
|
|||
|
|
timer += 1.0f;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// Start is called before the first frame update
|
|||
|
|
void Start()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Update is called once per frame
|
|||
|
|
void Update()
|
|||
|
|
{
|
|||
|
|
if (startCaptcha)
|
|||
|
|
{
|
|||
|
|
CaptchaTimerTick();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|