hengyang_client/lua_probject/base_project/Game/View/Lobby/PhoneLoginView2.lua

188 lines
5.6 KiB
Lua
Raw Normal View History

2025-11-06 17:37:53 +08:00
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._new_hide = false
self:init("ui://Lobby/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;
self.code = self._view:GetController("code")
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))
if DataManager.SelfUser._data_codeTiem and DataManager.SelfUser._data_codeTiem - os.time() > 0 then
self._left_time = DataManager.SelfUser._data_codeTiem - os.time()
self._view:GetChild("phone_input").text = DataManager.SelfUser._data_codephone
UpdateBeat:Add(self.OnUpdate, self)
self.code.selectedIndex = 1
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(LoddyController)
local passwd = self:CheckInputPasswd()
if not passwd then
return
end
loginCtr:IdPasswordLogin(uid, passwd, function(res)
ViewUtil.CloseModalWait2()
if res.ReturnCode ~= 0 then
if res.ReturnCode ~= 0 then
local guo_msg = MsgWindow.new(self._root_view, "验证码已发送", MsgWindow.MsgMode.OnlyOk)
guo_msg._new_hide = false
guo_msg:Show()
return
end
return
end
self._callback(res)
end)
else
---[[
--直接登入
local loginCtr = ControllerManager.GetController(LoddyController)
local phone = self:CheckInputPhone()
if not phone then
return
end
local code = self:CheckInputPhoneCode()
if not code then
return
end
loginCtr:PhoneBind(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:getCode()
local phone = self:CheckInputPhone()
if not phone then
self.code.selectedIndex = 0
return
end
--发送电话给后端
ViewUtil:ShowModalWait2(0.1)
local loginCtr = ControllerManager.GetController(LoginController)
loginCtr:GetPhoneCode(phone, function(res)
ViewUtil.CloseModalWait2()
if res.ReturnCode == 0 then
self.phone = phone
self._left_time = 60
DataManager.SelfUser._data_codeTiem = os.time() + 60
DataManager.SelfUser._data_codephone = phone
UpdateBeat:Add(self.OnUpdate, self)
else
if res.ReturnCode == 1 then
self._left_time = 15
DataManager.SelfUser._data_codeTiem = os.time() + 15
DataManager.SelfUser._data_codephone = phone
UpdateBeat:Add(self.OnUpdate, self)
ViewUtil.ErrorTip(self._root_view, "验证码还在有效期")
else
self.code.selectedIndex = 0
ViewUtil.ErrorTip(self._root_view, "网络超时,请重新获取验证码")
end
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 = 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 string.len(code) ~= 6 then
ViewUtil.ShowTips("请输入正确的验证码")
return
end
return code
end
return M