openExternalUrl.js 887 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { openPayWebview } from '@/hooks/usePayWebview'
  2. /**
  3. * 打开外部链接
  4. * @param {string} url
  5. * @param {string} [type] 'pay' 支付页:App 内 webview 页,H5 弹窗 iframe
  6. * @param {{ title?: string }} [options]
  7. */
  8. export function openExternalUrl(url, type, options = {}) {
  9. if (!url) return
  10. const title = options.title || 'Shop.Order.OrderDetails'
  11. if (type === 'pay') {
  12. // #ifdef APP-PLUS
  13. const webviewUrl = `/pages/common/webview?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}`
  14. uni.navigateTo({ url: webviewUrl })
  15. // #endif
  16. // #ifdef H5
  17. openPayWebview(url, title)
  18. // #endif
  19. return
  20. }
  21. // #ifdef APP-PLUS
  22. plus.runtime.openURL(url, (error) => {
  23. if (error) {
  24. uni.showToast({ title: '打开失败', icon: 'none' })
  25. }
  26. })
  27. // #endif
  28. // #ifdef H5
  29. window.open(url, '_blank')
  30. // #endif
  31. }