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 // 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初始化失败') } } }