KLUserCenterPanel.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ---@class KLUserCenterPanel:UIKmlLuaPanelBase
  2. ---@field view KLUserCenterPanelView
  3. local KLUserCenterPanel = class(UIKmlLuaPanelBase)
  4. local this =KLUserCenterPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. end
  10. ---注册UI事件和服务器消息
  11. function this:RegistEvents()
  12. end
  13. ---界面显示时调用一次
  14. function this:Show()
  15. self.env = SL:GetMetaValue("CS_MAIN_ENV")
  16. if self.env == "local" then
  17. self.url = "http://10.28.1.136/userCenter"
  18. elseif self.env == "dev" then
  19. self.url = "http://192.168.13.43:100/userCenter"
  20. elseif self.env == "test" then
  21. self.url = "http://sdkh5-test.yq712.shengaowl.com/userCenter"
  22. elseif self.env == "pre" then
  23. self.url = "http://sdkh5.yq712.shengaowl.com/userCenter"
  24. elseif self.env == "release" then
  25. self.url = "http://sdkh5.yq712.shengaowl.com/userCenter"
  26. end
  27. ---@type UnityEngine.GameObject
  28. local obj = GUI:GetGameObject(self.view.prefab_webview)
  29. ---@type Vuplex.WebView.Core.Scripts.WebViewEx.WebViewControl
  30. self.webViewControl = obj:GetComponentInChildren(typeof(CS.Vuplex.WebView.Core.Scripts.WebViewEx.WebViewControl))
  31. self:LoadUrl(self.url .. "?time=" .. tostring(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)))
  32. if DebugFlag.LogEnable then
  33. log(self.url)
  34. end
  35. self.webViewControl:SetOnInitialized(function()
  36. self:SetSize(GUI:getSizeDelta(self.view.prefab_webview))
  37. end )
  38. self:SetMessageFun(self.OnMessage,self)
  39. end
  40. ---创建或者刷新界面数据时调用
  41. function this:Refresh()
  42. end
  43. function this:Hide()
  44. end
  45. function this:Close()
  46. end
  47. -------------------------------------------------------------------------Other
  48. function this:LoadUrl(url)
  49. self.webViewControl:LoadURL(url)
  50. end
  51. function this:SetSize(width, height)
  52. self.webViewControl:SetSize(width, height)
  53. end
  54. function this:SetMessageFun(fun,ui)
  55. self.webViewControl:SetMessageHandler(function(json)
  56. fun(ui,json)
  57. end)
  58. end
  59. -------------------------------------------------------------------------接受协议
  60. function this:OnMessage(jsonStr)
  61. local jsonTbl = json.decode(jsonStr)
  62. if DebugFlag.LogEnable then
  63. log(jsonStr)
  64. end
  65. if jsonTbl.action == 1003 then --1003 关闭sdk
  66. GUI:UIPanel_Close("dev/ui/WebView/Panel/KLUserCenter/KLUserCenterPanel")
  67. elseif jsonTbl.action == 1004 then --1004 打开隐私协议
  68. SL:OpenURL(jsonTbl.data)
  69. elseif jsonTbl.action == 2003 then --2003 退出登录
  70. self:SwitchToLogin()
  71. elseif jsonTbl.action == 2005 then --2005 注销账号
  72. self:SwitchToLogin()
  73. elseif jsonTbl.action == 2006 then --2006 切换账号
  74. self:SwitchToLogin()
  75. end
  76. end
  77. -------------------------------------------------------------------------function
  78. function this:SwitchToLogin()
  79. GUI:UIPanel_Open("dev/ui/WebView/Panel/KLUserLogin/KLUserLoginPanel")
  80. GUI:UIPanel_Close("dev/ui/Login/Panel/KLSelectGameLogin/KLSelectGameLoginPanel")
  81. GUI:UIPanel_Close("dev/ui/WebView/Panel/KLUserCenter/KLUserCenterPanel")
  82. end
  83. return this