jump.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <html>
  2. <head>
  3. <title>打开小程序</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
  7. <script>
  8. window.onerror = e => {
  9. console.error(e)
  10. alert('发生错误' + e)
  11. }
  12. </script>
  13. <!-- weui 样式 -->
  14. <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css">
  15. </link>
  16. <!-- 调试用的移动端 console -->
  17. <!-- <script src="https://cdn.jsdelivr.net/npm/eruda"></script> -->
  18. <!-- <script>eruda.init();</script> -->
  19. <!-- 公众号 JSSDK -->
  20. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  21. <!-- 云开发 Web SDK -->
  22. <script src="https://res.wx.qq.com/open/js/cloudbase/1.1.0/cloud.js"></script>
  23. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  24. <script>
  25. import {urlschemaGeneratee} from "../src/api/business/ticket";
  26. function docReady (fn) {
  27. if (document.readyState === 'complete' || document.readyState === 'interactive') {
  28. fn()
  29. } else {
  30. document.addEventListener('DOMContentLoaded', fn);
  31. }
  32. }
  33. docReady(async function () {
  34. var ua = navigator.userAgent.toLowerCase()
  35. var isWXWork = ua.match(/wxwork/i) == 'wxwork'
  36. var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
  37. var isMobile = false
  38. var isDesktop = false
  39. if (navigator.userAgent.match(
  40. /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
  41. isMobile = true
  42. } else {
  43. isDesktop = true
  44. }
  45. if (isWeixin) {
  46. var containerEl = document.getElementById('wechat-web-container')
  47. containerEl.classList.remove('hidden')
  48. containerEl.classList.add('full', 'wechat-web-container')
  49. var launchBtn = document.getElementById('launch-btn')
  50. launchBtn.addEventListener('ready', function (e) {
  51. console.log('开放标签 ready')
  52. })
  53. launchBtn.addEventListener('launch', function (e) {
  54. console.log('开放标签 success')
  55. })
  56. launchBtn.addEventListener('error', function (e) {
  57. console.log('开放标签 fail', e.detail)
  58. })
  59. wx.config({
  60. // debug: true, // 调试时可开启
  61. appId: 'wx8533800e393dbd6b', // <!-- replace -->
  62. timestamp: 0, // 必填,填任意数字即可
  63. nonceStr: 'nonceStr', // 必填,填任意非空字符串即可
  64. signature: 'signature', // 必填,填任意非空字符串即可
  65. jsApiList: ['chooseImage'], // 必填,随意一个接口即可
  66. openTagList: ['wx-open-launch-weapp'], // 填入打开小程序的开放标签名
  67. })
  68. } else if (isDesktop) {
  69. // 在 pc 上则给提示引导到手机端打开
  70. var containerEl = document.getElementById('desktop-web-container')
  71. containerEl.classList.remove('hidden')
  72. containerEl.classList.add('full', 'desktop-web-container')
  73. } else {
  74. var containerEl = document.getElementById('public-web-container')
  75. containerEl.classList.remove('hidden')
  76. containerEl.classList.add('full', 'public-web-container')
  77. var c = new cloud.Cloud({
  78. // 必填,表示是未登录模式
  79. identityless: true,
  80. // 资源方 AppID - 小程序 AppID
  81. resourceAppid: 'wx8533800e393dbd6b', // <!-- replace -->
  82. // 资源方环境 ID - 云开发环境 ID
  83. resourceEnv: 'mangpiao-prod-0gc3lhscbc41fb6e', // <!-- replace -->
  84. })
  85. await c.init()
  86. window.c = c
  87. var buttonEl = document.getElementById('public-web-jump-button')
  88. var buttonLoadingEl = document.getElementById('public-web-jump-button-loading')
  89. try {
  90. await openWeapp(() => {
  91. buttonEl.classList.remove('weui-btn_loading')
  92. buttonLoadingEl.classList.add('hidden')
  93. })
  94. } catch (e) {
  95. buttonEl.classList.remove('weui-btn_loading')
  96. buttonLoadingEl.classList.add('hidden')
  97. throw e
  98. }
  99. }
  100. })
  101. async function openWeapp (onBeforeJump) {
  102. function GetRequest (name) {
  103. var url = window.parent.location.search; //获取url中"?"符后的字串
  104. // var theRequest = new Object();
  105. if (url.indexOf("?") != -1) {
  106. var str = url.substr(1);
  107. if (str.indexOf("#" != -1)) {
  108. str = str.substr(0);
  109. }
  110. strs = str.split("&");
  111. for (var i = 0; i < strs.length; i++) {
  112. if (strs[i].indexOf(name) != -1) {
  113. return strs[i].split("=")[1];
  114. }
  115. }
  116. }
  117. // return strs || null;
  118. }
  119. var aa = GetRequest()
  120. urlschemaGeneratee({}).then(res => {
  121. console.log('res', res)
  122. })
  123. }
  124. </script>
  125. <style>
  126. .hidden {
  127. display: none;
  128. }
  129. .full {
  130. position: absolute;
  131. top: 0;
  132. bottom: 0;
  133. left: 0;
  134. right: 0;
  135. }
  136. .public-web-container {
  137. display: flex;
  138. flex-direction: column;
  139. align-items: center;
  140. }
  141. .public-web-container p {
  142. position: absolute;
  143. top: 40%;
  144. }
  145. .public-web-container a {
  146. position: absolute;
  147. bottom: 40%;
  148. }
  149. .wechat-web-container {
  150. display: flex;
  151. flex-direction: column;
  152. align-items: center;
  153. }
  154. .wechat-web-container p {
  155. position: absolute;
  156. top: 40%;
  157. }
  158. .wechat-web-container wx-open-launch-weapp {
  159. position: absolute;
  160. bottom: 40%;
  161. left: 0;
  162. right: 0;
  163. display: flex;
  164. flex-direction: column;
  165. align-items: center;
  166. }
  167. .desktop-web-container {
  168. display: flex;
  169. flex-direction: column;
  170. align-items: center;
  171. }
  172. .desktop-web-container p {
  173. position: absolute;
  174. top: 40%;
  175. }
  176. </style>
  177. </head>
  178. <body>
  179. <div className="page full">
  180. <div id="public-web-container" className="hidden">
  181. <p className="">正在打开 “盲票小程序”...</p> <!-- replace -->
  182. <a id="public-web-jump-button" href="javascript:"
  183. className="weui-btn weui-btn_primary weui-btn_loading"
  184. onClick="openWeapp()">
  185. <span id="public-web-jump-button-loading"
  186. className="weui-primary-loading weui-primary-loading_transparent"><i
  187. className="weui-primary-loading__dot"></i></span>
  188. 打开小程序
  189. </a>
  190. </div>
  191. <div id="wechat-web-container" className="hidden">
  192. <p className="">点击以下按钮打开 “盲票小程序”</p> <!-- replace -->
  193. <!-- 跳转小程序的开放标签。文档 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html -->
  194. <wx-open-launch-weapp id="launch-btn" username="gh_cf2872611f66"
  195. path="pages/index/index?id=123456"
  196. env-version="trial">
  197. <!-- replace -->
  198. <template>
  199. <button
  200. style="width: 200px; height: 45px; text-align: center; font-size: 17px; display: block; margin: 0 auto; padding: 8px 24px; border: none; border-radius: 4px; background-color: #07c160; color:#fff;">
  201. 打开小程序
  202. </button>
  203. </template>
  204. </wx-open-launch-weapp>
  205. </div>
  206. <div id="desktop-web-container" className="hidden">
  207. <p className="">请在手机打开网页链接</p>
  208. </div>
  209. </div>
  210. </body>
  211. </html>