diff --git a/frontend/admin/src/api/httpClient.js b/frontend/admin/src/api/httpClient.js index 5c76777..aaea8ec 100644 --- a/frontend/admin/src/api/httpClient.js +++ b/frontend/admin/src/api/httpClient.js @@ -1,6 +1,6 @@ -import router from '@/router'; import { useAuthStore } from '@/stores/auth'; import axios from 'axios'; +import { useRouter } from 'vue-router'; // Create axios instance with default config const httpClient = axios.create({ @@ -37,6 +37,8 @@ httpClient.interceptors.response.use( if (error.response.status === 401) { const authStore = useAuthStore(); authStore.logout(); + const router = useRouter(); + // Redirect to login page router.push('/login'); } console.error('API Error:', error.response.status, error.response.data); diff --git a/frontend/wechat/src/views/ArticleDetail.vue b/frontend/wechat/src/views/ArticleDetail.vue index 3833147..23e9b4e 100644 --- a/frontend/wechat/src/views/ArticleDetail.vue +++ b/frontend/wechat/src/views/ArticleDetail.vue @@ -88,6 +88,7 @@ const fetchArticle = async () => { const { id } = route.params const { data } = await postApi.show(id) article.value = data + document.title = article.value.title // 定义“分享给朋友”及“分享到QQ”按钮的分享内容 const shareContent = { @@ -98,31 +99,29 @@ const fetchArticle = async () => { } // 调用微信 JS SDK 分享接口 if (window.wx) { - wx.ready(function () { - wx.updateTimelineShareData({ - title: shareContent.title, - link: shareContent.link, - imgUrl: shareContent.imgUrl, - success: function () { - console.log('分享成功') - }, - cancel: function () { - console.log('分享取消') - } - }) + wx.updateTimelineShareData({ + title: shareContent.title, + link: shareContent.link, + imgUrl: shareContent.imgUrl, + success: function () { + console.log('分享成功') + }, + cancel: function () { + console.log('分享取消') + } + }) - wx.updateAppMessageShareData({ - title: shareContent.title, - desc: shareContent.desc, - link: shareContent.link, - imgUrl: shareContent.imgUrl, - success: function () { - console.log('分享成功') - }, - cancel: function () { - console.log('分享取消') - } - }) + wx.updateAppMessageShareData({ + title: shareContent.title, + desc: shareContent.desc, + link: shareContent.link, + imgUrl: shareContent.imgUrl, + success: function () { + console.log('分享成功') + }, + cancel: function () { + console.log('分享取消') + } }) } } catch (error) { @@ -162,8 +161,8 @@ onUnmounted(() => {