fix: 分享

main
fadeaway 7 months ago
parent 928d1c2888
commit 76e70584ad

8
package-lock.json generated

@ -11,8 +11,7 @@
"lib-flexible": "^0.3.2", "lib-flexible": "^0.3.2",
"next": "14.1.3", "next": "14.1.3",
"react": "^18", "react": "^18",
"react-dom": "^18", "react-dom": "^18"
"weixin-js-sdk": "^1.6.5"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^19.1.0", "@commitlint/cli": "^19.1.0",
@ -8627,11 +8626,6 @@
} }
} }
}, },
"node_modules/weixin-js-sdk": {
"version": "1.6.5",
"resolved": "https://registry.npmmirror.com/weixin-js-sdk/-/weixin-js-sdk-1.6.5.tgz",
"integrity": "sha512-Gph1WAWB2YN/lMOFB/ymb+hbU/wYazzJgu6PMMktCy9cSCeW5wA6Zwt0dpahJbJ+RJEwtTv2x9iIu0U4enuVSQ=="
},
"node_modules/which": { "node_modules/which": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmmirror.com/which/-/which-2.0.2.tgz", "resolved": "https://registry.npmmirror.com/which/-/which-2.0.2.tgz",

@ -12,8 +12,7 @@
"lib-flexible": "^0.3.2", "lib-flexible": "^0.3.2",
"next": "14.1.3", "next": "14.1.3",
"react": "^18", "react": "^18",
"react-dom": "^18", "react-dom": "^18"
"weixin-js-sdk": "^1.6.5"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^19.1.0", "@commitlint/cli": "^19.1.0",

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

@ -34,6 +34,8 @@ export default function RootLayout({ children }: Readonly<{ children: React.Reac
`})();`, `})();`,
}} }}
/> />
{/* eslint-disable-next-line @next/next/no-sync-scripts */}
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js" />
</head> </head>
<body> <body>
<LibFlexible>{children}</LibFlexible> <LibFlexible>{children}</LibFlexible>

@ -2,8 +2,6 @@
import { /** useState, */ useEffect, useRef } from 'react'; import { /** useState, */ useEffect, useRef } from 'react';
import wx from 'weixin-js-sdk';
// import ImageWithBasePath from '@/components/ImageWithBasePath'; // import ImageWithBasePath from '@/components/ImageWithBasePath';
import { APPID } from '@/const'; import { APPID } from '@/const';
@ -29,7 +27,8 @@ export default function WXShareBtn() {
// }; // };
useEffect(() => { useEffect(() => {
if (!inWX) return; const wx = window.wx;
if (!inWX || !wx) return;
const { origin, pathname, searchParams } = new URL(window.location.href); const { origin, pathname, searchParams } = new URL(window.location.href);
const code = searchParams.get('code'); const code = searchParams.get('code');
@ -56,7 +55,12 @@ export default function WXShareBtn() {
timestamp, // 必填,生成签名的时间戳 timestamp, // 必填,生成签名的时间戳
nonceStr, // 必填,生成签名的随机串 nonceStr, // 必填,生成签名的随机串
signature, // 必填,签名 signature, // 必填,签名
jsApiList: ['updateAppMessageShareData', 'onMenuShareAppMessage', 'onMenuShareTimeline'], // 必填需要使用的JS接口列表 jsApiList: [
'updateAppMessageShareData',
'updateTimelineShareData',
'onMenuShareAppMessage',
'onMenuShareTimeline',
], // 必填需要使用的JS接口列表
}); });
wx.ready(function () { wx.ready(function () {
// setWxPrepared(true); // setWxPrepared(true);
@ -70,11 +74,12 @@ export default function WXShareBtn() {
title: '雀乐', // 分享标题 title: '雀乐', // 分享标题
link: `${origin}${pathname}${queryArr.length > 0 ? `?${queryArr.join('&')}` : ''}`, // 分享链接 link: `${origin}${pathname}${queryArr.length > 0 ? `?${queryArr.join('&')}` : ''}`, // 分享链接
desc: '一起记录独立音乐', // 分享描述 desc: '一起记录独立音乐', // 分享描述
imgUrl: 'https://indie.s3.bitiful.net/share.png', // 分享图标 imgUrl: 'https://m.indie.cn/img/share.png', // 分享图标
success() {}, success() {},
cancel() {}, cancel() {},
}; };
wx.updateAppMessageShareData(shareParam); wx.updateAppMessageShareData(shareParam);
wx.updateTimelineShareData(shareParam);
wx.onMenuShareAppMessage(shareParam); wx.onMenuShareAppMessage(shareParam);
wx.onMenuShareTimeline(shareParam); wx.onMenuShareTimeline(shareParam);
}); });

@ -4778,11 +4778,6 @@ util-deprecate@^1.0.2:
optionalDependencies: optionalDependencies:
fsevents "~2.3.3" fsevents "~2.3.3"
weixin-js-sdk@^1.6.5:
version "1.6.5"
resolved "https://registry.npmmirror.com/weixin-js-sdk/-/weixin-js-sdk-1.6.5.tgz"
integrity sha512-Gph1WAWB2YN/lMOFB/ymb+hbU/wYazzJgu6PMMktCy9cSCeW5wA6Zwt0dpahJbJ+RJEwtTv2x9iIu0U4enuVSQ==
which-boxed-primitive@^1.0.2: which-boxed-primitive@^1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.npmmirror.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz" resolved "https://registry.npmmirror.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz"

Loading…
Cancel
Save