|
@@ -23,6 +23,33 @@ const safeAreaInsets = systemInfo.safeAreaInsets
|
|
|
const userStore = useUserStore()
|
|
const userStore = useUserStore()
|
|
|
const baseUrl = import.meta.env.VITE_H5_BASE_URL
|
|
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 } = generateInviteShareLink()
|
|
|
|
|
+
|
|
|
|
|
+ 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')
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 推荐码
|
|
// 推荐码
|
|
|
const userInfo = computed(() => getUserInfoHook())
|
|
const userInfo = computed(() => getUserInfoHook())
|
|
|
const qrcodeConfig = ref<any>({
|
|
const qrcodeConfig = ref<any>({
|
|
@@ -74,7 +101,9 @@ function generateInviteShareLink() {
|
|
|
const inviteUrl = `${baseUrl}?referrer=${userInfo.value.invitedCode}`
|
|
const inviteUrl = `${baseUrl}?referrer=${userInfo.value.invitedCode}`
|
|
|
|
|
|
|
|
// 分享文案格式:[BandhuBuy] + 邀请注册链接 + 邀请文案
|
|
// 分享文案格式:[BandhuBuy] + 邀请注册链接 + 邀请文案
|
|
|
- const shareText = `[BandhuBuy] ${inviteUrl} Your friend invited you to register`
|
|
|
|
|
|
|
+ const shareText = t('share.inviteShareText', {
|
|
|
|
|
+ url: inviteUrl,
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
url: inviteUrl,
|
|
url: inviteUrl,
|
|
@@ -84,6 +113,10 @@ function generateInviteShareLink() {
|
|
|
|
|
|
|
|
// 检查APP是否安装
|
|
// 检查APP是否安装
|
|
|
function checkAppInstalled(platform: string): boolean {
|
|
function checkAppInstalled(platform: string): boolean {
|
|
|
|
|
+ const runtime = getPlusRuntime()
|
|
|
|
|
+ if (!runtime)
|
|
|
|
|
+ return false
|
|
|
|
|
+
|
|
|
const appSchemes = {
|
|
const appSchemes = {
|
|
|
facebook: { pname: 'com.facebook.katana', scheme: 'fb://' },
|
|
facebook: { pname: 'com.facebook.katana', scheme: 'fb://' },
|
|
|
whatsapp: { pname: 'com.whatsapp', scheme: 'whatsapp://' },
|
|
whatsapp: { pname: 'com.whatsapp', scheme: 'whatsapp://' },
|
|
@@ -95,7 +128,7 @@ function checkAppInstalled(platform: string): boolean {
|
|
|
if (!appInfo)
|
|
if (!appInfo)
|
|
|
return false
|
|
return false
|
|
|
|
|
|
|
|
- return plus.runtime.isApplicationExist({
|
|
|
|
|
|
|
+ return runtime.isApplicationExist({
|
|
|
pname: appInfo.pname,
|
|
pname: appInfo.pname,
|
|
|
action: appInfo.scheme,
|
|
action: appInfo.scheme,
|
|
|
})
|
|
})
|
|
@@ -105,6 +138,23 @@ function checkAppInstalled(platform: string): boolean {
|
|
|
function openSocialApp(platform: string) {
|
|
function openSocialApp(platform: string) {
|
|
|
const { url, text } = generateInviteShareLink()
|
|
const { url, text } = generateInviteShareLink()
|
|
|
|
|
|
|
|
|
|
+ const runtime = getPlusRuntime()
|
|
|
|
|
+ if (!runtime) {
|
|
|
|
|
+ if (isH5ShareSupported()) {
|
|
|
|
|
+ ;(navigator as any).share({
|
|
|
|
|
+ title: 'BandhuBuy',
|
|
|
|
|
+ text,
|
|
|
|
|
+ url,
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ openH5ShareTarget(platform)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ openH5ShareTarget(platform)
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 先复制分享内容到剪贴板
|
|
// 先复制分享内容到剪贴板
|
|
|
uni.setClipboardData({
|
|
uni.setClipboardData({
|
|
|
data: text,
|
|
data: text,
|
|
@@ -122,7 +172,7 @@ function openSocialApp(platform: string) {
|
|
|
|
|
|
|
|
const shareUrl = shareUrls[platform]
|
|
const shareUrl = shareUrls[platform]
|
|
|
if (shareUrl) {
|
|
if (shareUrl) {
|
|
|
- plus.runtime.openURL(shareUrl, (error) => {
|
|
|
|
|
|
|
+ runtime.openURL(shareUrl, (error: any) => {
|
|
|
console.error('打开APP失败:', error)
|
|
console.error('打开APP失败:', error)
|
|
|
toast.info(t('share.appNotInstalled'))
|
|
toast.info(t('share.appNotInstalled'))
|
|
|
})
|
|
})
|
|
@@ -131,6 +181,11 @@ function openSocialApp(platform: string) {
|
|
|
|
|
|
|
|
// 统一分享处理方法
|
|
// 统一分享处理方法
|
|
|
function handleShare(platform: string) {
|
|
function handleShare(platform: string) {
|
|
|
|
|
+ if (!getPlusRuntime()) {
|
|
|
|
|
+ openSocialApp(platform)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 检查APP是否安装
|
|
// 检查APP是否安装
|
|
|
if (!checkAppInstalled(platform)) {
|
|
if (!checkAppInstalled(platform)) {
|
|
|
toast.info(t('share.appNotInstalled'))
|
|
toast.info(t('share.appNotInstalled'))
|