first commit

This commit is contained in:
zhouyanli
2026-10-27 13:54:39 +08:00
commit 5c9aca27e8
24 changed files with 1498 additions and 0 deletions

71
utils/pet-app.js Normal file
View File

@@ -0,0 +1,71 @@
import config from '@/config'
/**
* 小程序内不做添加设备,只负责把用户交回宠物 App。
* 支付宝小程序无法直接拉起任意第三方 App,openUrl 需要在开放平台报备后才能用,
* 所以默认走「提示 + 复制下载链接」的兜底。
*/
function copyText(text) {
uni.setClipboardData({
data: text,
success: () => uni.showToast({ title: '链接已复制', icon: 'none' })
})
}
function tryOpenUrl(url) {
if (!url) return false
try {
// #ifdef MP-ALIPAY
if (typeof my !== 'undefined' && my.ap && typeof my.ap.openURL === 'function') {
my.ap.openURL({ url, fail: () => {} })
return true
}
// #endif
// #ifdef H5
window.location.href = url
return true
// #endif
} catch (e) {
// 忽略,走兜底
}
return false
}
export function openPetApp() {
const { openUrl, downloadUrl } = config.petApp
const content = '添加设备、绑定项圈需要在宠物 App 内完成。'
if (openUrl && downloadUrl) {
uni.showModal({
title: '前往宠物 App 添加设备',
content,
confirmText: '打开 App',
cancelText: '复制链接',
success: (res) => {
if (res.confirm && tryOpenUrl(openUrl)) return
copyText(downloadUrl)
}
})
return
}
if (downloadUrl) {
uni.showModal({
title: '前往宠物 App 添加设备',
content: `${content}是否复制 App 下载链接?`,
confirmText: '复制链接',
success: (res) => {
if (res.confirm) copyText(downloadUrl)
}
})
return
}
uni.showModal({
title: '前往宠物 App 添加设备',
content,
showCancel: false,
confirmText: '我知道了'
})
}