189 lines
5.5 KiB
Lua
189 lines
5.5 KiB
Lua
|
|
local PhoneLoginView = {}
|
||
|
|
|
||
|
|
local M = PhoneLoginView
|
||
|
|
|
||
|
|
function PhoneLoginView.new(type, callback)
|
||
|
|
setmetatable(M, { __index = BaseWindow })
|
||
|
|
local self = setmetatable({}, { __index = M })
|
||
|
|
self.class = "PhoneLoginView"
|
||
|
|
self._callback = callback
|
||
|
|
self._close_destroy = true
|
||
|
|
self.codeType = type
|
||
|
|
self:init("ui://Login/PhnoeLogin")
|
||
|
|
|
||
|
|
return self
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:init(url)
|
||
|
|
BaseWindow.init(self, url)
|
||
|
|
self.login_type = self._view:GetController("type")
|
||
|
|
self.login_type.selectedIndex = self.codeType;
|
||
|
|
|
||
|
|
local btn_login = self._view:GetChild("btn_login")
|
||
|
|
btn_login.onClick:Add(handler(self, function()
|
||
|
|
self:login()
|
||
|
|
end))
|
||
|
|
|
||
|
|
local btn_getCode = self._view:GetChild("btn_code_send")
|
||
|
|
btn_getCode.onClick:Add(handler(self, function()
|
||
|
|
self:getCode()
|
||
|
|
end))
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:login()
|
||
|
|
if self.codeType == 0 then
|
||
|
|
local uid = self:CheckInputId()
|
||
|
|
if not uid then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
ViewUtil.ShowModalWait(self._root_view, "正在登录游戏...")
|
||
|
|
local loginCtr = ControllerManager.GetController(LoginController)
|
||
|
|
local passwd = self:CheckInputPasswd()
|
||
|
|
if not passwd then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
loginCtr:IdPasswordLogin(uid, passwd, function(res)
|
||
|
|
ViewUtil.CloseModalWait()
|
||
|
|
if res.ReturnCode ~= 0 then
|
||
|
|
ViewUtil.ErrorTip(res.ReturnCode, "ID或者密码错误")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
self._callback(res)
|
||
|
|
end)
|
||
|
|
else
|
||
|
|
---[[
|
||
|
|
--直接登入
|
||
|
|
local loginCtr = ControllerManager.GetController(LoginController)
|
||
|
|
|
||
|
|
local phone = self._view:GetChild("phone_input").text
|
||
|
|
if not phone then
|
||
|
|
ViewUtil.ShowTips("请输入账号")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
loginCtr:IdPasswordLogin(phone, "123456", function(res)
|
||
|
|
if res.ReturnCode ~= 0 then
|
||
|
|
ViewUtil.ErrorTip(self._root_view, "ID或者密码错误")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
self._callback(res)
|
||
|
|
end)
|
||
|
|
--]]
|
||
|
|
local code = self:CheckInputPhoneCode()
|
||
|
|
if not code then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
ViewUtil.ShowModalWait(self._root_view, "正在登录游戏...")
|
||
|
|
local phone = self:CheckInputPhone()
|
||
|
|
if not phone then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
local loginCtr = ControllerManager.GetController(LoginController)
|
||
|
|
if false then
|
||
|
|
loginCtr:PhoneLogin(phone, code, function(res)
|
||
|
|
ViewUtil.CloseModalWait()
|
||
|
|
if res.ReturnCode == "100" then
|
||
|
|
ViewUtil.ErrorTip(self._root_view, "验证码错误")
|
||
|
|
elseif res.ReturnCode == "101" then
|
||
|
|
ViewUtil.ErrorTip(self._root_view, "验证码失效")
|
||
|
|
end
|
||
|
|
self._callback(res)
|
||
|
|
end)
|
||
|
|
else
|
||
|
|
--测试先假验证
|
||
|
|
if code == "7777" then
|
||
|
|
loginCtr:IdPasswordLogin("168168", "123456", function(res)
|
||
|
|
if res.ReturnCode ~= 0 then
|
||
|
|
ViewUtil.ErrorTip(self._root_view, "ID或者密码错误")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
self._callback(res)
|
||
|
|
end)
|
||
|
|
elseif code == "6666" then
|
||
|
|
ViewUtil.ErrorTip(self._root_view, "验证码错误")
|
||
|
|
else
|
||
|
|
ViewUtil.ErrorTip(self._root_view, "验证码失效")
|
||
|
|
end
|
||
|
|
ViewUtil.CloseModalWait()
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:getCode()
|
||
|
|
local phone = self:CheckInputPhone()
|
||
|
|
if not phone then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
--发送电话给后端
|
||
|
|
local loginCtr = ControllerManager.GetController(LoginController)
|
||
|
|
loginCtr:GetPhoneCode(phone, function(res)
|
||
|
|
if res.ReturnCode == 0 then
|
||
|
|
self.code = self._view:GetController("code")
|
||
|
|
self.code.selectedIndex = 1;
|
||
|
|
self._left_time = 15
|
||
|
|
UpdateBeat:Add(self.OnUpdate, self)
|
||
|
|
else
|
||
|
|
ViewUtil.ErrorTip(self._root_view, "验证码发送失败")
|
||
|
|
end
|
||
|
|
end)
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:OnUpdate()
|
||
|
|
local deltaTime = Time.deltaTime
|
||
|
|
local _left_time = self._left_time
|
||
|
|
if (_left_time > 0) then
|
||
|
|
_left_time = _left_time - deltaTime
|
||
|
|
_left_time = math.max(0, _left_time)
|
||
|
|
local leftTime = math.floor(_left_time)
|
||
|
|
self._view:GetChild("code_send_text").text = tostring(leftTime) .. "后重新发送"
|
||
|
|
self._left_time = _left_time
|
||
|
|
else
|
||
|
|
self.code.selectedIndex.selectedIndex = 0
|
||
|
|
UpdateBeat:Remove(self.OnUpdate, self)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:Destroy()
|
||
|
|
BaseWindow.Destroy(self)
|
||
|
|
UpdateBeat:Remove(self.OnUpdate, self)
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:CheckInputId()
|
||
|
|
local uid = self._view:GetChild("phone_input").text
|
||
|
|
if not (string.len(uid) >= 6) then
|
||
|
|
ViewUtil.ShowTips("请输入正确的用户ID")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return uid
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:CheckInputPasswd()
|
||
|
|
local tex_passwd = self._view:GetChild("tex_passwd").text
|
||
|
|
if string.len(tex_passwd) < 6 then
|
||
|
|
ViewUtil.ShowTips("密码最少六位")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return tex_passwd
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:CheckInputPhone()
|
||
|
|
local phone = self._view:GetChild("phone_input").text
|
||
|
|
if not (string.len(phone) == 11) then
|
||
|
|
ViewUtil.ShowTips("请输入正确的电话号码")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return phone
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:CheckInputPhoneCode()
|
||
|
|
local code = self._view:GetChild("code_input").text
|
||
|
|
if not (string.len(code) >= 4) then
|
||
|
|
ViewUtil.ShowTips("请输入正确的验证码")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return code
|
||
|
|
end
|
||
|
|
|
||
|
|
return M
|