<!DOCTYPE html>
|
<html lang="en">
|
<head>
|
<meta charset="UTF-8" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<title>share</title>
|
</head>
|
<style>
|
body,
|
html {
|
margin: 0;
|
height: 100%;
|
}
|
html {
|
overflow-y: hidden;
|
}
|
</style>
|
<script src="../static/config/globalConfig.js"></script>
|
<script>
|
function isMobile() {
|
const userAgentInfo = navigator.userAgent;
|
const mobileAgents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
|
const mobileFlag = mobileAgents.some((mobileAgent) => {
|
return userAgentInfo.indexOf(mobileAgent) > 0;
|
});
|
|
return mobileFlag;
|
}
|
|
const isTest = window.globalConfig.Mode === 'test';
|
const MobileProdShareRealUrl = window.globalConfig.WebApiUrl.MobileProdShareRealUrl;
|
const MobileTestShareRealUrl = window.globalConfig.WebApiUrl.MobileTestShareRealUrl;
|
const getSearchParams = (url) => {
|
// 获取查询参数前的 ? 对应的索引位置
|
const searchIndex = url.indexOf('?');
|
// 截取出查询参数字符串,并根据 & 将其分割成一个个 name=bruce 形式字符串组成的数组
|
const searchParamsArray = url.slice(searchIndex + 1).split('&');
|
// 遍历数组,组成查询参数对象
|
return searchParamsArray.reduce((pre, cur) => {
|
const [key, value] = cur.split('=');
|
return {
|
...pre,
|
// 需要使用 decodeURIComponent 对参数进行解码
|
[key]: decodeURIComponent(value),
|
};
|
}, {});
|
};
|
|
/**
|
*
|
* @param {*} func 防抖函数
|
* @param {*} wait 等待时长(毫秒)
|
* @param {*} immediate 是否先立即触发一次
|
* @description 使用方法见{@link https://mp.weixin.qq.com/s/vfnqmE1EG8UCedduDJE7Eg}
|
* 触发了事件会在n毫秒后执行,但是如果在这n毫秒内又去触发,计时器又会重新计算n毫秒,等n毫秒后触发
|
*
|
* 事件会置后触发,新来的事件会覆盖之前的事件
|
* @returns
|
*/
|
const debounce = (func, wait = 300, immediate = false) => {
|
if (!func) return undefined;
|
let timer = null;
|
return function (...arg) {
|
if (timer !== null) {
|
clearTimeout(timer);
|
} else if (immediate) {
|
func.apply(this, arg);
|
}
|
timer = setTimeout(() => {
|
func.apply(this, arg);
|
timer = null;
|
}, wait);
|
};
|
};
|
const getBaseUrl = () => {
|
const serveUrl = window.location.origin + window.location.pathname;
|
const shareSuffix = window.globalConfig.WebApiUrl.ShareUrl;
|
return serveUrl.replace(shareSuffix, '');
|
};
|
const urlParams = getSearchParams(window.location.search);
|
const id = urlParams.id;
|
|
let pcShareUrl;
|
let mobileShareUrl;
|
const pcBaseUrl = getBaseUrl();
|
|
if (isTest) {
|
pcShareUrl = `${pcBaseUrl}/#/share?id=${id}`;
|
mobileShareUrl = `${MobileTestShareRealUrl}/#/share?id=${id}`;
|
} else {
|
pcShareUrl = `${pcBaseUrl}/#/share?id=${id}`;
|
mobileShareUrl = `${MobileProdShareRealUrl}/#/share?id=${id}`;
|
}
|
window.location.href = isMobile() ? mobileShareUrl : pcShareUrl;
|
</script>
|
<body></body>
|
</html>
|