Ver Fonte

任务分享详情完成

yuanmingze há 1 mês atrás
pai
commit
5f48f2cff5

+ 52 - 6
src/pages/information/detail/index.vue

@@ -26,7 +26,14 @@ import { computed, ref } from 'vue'
 import { onLoad } from '@dcloudio/uni-app'
 import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html'
 
-import { getAlbumByIdApi, getArticleByIdApi } from '@/services/modules/information'
+import { getWXLoginCode } from '@/lib/wechatService'
+
+import {
+  getAlbumByIdApi,
+  getArticleByIdApi,
+  shareAlbumByIdApi,
+  shareArticleByIdApi,
+} from '@/services/modules/information'
 import type { AlbumPageNewItem, ArticleItem } from '@/services/modules/information/type'
 
 type DetailType = 'academic' | 'album'
@@ -35,6 +42,9 @@ type DetailItem = ArticleItem | AlbumPageNewItem
 interface PageQuery {
   id?: string
   type?: DetailType
+  shareUserId?: string
+  packageId?: string
+  remark?: string
 }
 
 const detail = ref<DetailItem>()
@@ -67,19 +77,19 @@ const content = computed(() => {
 })
 
 onLoad((query) => {
-  const { id, type = 'academic' } = query as PageQuery
+  const pageQuery = query as PageQuery
+  const { id, type = 'academic' } = pageQuery
 
   if (!id) return
 
   detailType.value = type
 
-  void getDetail(id)
+  void getDetail(id, pageQuery)
 })
 
-const getDetail = async (id: string): Promise<void> => {
+const getDetail = async (id: string, query: PageQuery): Promise<void> => {
   try {
-    const { data } =
-      detailType.value === 'academic' ? await getArticleByIdApi(id) : await getAlbumByIdApi(id)
+    const { data } = await requestDetail(id, query)
 
     detail.value = data
   } catch (error) {
@@ -92,6 +102,42 @@ const getDetail = async (id: string): Promise<void> => {
   }
 }
 
+const requestDetail = async (id: string, query: PageQuery) => {
+  const { shareUserId = '', packageId = '', remark = '' } = query
+
+  if (!shareUserId || !packageId) {
+    return detailType.value === 'academic' ? getArticleByIdApi(id) : getAlbumByIdApi(id)
+  }
+
+  let openUserId = ''
+
+  try {
+    const loginResult = await getWXLoginCode()
+    openUserId = loginResult?.code || ''
+  } catch (error) {
+    console.error('get WeChat login code for shared information failed:', error)
+  }
+
+  const commonParams = {
+    shareUserId,
+    openUserId,
+    type: 'open',
+    packageId,
+    sharePicUrl: '',
+    remark,
+  } as const
+
+  return detailType.value === 'academic'
+    ? shareArticleByIdApi({
+        ...commonParams,
+        articleId: id,
+      })
+    : shareAlbumByIdApi({
+        ...commonParams,
+        id,
+      })
+}
+
 const formatRichText = (html: string): string => {
   return html
     .replace(

+ 2 - 1
src/pages/information/index.vue

@@ -359,8 +359,9 @@ onShareAppMessage((res) => {
     })
   }
 
-  sharePopupVisible.value = false
+  console.log(`/pages/information/detail/index?${query.join('&')}`)
 
+  sharePopupVisible.value = false
   return {
     title,
     path: `/pages/information/detail/index?${query.join('&')}`,

+ 1 - 1
src/services/modules/information/type.d.ts

@@ -95,7 +95,7 @@ export type GetPackageListByTaskTypeResponse = SharePackageItem[]
 export interface ShareRequestBase {
   shareUserId: string
   openUserId: string
-  type: 'share'
+  type: 'share' | 'open'
   packageId: string
   sharePicUrl: string
   remark: string