分享好友&分享朋友圈改造

This commit is contained in:
maqian
2025-10-17 17:35:05 +08:00
parent 16cafaf091
commit 66c4f67018
18 changed files with 159 additions and 71 deletions

View File

@@ -15,7 +15,7 @@ import S from '@/spx'
import { View } from '@tarojs/components'
import { SpPage, SpSearch, SpSkuSelect, SpTabbar, SpLogin } from '@/components'
import { WgtsContext } from '@/pages/home/wgts/wgts-context'
import { getDistributorId, log, entryLaunch, pickBy, showToast, VERSION_STANDARD } from '@/utils'
import { getDistributorId, log, entryLaunch, pickBy, showToast, VERSION_STANDARD, buildSharePath } from '@/utils'
import { platformTemplateName, transformPlatformUrl } from '@/utils/platform'
import { useLogin, useNavigation, useLocation, useModal } from '@/hooks'
import { SG_ROUTER_PARAMS } from '@/consts/localstorage'
@@ -107,8 +107,11 @@ function CustomPage(props) {
const getAppShareInfo = async () => {
const { id } = await entryLaunch.getRouteParams($instance.router.params)
const { userId } = Taro.getStorageSync('userinfo')
const query = userId ? `?uid=${userId}&id=${id}` : `?id=${id}`
let path = `/pages/custom/custom-page${query}`
const params = { id }
if (userId) {
params.uid = userId
}
const path = buildSharePath('/pages/custom/custom-page', params)
log.debug(`getAppShareInfo: ${path}`)
return {

View File

@@ -35,7 +35,8 @@ import {
pickBy,
log,
showToast,
entryLaunch
entryLaunch,
buildSharePath
} from '@/utils'
import { updateShopInfo } from '@/store/slices/shop'
import {
@@ -145,7 +146,7 @@ function Home() {
if (VERSION_STANDARD) {
params = Object.assign(params, { dtid: getCurrentShopId() })
}
let path = `/pages/index${isEmpty(params) ? '' : '?' + resolveStringifyParams(params)}`
const path = buildSharePath('/pages/index', params)
console.log('useShareAppMessage path:', path, params)

View File

@@ -39,7 +39,8 @@ import {
isAPP,
showToast,
getDistributorId,
VERSION_STANDARD
VERSION_STANDARD,
buildSharePath
} from '@/utils'
import { fetchUserFavs } from '@/store/slices/user'
@@ -237,7 +238,7 @@ function EspierDetail(props) {
if (userInfo) {
query['uid'] = userInfo.user_id
}
const path = `/pages/item/espier-detail?${qs.stringify(query)}`
const path = buildSharePath('/pages/item/espier-detail', query)
log.debug(`share path: ${path}`)
return {
title: itemName,

View File

@@ -8,7 +8,7 @@ import { AtButton } from 'taro-ui'
import { SpPage } from '@/components'
import api from '@/api'
import doc from '@/doc'
import { pickBy, log } from '@/utils'
import { pickBy, log, buildSharePath } from '@/utils'
import { withPageWrapper } from '@/hocs'
import { WgtFilm, WgtSlider, WgtWriting, WgtGoods, WgtHeading } from '../home/wgts'
import './detail.scss'
@@ -47,7 +47,7 @@ function GuideRecommendDetail(props) {
gu: `${work_userid}_${shop_code}`,
subtask_id
}
const sharePath = `/pages/recommend/detail?${qs.stringify(query)}`
const sharePath = buildSharePath('/pages/recommend/detail', query)
log.debug(`【/pages/recommend/detail】onShareAppMessage path: ${sharePath}`)
return {
title: title,

View File

@@ -7,9 +7,14 @@ import qs from 'qs'
import { entryLaunch, showToast } from '@/utils'
/**
* path 页面路径(必穿参数)(参数格式 path=/pages/indes
* 其余参数会自动携带到path后面不用手动处理
* scene=uid%3D884%26id%3D121%26qr%3DY%26path%3D%2Fsubpages%2Fprescription%2Fprescription-information(页面参数,可供验证)
* 统一分享落地页
* 参数说明:
* - target_path: 目标页面路径 (必传, 如: target_path=pages/index)
* - 其余参数会自动携带到目标页面 target_path=pages/item/espier-detail&id=123
*
* 兼容旧的场景:
* - from_scene: 导购欢迎语场景
* - t: 特殊场景标识(如处方药)
* @returns
*/
function ShareIand() {
@@ -23,47 +28,94 @@ function ShareIand() {
const resloveRouterParams = async () => {
const routeParams = await entryLaunch.getRouteParams(router)
Taro.setStorageSync(SG_ROUTER_PARAMS, routeParams)
if (/^guide_welcome/.test(routeParams?.from_scene)) {
// 导购欢迎语
if (routeParams.from_scene == 'guide_welcome_home') {
// 导购欢迎语--商城首页
Taro.redirectTo({ url: '/pages/index' })
} else if (routeParams.from_scene == 'guide_welcome_category') {
// 导购欢迎语--商城分类页
Taro.redirectTo({ url: '/pages/category/index' })
} else if (routeParams.from_scene == 'guide_welcome_couponlist') {
// 导购欢迎语--商城优惠券中心
Taro.redirectTo({ url: '/subpages/marketing/coupon-center' })
} else if (routeParams.from_scene == 'guide_welcome_recommend') {
// 导购欢迎语--商城种草
Taro.redirectTo({ url: '/pages/recommend/list' })
} else if (routeParams.from_scene == 'guide_welcome_member') {
// 导购欢迎语--商城会员中心
Taro.redirectTo({ url: '/subpages/member/index' })
} else if (routeParams.from_scene == 'guide_welcome_itemlist') {
// 导购欢迎语--商城商品列表
Taro.redirectTo({ url: '/pages/item/list' })
} else {
showToast('未匹配到参数')
}
// 欢迎语携带用户编号
if (routeParams?.gu || routeParams?.gu_user_id) { // 导购参数处理
Taro.setStorageSync(SG_GUIDE_PARAMS, routeParams)
Taro.setStorageSync(SG_GUIDE_PARAMS_UPDATETIME, dayjs().unix())
if (S.getAuthToken()) {
entryLaunch.postGuideUV()
entryLaunch.postGuideTask()
}
} else {
// 分享的太阳码场景
const _tempParams = {}
if (routeParams?.t == 1) { // 处方药
_tempParams.order_id = routeParams.oi
_tempParams.prescription_order_random = routeParams.r
Taro.redirectTo({ url: `/subpages/prescription/prescription-information?${qs.stringify(_tempParams)}` })
entryLaunch.postGuideUV() // 导购uv上报
entryLaunch.postGuideTask() // 导购任务上报
}
}
debugger
// 处理导购欢迎语场景
if (/^guide_welcome/.test(routeParams?.from_scene)) {
handleGuideWelcome(routeParams)
return
}
// 处理处方药场景
if (routeParams?.t == 1) {
handlePrescription(routeParams)
return
}
// 处理通用分享场景
if (routeParams?.target_path) {
debugger
handleGeneralShare(routeParams)
return
}
// 默认跳转到首页
Taro.redirectTo({ url: '/pages/index' })
}
// 处理导购欢迎语
const handleGuideWelcome = (routeParams) => {
const welcomeRoutes = {
'guide_welcome_home': '/pages/index', // 导购欢迎语--商城首页
'guide_welcome_category': '/pages/category/index', // 导购欢迎语--商城分类页
'guide_welcome_couponlist': '/subpages/marketing/coupon-center', // 导购欢迎语--商城优惠券中心
'guide_welcome_recommend': '/pages/recommend/list', // 导购欢迎语--商城种草
'guide_welcome_member': '/subpages/member/index', // 导购欢迎语--商城会员中心
'guide_welcome_itemlist': '/pages/item/list' // 导购欢迎语--商城商品列表
}
const targetUrl = welcomeRoutes[routeParams.from_scene]
if (targetUrl) {
Taro.redirectTo({ url: targetUrl })
} else {
showToast('未匹配到参数')
}
}
// 处理处方药场景
const handlePrescription = (routeParams) => {
const params = {
order_id: routeParams.oi,
prescription_order_random: routeParams.r
}
Taro.redirectTo({
url: `/subpages/prescription/prescription-information?${qs.stringify(params)}`
})
}
// 处理通用分享场景
// 1、海报分享 pages/share-land?scene=share_id%3D68f2037ca18f8 通过shareid获取参数
// 2、小程序转发 pages/share-land?target_path=pages/item/espier-detail&id=123
// 3、其他小程序跳转过来 pages/share-land?target_path=pages/item/espier-detail&id=123
// 4、小程序卡片跳转过来 pages/share-land?target_path=pages/item/espier-detail&id=123
const handleGeneralShare = (routeParams) => { // routeParamspa
const { target_path, ...otherParams } = routeParams
// 过滤掉内部使用的参数
const filteredParams = { ...otherParams }
delete filteredParams.scene
delete filteredParams.$taroTimestamp
// 确保路径以 / 开头
let normalizedPath = target_path
if (normalizedPath && !normalizedPath.startsWith('/')) {
normalizedPath = '/' + normalizedPath
}
// 构建目标URL
const queryString = qs.stringify(filteredParams)
const targetUrl = queryString ? `${normalizedPath}?${queryString}` : normalizedPath
console.log('通用分享跳转:', targetUrl)
Taro.redirectTo({ url: targetUrl })
}
return null

View File

@@ -35,7 +35,8 @@ import {
classNames,
navigateTo,
VERSION_PLATFORM,
isAPP
isAPP,
buildSharePath
} from '@/utils'
import doc from '@/doc'
@@ -183,7 +184,7 @@ function EspierDetail(props) {
if (userInfo) {
query['uid'] = userInfo.uid
}
const path = `/pages/item/espier-detail?${qs.stringify(query)}`
const path = buildSharePath('/pages/item/espier-detail', query)
log.debug(`share path: ${path}`)
return {
title: itemName,

View File

@@ -5,7 +5,7 @@ import Taro, { useShareAppMessage, useDidShow, getCurrentInstance } from '@taroj
import { View, Text, Button } from '@tarojs/components'
import { SpPage, SpImage, SpButton, SpUpload, SpCell } from '@/components'
import { AtCountdown, AtButton, AtProgress } from 'taro-ui'
import { calcTimer, pickBy, log, isArray } from '@/utils'
import { calcTimer, pickBy, log, isArray, buildSharePath } from '@/utils'
import doc from '@/doc'
import api from '@/api'
@@ -52,7 +52,7 @@ function GroupLeaderDetail(props) {
}
useShareAppMessage(() => {
const path = `/subpages/community/group-memberdetail?activity_id=${detail.activityId}`
const path = buildSharePath('/subpages/community/group-memberdetail', { activity_id: detail.activityId })
log.debug(`share path: ${path}`)
return {
imageUrl: shareImageUrl,

View File

@@ -12,7 +12,7 @@ import { SpPage, SpScrollView, CouponItem } from '@/components'
import api from '@/api'
import doc from '@/doc'
import qs from 'qs'
import { pickBy, log } from '@/utils'
import { pickBy, log, buildSharePath } from '@/utils'
import { useQwLogin } from '@/hooks'
import {
BaHomeWgts,
@@ -72,7 +72,7 @@ function GuideCouponIndex(props) {
// subtask_id: subtaskId
}
const path = `/subpages/marketing/coupon-center?${qs.stringify(query)}`
const path = buildSharePath('/subpages/marketing/coupon-center', query)
log.debug(`getAppShareInfo: ${path}`)
return {
title: title,

View File

@@ -11,7 +11,7 @@ import qs from 'qs'
import { AtButton } from 'taro-ui'
import { SpScreenAd, SpPage, SpSearch, SpRecommend, SpTabbar } from '@/components'
import api from '@/api'
import { isWeixin, log } from '@/utils'
import { isWeixin, log, buildSharePath } from '@/utils'
import entryLaunch from '@/utils/entryLaunch'
import { updateStoreInfo } from '@/store/slices/guide'
import { useImmer } from 'use-immer'
@@ -78,7 +78,7 @@ function GuideCustomPage() {
gu: `${work_userid}_${shop_code}`,
subtask_id
}
const path = `/pages/custom/custom-page?${qs.stringify(query)}`
const path = buildSharePath('/pages/custom/custom-page', query)
log.debug(`share path: ${path}`)
return {

View File

@@ -35,7 +35,8 @@ import {
isWeb,
pickBy,
classNames,
navigateTo
navigateTo,
buildSharePath
} from '@/utils'
import doc from '@/doc'
@@ -198,7 +199,7 @@ function EspierDetail(props) {
gu: `${work_userid}_${shop_code}`,
subtask_id: subtaskId
}
const path = `/pages/item/espier-detail?${qs.stringify(query)}`
const path = buildSharePath('/pages/item/espier-detail', query)
console.log('gu---------------------',path)
log.debug(`share path: ${path}`)
return {

View File

@@ -8,7 +8,7 @@ import { AtButton } from 'taro-ui'
import { SpPage } from '@/components'
import api from '@/api'
import doc from '@/doc'
import { pickBy, log } from '@/utils'
import { pickBy, log, buildSharePath } from '@/utils'
import { WgtFilm, WgtSlider, WgtWriting, WgtGoods, WgtHeading } from '../components/wgts'
import './detail.scss'
@@ -46,7 +46,7 @@ function GuideRecommendDetail(props) {
gu: `${work_userid}_${shop_code}`,
subtask_id
}
const sharePath = `/pages/recommend/detail?${qs.stringify(query)}`
const sharePath = buildSharePath('/pages/recommend/detail', query)
log.debug(`【guide/recommend/detail】onShareAppMessage path: ${sharePath}`)
return {
title: title,

View File

@@ -6,7 +6,7 @@ import { AtButton, AtInput, AtActionSheet, AtActionSheetItem } from 'taro-ui'
import { SpHtml, SpFloatMenuItem, SpPage, SpImage, SpLoading, SpLogin, SpScrollView } from '@/components'
import S from '@/spx'
import { WgtFloorImg } from '@/pages/home/wgts'
import { classNames, isWeb, isWeixin, showToast, pickBy, isNumber } from '@/utils'
import { classNames, isWeb, isWeixin, showToast, pickBy, isNumber, buildSharePath } from '@/utils'
import api from '@/api'
import doc from '@/doc'
@@ -131,10 +131,11 @@ function UgcNoteDetail(props) {
draft.info['shareNums'] = shareInfo.share_nums
})
}
console.log(`useShareAppMessage:`, `/subpages/mdugc/note-detail?post_id=${post_id}`)
const path = buildSharePath('/subpages/mdugc/note-detail', { post_id })
console.log(`useShareAppMessage:`, path)
return {
title: info.title,
path: `/subpages/mdugc/note-detail?post_id=${post_id}`,
path,
imageUrl: info.cover
}
})

View File

@@ -11,6 +11,7 @@ import { useImmer } from 'use-immer'
import S from '@/spx'
import qs from 'qs'
import req from '@/api/req'
import { buildSharePath } from '@/utils'
import { SpLogin, SpImage, SpTabbar, SpPage, SpCell } from '@/components'
import api from '@/api'
@@ -185,10 +186,11 @@ function MemberIndex(props) {
const { logo } = await api.distribution.getDistributorInfo({
distributor_id: 0
})
const path = buildSharePath('/pages/index', {})
return {
title: share_title,
imageUrl: share_pic_wechatapp || logo,
path: '/pages/index'
path: path
}
})

View File

@@ -35,7 +35,8 @@ import {
classNames,
navigateTo,
VERSION_PLATFORM,
isAPP
isAPP,
buildSharePath
} from '@/utils'
import doc from '@/doc'
@@ -167,7 +168,7 @@ function PointShopEspierDetail(props) {
if (userInfo) {
query['uid'] = userInfo.user_id
}
const path = `/subpages/pointshop/espier-detail?${qs.stringify(query)}`
const path = buildSharePath('/subpages/pointshop/espier-detail', query)
log.debug(`share path: ${path}`)
return {
title: itemName,

View File

@@ -28,7 +28,8 @@ import {
classNames,
pickBy,
showToast,
log
log,
buildSharePath
} from '@/utils'
import {
updatePurchaseShareInfo,
@@ -168,11 +169,17 @@ function Home() {
const activity_id = router.params?.activity_id || purchase_share_info?.activity_id
const enterprise_id = router.params?.enterprise_id || purchase_share_info?.enterprise_id
const data = await api.purchase.getEmployeeInviteCode({ enterprise_id, activity_id })
log.debug(`/pages/purchase/auth?code=${data.invite_code}`)
const params = {
code: data.invite_code,
enterprise_id,
activity_id
}
const path = buildSharePath('/pages/purchase/auth', params)
log.debug(path)
resolve({
title: activityInfo.name,
imageUrl: activityInfo.share_pic,
path: `/pages/purchase/auth?code=${data.invite_code}&enterprise_id=${enterprise_id}&activity_id=${activity_id}`
path
})
}
})

View File

@@ -31,7 +31,8 @@ import {
entryLaunch,
pickBy,
log,
showToast
showToast,
buildSharePath
} from '@/utils'
import { useImmer } from 'use-immer'
import { useNavigation, useDebounce } from '@/hooks'
@@ -269,7 +270,7 @@ function StoreIndex() {
const query = {
dtid
}
const path = `/subpages/store/index?${qs.stringify(query)}`
const path = buildSharePath('/subpages/store/index', query)
log.debug(`share path: ${path}`)
return {
title: storeInfo?.name,

View File

@@ -64,6 +64,8 @@ class EntryLaunch {
..._options,
...res
}
delete _options?.distributorInfo
delete _options?.salespersonInfo
}
} else {
_options = params

View File

@@ -883,6 +883,21 @@ export const pxToUnitRpx = (px) => {
return Taro.pxTransform(px * 2)
}
/**
* 构建统一分享路径
* @param {string} target_path - 目标页面路径
* @param {object} params - 路径参数
* @returns {string} 统一的分享落地页路径
*/
export function buildSharePath(target_path, params = {}) {
const shareParams = {
target_path: target_path,
...params
}
const queryString = qs.stringify(shareParams)
return `/pages/share-land${queryString ? '?' + queryString : ''}`
}
export {
classNames,
log,