From 21fee2dc9a0bf2d3106c0bfefb777f3eaa5b4f5d Mon Sep 17 00:00:00 2001 From: liuyiwuqing <1520431201@qq.com> Date: Tue, 25 Nov 2025 21:32:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E9=99=90=E5=88=B6=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E6=94=AF=E6=8C=81=E8=AF=84=E8=AE=BA=E5=90=8E=E8=AE=BF?= =?UTF-8?q?=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入 getOpenid 和 getNologinEmail 方法统一管理认证信息 - 替换原有直接读取 storage 方式为封装方法调用 - 优化文章详情页按钮文案展示逻辑 - 新增评论后自动刷新限制阅读内容功能 - 调整评论权限提示逻辑,跳转至评论弹窗而非 toast 提示 --- api/v2/all.api.js | 11 +++++++---- pagesA/article-detail/article-detail.vue | 16 ++++++++-------- utils/auth.js | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/api/v2/all.api.js b/api/v2/all.api.js index 140ffea..fba1a42 100644 --- a/api/v2/all.api.js +++ b/api/v2/all.api.js @@ -10,6 +10,7 @@ import qs from 'qs' import { getAppConfigs } from '@/config/index.js' +import {getNologinEmail, getOpenid} from "@/utils/auth"; export default { /** @@ -27,7 +28,8 @@ export default { getPostByName: (name) => { return HttpHandler.Get(`/apis/api.content.halo.run/v1alpha1/posts/${name}`, {}, { header: { - 'Wechat-Session-Id': uni.getStorageSync('openid'), + 'Wechat-Session-Id': getOpenid(), + 'nologin-email': getNologinEmail() } }) }, @@ -197,7 +199,8 @@ export default { return HttpHandler.Post(`/apis/tools.muyin.site/v1alpha1/restrict-read/check`, params, { header: { 'Authorization': getAppConfigs().pluginConfig.toolsPlugin?.Authorization, - 'Wechat-Session-Id': uni.getStorageSync('openid'), + 'Wechat-Session-Id': getOpenid(), + 'nologin-email': getNologinEmail() } }) }, @@ -209,7 +212,7 @@ export default { return HttpHandler.Get(`/apis/tools.muyin.site/v1alpha1/restrict-read/create`, null, { header: { 'Authorization': getAppConfigs().pluginConfig.toolsPlugin?.Authorization, - 'Wechat-Session-Id': uni.getStorageSync('openid'), + 'Wechat-Session-Id': getOpenid(), } }) }, @@ -221,7 +224,7 @@ export default { return HttpHandler.Post(`/apis/linkssubmit.muyin.site/v1alpha1/submit`, form, { header: { 'Authorization': getAppConfigs().pluginConfig.linksSubmitPlugin?.Authorization, - 'Wechat-Session-Id': uni.getStorageSync('openid'), + 'Wechat-Session-Id': getOpenid(), } }) }, diff --git a/pagesA/article-detail/article-detail.vue b/pagesA/article-detail/article-detail.vue index 46aa188..b9cce5e 100644 --- a/pagesA/article-detail/article-detail.vue +++ b/pagesA/article-detail/article-detail.vue @@ -101,7 +101,7 @@ :loading="true" :lines="3" :tip-text="`此处内容已隐藏,「${getRestrictReadTypeName(result)}可见」`" - button-text="查看更多" + :button-text="`${getRestrictReadTypeName(result)}`" button-color="#1890ff" skeleton-color="#f0f0f0" skeleton-highlight="#e0e0e0" @@ -129,7 +129,7 @@ :loading="true" :lines="3" :tip-text="`此处内容已隐藏,「${getRestrictReadTypeName(result)}可见」`" - button-text="查看更多" + :button-text="`${getRestrictReadTypeName(result)}`" button-color="#1890ff" skeleton-color="#f0f0f0" skeleton-highlight="#e0e0e0" @@ -726,8 +726,10 @@ export default { this.commentModal.show = true; }, fnOnCommentModalClose({ refresh, isSubmit }) { - console.log('refresh', refresh); - console.log('isSubmit', isSubmit); + // 评论后自动刷新 + if (this.result?.metadata?.annotations?.restrictReadEnable === 'comment') { + this.fnGetData(); + } if (refresh && isSubmit && this.$refs.commentListRef) { this.$refs.commentListRef.fnGetData(); } @@ -1236,10 +1238,8 @@ export default { this.verificationCodeModal.show = true; return; } else if (restrictReadEnable === 'comment') { - uni.showToast({ - title: '前往web端评论后访问', - icon: 'none' - }); + this.fnToComment(); + return; } else if (restrictReadEnable === 'login') { uni.showToast({ title: '前往web端登录后访问', diff --git a/utils/auth.js b/utils/auth.js index c3c3ac3..d979ea1 100644 --- a/utils/auth.js +++ b/utils/auth.js @@ -76,3 +76,20 @@ export function checkHasWxLogin() { export function checkHasAdminLogin() { return !!getCache('APP_ADMIN_LOGIN_TOKEN') } + +/** + * 获取openid + */ +export function getOpenid() { + return uni.getStorageSync('openid'); +} + +/** + * 获取nologin-email + */ +export function getNologinEmail() { + let Visitor = uni.getStorageSync('Visitor'); + if (!Visitor) return ''; + Visitor = JSON.parse(Visitor) + return Visitor.email || Visitor.author || ''; +}