|
|
@@ -368,6 +368,34 @@ const socialPlatforms = ref([
|
|
|
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
|
|
|
@@ -375,7 +403,10 @@ function generateShareLink() {
|
|
|
|
|
|
// 分享文案格式:[BandhuBuy] + 商品链接 + 商品名称 + 邀请文案
|
|
|
const productName = detail.value.storeName
|
|
|
- const shareText = `[BandhuBuy] ${productUrl} ${productName}\nGet it on BandhuBuy now!`
|
|
|
+ const shareText = t('share.productShareText', {
|
|
|
+ url: productUrl,
|
|
|
+ productName,
|
|
|
+ })
|
|
|
|
|
|
return {
|
|
|
url: productUrl,
|
|
|
@@ -395,6 +426,10 @@ 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://' },
|
|
|
@@ -406,7 +441,7 @@ function checkAppInstalled(platform: string): boolean {
|
|
|
if (!appInfo)
|
|
|
return false
|
|
|
|
|
|
- return plus.runtime.isApplicationExist({
|
|
|
+ return runtime.isApplicationExist({
|
|
|
pname: appInfo.pname,
|
|
|
action: appInfo.scheme,
|
|
|
})
|
|
|
@@ -416,6 +451,23 @@ function checkAppInstalled(platform: string): boolean {
|
|
|
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,
|
|
|
@@ -433,7 +485,7 @@ function openSocialApp(platform: string) {
|
|
|
|
|
|
const shareUrl = shareUrls[platform]
|
|
|
if (shareUrl) {
|
|
|
- plus.runtime.openURL(shareUrl, (error) => {
|
|
|
+ runtime.openURL(shareUrl, (error: any) => {
|
|
|
console.error('打开APP失败:', error)
|
|
|
toast.info(t('share.appNotInstalled'))
|
|
|
})
|
|
|
@@ -447,6 +499,12 @@ function handleShare(platform: string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if (!getPlusRuntime()) {
|
|
|
+ openSocialApp(platform)
|
|
|
+ showShare.value = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// 检查APP是否安装
|
|
|
if (!checkAppInstalled(platform)) {
|
|
|
toast.info(t('share.appNotInstalled'))
|