This commit is contained in:
lcj
2026-07-13 11:15:59 +08:00
parent 45a74578fc
commit ee0825c1e6
7 changed files with 225 additions and 18 deletions
+16 -1
View File
@@ -26,7 +26,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { post, getToken } from '../../../api/request'
import { BASE_URL } from '../../../config'
import { useUserStore } from '../../../store/user'
@@ -42,6 +42,7 @@ const buyPrice = ref('0')
const skuId = ref('')
const loading = ref(true)
const paying = ref(false)
const shareTitle = ref('爱上萍乡旅游年卡')
onLoad((query) => {
goodsId.value = (query?.goodsId as string) || '821926819630853'
@@ -55,6 +56,7 @@ function sanitizeHtml(html: string): string {
interface CardModelDetail {
cardModel: any
name: string
goods: { id: string; mainPic: string }
goodsInfo: { introduction: string }
sku: Array<{ id: string; buyPrice: number }>
@@ -65,6 +67,7 @@ onMounted(async () => {
const data = await post<CardModelDetail>(`${BASE_URL}/open-api/xgh/cardModelDetail?goodsId=${goodsId.value}`, {})
cardModleId.value = data.cardModel?.id || ''
mainPic.value = data.goods?.mainPic || ''
shareTitle.value = data.name || data.cardModel?.name || '爱上萍乡旅游年卡'
introduction.value = sanitizeHtml(data.goodsInfo?.introduction || '')
const sku = data.sku?.[0]
skuId.value = sku?.id || ''
@@ -77,6 +80,18 @@ onMounted(async () => {
}
})
onShareAppMessage(() => ({
title: shareTitle.value,
path: `/packages/user/pages/buy?goodsId=${goodsId.value}`,
imageUrl: mainPic.value,
}))
onShareTimeline(() => ({
title: shareTitle.value,
query: `goodsId=${goodsId.value}`,
imageUrl: mainPic.value,
}))
async function handleBuy() {
if (!userStore.isLogin) {
uni.navigateTo({ url: '/pages/login/login' })