Bladeren bron

feat(share): 添加分享功能的条件判断并优化分享链接

EvilDragon 3 maanden geleden
bovenliggende
commit
691cf6ac50

+ 3 - 2
packages/app/src/components/navbar-evo.vue

@@ -9,8 +9,9 @@ const props = withDefaults(
     title?: string
     dark?: boolean
     placeholder?: boolean
+    isShowBack?: boolean
   }>(),
-  {},
+  { isShowBack: true },
 )
 const slots = defineSlots<{
   prepend(): any
@@ -44,7 +45,7 @@ onMounted(() => {
       >
         <template v-slot:[aa]>
           <div class="flex items-center gap-4.5 w-full h-full">
-            <div class="flex items-center justify-center overflow-hidden">
+            <div class="flex items-center justify-center overflow-hidden" v-if="isShowBack">
               <wd-icon
                 v-if="pages.length === 1"
                 name="home"

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

@@ -58,7 +58,7 @@ export const usePermissions = () => {
     about: isDesigner.value,
     toDesignerHomePage: isLogined.value,
     checkInAtStoreTask: isDesigner.value,
-    // shareMoment: isLogined.value && isDesigner.value && userInfo.value.level.level > 1,
+    shareMoment: isLogined.value && isDesigner.value && userInfo.value.level.level > 1,
   }))
   return { isLogined, isDesigner, routes, features }
 }

+ 4 - 2
packages/app/src/pages/home/index.vue

@@ -68,10 +68,12 @@ onShareAppMessage(async ({ from, target }) => {
   console.log('target', target)
   const res: Page.CustomShareContent = {}
   if (from === 'button') {
-    handleShareClick()
+    if (!features.value.shareMoment) {
+      return handleShareClick()
+    }
     console.log('分享')
     await shareCircle(target.dataset.options.id)
-    res.path = `/pages/home/moment/index?id=${target.dataset.options.id}`
+    res.path = `/pages/home/moment/index?id=${target.dataset.options.id}&isShared=true`
     res.imageUrl = target.dataset.options.bannerUrls[0]
     res.title = `${target.dataset.options.stylistName}: ${target.dataset.options.circleDesc}`
   }

+ 22 - 5
packages/app/src/pages/home/moment/index.vue

@@ -16,7 +16,7 @@ import {
   getCircleUpvotes,
   shareCircle,
 } from '../../../core/libs/requests'
-import { handleUpvoteClick } from '../../../core/libs/actions'
+import { handleShareClick, handleUpvoteClick } from '../../../core/libs/actions'
 import CommentItem from '../components/comment-item.vue'
 import { useUserStore } from '../../../store'
 import { storeToRefs } from 'pinia'
@@ -27,11 +27,14 @@ import BottomAppBar from '@/components/bottom-app-bar.vue'
 import { likeActived, likeBlack } from '@designer-hub/assets/src/icons'
 import NavBarEvo from '@/components/navbar-evo.vue'
 import { useRouter } from '../../../core/utils/router'
+import { usePermissions } from '../../../composables/permissions'
 
+const { features } = usePermissions()
 const userStore = useUserStore()
 const { userInfo } = storeToRefs(userStore)
 const router = useRouter()
 const id = ref()
+const isShared = ref(false)
 const { data, run } = useRequest(() => getCircle(id.value), { initialData: {} })
 const { data: reviews, run: runGetReviews } = useRequest(
   () => getCircleReviews({ circleId: id.value }),
@@ -84,21 +87,35 @@ const handleSend = async () => {
   }
 }
 onMounted(async () => {})
-onLoad(async (query: { id: string }) => {
+onLoad(async (query: { id: string; isShared?: boolean }) => {
   id.value = query.id
+  isShared.value = query.isShared
   await run()
   await runGetReviews()
   await setSwiperStyle()
   await setCircleUpvotes()
 })
-onShareAppMessage(async () => {
+// onShareAppMessage(async () => {
+//   await shareCircle(id.value)
+//   return { title: data.value?.circleDesc }
+// })
+onShareAppMessage(async ({ from, target }) => {
+  console.log('from', from)
+  console.log('target', target)
+  if (!features.value.shareMoment) {
+    return handleShareClick()
+  }
+  const res: Page.CustomShareContent = {}
   await shareCircle(id.value)
-  return { title: data.value?.circleDesc }
+  res.path = `/pages/home/moment/index?id=${id.value}&isShared=true`
+  res.imageUrl = data.value?.bannerUrls[0]
+  res.title = `${data.value?.stylistName}: ${data.value?.circleDesc}`
+  return res
 })
 </script>
 <template>
   <view class="bg-white flex-grow">
-    <NavBarEvo placeholder>
+    <NavBarEvo placeholder :isShowBack="!isShared">
       <template #prepend>
         <div
           class="flex items-center gap-2"

+ 14 - 10
packages/app/src/pages/mine/homepage/index.vue

@@ -28,14 +28,17 @@ import { requestToast } from '../../../core/utils/common'
 import { ComponentExposed } from 'vue-component-type-helpers'
 import dayjs from 'dayjs'
 import wechatChannels from '@designer-hub/assets/src/libs/assets/wechatChannels'
-import { handleUpvoteClick } from '@/core/libs/actions'
+import { handleUpvoteClick, handleShareClick } from '../../../core/libs/actions'
+import { usePermissions } from '../../../composables/permissions'
 
+const { features } = usePermissions()
 const { alert, confirm } = useMessage()
 const router = useRouter()
 const userStore = useUserStore()
 const { userInfo } = storeToRefs(userStore)
 const pageHelperRef = ref<ComponentExposed<typeof PageHelper>>()
 const id = ref()
+const isShared = ref(false)
 const tab = ref('2')
 const tabs = ref([
   { label: '案例', value: '2' },
@@ -122,13 +125,16 @@ const handleUnbundle = async () => {
     },
   })
 }
-onLoad(async (query: { id: string }) => {
+onLoad(async (query: { id: string; isShared?: string }) => {
   if (query.id) {
     id.value = query.id
   } else {
     id.value = userInfo.value.userId
     // memberInfo.value =
   }
+  if (query.isShared) {
+    isShared.value = true
+  }
   await setMemberInfo()
   await setDesignerInfo()
   if (!isOwn.value) {
@@ -148,23 +154,21 @@ onUnload(async () => {
     })
   }
 })
-// onShareAppMessage(() => ({
-//   title: `${userInfo.value.nickname}: “${designerInfo.value.designDesc}”`,
-//   imageUrl: designerInfo.value?.sharePageUrl,
-//   path: `/pages/mine/homepage/index?id=${id.value}`,
-// }))
 onShareAppMessage(async ({ from, target }) => {
   const res: Page.CustomShareContent = {}
   if (from === 'button') {
+    if (!features.value.shareMoment) {
+      return handleShareClick()
+    }
     await shareCircle(target.id)
-    res.path = `/pages/home/moment/index?id=${target.id}`
+    res.path = `/pages/home/moment/index?id=${target.id}&isShared=true`
     res.imageUrl = target.dataset.options.bannerUrls[0]
     res.title = `${target.dataset.options.stylistName}: ${target.dataset.options.circleDesc}`
   }
   if (from === 'menu') {
     res.title = `${userInfo.value.nickname}: “${designerInfo.value.designDesc}”`
     res.imageUrl = designerInfo.value?.sharePageUrl
-    res.path = `/pages/mine/homepage/index?id=${id.value}`
+    res.path = `/pages/mine/homepage/index?id=${id.value}&isShared=true`
   }
   return res
 })
@@ -175,7 +179,7 @@ defineExpose({
 </script>
 <template>
   <div class="flex-grow flex flex-col">
-    <NavbarEvo transparent dark></NavbarEvo>
+    <NavbarEvo transparent dark :isShowBack="!isShared"></NavbarEvo>
     <div class="relative">
       <wd-img
         width="100%"