h5-down-app-tip.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="count" style="position: relative;z-index: 9999;">
  3. <!-- #ifdef H5 -->
  4. <view class="es-c es-share-bg-box">
  5. <image class="image x-c" src="/static/images/other/bg_bar.png"></image>
  6. <view class="es-bc-white x-c es-pt-10" style="width: 100%;">下载中康未来App,查看更多内容↓</view>
  7. <view class="line flex es-h-1 es-bc-fa"></view>
  8. <view class="es-bc-white x-bc es-pl-20 es-pr-20 es-pb-20 es-pt-10">
  9. <view class="left x-f">
  10. <image class="es-w-100 es-h-100 es-mr-20" style="flex-shrink: 0;" src="@/static/logo.png"></image>
  11. <view class="y-b">
  12. <view class="es-fs-30 es-fw-bold es-c-33 es-mb-10 x-f">中康未来</view>
  13. <view class="es-fs-26 es-fw-n es-c-33" style="text-align: left;">古籍·中药·方剂大全</view>
  14. </view>
  15. </view>
  16. <view class="es-br-20 es-w-250 es-bc es es-pc es-ac es-fw-bold es-fs-30" style="min-height: 80rpx;" @tap="openApp('btn')">
  17. <view class="es-ml-30 es-mr-30">App内打开</view>
  18. </view>
  19. <!-- <template v-if="isWechat">
  20. <wx-open-launch-app appid="" :extinfo="extinfo" @launch="AppLaunch" @error="AppError">
  21. <component :is="'script'" type="text/wxtag-template">
  22. <button id="footer-btn"
  23. style="min-height: 40px;border-radius: 10px;display: flex;align-items: center;justify-content: center;font-weight: 700;font-size: 15px;background: #2583EB;color: #fff">
  24. App内打开
  25. </button>
  26. </component>
  27. </wx-open-launch-app>
  28. </template> -->
  29. </view>
  30. </view>
  31. <!-- #endif -->
  32. </view>
  33. </template>
  34. <script>
  35. import * as wx from 'weixin-js-sdk'
  36. import {getWxConfig} from "@/api/common.js";
  37. export default {
  38. props: ['pageUrl','type','courseId'],
  39. data() {
  40. return {
  41. timer: null,
  42. isWechat: false,
  43. // 跳转所需额外信息
  44. extinfo: "zklive://pagesApp",
  45. }
  46. },
  47. created() {
  48. this.isWechat = String(navigator?.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger"
  49. // this.initWXConfig()
  50. },
  51. methods: {
  52. initWXConfig(packageVal) {
  53. if(this.isWechat) {
  54. const pagesUrl = encodeURIComponent(this.pageUrl)
  55. this.extinfo = "zklive://pagesApp?pagesUrl="+pagesUrl;
  56. let url = window.location.href.split('#')[0]
  57. let param ={
  58. url: encodeURIComponent(url)
  59. }
  60. uni.showLoading({
  61. title: '加载中'
  62. });
  63. getWxConfig(param).then(res => {
  64. uni.hideLoading();
  65. if (res.code == 200) {
  66. wx.config({
  67. debug: false,
  68. appId: res.data.appId,
  69. timestamp: res.data.timestamp,
  70. nonceStr: res.data.nonceStr,
  71. signature: res.data.signature,
  72. jsApiList: ['requestMerchantTransfer','updateAppMessageShareData'],
  73. openTagList: ['wx-open-launch-app']
  74. });
  75. wx.error(function(error){
  76. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  77. });
  78. } else {
  79. uni.showToast({
  80. title: res.msg,
  81. icon: 'none'
  82. })
  83. }
  84. }).catch(err=>{
  85. uni.hideLoading();
  86. })
  87. } else {
  88. // 非微信浏览器
  89. this.openApp()
  90. }
  91. },
  92. AppLaunch(e){
  93. console.log("success",e)
  94. },
  95. AppError(e){
  96. if(e.detail.errMsg == "launch:fail"){
  97. window.location.href = uni.getStorageSync('h5Path') + "/pages/index/appDownload";
  98. } else {
  99. uni.showToast({
  100. title: e.detail.errMsg,
  101. icon: 'error'
  102. })
  103. }
  104. },
  105. // 判断浏览器是否为头部APP(判断是否为微信或则其它APP浏览器,如果是则引导外置浏览器打开)
  106. isBlackApp() {
  107. var u = navigator.userAgent.toLowerCase();
  108. return /micromessenger/i.test(u) || u.indexOf("weibo") > -1 || u.indexOf("qq") > -1 || u.indexOf('mqqbrowser') > -1;
  109. },
  110. openApp(type){
  111. if(type == 'btn') {
  112. // 打开app,打不开跳转下载页
  113. const isOpenMode = this.isOpenMode()
  114. if(isOpenMode == 1 ||isOpenMode == 4) {
  115. if (this.isBlackApp() ) {
  116. // 头部APP让网页显示提示在浏览器中打开
  117. window.location.href = "https://m.malink.cn/s/yaIBJz"
  118. // uni.showToast({
  119. // title: '复制页面链接在浏览器中打开',
  120. // icon: 'none'
  121. // })
  122. } else {
  123. // 不是头部APP就直接打开
  124. const pagesUrl = encodeURIComponent(this.pageUrl)
  125. let schemeUrl = ''
  126. if(this.type == 'course') {
  127. schemeUrl = "zklive://course?courseId="+this.courseId;
  128. }else {
  129. // window.location.href="zklive://pagesApp?pagesUrl="+pagesUrl;
  130. schemeUrl = "zklive://pagesApp?pagesUrl="+pagesUrl;
  131. }
  132. this.jumpApp(schemeUrl);
  133. this.noApp();
  134. }
  135. }
  136. } else {
  137. // 直接打开,打不开不跳转
  138. const isOpenMode = this.isOpenMode()
  139. if(isOpenMode == 4) {
  140. const pagesUrl = encodeURIComponent(this.pageUrl)
  141. let schemeUrl = ''
  142. if(this.type == 'course') {
  143. schemeUrl = "zklive://course?courseId="+this.courseId;
  144. }else {
  145. // window.location.href="zklive://pagesApp?pagesUrl="+pagesUrl;
  146. schemeUrl = "zklive://pagesApp?pagesUrl="+pagesUrl;
  147. }
  148. this.jumpApp(schemeUrl);
  149. }
  150. }
  151. },
  152. // 跳转打开app
  153. jumpApp(t) {
  154. console.log(t, "===========》jumpApp");
  155. try {
  156. var e = navigator.userAgent.toLowerCase(),
  157. n = e.match(/cpu iphone os (.*?) like mac os/);
  158. if (((n = null !== n ? n[1].replace(/_/g, ".") : 0), parseInt(n) >= 9)) {
  159. //ios8之后的版本
  160. window.location.href = t;
  161. } else { //注意iOS8之前是可以使用iframe来实现的
  162. var r = document.createElement("iframe");
  163. (r.src = t), (r.style.display = "none"), document.body.appendChild(r);
  164. }
  165. } catch (e) {
  166. window.location.href = t;
  167. }
  168. },
  169. // 无响应或者没安装跳转下载
  170. noApp() {
  171. console.log("===========》noApp");
  172. var t = Date.now(),
  173. r = uni.getStorageSync('h5Path') + "/pages/index/appDownload";
  174. this.timer = setTimeout(()=> {
  175. return Date.now() - t > 3200 ?
  176. (clearTimeout(this.timer), !1) :
  177. !document.webkitHidden &&
  178. !document.hidden &&
  179. void(location.href = r);
  180. }, 3000);
  181. },
  182. isOpenMode() {
  183. //平台、设备和操作系统
  184. var system = {
  185. win: false,
  186. mac: false,
  187. xll: false,
  188. ipad: false
  189. };
  190. //检测平台
  191. var p = navigator.platform;
  192. system.win = p.indexOf("Win") == 0;
  193. system.mac = p.indexOf("Mac") == 0;
  194. system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
  195. system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;
  196. //跳转语句,如果是手机访问就自动跳转到wap.baidu.com页面
  197. if (system.win || system.mac || system.xll || system.ipad) {
  198. var ua = navigator.userAgent.toLowerCase();
  199. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  200. // alert("在PC端微信上打开的");
  201. return 2;
  202. } else {
  203. // alert("在PC端非微信上打开的");
  204. return 3;
  205. }
  206. } else {
  207. var ua = navigator.userAgent.toLowerCase();
  208. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  209. // alert("在手机端微信上打开的");
  210. return 1;
  211. } else {
  212. // alert("在手机上非微信上打开的");
  213. return 4;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .es-share-bg-box {
  222. position: fixed;
  223. z-index: 999;
  224. bottom: 0;
  225. left:0;
  226. width: 100%;
  227. text-align: center;
  228. .image{
  229. width: 100%;
  230. height:100rpx ;
  231. }
  232. }
  233. </style>