KLUserLoginPanel.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. ---@class KLUserLoginPanel:UIKmlLuaPanelBase
  2. ---@field view KLUserLoginPanelView
  3. local KLUserLoginPanel = class(UIKmlLuaPanelBase)
  4. local this = KLUserLoginPanel
  5. local EnvDatas = {
  6. ["local"] = {
  7. ["SDKUrl"] = "http://10.28.1.136/login",
  8. ["PlatformId"] = "0",
  9. ["GameId"] = "1",
  10. ["ChannelId"] = "65",
  11. ["ClientOS"] = "wap",
  12. },
  13. ["dev"] = {
  14. ["SDKUrl"] = "http://192.168.13.43:100/login",
  15. ["PlatformId"] = "0",
  16. ["GameId"] = "1",
  17. ["ChannelId"] = "65",
  18. ["ClientOS"] = "wap",
  19. },
  20. ["test"] = {
  21. ["SDKUrl"] = "http://sdkh5-test.yq712.shengaowl.com/login",
  22. ["PlatformId"] = "0",
  23. ["GameId"] = "76",
  24. ["ChannelId"] = "65",
  25. ["ClientOS"] = "wap",
  26. },
  27. ["pre"] = {
  28. ["SDKUrl"] = "http://sdkh5.yq712.shengaowl.com/login",
  29. ["PlatformId"] = "0",
  30. ["GameId"] = "23",
  31. ["ChannelId"] = "4",
  32. ["ClientOS"] = "wap",
  33. },
  34. ["release"] = {
  35. ["SDKUrl"] = "http://sdkh5.yq712.shengaowl.com/login",
  36. ["PlatformId"] = "0",
  37. ["GameId"] = "23",
  38. ["ChannelId"] = "4",
  39. ["ClientOS"] = "wap",
  40. },
  41. }
  42. function this.SDKUrl()
  43. if EnvDatas[this.env] then
  44. return EnvDatas[this.env].SDKUrl
  45. end
  46. end
  47. function this.PlatformId()
  48. if EnvDatas[this.env] then
  49. return EnvDatas[this.env].PlatformId
  50. end
  51. end
  52. function this.GameId()
  53. if EnvDatas[this.env] then
  54. return EnvDatas[this.env].GameId
  55. end
  56. end
  57. function this.ChannelId()
  58. if EnvDatas[this.env] then
  59. return EnvDatas[this.env].ChannelId
  60. end
  61. end
  62. function this.ClientOS()
  63. if EnvDatas[this.env] then
  64. return EnvDatas[this.env].ClientOS
  65. end
  66. end
  67. function this:AsyncLoadUI()
  68. end
  69. ---创建时调用一次
  70. function this:Init()
  71. end
  72. ---注册UI事件和服务器消息
  73. function this:RegistEvents()
  74. end
  75. ---界面显示时调用一次
  76. function this:Show()
  77. --self.IsSkip()
  78. GUI:SetActive(self.view.clickMask, true)
  79. GUI:SetActive(self.view.biaozhu, true)
  80. self.env = SL:GetMetaValue("CS_MAIN_ENV")
  81. this.env = self.env
  82. SL:OpenWaitingUI({ isTips = true, msg = "登录界面加载中...", waitTimeClose = 30, timeOutCallBack = function()
  83. SL:CommonTipsMessage({ showTips = "加载失败" })
  84. end })
  85. ---@type UnityEngine.GameObject
  86. local obj = GUI:GetGameObject(self.view.prefab_webview)
  87. ---@type Vuplex.WebView.Core.Scripts.WebViewEx.WebViewControl
  88. self.webViewControl = obj:GetComponentInChildren(typeof(CS.Vuplex.WebView.Core.Scripts.WebViewEx.WebViewControl))
  89. self:LoadUrl(this.SDKUrl() .. "?time=" .. tostring(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)))
  90. self.webViewControl:SetOnInitialized(function()
  91. self:SetSize(GUI:getSizeDelta(self.view.prefab_webview))
  92. SL.LauncherUI:Close()
  93. end)
  94. self:SetMessageFun(self.OnMessage, self)
  95. end
  96. ---创建或者刷新界面数据时调用
  97. function this:Refresh()
  98. end
  99. function this:Hide()
  100. end
  101. function this:Close()
  102. self.webViewControl:SetOnInitialized(nil)
  103. end
  104. -------------------------------------------------------------------------Other
  105. function this:LoadUrl(url)
  106. self.webViewControl:LoadURL(url)
  107. end
  108. function this:SetSize(width, height)
  109. self.webViewControl:SetSize(width, height)
  110. end
  111. function this:SendPageMsg()
  112. local channelId = SL:GetMetaValue("CHANNEL_ID")
  113. if string.isNullOrEmpty(channelId) then
  114. channelId = this.ChannelId()
  115. end
  116. -- 设置变量
  117. local action = tostring(2002)
  118. local platformId = this.PlatformId()
  119. local gameId = this.GameId()
  120. channelId = this.ChannelId()
  121. -- 创建数据表
  122. self.data = {
  123. platformId = platformId,
  124. channelId = channelId,
  125. gameId = gameId
  126. }
  127. -- 创建最终的消息表
  128. self.msgTable = {
  129. data = self.data,
  130. action = action
  131. }
  132. -- 将表编码为JSON字符串
  133. local msg = SL:JsonEncode(self.msgTable)
  134. SL:Log(msg)
  135. self:SendJsonMessage(msg)
  136. end
  137. function this:SendJsonMessage(json)
  138. self.webViewControl:SendJsonMessage(json)
  139. end
  140. function this:SetMessageFun(fun, ui)
  141. self.webViewControl:SetMessageHandler(function(json)
  142. fun(ui, json)
  143. end)
  144. end
  145. function this:OnMessage(jsonStr)
  146. local jsonTbl = SL:JsonDecode(jsonStr)
  147. SL:Log(jsonStr)
  148. if jsonTbl.action == 1003 then
  149. --1003 关闭sdk
  150. GUI:UIPanel_Close("dev/ui/WebView/Panel/KLUserLogin/KLUserLoginPanel")
  151. elseif jsonTbl.action == 1004 then
  152. --1004 打开隐私协议
  153. SL:OpenURL(jsonTbl.data)
  154. elseif jsonTbl.action == 1005 then
  155. --1005 开始监听
  156. if jsonTbl.data.action == 2002 then
  157. self:SendPageMsg()
  158. SL:HideWaitingUI()
  159. end
  160. elseif jsonTbl.action == 2002 then
  161. --2002 登录成功
  162. self.sdkTokenData = jsonTbl
  163. local env = self.env
  164. GUI:UIPanel_Open("dev/ui/Login/Panel/KLSelectGameLogin/KLSelectGameLoginPanel", nil, nil, { sdkTokenData = self.sdkTokenData, msgData = self.data, env = env, clientOS = this.ClientOS() })
  165. GUI:UIPanel_Close("dev/ui/WebView/Panel/KLUserLogin/KLUserLoginPanel")
  166. elseif jsonTbl.action == -2002 then
  167. --2002 登录失败
  168. self.failSDKData = jsonTbl
  169. elseif jsonTbl.action == 2003 then
  170. --2003 退出登录
  171. end
  172. end
  173. return this