|
|
@@ -19,6 +19,7 @@ import { requireLogin } from '@/hooks/usePageAuth'
|
|
|
import { t } from '@/locale'
|
|
|
import { formatNumber } from '@/utils/index'
|
|
|
import { goBack, toPage } from '@/utils/page'
|
|
|
+import { handleSocialShare } from '@/utils/social'
|
|
|
import { toast } from '@/utils/toast'
|
|
|
import CustomTooltip from './components/CustomTooltip.vue'
|
|
|
import NotificationCarousel from './components/NotificationCarousel.vue'
|
|
|
@@ -369,33 +370,6 @@ const showShare = ref<boolean>(false)
|
|
|
|
|
|
const baseUrl = import.meta.env.VITE_H5_BASE_URL
|
|
|
|
|
|
-function getPlusRuntime() {
|
|
|
- const p = (globalThis as any)?.plus
|
|
|
- return p?.runtime
|
|
|
-}
|
|
|
-
|
|
|
-function isH5ShareSupported() {
|
|
|
- return typeof navigator !== 'undefined' && typeof (navigator as any).share === 'function'
|
|
|
-}
|
|
|
-
|
|
|
-function openH5ShareTarget(platform: string) {
|
|
|
- const { url, text } = generateShareLink()
|
|
|
-
|
|
|
- const targets: Record<string, string> = {
|
|
|
- facebook: `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`,
|
|
|
- whatsapp: `https://wa.me/?text=${encodeURIComponent(text)}`,
|
|
|
- twitter: `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}`,
|
|
|
- instagram: 'https://www.instagram.com/',
|
|
|
- }
|
|
|
-
|
|
|
- const targetUrl = targets[platform]
|
|
|
- if (!targetUrl)
|
|
|
- return
|
|
|
-
|
|
|
- if (typeof window !== 'undefined' && typeof window.open === 'function')
|
|
|
- window.open(targetUrl, '_blank')
|
|
|
-}
|
|
|
-
|
|
|
// 生成商品分享链接
|
|
|
function generateShareLink() {
|
|
|
// 基础域名 - 根据需求使用bandhubuy.shop.com
|
|
|
@@ -424,74 +398,6 @@ function copyToClipboard() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// 检查APP是否安装
|
|
|
-function checkAppInstalled(platform: string): boolean {
|
|
|
- const runtime = getPlusRuntime()
|
|
|
- if (!runtime)
|
|
|
- return false
|
|
|
-
|
|
|
- const appSchemes = {
|
|
|
- facebook: { pname: 'com.facebook.katana', scheme: 'fb://' },
|
|
|
- whatsapp: { pname: 'com.whatsapp', scheme: 'whatsapp://' },
|
|
|
- instagram: { pname: 'com.instagram.android', scheme: 'instagram://' },
|
|
|
- twitter: { pname: 'com.twitter.android', scheme: 'twitter://' },
|
|
|
- }
|
|
|
-
|
|
|
- const appInfo = appSchemes[platform]
|
|
|
- if (!appInfo)
|
|
|
- return false
|
|
|
-
|
|
|
- return runtime.isApplicationExist({
|
|
|
- pname: appInfo.pname,
|
|
|
- action: appInfo.scheme,
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-// 打开社交媒体APP分享
|
|
|
-function openSocialApp(platform: string) {
|
|
|
- const { url, text } = generateShareLink()
|
|
|
-
|
|
|
- const runtime = getPlusRuntime()
|
|
|
- if (!runtime) {
|
|
|
- if (isH5ShareSupported()) {
|
|
|
- ;(navigator as any).share({
|
|
|
- title: detail.value.storeName,
|
|
|
- text,
|
|
|
- url,
|
|
|
- }).catch(() => {
|
|
|
- openH5ShareTarget(platform)
|
|
|
- })
|
|
|
- }
|
|
|
- else {
|
|
|
- openH5ShareTarget(platform)
|
|
|
- }
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 先复制分享内容到剪贴板
|
|
|
- uni.setClipboardData({
|
|
|
- data: text,
|
|
|
- success: () => {
|
|
|
- console.log('分享内容已复制到剪贴板')
|
|
|
- },
|
|
|
- })
|
|
|
-
|
|
|
- const shareUrls = {
|
|
|
- facebook: `fb://facewebmodal/f?href=${encodeURIComponent(url)}`,
|
|
|
- whatsapp: `whatsapp://send?text=${encodeURIComponent(text)}`,
|
|
|
- instagram: 'instagram://camera', // Instagram不支持直接分享链接,打开相机
|
|
|
- twitter: `twitter://post?message=${encodeURIComponent(text)}`,
|
|
|
- }
|
|
|
-
|
|
|
- const shareUrl = shareUrls[platform]
|
|
|
- if (shareUrl) {
|
|
|
- runtime.openURL(shareUrl, (error: any) => {
|
|
|
- console.error('打开APP失败:', error)
|
|
|
- toast.info(t('share.appNotInstalled'))
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
// 统一分享处理方法
|
|
|
function handleShare(platform: string) {
|
|
|
if (platform === 'copyLink') {
|
|
|
@@ -499,22 +405,8 @@ function handleShare(platform: string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if (!getPlusRuntime()) {
|
|
|
- openSocialApp(platform)
|
|
|
- showShare.value = false
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 检查APP是否安装
|
|
|
- if (!checkAppInstalled(platform)) {
|
|
|
- toast.info(t('share.appNotInstalled'))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 打开对应的社交媒体APP
|
|
|
- openSocialApp(platform)
|
|
|
-
|
|
|
- // 关闭分享弹窗
|
|
|
+ const shareData = generateShareLink()
|
|
|
+ handleSocialShare(platform, shareData)
|
|
|
showShare.value = false
|
|
|
}
|
|
|
|