---@class KLUserLoginPanel:UIKmlLuaPanelBase ---@field view KLUserLoginPanelView local KLUserLoginPanel = class(UIKmlLuaPanelBase) local this = KLUserLoginPanel local EnvDatas = { ["local"] = { ["SDKUrl"] = "http://10.28.1.136/login", ["PlatformId"] = "0", ["GameId"] = "1", ["ChannelId"] = "65", ["ClientOS"] = "wap", }, ["dev"] = { ["SDKUrl"] = "http://192.168.13.43:100/login", ["PlatformId"] = "0", ["GameId"] = "1", ["ChannelId"] = "65", ["ClientOS"] = "wap", }, ["test"] = { ["SDKUrl"] = "http://sdkh5-test.yq712.shengaowl.com/login", ["PlatformId"] = "0", ["GameId"] = "76", ["ChannelId"] = "65", ["ClientOS"] = "wap", }, ["pre"] = { ["SDKUrl"] = "http://sdkh5.yq712.shengaowl.com/login", ["PlatformId"] = "0", ["GameId"] = "23", ["ChannelId"] = "4", ["ClientOS"] = "wap", }, ["release"] = { ["SDKUrl"] = "http://sdkh5.yq712.shengaowl.com/login", ["PlatformId"] = "0", ["GameId"] = "23", ["ChannelId"] = "4", ["ClientOS"] = "wap", }, } function this.SDKUrl() if EnvDatas[this.env] then return EnvDatas[this.env].SDKUrl end end function this.PlatformId() if EnvDatas[this.env] then return EnvDatas[this.env].PlatformId end end function this.GameId() if EnvDatas[this.env] then return EnvDatas[this.env].GameId end end function this.ChannelId() if EnvDatas[this.env] then return EnvDatas[this.env].ChannelId end end function this.ClientOS() if EnvDatas[this.env] then return EnvDatas[this.env].ClientOS end end function this:AsyncLoadUI() end ---创建时调用一次 function this:Init() end ---注册UI事件和服务器消息 function this:RegistEvents() end ---界面显示时调用一次 function this:Show() --self.IsSkip() GUI:SetActive(self.view.clickMask, true) GUI:SetActive(self.view.biaozhu, true) self.env = SL:GetMetaValue("CS_MAIN_ENV") this.env = self.env SL:OpenWaitingUI({ isTips = true, msg = "登录界面加载中...", waitTimeClose = 30, timeOutCallBack = function() SL:CommonTipsMessage({ showTips = "加载失败" }) end }) ---@type UnityEngine.GameObject local obj = GUI:GetGameObject(self.view.prefab_webview) ---@type Vuplex.WebView.Core.Scripts.WebViewEx.WebViewControl self.webViewControl = obj:GetComponentInChildren(typeof(CS.Vuplex.WebView.Core.Scripts.WebViewEx.WebViewControl)) self:LoadUrl(this.SDKUrl() .. "?time=" .. tostring(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME))) self.webViewControl:SetOnInitialized(function() self:SetSize(GUI:getSizeDelta(self.view.prefab_webview)) SL.LauncherUI:Close() end) self:SetMessageFun(self.OnMessage, self) end ---创建或者刷新界面数据时调用 function this:Refresh() end function this:Hide() end function this:Close() self.webViewControl:SetOnInitialized(nil) end -------------------------------------------------------------------------Other function this:LoadUrl(url) self.webViewControl:LoadURL(url) end function this:SetSize(width, height) self.webViewControl:SetSize(width, height) end function this:SendPageMsg() local channelId = SL:GetMetaValue("CHANNEL_ID") if string.isNullOrEmpty(channelId) then channelId = this.ChannelId() end -- 设置变量 local action = tostring(2002) local platformId = this.PlatformId() local gameId = this.GameId() channelId = this.ChannelId() -- 创建数据表 self.data = { platformId = platformId, channelId = channelId, gameId = gameId } -- 创建最终的消息表 self.msgTable = { data = self.data, action = action } -- 将表编码为JSON字符串 local msg = SL:JsonEncode(self.msgTable) SL:Log(msg) self:SendJsonMessage(msg) end function this:SendJsonMessage(json) self.webViewControl:SendJsonMessage(json) end function this:SetMessageFun(fun, ui) self.webViewControl:SetMessageHandler(function(json) fun(ui, json) end) end function this:OnMessage(jsonStr) local jsonTbl = SL:JsonDecode(jsonStr) SL:Log(jsonStr) if jsonTbl.action == 1003 then --1003 关闭sdk GUI:UIPanel_Close("dev/ui/WebView/Panel/KLUserLogin/KLUserLoginPanel") elseif jsonTbl.action == 1004 then --1004 打开隐私协议 SL:OpenURL(jsonTbl.data) elseif jsonTbl.action == 1005 then --1005 开始监听 if jsonTbl.data.action == 2002 then self:SendPageMsg() SL:HideWaitingUI() end elseif jsonTbl.action == 2002 then --2002 登录成功 self.sdkTokenData = jsonTbl local env = self.env GUI:UIPanel_Open("dev/ui/Login/Panel/KLSelectGameLogin/KLSelectGameLoginPanel", nil, nil, { sdkTokenData = self.sdkTokenData, msgData = self.data, env = env, clientOS = this.ClientOS() }) GUI:UIPanel_Close("dev/ui/WebView/Panel/KLUserLogin/KLUserLoginPanel") elseif jsonTbl.action == -2002 then --2002 登录失败 self.failSDKData = jsonTbl elseif jsonTbl.action == 2003 then --2003 退出登录 end end return this