feat(user): 使用微信原生 Picker 替换所在地选择弹层
- 删除 NutUI Address 相关导入、状态及地区数据转换逻辑 - 新增派生 regionValue 用于绑定微信原生 Picker 的 value - 将 handleRegionChange 调整为处理微信 Picker 的事件 - 将所在地选择 UI 修改为微信原生 Picker 包裹的视图结构 - 地图定位失败使用弹窗提示,引导用户手动选择或重试 - 移除手动打开地区选择器的函数及 NutUI 组件 - 保留 RegionData 用于文本智能识别解析 - 编译通过,提升在无地图或无权限环境下的地区选择稳定性
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import React, { useEffect, useState, useRef } from 'react'
|
||||
import { View, Text, Image, ScrollView } from '@tarojs/components'
|
||||
import Taro, { useRouter } from '@tarojs/taro'
|
||||
import { getShopGroupBuy, listShopGroupBuyRecords, joinGroupBuy, createGroupBuy } from '@/api/shop/shopGroupBuy'
|
||||
@@ -8,9 +8,13 @@ import type { ShopGoods } from '@/api/shop/shopGoods/model'
|
||||
import type { ShopGoodsSku } from '@/api/shop/shopGoodsSku/model'
|
||||
import SkuSelector from '@/components/business/SkuSelector'
|
||||
import { getCompressedImageUrl } from '@/utils/image'
|
||||
import { useShare } from '@/hooks/useShare'
|
||||
import SharePoster, { SharePosterHandle } from '@/components/SharePoster'
|
||||
|
||||
definePageConfig({
|
||||
navigationBarTitleText: '拼团详情',
|
||||
enableShareAppMessage: true,
|
||||
enableShareTimeline: true,
|
||||
})
|
||||
|
||||
const GroupBuyDetailPage: React.FC = () => {
|
||||
@@ -25,6 +29,31 @@ const GroupBuyDetailPage: React.FC = () => {
|
||||
const [skuVisible, setSkuVisible] = useState(false)
|
||||
const [pendingRecordId, setPendingRecordId] = useState<number | null>(null)
|
||||
|
||||
// 分享 / 朋友圈
|
||||
const posterRef = useRef<SharePosterHandle>(null)
|
||||
const [posterPath, setPosterPath] = useState('')
|
||||
useShare({
|
||||
title: groupBuy?.goodsName || groupBuy?.product?.name || '拼团商品推荐',
|
||||
path: `/pages/shop/group-buy-detail?groupBuyId=${groupBuyId}`,
|
||||
query: `groupBuyId=${groupBuyId}`,
|
||||
imageUrl: posterPath || groupBuy?.goodsImage || groupBuy?.product?.image || undefined,
|
||||
})
|
||||
|
||||
// 数据加载完成后异步生成分享海报(带小程序码)
|
||||
useEffect(() => {
|
||||
if (groupBuy) {
|
||||
posterRef.current
|
||||
?.generate({
|
||||
cover: groupBuy.goodsImage || groupBuy.product?.image,
|
||||
title: groupBuy.goodsName || groupBuy.product?.name || '拼团商品',
|
||||
price: groupBuy.groupPrice,
|
||||
page: 'pages/shop/group-buy-detail',
|
||||
})
|
||||
.then(setPosterPath)
|
||||
.catch(() => {})
|
||||
}
|
||||
}, [groupBuy])
|
||||
|
||||
useEffect(() => {
|
||||
if (groupBuyId) {
|
||||
fetchData()
|
||||
@@ -317,6 +346,8 @@ const GroupBuyDetailPage: React.FC = () => {
|
||||
onClose={() => setSkuVisible(false)}
|
||||
onConfirm={handleSkuConfirm}
|
||||
/>
|
||||
{/* 分享海报画布(离屏,用于生成带小程序码的海报图) */}
|
||||
<SharePoster ref={posterRef} />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import React, { useState, useEffect, useRef } from 'react'
|
||||
import { View, Text, Image, ScrollView, Swiper, SwiperItem, RichText } from '@tarojs/components'
|
||||
import { Tag } from '@nutui/nutui-react-taro'
|
||||
import Taro, { useRouter, useShareAppMessage } from '@tarojs/taro'
|
||||
import Taro, { useRouter } from '@tarojs/taro'
|
||||
import { getShopGoods } from '@/api/shop/shopGoods'
|
||||
import {
|
||||
addShopGoodsFavorite,
|
||||
@@ -14,12 +14,16 @@ import SkuSelector from '@/components/business/SkuSelector'
|
||||
import { useCartContext } from '@/contexts/CartContext'
|
||||
import { useUserContext } from '@/contexts/UserContext'
|
||||
import { useScrollHeight } from '@/hooks/useScrollHeight'
|
||||
import { useShare } from '@/hooks/useShare'
|
||||
import SharePoster, { SharePosterHandle } from '@/components/SharePoster'
|
||||
import { isGuest } from '@/utils/auth'
|
||||
import { requireLogin } from '@/utils/login-guard'
|
||||
import { isVipMember } from '@/utils/vip'
|
||||
|
||||
definePageConfig({
|
||||
navigationBarTitleText: '商品详情',
|
||||
enableShareAppMessage: true,
|
||||
enableShareTimeline: true,
|
||||
})
|
||||
|
||||
const ProductDetailPage: React.FC = () => {
|
||||
@@ -35,13 +39,14 @@ const ProductDetailPage: React.FC = () => {
|
||||
// 底部操作栏高度约 90px(含按钮 + 安全区),动态计算 ScrollView 可用高度
|
||||
const scrollHeight = useScrollHeight(44)
|
||||
|
||||
// 微信分享配置
|
||||
useShareAppMessage(() => {
|
||||
return {
|
||||
title: product?.name || product?.goodsName || '优质商品推荐',
|
||||
path: `/pages/shop/product-detail?id=${id}`,
|
||||
imageUrl: product?.image || ''
|
||||
}
|
||||
// 分享 / 朋友圈
|
||||
const posterRef = useRef<SharePosterHandle>(null)
|
||||
const [posterPath, setPosterPath] = useState('')
|
||||
useShare({
|
||||
title: product?.name || product?.goodsName || '优质商品推荐',
|
||||
path: `/pages/shop/product-detail?id=${id}`,
|
||||
query: `id=${id}`,
|
||||
imageUrl: posterPath || product?.image || undefined,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
@@ -53,10 +58,20 @@ const ProductDetailPage: React.FC = () => {
|
||||
}
|
||||
}, [id, isLoggedIn])
|
||||
|
||||
// 监听 product 变化后再添加到历史记录
|
||||
// 监听 product 变化后再添加到历史记录,并异步生成分享海报
|
||||
useEffect(() => {
|
||||
if (product) {
|
||||
addToHistory()
|
||||
posterRef.current
|
||||
?.generate({
|
||||
cover: product.image,
|
||||
title: product.name || product.goodsName || '优质商品推荐',
|
||||
price:
|
||||
product.dealerPrice && isVipMember() ? product.dealerPrice : product.price,
|
||||
page: 'pages/shop/product-detail',
|
||||
})
|
||||
.then(setPosterPath)
|
||||
.catch(() => {})
|
||||
}
|
||||
}, [product])
|
||||
|
||||
@@ -444,6 +459,9 @@ const ProductDetailPage: React.FC = () => {
|
||||
onClose={() => setSkuVisible(false)}
|
||||
onConfirm={handleSkuConfirm}
|
||||
/>
|
||||
|
||||
{/* 分享海报画布(离屏,用于生成带小程序码的海报图) */}
|
||||
<SharePoster ref={posterRef} />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import React, { useEffect, useState, useRef } from 'react'
|
||||
import { View, Text, Image, ScrollView } from '@tarojs/components'
|
||||
import Taro, { useRouter } from '@tarojs/taro'
|
||||
import { getShopSeckill, createSeckillOrder } from '@/api/shop/shopSeckill'
|
||||
@@ -7,9 +7,13 @@ import type { ShopSeckill } from '@/api/shop/shopSeckill/model'
|
||||
import type { ShopGoods } from '@/api/shop/shopGoods/model'
|
||||
import type { ShopGoodsSku } from '@/api/shop/shopGoodsSku/model'
|
||||
import SkuSelector from '@/components/business/SkuSelector'
|
||||
import { useShare } from '@/hooks/useShare'
|
||||
import SharePoster, { SharePosterHandle } from '@/components/SharePoster'
|
||||
|
||||
definePageConfig({
|
||||
navigationBarTitleText: '秒杀详情',
|
||||
enableShareAppMessage: true,
|
||||
enableShareTimeline: true,
|
||||
})
|
||||
|
||||
const SeckillDetailPage: React.FC = () => {
|
||||
@@ -24,6 +28,31 @@ const SeckillDetailPage: React.FC = () => {
|
||||
const [countdown, setCountdown] = useState('')
|
||||
const [skuVisible, setSkuVisible] = useState(false)
|
||||
|
||||
// 分享 / 朋友圈
|
||||
const posterRef = useRef<SharePosterHandle>(null)
|
||||
const [posterPath, setPosterPath] = useState('')
|
||||
useShare({
|
||||
title: seckill?.goodsName || seckill?.product?.name || '秒杀商品推荐',
|
||||
path: `/pages/shop/seckill-detail?seckillId=${seckillId}`,
|
||||
query: `seckillId=${seckillId}`,
|
||||
imageUrl: posterPath || seckill?.goodsImage || seckill?.product?.image || undefined,
|
||||
})
|
||||
|
||||
// 数据加载完成后异步生成分享海报(带小程序码)
|
||||
useEffect(() => {
|
||||
if (seckill) {
|
||||
posterRef.current
|
||||
?.generate({
|
||||
cover: seckill.goodsImage || seckill.product?.image,
|
||||
title: seckill.goodsName || seckill.product?.name || '秒杀商品',
|
||||
price: seckill.seckillPrice,
|
||||
page: 'pages/shop/seckill-detail',
|
||||
})
|
||||
.then(setPosterPath)
|
||||
.catch(() => {})
|
||||
}
|
||||
}, [seckill])
|
||||
|
||||
useEffect(() => {
|
||||
if (seckillId) {
|
||||
fetchData()
|
||||
@@ -272,6 +301,8 @@ const SeckillDetailPage: React.FC = () => {
|
||||
onClose={() => setSkuVisible(false)}
|
||||
onConfirm={handleSkuConfirm}
|
||||
/>
|
||||
{/* 分享海报画布(离屏,用于生成带小程序码的海报图) */}
|
||||
<SharePoster ref={posterRef} />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user