import qs from 'qs'; export function getMobileOperatingSystem() { // #ifdef H5 const userAgent = navigator.userAgent || navigator.vendor || window.opera; // Windows Phone must come first because its UA also contains "Android" if (/windows phone/i.test(userAgent)) { return "Windows Phone"; } if (/android/i.test(userAgent)) { return "Android"; } // iOS detection from: http://stackoverflow.com/a/9039885/177710 if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { return "iOS"; } return "unknown"; // #endif // #ifndef H5 return "unknown"; // #endif } export function getQueryParam() { // let query: Record = {}; let query = {}; query = location.search .slice(1) .split('&') .map((p) => p.split('=')) // .reduce((obj: Record, pair) => { .reduce((obj, pair) => { const [key, value] = pair.map(decodeURIComponent); obj[key] = value; return obj; }, {}); return query; } // export function isInWeixinH5() { // TODO: 发布前取消注释 return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1; // return true; } // 判断当前运行平台 export function getPlatform() { const userAgent = navigator.userAgent.toLowerCase() // 微信小程序 if (/miniprogram/g.test(userAgent)) { return "miniprogram" } // 微信公众号 if (/micromessenger/g.test(userAgent)) { return "micromessenger" } // TODO: 发布前取消注释 return 'browser' } export function getUrlParams(url = window.location.href) { const str = `${url}`.split('?')[1] if(!str) return {} return qs.parse(str); }