WebView.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const UIHelper = require("UIHelper");
  2. var WebViewNode = null;
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. },
  7. onLoad: function () {
  8. },
  9. update: function (dt) {
  10. },
  11. hide:function(){
  12. if(WebViewNode){
  13. WebViewNode.active = false;
  14. cc.vv.reflection.changeOrientation("Landscape");
  15. }
  16. },
  17. onWebviewEvent:function(Target,data){
  18. /*if(Target.url == ""){
  19. return;
  20. }
  21. if(WebViewNode){
  22. setTimeout(() => {
  23. WebViewNode.getChildByName("WaitNode").active = false;
  24. WebViewNode.getChildByName("WebView").opacity = 255;
  25. cc.vv.reflection.changeOrientation("Portrait");
  26. }, 2000);
  27. }*/
  28. },
  29. statics:{
  30. createWebViewNode:function() {
  31. WebViewNode = null;
  32. if(!WebViewNode) {
  33. cc.resources.load("GamePrefabs/Public/WebViewNode", cc.Prefab, function (err, prefab) {
  34. var runScene = cc.director.getScene();
  35. WebViewNode = cc.instantiate(prefab);
  36. WebViewNode.parent = runScene;
  37. WebViewNode.name ="WebViewNode";
  38. WebViewNode.setPosition(cc.winSize.width / 2, cc.winSize.height / 2);
  39. WebViewNode.active = false;
  40. });
  41. }
  42. },
  43. isActive(){
  44. if(WebViewNode){
  45. return WebViewNode.active;
  46. }
  47. return false;
  48. },
  49. openURL:function(url){
  50. UIHelper.showWaitNode();
  51. let startTime = Date.now();
  52. WebViewNode.getChildByName("WebView").getComponent(cc.WebView).loadURL(
  53. url,
  54. () => {
  55. UIHelper.hideWaitNode();
  56. WebViewNode.active = true;
  57. cc.vv.reflection.changeOrientation("Portrait");
  58. },
  59. null,
  60. () => {
  61. UIHelper.hideWaitNode();
  62. Global.print("WebView:: openURL: 载入URL发生问题(" + url + ")")
  63. });
  64. },
  65. close:function(){
  66. WebViewNode.active = false;
  67. cc.vv.reflection.changeOrientation("Landscape");
  68. },
  69. },
  70. });