|
|
@@ -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(
|