From 66c4f67018315778a30bbcd646105dcd0a8b6201 Mon Sep 17 00:00:00 2001 From: maqian Date: Fri, 17 Oct 2025 17:35:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=A5=BD=E5=8F=8B&=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E6=9C=8B=E5=8F=8B=E5=9C=88=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/custom/custom-page.js | 9 +- src/pages/index.js | 5 +- src/pages/item/espier-detail.js | 5 +- src/pages/recommend/detail.js | 4 +- src/pages/share-land.js | 130 +++++++++++++------ src/subpages/community/espier-detail.js | 5 +- src/subpages/community/group-leaderdetail.js | 4 +- src/subpages/guide/coupon-home/index.js | 4 +- src/subpages/guide/custom/custom-page.js | 4 +- src/subpages/guide/item/espier-detail.js | 5 +- src/subpages/guide/recommend/detail.js | 4 +- src/subpages/mdugc/note-detail.js | 7 +- src/subpages/member/index.js | 4 +- src/subpages/pointshop/espier-detail.js | 5 +- src/subpages/purchase/index.js | 13 +- src/subpages/store/index.js | 5 +- src/utils/entryLaunch.js | 2 + src/utils/index.js | 15 +++ 18 files changed, 159 insertions(+), 71 deletions(-) diff --git a/src/pages/custom/custom-page.js b/src/pages/custom/custom-page.js index f192dedd8..06a15488b 100644 --- a/src/pages/custom/custom-page.js +++ b/src/pages/custom/custom-page.js @@ -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 { diff --git a/src/pages/index.js b/src/pages/index.js index 617b0c9b4..70d62f1d3 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -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) diff --git a/src/pages/item/espier-detail.js b/src/pages/item/espier-detail.js index 2053e4c39..a9007f7cd 100644 --- a/src/pages/item/espier-detail.js +++ b/src/pages/item/espier-detail.js @@ -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, diff --git a/src/pages/recommend/detail.js b/src/pages/recommend/detail.js index 907338e79..ac64701fb 100644 --- a/src/pages/recommend/detail.js +++ b/src/pages/recommend/detail.js @@ -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, diff --git a/src/pages/share-land.js b/src/pages/share-land.js index 497501fea..facc2b2d0 100644 --- a/src/pages/share-land.js +++ b/src/pages/share-land.js @@ -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) => { // routeParams:pa + 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 diff --git a/src/subpages/community/espier-detail.js b/src/subpages/community/espier-detail.js index 95660d42d..371c8195b 100644 --- a/src/subpages/community/espier-detail.js +++ b/src/subpages/community/espier-detail.js @@ -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, diff --git a/src/subpages/community/group-leaderdetail.js b/src/subpages/community/group-leaderdetail.js index f502a4109..2aabd6ba6 100644 --- a/src/subpages/community/group-leaderdetail.js +++ b/src/subpages/community/group-leaderdetail.js @@ -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, diff --git a/src/subpages/guide/coupon-home/index.js b/src/subpages/guide/coupon-home/index.js index f17d9c7eb..872a34d3b 100644 --- a/src/subpages/guide/coupon-home/index.js +++ b/src/subpages/guide/coupon-home/index.js @@ -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, diff --git a/src/subpages/guide/custom/custom-page.js b/src/subpages/guide/custom/custom-page.js index 59b173d29..7c0f38cf8 100644 --- a/src/subpages/guide/custom/custom-page.js +++ b/src/subpages/guide/custom/custom-page.js @@ -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 { diff --git a/src/subpages/guide/item/espier-detail.js b/src/subpages/guide/item/espier-detail.js index ca39ca1d2..5bb29e85b 100644 --- a/src/subpages/guide/item/espier-detail.js +++ b/src/subpages/guide/item/espier-detail.js @@ -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 { diff --git a/src/subpages/guide/recommend/detail.js b/src/subpages/guide/recommend/detail.js index e4d09305b..4b1e16435 100644 --- a/src/subpages/guide/recommend/detail.js +++ b/src/subpages/guide/recommend/detail.js @@ -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, diff --git a/src/subpages/mdugc/note-detail.js b/src/subpages/mdugc/note-detail.js index 22e891662..b7ccb1657 100644 --- a/src/subpages/mdugc/note-detail.js +++ b/src/subpages/mdugc/note-detail.js @@ -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 } }) diff --git a/src/subpages/member/index.js b/src/subpages/member/index.js index 7ae373ea1..7e8359674 100644 --- a/src/subpages/member/index.js +++ b/src/subpages/member/index.js @@ -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 } }) diff --git a/src/subpages/pointshop/espier-detail.js b/src/subpages/pointshop/espier-detail.js index bf3756a81..41bedd70d 100644 --- a/src/subpages/pointshop/espier-detail.js +++ b/src/subpages/pointshop/espier-detail.js @@ -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, diff --git a/src/subpages/purchase/index.js b/src/subpages/purchase/index.js index a55ecab53..cfe368726 100644 --- a/src/subpages/purchase/index.js +++ b/src/subpages/purchase/index.js @@ -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 }) } }) diff --git a/src/subpages/store/index.js b/src/subpages/store/index.js index 999659567..72f119a59 100644 --- a/src/subpages/store/index.js +++ b/src/subpages/store/index.js @@ -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, diff --git a/src/utils/entryLaunch.js b/src/utils/entryLaunch.js index df6beb0d4..ee3140cc2 100644 --- a/src/utils/entryLaunch.js +++ b/src/utils/entryLaunch.js @@ -64,6 +64,8 @@ class EntryLaunch { ..._options, ...res } + delete _options?.distributorInfo + delete _options?.salespersonInfo } } else { _options = params diff --git a/src/utils/index.js b/src/utils/index.js index ebfe64f1a..0d6d92ff5 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -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,