| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import { Message, Modal } from '@arco-design/web-vue'
- let guideVisible = false
- export function isInstalledWebApp() {
- if (typeof window === 'undefined') return false
- return Boolean(
- window.matchMedia?.('(display-mode: standalone)').matches ||
- window.matchMedia?.('(display-mode: window-controls-overlay)').matches ||
- window.navigator?.standalone === true
- )
- }
- export function showOpenInBrowserGuide({
- feature = '当前功能',
- url = window.location.href
- } = {}) {
- if (!isInstalledWebApp()) return false
- if (guideVisible) return true
- guideVisible = true
- Modal.confirm({
- title: '请前往浏览器操作',
- content: `${feature}需要跳转到第三方页面。安装后的应用窗口可能无法完成授权或支付,请在浏览器打开当前页面后继续操作。`,
- okText: '打开浏览器',
- cancelText: '我知道了',
- async onOk() {
- try {
- await window.navigator.clipboard?.writeText(url)
- Message.success('页面链接已复制,可在浏览器中粘贴打开')
- } catch (error) {
- console.log(error)
- }
- window.open(url, '_blank', 'noopener')
- guideVisible = false
- },
- onCancel() {
- guideVisible = false
- },
- onClose() {
- guideVisible = false
- }
- })
- return true
- }
|