Kaynağa Gözat

feat(auth): 限制阅读支持评论后访问

- 引入 getOpenid 和 getNologinEmail 方法统一管理认证信息
- 替换原有直接读取 storage 方式为封装方法调用
- 优化文章详情页按钮文案展示逻辑
- 新增评论后自动刷新限制阅读内容功能
- 调整评论权限提示逻辑,跳转至评论弹窗而非 toast 提示
liuyiwuqing 4 ay önce
ebeveyn
işleme
21fee2dc9a
3 değiştirilmiş dosya ile 32 ekleme ve 12 silme
  1. 7 4
      api/v2/all.api.js
  2. 8 8
      pagesA/article-detail/article-detail.vue
  3. 17 0
      utils/auth.js

+ 7 - 4
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(),
 			}
 		})
 	},

+ 8 - 8
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端登录后访问',

+ 17 - 0
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 || '';
+}