feat(分享): 添加新闻详情页的微信分享功能
在indexNewsInfo.vue中添加微信分享URL生成和跳转逻辑 更新index.html中的微信JS-SDK相关代码 移除minihome/index.vue中无用的样式注释 修复pages.json文件格式问题
This commit is contained in:
parent
e8a9f2cb91
commit
2dc59ae87d
95
index.html
95
index.html
|
|
@ -16,9 +16,9 @@
|
|||
<!-- <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"}
|
||||
console.log("🚀 ~ window.location.href:", window.location.href);
|
||||
|
||||
const urlParams = parseUrlParams();
|
||||
wx.miniProgram.postMessage({
|
||||
data: {
|
||||
type: "share_info",
|
||||
|
|
@ -28,6 +28,26 @@
|
|||
},
|
||||
});
|
||||
|
||||
// const currentRoute = getCurrentRoute();
|
||||
// console.log("当前纯路由地址:", currentRoute); // 输出:/pages/detail/indexNewsInfo
|
||||
|
||||
function getCurrentRoute() {
|
||||
// 1. 获取hash(处理hash为空的边界情况)
|
||||
const hash = window.location.hash || "";
|
||||
if (!hash || hash === "#") return "";
|
||||
|
||||
// 2. 去掉开头的#,得到 hash 主体(如 /pages/detail/indexNewsInfo?id=xxx)
|
||||
const hashMain = hash.slice(1);
|
||||
|
||||
// 3. 拆分路由和参数(以?为分隔符,取第一部分)
|
||||
const routePart = hashMain.split("?")[0];
|
||||
|
||||
// 4. 兼容:去除路由前后多余的空格(防异常)
|
||||
const pureRoute = routePart.trim();
|
||||
|
||||
return pureRoute;
|
||||
}
|
||||
|
||||
// ========== 核心:URL参数解析函数 ==========
|
||||
function parseUrlParams() {
|
||||
const params = {};
|
||||
|
|
@ -78,6 +98,77 @@
|
|||
<body>
|
||||
<div id="app"><!--app-html--></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
|
||||
<script>
|
||||
// // 路由变化的处理逻辑
|
||||
// function handleRouteChange() {
|
||||
// console.log("🚀 ~ handleRouteChange ~ handleRouteChange:");
|
||||
// const { route, params } = parseH5Route();
|
||||
// console.log("H5地址变化:", {
|
||||
// 路由: route, // 如 "/pages/detail/indexNewsInfo"
|
||||
// 参数: params, // 如 {id: "98511"}
|
||||
// });
|
||||
|
||||
// if (route === "/pages/detail/indexNewsInfo") {
|
||||
// wx.miniProgram.navigateTo({
|
||||
// url: "/pages/webView/index?url=" + encodeURIComponent(shareUrl),
|
||||
// });
|
||||
// }
|
||||
// // 更新全局变量,供Uniapp页面使用
|
||||
// window.currentH5Route = { route, params };
|
||||
// // 派发自定义事件,供Vue页面监听
|
||||
// window.dispatchEvent(new CustomEvent("h5RouteChanged", { detail: { route, params } }));
|
||||
// }
|
||||
|
||||
// // 监听hash变化(Uniapp默认hash路由)
|
||||
// window.addEventListener("hashchange", handleRouteChange);
|
||||
// // 监听history变化(如浏览器前进/后退、history.pushState)
|
||||
// window.addEventListener("popstate", handleRouteChange);
|
||||
|
||||
// // 初始化解析
|
||||
// handleRouteChange();
|
||||
|
||||
// // 页面卸载时移除监听,防止内存泄漏
|
||||
// window.addEventListener("beforeunload", () => {
|
||||
// window.removeEventListener("hashchange", handleRouteChange);
|
||||
// window.removeEventListener("popstate", handleRouteChange);
|
||||
// });
|
||||
|
||||
// // 解析H5路由(兼容hash/history)
|
||||
// function parseH5Route() {
|
||||
// let route = "";
|
||||
// let params = {};
|
||||
// const { hash, pathname, search } = window.location;
|
||||
|
||||
// // 处理Uniapp默认的hash路由
|
||||
// if (hash) {
|
||||
// const hashMain = hash.slice(1);
|
||||
// const [routePart, paramPart] = hashMain.split("?");
|
||||
// route = routePart;
|
||||
// // 解析hash参数
|
||||
// if (paramPart) {
|
||||
// const paramArr = paramPart.split("&");
|
||||
// paramArr.forEach((item) => {
|
||||
// const [key, value] = item.split("=");
|
||||
// if (key) params[key] = decodeURIComponent(value || "");
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// // 处理history路由
|
||||
// else {
|
||||
// route = pathname;
|
||||
// // 解析search参数
|
||||
// if (search) {
|
||||
// const searchParams = new URLSearchParams(search.slice(1));
|
||||
// searchParams.forEach((value, key) => {
|
||||
// params[key] = decodeURIComponent(value);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// return { route, params };
|
||||
// }
|
||||
</script>
|
||||
<!-- <script type="text/javascript">
|
||||
var link = location.href.split("#")[0];
|
||||
console.log("🚀 ~ link:", link);
|
||||
|
|
|
|||
|
|
@ -152,6 +152,18 @@ onLoad(async (option: any) => {
|
|||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
let shareUrl =
|
||||
"https://cankao.cs.com.cn/jnh/#/pages/detail/indexNewsInfo?id=" +
|
||||
option.id +
|
||||
"&phone=" +
|
||||
uni.getStorageSync("token") +
|
||||
"&userType=" +
|
||||
userType.value;
|
||||
|
||||
wx.miniProgram.navigateTo({
|
||||
url: "/pages/webView/index?url=" + encodeURIComponent(shareUrl),
|
||||
});
|
||||
});
|
||||
|
||||
const newList = async (columnId: number) => {
|
||||
|
|
@ -263,6 +275,7 @@ function goLogin() {
|
|||
}
|
||||
|
||||
import { useTimerStore } from "@/stores/timerStore";
|
||||
import wx from "weixin-js-sdk";
|
||||
|
||||
// function initWxConfig() {
|
||||
// getWeChatSdkData({ url: window.location.href }).then((res: any) => {
|
||||
|
|
|
|||
|
|
@ -25,15 +25,13 @@
|
|||
></view>
|
||||
|
||||
<view class="content">
|
||||
<view
|
||||
:style="{
|
||||
<!-- :style="{
|
||||
position: 'sticky',
|
||||
top: getNavHeight() + 'px',
|
||||
backgroundColor: isScroll ? '#fff' : 'transparent',
|
||||
zIndex: '9999',
|
||||
}"
|
||||
v-if="tabIndex == 0 || tabIndex == 2"
|
||||
>
|
||||
}" -->
|
||||
<view v-if="tabIndex == 0 || tabIndex == 2">
|
||||
<!-- <view class="r_sreach">
|
||||
<image class="logo_text" src="https://cankao.obs.cn-east-3.myhuaweicloud.com/mini/newmini/logo_text_icon.png">
|
||||
</image>
|
||||
|
|
|
|||
Loading…
Reference in New Issue