h5-down-app-tip.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 v-if="!isWechat" 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. <!-- 此处的APPID为移动应用APPID -->
  21. <wx-open-launch-app appid="wx703c4bd07bbd1695" :extinfo="extinfo" @launch="AppLaunch" @error="AppError">
  22. <component :is="'script'" type="text/wxtag-template">
  23. <button id="footer-btn" class="es-br-20 es-w-250 es-bc es es-pc es-ac es-fw-bold es-fs-30 es-ml-30 es-mr-30" style="min-height: 80rpx;">
  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: "rtlive://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 = "rtlive://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. uni.showToast({
  118. title: '复制页面链接在浏览器中打开',
  119. icon: 'none'
  120. })
  121. } else {
  122. // 不是头部APP就直接打开
  123. const pagesUrl = encodeURIComponent(this.pageUrl)
  124. let schemeUrl = ''
  125. if(this.type == 'course') {
  126. schemeUrl = "rtlive://course?courseId="+this.courseId;
  127. }else {
  128. // window.location.href="rtlive://pagesApp?pagesUrl="+pagesUrl;
  129. schemeUrl = "rtlive://pagesApp?pagesUrl="+pagesUrl;
  130. }
  131. this.jumpApp(schemeUrl);
  132. this.noApp();
  133. }
  134. }
  135. } else {
  136. // 直接打开,打不开不跳转
  137. const isOpenMode = this.isOpenMode()
  138. if(isOpenMode == 4) {
  139. const pagesUrl = encodeURIComponent(this.pageUrl)
  140. let schemeUrl = ''
  141. if(this.type == 'course') {
  142. schemeUrl = "rtlive://course?courseId="+this.courseId;
  143. }else {
  144. // window.location.href="rtlive://pagesApp?pagesUrl="+pagesUrl;
  145. schemeUrl = "rtlive://pagesApp?pagesUrl="+pagesUrl;
  146. }
  147. this.jumpApp(schemeUrl);
  148. }
  149. }
  150. },
  151. // 跳转打开app
  152. jumpApp(t) {
  153. console.log(t, "===========》jumpApp");
  154. try {
  155. var e = navigator.userAgent.toLowerCase(),
  156. n = e.match(/cpu iphone os (.*?) like mac os/);
  157. if (((n = null !== n ? n[1].replace(/_/g, ".") : 0), parseInt(n) >= 9)) {
  158. //ios8之后的版本
  159. window.location.href = t;
  160. } else { //注意iOS8之前是可以使用iframe来实现的
  161. var r = document.createElement("iframe");
  162. (r.src = t), (r.style.display = "none"), document.body.appendChild(r);
  163. }
  164. } catch (e) {
  165. window.location.href = t;
  166. }
  167. },
  168. // 无响应或者没安装跳转下载
  169. noApp() {
  170. console.log("===========》noApp");
  171. var t = Date.now(),
  172. r = uni.getStorageSync('h5Path') + "/pages/index/appDownload";
  173. this.timer = setTimeout(()=> {
  174. return Date.now() - t > 3200 ?
  175. (clearTimeout(this.timer), !1) :
  176. !document.webkitHidden &&
  177. !document.hidden &&
  178. void(location.href = r);
  179. }, 3000);
  180. },
  181. isOpenMode() {
  182. //平台、设备和操作系统
  183. var system = {
  184. win: false,
  185. mac: false,
  186. xll: false,
  187. ipad: false
  188. };
  189. //检测平台
  190. var p = navigator.platform;
  191. system.win = p.indexOf("Win") == 0;
  192. system.mac = p.indexOf("Mac") == 0;
  193. system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
  194. system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;
  195. //跳转语句,如果是手机访问就自动跳转到wap.baidu.com页面
  196. if (system.win || system.mac || system.xll || system.ipad) {
  197. var ua = navigator.userAgent.toLowerCase();
  198. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  199. // alert("在PC端微信上打开的");
  200. return 2;
  201. } else {
  202. // alert("在PC端非微信上打开的");
  203. return 3;
  204. }
  205. } else {
  206. var ua = navigator.userAgent.toLowerCase();
  207. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  208. // alert("在手机端微信上打开的");
  209. return 1;
  210. } else {
  211. // alert("在手机上非微信上打开的");
  212. return 4;
  213. }
  214. }
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .es-share-bg-box {
  221. position: fixed;
  222. z-index: 999;
  223. bottom: 0;
  224. left:0;
  225. width: 100%;
  226. text-align: center;
  227. .image{
  228. width: 100%;
  229. height:100rpx ;
  230. }
  231. }
  232. </style>