cankao-h5/index.html

158 lines
5.3 KiB
HTML
Raw Normal View History

2025-08-10 16:44:02 +08:00
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script>
var coverSupport =
"CSS" in window &&
typeof CSS.supports === "function" &&
(CSS.supports("top: env(a)") || CSS.supports("top: constant(a)"));
document.write(
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
(coverSupport ? ", viewport-fit=cover" : "") +
'" />'
);
</script>
<!-- <script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> -->
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script type="text/javascript">
const urlParams = parseUrlParams();
console.log("解析后的URL参数", urlParams); // 示例输出:{name: "张三", age: "20"}
wx.miniProgram.postMessage({
data: {
type: "share_info",
userType: urlParams?.userType || null,
phone: urlParams?.phone || null,
id: urlParams?.id || null,
},
});
// ========== 核心URL参数解析函数 ==========
function parseUrlParams() {
const params = {};
let search = window.location.search; // 获取 ? 后的参数(如 ?name=test&age=18
let hash = window.location.hash; // 获取 # 后的参数(如 #/pages/index?name=test
2025-08-10 16:44:02 +08:00
// 步骤1优先解析 search 参数history模式
if (search) {
// 去掉开头的 ?,拆分参数对
const searchParams = new URLSearchParams(search.slice(1));
searchParams.forEach((value, key) => {
// 解码中文/特殊字符(解决小程序传参中文乱码)
params[key] = decodeURIComponent(value);
});
}
// 步骤2解析 hash 中的参数Uniapp H5 默认 hash 路由,参数可能在 # 后)
if (hash) {
// 提取 hash 中 ? 后的部分(如 #/pages/index?name=test → ?name=test
const hashQuery = hash.split("?")[1];
if (hashQuery) {
const hashParams = new URLSearchParams(hashQuery);
hashParams.forEach((value, key) => {
params[key] = decodeURIComponent(value); // 解码
});
}
}
return params;
}
</script>
<!-- <script
2025-08-10 16:44:02 +08:00
type="text/javascript"
src="//res.wx.qq.com/open/js/jweixin-1.6.0.js"
></script>
<script>
window.jWeixin = window.wx;
delete window.wx;
</script>
<script src="https://www.cs.com.cn/js/2020/jquery-3.4.1.min.js"></script> -->
<!-- <link rel="icon" href="/src/assets/favicon.ico" /> -->
<title></title>
<!--preload-links-->
<!--app-context-->
</head>
2025-08-10 16:44:02 +08:00
<body>
<div id="app"><!--app-html--></div>
<script type="module" src="/src/main.ts"></script>
<!-- <script type="text/javascript">
2025-08-10 16:44:02 +08:00
var link = location.href.split("#")[0];
console.log("🚀 ~ link:", link);
var link2 = location.href.split("#")[1];
console.log("🚀 ~ link2:", link2);
$.ajax({
url: "https://cankao.cs.com.cn/mini/wechat/share",
type: "GET",
data: {
url: link,
},
async: true,
dataType: "json",
success: function (res) {
const { data } = res;
console.log("🚀 ~ data:", data);
jWeixin.config({
debug: false,
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
signature: data.signature,
jsApiList: [
"updateAppMessageShareData",
"updateTimelineShareData",
"onMenuShareTimeline",
"onMenuShareAppMessage",
],
});
jWeixin.error(function (res) {
console.log(res);
});
jWeixin.ready(function () {
jWeixin.updateAppMessageShareData({
title: "中证参考",
desc: "天下事 早知道",
link: link,
imgUrl: "https://cankao.cs.com.cn/static/share-default.jpg",
success: function () {},
});
jWeixin.updateTimelineShareData({
title: "中证参考",
desc: "天下事 早知道",
link: link,
imgUrl: "https://cankao.cs.com.cn/static/share-default.jpg",
success: function () {},
});
jWeixin.onMenuShareAppMessage({
title: "中证参考",
desc: "天下事 早知道",
link: link,
imgUrl: "https://cankao.cs.com.cn/static/share-default.jpg",
trigger: function (res) {},
success: function (res) {},
cancel: function (res) {},
fail: function (res) {},
});
jWeixin.onMenuShareTimeline({
title: "中证参考",
desc: "天下事 早知道",
link: link,
imgUrl: "https://cankao.cs.com.cn/static/share-default.jpg",
trigger: function (res) {},
success: function (res) {},
cancel: function (res) {},
fail: function (res) {},
});
});
},
error: function (error) {},
});
</script> -->
</body>
</html>