extSdk.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. window.onResume = document.createEvent('Event');
  2. window.onResume.initEvent('onResume', true, true);
  3. window.WjySdk = {
  4. fnId : 0,
  5. cbList : [],
  6. }
  7. /**
  8. * 定时执行方法,防止ios里的延迟
  9. */
  10. WjySdk.run = function(funName,args,duration){
  11. var self = this,timer;
  12. duration = duration || 500;
  13. self[funName].apply(WjySdk,args);
  14. timer = setInterval(function(){
  15. if(typeof window.Wjy != "undefined"){
  16. clearInterval(timer);
  17. }
  18. self[funName].apply(WjySdk,args);
  19. },duration);
  20. }
  21. WjySdk.run2 = function(funName, args, duration){
  22. var self = this;
  23. var duration = duration || 500;
  24. var timer;
  25. var times = 0; //最大尝试次数
  26. if(typeof window.Wjy != "undefined") {
  27. self[funName].apply(WjySdk, args);
  28. } else {
  29. timer = setInterval(function(){
  30. //最多尝试5次
  31. if(typeof window.Wjy != "undefined" || times == 5){
  32. self[funName].apply(WjySdk, args);
  33. clearInterval(timer);
  34. } else {
  35. times += 1;
  36. }
  37. }, duration)
  38. }
  39. }
  40. /**
  41. * 检查注入状态
  42. * @param {String} name 方法名
  43. */
  44. WjySdk.checkInject = function(name) {
  45. if (typeof window.Wjy != "undefined") {
  46. if(typeof Wjy[name] == "undefined") {
  47. console.log('没有' + name + '这个方法')
  48. return false;
  49. } else {
  50. return true;
  51. }
  52. } else {
  53. console.log("js方法未注入!name:" + name)
  54. return false;
  55. }
  56. }
  57. WjySdk.callfn = function() {
  58. var _fnId = this.fnId++;
  59. var name = arguments[0];
  60. var param = [];
  61. for(var i = 1; i < arguments.length; i++) {
  62. if(typeof arguments[i] == "function") {
  63. this.cbList[_fnId] = arguments[i];
  64. arguments[i] = 'WjySdk.cbList[' + _fnId + ']';
  65. }
  66. param.push(arguments[i]);
  67. }
  68. if(this.checkInject(name)) {
  69. // console.log('Wjy[' + name + '](' + param.join(',') + ')');
  70. Wjy[name].apply(Wjy, param);
  71. return true;
  72. } else {
  73. // console.error('Wjy[' + name + '] is not exist.');
  74. return false;
  75. }
  76. }
  77. WjySdk.appBridge = function(uri) {
  78. var iframe = document.createElement("IFRAME");
  79. iframe.setAttribute('src', uri);
  80. document.documentElement.appendChild(iframe);
  81. iframe.parentNode.removeChild(iframe);
  82. iframe = null;
  83. }
  84. //已经反馈
  85. WjySdk.openFeedback = function(){
  86. return this.callfn("openFeedback");
  87. }
  88. //设置up主抽奖通知栏
  89. WjySdk.openNotificationSettingIfNeeded = function(msg){
  90. return this.callfn("openNotificationSettingIfNeeded",msg);
  91. }
  92. WjySdk.openLogin = function() {
  93. return this.callfn("openLogin");
  94. }
  95. WjySdk.getUserInfo = function(callback) {
  96. return this.callfn("getUserInfo", callback);
  97. }
  98. WjySdk.getDeviceInfo = function(callback) {
  99. return this.callfn("getDeviceInfo", callback);
  100. }
  101. WjySdk.openUrl = function(url, title, needTopBar) {
  102. title = title || '';
  103. needTopBar = needTopBar !== null ? needTopBar : true;
  104. return this.callfn("openUrl", url, title, needTopBar);
  105. }
  106. WjySdk.copy = function(txt) {
  107. return this.callfn("copy", txt);
  108. }
  109. WjySdk.historyBack = function() {
  110. return this.callfn("historyBack");
  111. }
  112. WjySdk.closeWebview = function() {
  113. return this.callfn("closeWebview");
  114. }
  115. WjySdk.setTitle = function(title) {
  116. return this.callfn("setTitle", title);
  117. }
  118. WjySdk.getNetworkType = function(callback) {
  119. return this.callfn("getNetworkType", callback);
  120. }
  121. WjySdk.getSupportShareType = function(callback) {
  122. return this.callfn("getSupportShareType", callback);
  123. }
  124. WjySdk.shareMessage = function(type, title, link, desc, imgUrl) {
  125. return this.callfn("shareMessage", type, title, link, desc, imgUrl);
  126. }
  127. WjySdk.showLoading = function(txt) {
  128. txt = txt || '正在加载中...';
  129. return this.callfn("showLoading", txt);
  130. }
  131. WjySdk.hideLoading = function() {
  132. return this.callfn("hideLoading");
  133. }
  134. WjySdk.showTip = function(txt, timeout) {
  135. return this.callfn("showTip", txt, timeout);
  136. }
  137. WjySdk.showErrorTip = function(txt, timeout) {
  138. if (window.Ouj && Ouj.showErrortip) {
  139. OujSdk.showTip(txt, timeout);
  140. } else {
  141. return this.callfn("showErrortip", txt, timeout);
  142. }
  143. }
  144. WjySdk.showDialog = function(txt) {
  145. return this.callfn("showDialog", txt);
  146. }
  147. WjySdk.confirm = function(txt, callback, title, buttonLables) {
  148. title = title || '提醒';
  149. buttonLables = buttonLables || '确定,取消';
  150. return this.callfn("confirm", title, txt, callback, buttonLables);
  151. }
  152. WjySdk.hideTopBar = function(flag) {
  153. return this.callfn("hideTopBar",flag);
  154. }
  155. WjySdk.hideMenuButton = function() {
  156. return this.callfn("hideMenuButton");
  157. }
  158. WjySdk.hideShare = function() {
  159. return this.callfn("hideShare");
  160. }
  161. WjySdk.aliPay = function(platformData, callback) {
  162. return this.callfn("aliPay", platformData, callback);
  163. }
  164. WjySdk.wxPay = function(platformData, callback) {
  165. if (typeof platformData == 'object') {
  166. platformData = JSON.stringify(platformData);
  167. }
  168. return this.callfn("wxPay", platformData, callback);
  169. }
  170. WjySdk.setShareInfo = function(title, link, desc, imgUrl) {
  171. return this.callfn("setShareInfo", title, link, desc, imgUrl);
  172. }
  173. WjySdk.toIndex = function() {
  174. return this.appBridge("glance://toIndex");
  175. }
  176. //预告片
  177. WjySdk.toVideoPreview = function(articleId) {
  178. return this.openUrl("glance://toVideoPreview?articleId="+articleId)
  179. }
  180. //解说视频
  181. WjySdk.toCommentaryDetail = function(commentaryId) {
  182. return this.openUrl("glance://toCommentaryDetail?commentaryId="+commentaryId)
  183. }
  184. //电影详情
  185. WjySdk.toVideoDetail = function(articleId) {
  186. return this.openUrl("glance://toVideoDetail?articleId="+articleId)
  187. }
  188. export default WjySdk;