index.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,viewport-fit=cover">
  6. <title>功道云</title>
  7. <script src="html5plus://ready"></script>
  8. <script src="static/js/polyfill.min.js"></script>
  9. <script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
  10. <script type="text/javascript" src="//open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script>
  11. <script>
  12. //某些情况下安卓没有提前注入plus对象,导致异常,有这种情况出现直接reload,直到plus存在
  13. if (window.navigator.userAgent.toLowerCase().match(/html5plus/i) == 'html5plus') {
  14. if (!window.plus) {
  15. window.location.reload()
  16. }
  17. }
  18. if (window.plus) {
  19. function set_item(key, val){
  20. if(window.plus){
  21. return plus.storage.setItem(key, val)
  22. }else{
  23. return localStorage.setItem(key, val)
  24. }
  25. }
  26. function get_item(key){
  27. if(window.plus){
  28. return plus.storage.getItem(key)
  29. }else{
  30. return localStorage.getItem(key)
  31. }
  32. }
  33. //plus.storage.removeItem('first_init')
  34. if(!get_item('first_init') && plus.webview.currentWebview().id == plus.runtime.appid){
  35. set_item('first_init', '1');
  36. plus.io.requestFileSystem( plus.io.PRIVATE_WWW, function( fs ) {
  37. var full_url = 'file://'+fs.root.fullPath+'init.html'
  38. var init_w = plus.webview.create(full_url,full_url);
  39. init_w.show()
  40. }, function ( e ) {
  41. console.log(e)
  42. } );
  43. }
  44. plus.navigator.setStatusBarStyle('light');
  45. document.documentElement.style.backgroundColor = '#26A2FF';
  46. plus.navigator.setStatusBarBackground('#26A2FF');
  47. function setBadgeNumber(newNum) {
  48. plus.runtime.setBadgeNumber(newNum);
  49. if (plus.os.name != 'Android') {
  50. var GeTuiSdk = plus.ios.importClass('GeTuiSdk');
  51. GeTuiSdk.setBadge(newNum);
  52. }
  53. }
  54. if (plus.navigator.isImmersedStatusbar()) {
  55. var bar_height = plus.navigator.getStatusbarHeight();
  56. document.documentElement.style.marginTop = bar_height + 'px';
  57. document.documentElement.style.height = 'calc(100vh - ' + bar_height + 'px)'
  58. document.documentElement.classList.add('app_view_html')
  59. var myEvent = new Event('resize');
  60. window.dispatchEvent(myEvent);
  61. plus.webview.currentWebview().setStyle({
  62. softinputMode: "adjustResize",
  63. })
  64. }
  65. var first = null
  66. //解决在hbuilder中ios打包后,获取焦点失效的bug
  67. //setInterval(function () {
  68. var wv_current = plus.webview.currentWebview().nativeInstanceObject()
  69. if (plus.os.name != 'Android') {
  70. wv_current.plusCallMethod({
  71. 'setKeyboardDisplayRequiresUserAction': false
  72. })
  73. }
  74. var webview = plus.webview.all();
  75. webview = webview[webview.length - 1]
  76. //}, 1000)
  77. plus.key.addEventListener('backbutton', function (e) {
  78. if (plus.storage.getItem('qr_scaning')) {
  79. return false;
  80. }
  81. webview.canBack(function (e) {
  82. if (e.canBack) {
  83. webview.back()
  84. } else {
  85. if (webview.id == plus.runtime.appid) {
  86. //首次按键,提示‘再按一次退出应用’
  87. if (!first) {
  88. first = new Date().getTime()
  89. plus.nativeUI.toast("再按一次退出应用");
  90. setTimeout(function () {
  91. first = null
  92. }, 1000)
  93. } else {
  94. if (new Date().getTime() - first < 1500) {
  95. plus.runtime.quit()
  96. }
  97. }
  98. } else {
  99. webview.close();
  100. }
  101. }
  102. })
  103. })
  104. var wgtVer = null;
  105. plus.runtime.getProperty(plus.runtime.appid, function (inf) {
  106. wgtVer = inf.version
  107. });
  108. }
  109. window.onload = function () {
  110. if(window.plus){
  111. document.body.classList.add('on_app')
  112. }
  113. (function (window) {
  114. window.addEventListener('focusout', function () {
  115. //软键盘收起的事件处理
  116. window.setTimeout(function () {
  117. if (!(document.activeElement && (document.activeElement.type == 'textarea' || document.activeElement.type == 'text' || document.activeElement.type == 'password' || document.activeElement.type == 'search'||document.activeElement.type == 'tel'))) {
  118. let ua = window.navigator.userAgent.toLowerCase();
  119. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  120. window.scroll(0, 0)
  121. }
  122. }
  123. }, 300)
  124. });
  125. var winW = document.documentElement.clientWidth || window.innerWidth
  126. if (winW > 750) {
  127. winW = 750
  128. }
  129. var fontSize = Math.round(winW / 7.5)
  130. if (fontSize % 2 > 0) {
  131. fontSize += 1
  132. }
  133. setInterval(function () {
  134. document.body.style.height = '100%'
  135. }, 100)
  136. document.documentElement.style.fontSize = fontSize + 'px'
  137. window.onresize = function () {
  138. if (window.plus) {
  139. setTimeout(function () {
  140. var bar_height = plus.navigator.getStatusbarHeight();
  141. document.documentElement.style.marginTop = bar_height + 'px';
  142. document.documentElement.style.backgroundColor = '#26A2FF';
  143. document.documentElement.style.height = 'calc(100vh - ' + bar_height + 'px)'
  144. }, 100)
  145. }
  146. var winW = document.documentElement.clientWidth || window.innerWidth
  147. document.body.clientWidth
  148. if (winW > 750) {
  149. winW = 750
  150. }
  151. fontSize = Math.round(winW / 7.5)
  152. if (fontSize % 2 > 0) {
  153. fontSize += 1
  154. }
  155. document.documentElement.style.fontSize = fontSize + 'px'
  156. }
  157. setTimeout(function () {
  158. document.body.style.opacity = 1;
  159. document.documentElement.style.opacity = 1;
  160. if (window.plus && plus.webview.currentWebview().id == plus.runtime.appid) {
  161. localStorage.setItem('window_height', plus.screen.resolutionHeight + 1)
  162. }
  163. }, 100)
  164. }(window))
  165. }
  166. </script>
  167. </head>
  168. <body style="opacity: 0">
  169. <div id="app"></div>
  170. <!-- built files will be auto injected -->
  171. </body>
  172. <!-- <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=a3b5fef4a3a2984284387ae5e2c340ed&plugin=AMap.Geocoder"></script>
  173. <script src="https://webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script> -->
  174. </html>