Browse Source

feat: 添加点赞功能的权限检查逻辑;优化相关组件的权限管理

EvilDragon 1 tháng trước cách đây
mục cha
commit
a26a3441c0

+ 6 - 2
packages/app/src/components/moment-item.vue

@@ -24,7 +24,7 @@ const props = withDefaults(
 )
 const emits = defineEmits<{ delete: [id: number]; like: [options: any] }>()
 const router = useRouter()
-const { features } = usePermissions()
+const { features, clickByPermission } = usePermissions()
 const memberLevelsStore = useMemberLevelsStore()
 const { getMemberLevelLogo } = memberLevelsStore
 const dictStore = useDictStore()
@@ -187,7 +187,11 @@ onMounted(async () => {
         <view
           class="flex items-center text-3.5 font-400 line-height-5.5"
           :class="[options.ownUpvote ? 'text-[#ca5141]' : 'text-[rgba(0,0,0,0.85)]']"
-          @click.stop="emits('like', { upvote: options.ownUpvote, circleId: options.id })"
+          @click.stop="
+            clickByPermission('thumbsUp', () =>
+              emits('like', { upvote: options.ownUpvote, circleId: options.id }),
+            )
+          "
         >
           <template v-if="options.ownUpvote">
             <wd-img width="18" height="18" :src="likeActived"></wd-img>

+ 5 - 1
packages/app/src/composables/permissions.ts

@@ -81,12 +81,16 @@ export const usePermissions = () => {
    * 按钮操作权限
    */
   const clickByPermission = (
-    name: 'wechatAgentExchange' | 'caseExchange' | 'mallExchange',
+    name: 'wechatAgentExchange' | 'caseExchange' | 'mallExchange' | 'thumbsUp',
     callback: () => void,
   ) => {
     const features = [
       { name: 'mallExchange', meta: { canNotLogin: false, canNotDesigner: false } },
       { name: 'wechatAgentExchange', meta: { canNotLogin: false, canNotDesigner: false } },
+      /**
+       * 点赞需登录
+       */
+      { name: 'thumbsUp', meta: { canNotLogin: false, canNotDesigner: true } },
     ]
     const feature = features.find((item) => item.name === name)
     if (feature) {

+ 12 - 10
packages/app/src/pages/home/moment/index.vue

@@ -33,9 +33,9 @@ import WdInput from 'wot-design-uni/components/wd-input/wd-input.vue'
 import { getRect, addUnit } from 'wot-design-uni/components/common/util'
 import Card from '@/components/card.vue'
 import { get } from 'radash'
-import { DictType } from '@/core/libs/models'
+import { DictType } from '../../../core/libs/models'
 
-const { features } = usePermissions()
+const { features, clickByPermission } = usePermissions()
 const userStore = useUserStore()
 const { userInfo } = storeToRefs(userStore)
 const router = useRouter()
@@ -374,14 +374,16 @@ onShareAppMessage(async ({ from, target }) => {
           <view
             class="flex flex-col items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5"
             @click="
-              handleUpvoteClick(
-                {
-                  upvote: data.ownUpvote,
-                  circleId: data.id,
-                  userId: userInfo.userId,
-                  userName: userInfo.nickname,
-                },
-                () => run(),
+              clickByPermission('thumbsUp', () =>
+                handleUpvoteClick(
+                  {
+                    upvote: data.ownUpvote,
+                    circleId: data.id,
+                    userId: userInfo.userId,
+                    userName: userInfo.nickname,
+                  },
+                  () => run(),
+                ),
               )
             "
           >