hi-download/src/utils/openinstall.ts
speakeloudest 4297d5fd29
All checks were successful
site-dist-deploy / build-and-deploy (push) Successful in 1m32s
处理下载页的平台判断
2026-04-20 04:24:23 +03:00

84 lines
3.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getAllQueryString } from '@/utils/url-utils.ts'
/**
* OpenInstall sdk 用于上报h5邀请参数
* 自动注册openinstall sdk 挂在到window对象上 通过window.OI_SDK访问
* sdk初始化时会自动检索url上的参数并作为拉起下载或唤醒app时的参数
*/
const script = document.createElement('script')
script.type = 'text/javascript'
script.charset = 'UTF-8'
script.src = 'https://web.cdn.openinstall.io/openinstall.js'
document.head.appendChild(script)
script.addEventListener('load', () => {
window.OI_SDK = new OpenInstallSdk()
})
class OpenInstallSdk {
public urlQuery: any // openinstall.js中提供的api解析当前网页url中的查询参数并对data进行赋值
public OI: Record<string, any> // openinstall 实例
constructor() {
this.OI = {}
this.urlQuery = window.OpenInstall.parseUrlParams()
const id = getAllQueryString('id')
if (id) {
this.urlQuery = {
platform: 'merchant',
code: id,
}
}
this.init()
}
async init() {
try {
this.OI = new window.OpenInstall({
appKey: 'alf57p',
onready: function () { // 初始化成功回调方法。当初始化完成后,会自动进入
// this.schemeWakeup()// 尝试使用scheme打开App主要用于Android以及iOS的QQ环境中
// const m = this
// const button = document.getElementById('downloadButton_apple')
// const button_mac = document.getElementById('downloadButton_mac')
// const button1 = document.getElementById('downloadButton_android')
// const ic = getAllQueryString('ic') || 'uSSfgY6oAP'
// if (button) {
// button.onclick = function () {
// if (ic) {
// m.wakeupOrInstall({ data: { platform: 'download', inviteCode: ic } })
// } else {
// m.wakeupOrInstall()// 此方法为scheme、Universal Link唤醒以及引导下载的作用必须调用且不可额外自行跳转下载
// }
// return false
// }
// }
// if(button_mac) {
// button_mac.onclick = function () {
// if (ic) {
// m.wakeupOrInstall({ data: { platform: 'download', inviteCode: ic } })
// } else {
// m.wakeupOrInstall()// 此方法为scheme、Universal Link唤醒以及引导下载的作用必须调用且不可额外自行跳转下载
// }
// return false
// }
// }
// if (button1) {
// button1.onclick = function () {
// if (ic) {
// m.wakeupOrInstall({ data: { platform: 'download', inviteCode: ic } })
// } else {
// m.wakeupOrInstall()// 此方法为scheme、Universal Link唤醒以及引导下载的作用必须调用且不可额外自行跳转下载
// }
// return false
// }
// }
},
}, this.urlQuery)// 初始化时传入data作为一键拉起/App传参安装时候的参数
} catch (e) {
console.log(e, 'OpenInstall——sdk初始化失败')
}
}
}