13404089107
2026-04-24 cf70b4c4a0a0f10aed23dc2f70cdb707afd67519
feat(分享): 为课程和直播分享增加H5链接和富媒体支持

- 在课程详情、直播详情和直播观看页中新增生成H5分享链接的函数
- 将微信分享从纯文本升级为富媒体卡片分享(type: 0),包含标题、描述、链接和缩略图
- 统一处理空ID时的默认跳转链接,使用config.BASE_URL配置
3个文件已修改
53 ■■■■■ 已修改文件
traditionalApp/pages/courseDetail/courseDetail.vue 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/pages/liveDetail/liveDetail.vue 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/pages/watchLive/watchLive.vue 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/pages/courseDetail/courseDetail.vue
@@ -278,6 +278,7 @@
<script setup lang="ts">
import { computed, getCurrentInstance, nextTick, ref } from 'vue'
import { onHide, onLoad, onShow, onUnload } from '@dcloudio/uni-app'
import config from '@/config/index.js'
import {
    favoriteHealthCourse,
    getHealthCourseDetail,
@@ -785,6 +786,16 @@
}
/**
 * 生成课程 H5 分享链接,供微信好友打开页面详情。
 */
function buildCourseShareUrl() {
    if (!courseId.value) {
        return `${config.BASE_URL}/#/pages/healthCourses/healthCourses`
    }
    return `${config.BASE_URL}/#/pages/courseDetail/courseDetail?id=${encodeURIComponent(courseId.value)}`
}
/**
 * 通过微信好友聊天场景分享当前课程。
 */
function shareToWechatSession() {
@@ -806,8 +817,11 @@
            return
        }
        weixinService.send({
            type: 'text',
            type: 0,
            title: courseDetail.value.title.trim() || '养生课程',
            content: buildCourseShareText(),
            href: buildCourseShareUrl(),
            thumbs: courseDetail.value.bannerImages[0] ? [courseDetail.value.bannerImages[0]] : undefined,
            extra: {
                scene: 'WXSceneSession',
            },
traditionalApp/pages/liveDetail/liveDetail.vue
@@ -91,6 +91,7 @@
    import { computed, ref } from 'vue'
    import { onLoad, onShow } from '@dcloudio/uni-app'
    import { getLiveCourseDetail, reserveLiveCourseSession } from './service'
    import config from '@/config/index.js'
    type LiveDisplayStatus = 'NOT_STARTED' | 'LIVING' | 'ENDED'
    type LiveActionStatus = 'RESERVABLE' | 'RESERVED' | 'WATCHABLE' | 'CLOSED'
@@ -341,6 +342,17 @@
    }
    /**
     * 生成直播详情 H5 分享链接,供微信好友直接打开页面。
     */
    function buildLiveShareUrl() {
        const currentCourseId = String(liveDetail.value.courseId || courseId.value || '').trim()
        if (!currentCourseId) {
            return `${config.BASE_URL}/#/pages/home/home`
        }
        return `${config.BASE_URL}/#/pages/liveDetail/liveDetail?id=${encodeURIComponent(currentCourseId)}`
    }
    /**
     * 直接拉起微信好友聊天分享当前直播。
     */
    function shareToWechatSession() {
@@ -362,8 +374,11 @@
                return
            }
            weixinService.send({
                type: 'text',
                type: 0,
                title: liveDetail.value.title?.trim() || '养生直播',
                content: buildLiveShareText(),
                href: buildLiveShareUrl(),
                thumbs: liveDetail.value.displayImage || liveDetail.value.coverImage ? [liveDetail.value.displayImage || liveDetail.value.coverImage] : undefined,
                extra: {
                    scene: 'WXSceneSession',
                },
traditionalApp/pages/watchLive/watchLive.vue
@@ -139,6 +139,7 @@
import { computed, getCurrentInstance, nextTick, ref } from 'vue';
import { onHide, onLoad, onShow, onUnload } from '@dcloudio/uni-app';
import { getLiveCourseDetail, getLiveQuizStatus, submitLiveQuiz, uploadLiveWatchRecord } from './service';
import config from '@/config/index.js';
type LiveActionStatus = 'RESERVABLE' | 'RESERVED' | 'WATCHABLE' | 'CLOSED'
type QuizViewState = 'answering' | 'success' | 'wrong' | 'unopened'
@@ -1038,6 +1039,20 @@
}
/**
 * 生成直播观看页 H5 分享链接,供微信好友直接打开页面。
 */
function buildWatchLiveShareUrl() {
    if (!courseId.value) {
        return `${config.BASE_URL}/#/pages/home/home`
    }
    const queryList = [`courseId=${encodeURIComponent(courseId.value)}`]
    if (activeSessionId.value) {
        queryList.push(`sessionId=${encodeURIComponent(activeSessionId.value)}`)
    }
    return `${config.BASE_URL}/#/pages/watchLive/watchLive?${queryList.join('&')}`
}
/**
 * 直接拉起微信好友聊天分享当前直播。
 */
function shareToWechatSession() {
@@ -1059,8 +1074,11 @@
            return
        }
        weixinService.send({
            type: 'text',
            type: 0,
            title: liveDetail.value.title?.trim() || '直播观看',
            content: buildWatchLiveShareText(),
            href: buildWatchLiveShareUrl(),
            thumbs: liveDetail.value.displayImage || liveDetail.value.coverImage ? [liveDetail.value.displayImage || liveDetail.value.coverImage] : undefined,
            extra: {
                scene: 'WXSceneSession',
            },