openApp.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const openApp = function (url) {
  2. const res = uni.getSystemInfoSync()
  3. var ua = window.navigator.userAgent.toLowerCase();
  4. if (ua.match(/MicroMessenger/i) == 'micromessenger' || ua.match(/WeiBo/i) == "weibo" || ua.match(/QQ/i) == "qqbrowser ") {
  5. uni.showToast({
  6. icon: 'none',
  7. title: '右上角在浏览器打开',
  8. mask: true
  9. })
  10. } else {
  11. if (res.platform === 'ios') {
  12. // window.location.href = `airsmart://?page=${page}&channel=${channel}&audioType=${audioType}&audioId=${audioId}`
  13. window.location.href = `airsmart://${url}&cmd=openPage`
  14. } else {
  15. // window.location.href = `airsmart://com.muzen.radioplayer:8888/main?page=${page}&channel=${channel}&audioType=${audioType}&audioId=${audioId}`
  16. window.location.href = `airsmart://muzen${url}&cmd=openPage`
  17. }
  18. var timer = setTimeout(() => {
  19. if (res.platform === 'ios') {
  20. window.location.href = 'itms-appss://itunes.apple.com/cn/app/apple-store/id1621419943?mt=8'
  21. } else {
  22. window.location.href = 'http://download.radio1964.com/readme?'
  23. }
  24. }, 3000)
  25. }
  26. document.addEventListener('visibilitychange', function () {
  27. if (document.hidden) {
  28. clearTimeout(timer)
  29. }
  30. })
  31. window.onpagehide = event => {
  32. if (event.persisted) {
  33. clearTimeout(timer)
  34. }
  35. }
  36. }
  37. export default openApp;