119 lines
3.1 KiB
Lua
119 lines
3.1 KiB
Lua
|
|
local IdPasswordLoginView = {}
|
||
|
|
|
||
|
|
local M = IdPasswordLoginView
|
||
|
|
|
||
|
|
function IdPasswordLoginView.new(type, callback)
|
||
|
|
setmetatable(M, { __index = BaseWindow })
|
||
|
|
local self = setmetatable({}, { __index = M })
|
||
|
|
self.class = "IdPasswordLoginView"
|
||
|
|
self._callback = callback
|
||
|
|
self._close_destroy = true
|
||
|
|
self.codeType = type
|
||
|
|
self:init("ui://Login/IDLogin")
|
||
|
|
|
||
|
|
return self
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:init(url)
|
||
|
|
BaseWindow.init(self, url)
|
||
|
|
|
||
|
|
local btn_login = self._view:GetChild("btn_login")
|
||
|
|
btn_login.onClick:Add(handler(self, function()
|
||
|
|
self:login()
|
||
|
|
end))
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:login()
|
||
|
|
if self.codeType == 0 then
|
||
|
|
local uid = self:CheckInputId()
|
||
|
|
if not uid then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
local loginCtr = ControllerManager.GetController(LoginController)
|
||
|
|
local passwd = self:CheckInputPasswd()
|
||
|
|
if not passwd then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
ViewUtil.ShowModalWait2()
|
||
|
|
loginCtr:IdPasswordLogin(uid, passwd, function(res)
|
||
|
|
ViewUtil.CloseModalWait2()
|
||
|
|
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:CheckInputPhone()
|
||
|
|
if not phone then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
local code = self:CheckInputPhoneCode()
|
||
|
|
if not code then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
loginCtr:PhoneLogin(phone, code, function(res)
|
||
|
|
if res.ReturnCode ~= 0 then
|
||
|
|
local msg_txt = "验证码错误"
|
||
|
|
if (Table_Error_code_Map[res.ReturnCode] ~= nil) then
|
||
|
|
msg_txt = Table_Error_code_Map[res.ReturnCode].note
|
||
|
|
end
|
||
|
|
local guo_msg = MsgWindow.new(self._root_view, msg_txt, MsgWindow.MsgMode.OnlyOk)
|
||
|
|
guo_msg._new_hide = false
|
||
|
|
guo_msg:Show()
|
||
|
|
return
|
||
|
|
end
|
||
|
|
self._callback(res)
|
||
|
|
self:Destroy()
|
||
|
|
end)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:Destroy()
|
||
|
|
getmetatable(M).__index.Destroy(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) < 8 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 string.len(code) ~= 6 then
|
||
|
|
ViewUtil.ShowTips("请输入正确的验证码")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return code
|
||
|
|
end
|
||
|
|
|
||
|
|
return M
|