fix: auth
Some checks failed
build quyun / Build (push) Failing after 1m26s

This commit is contained in:
2025-12-20 11:18:59 +08:00
parent c42f2c651f
commit fdbf26d751
6 changed files with 71 additions and 97 deletions

View File

@@ -1,11 +0,0 @@
import client from './client';
export const wechatApi = {
jsSdk() {
return client.get('/wechats/js-sdk', {
params: {
url: window.location.href.split('#')[0],
},
});
},
}

View File

@@ -1,6 +1,8 @@
import wx from "weixin-js-sdk";
export function useWxSDK() {
let ready = false;
/**
* 初始化设置
*/
@@ -24,8 +26,13 @@ export function useWxSDK() {
});
wx.ready(() => {
console.log("wx.ready called");
ready = true;
resolve(true);
});
wx.error(() => {
ready = false;
resolve(false);
});
});
}
@@ -35,39 +42,46 @@ export function useWxSDK() {
onSuccess = () => { },
onCancel = () => { }
) {
if (!ready) {
return;
}
console.log("setShareInfo called", shareInfo);
wx.updateTimelineShareData({
title: shareInfo.title, // 分享标题
link: shareInfo.link, // 分享链接可以不是当前页面该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareInfo.imgUrl,
success: function (e) {
console.log("分享朋友圈成功", e);
// 用户确认分享后执行的回调函数
onSuccess();
},
cancel: function (e) {
console.log("分享朋友圈取消", e);
onCancel();
// 用户取消分享后执行的回调函数
},
});
wx.updateAppMessageShareData({
title: shareInfo.title, // 分享标题
desc: shareInfo.desc,
link: shareInfo.link, // 分享链接可以不是当前页面该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareInfo.imgUrl,
type: "link", // 分享类型,music、video或link不填默认为link
success: function (e) {
// 用户确认分享后执行的回调函数
console.log("分享成功", e);
onSuccess();
},
cancel: function (e) {
// 用户取消分享后执行的回调函数
console.log("分享取消", e);
onCancel();
},
});
try {
wx.updateTimelineShareData({
title: shareInfo.title, // 分享标题
link: shareInfo.link, // 分享链接可以不是当前页面该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareInfo.imgUrl,
success: function (e) {
console.log("分享朋友圈成功", e);
// 用户确认分享后执行的回调函数
onSuccess();
},
cancel: function (e) {
console.log("分享朋友圈取消", e);
onCancel();
// 用户取消分享后执行的回调函数
},
});
wx.updateAppMessageShareData({
title: shareInfo.title, // 分享标题
desc: shareInfo.desc,
link: shareInfo.link, // 分享链接可以不是当前页面该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: shareInfo.imgUrl,
type: "link", // 分享类型,music、video或link不填默认为link
success: function (e) {
// 用户确认分享后执行的回调函数
console.log("分享成功", e);
onSuccess();
},
cancel: function (e) {
// 用户取消分享后执行的回调函数
console.log("分享取消", e);
onCancel();
},
});
} catch {
// ignore
}
}
/** 是否是ios微信 */
@@ -80,4 +94,4 @@ export function useWxSDK() {
setShareInfo,
isiOSWechat,
};
}
}

View File

@@ -9,7 +9,6 @@ import { onMounted, onUnmounted, ref } from "vue";
import { BsChevronLeft } from "vue-icons-plus/bs";
import { useRoute, useRouter } from "vue-router";
import { postApi } from "../api/postApi";
import { wechatApi } from "../api/wechatApi";
import { useWxSDK } from "../hooks/useWxSDK";
const wx = useWxSDK();
@@ -172,25 +171,6 @@ const handleBack = () => {
};
onMounted(async () => {
wechatApi
.jsSdk()
.then((resp) => {
wx.initConfig(resp.data).then(() => {
wx.setShareInfo({
title: article.value.title,
desc: article.value.content,
link: window.location.href,
imgUrl: article.value.head_images[0],
});
});
})
.catch((error) => {
console.error("Failed to initialize WeChat SDK:", error);
})
.finally(() => {
});
await fetchArticle();
});

File diff suppressed because one or more lines are too long