Переглянути джерело

feat: update 国际化 分享頁

叶静 1 тиждень тому
батько
коміт
1c52ea8923

+ 1 - 1
src/locale/bn.json

@@ -394,7 +394,7 @@
   "upgrade.version": "সংস্করণ {version}",
   "upgrade.download": "এখনই আপডেট ডাউনলোড করুন",
   "upgrade.downloading": "প্যাকেজ ডাউনলোড হচ্ছে, অনুগ্রহ করে অপেক্ষা করুন...",
-  "upgrade.downloadProgress": "{downloaded}M/{total}M",
+  "upgrade.downloadProgress": "{0}M/{1}M",
   "upgrade.install": "ডাউনলোড সম্পূর্ণ, এখনই ইনস্টল করুন",
   "upgrade.installing": "ইনস্টল করা হচ্ছে...",
   "upgrade.installIncomplete": "ইনস্টলেশন অসম্পূর্ণ, ইনস্টল করতে ক্লিক করুন",

+ 1 - 1
src/locale/en.json

@@ -407,7 +407,7 @@
   "upgrade.version": "Version {version}",
   "upgrade.download": "Download Update Now",
   "upgrade.downloading": "Downloading package, please wait...",
-  "upgrade.downloadProgress": "{downloaded}M/{total}M",
+  "upgrade.downloadProgress": "{0}M/{1}M",
   "upgrade.install": "Download complete, install now",
   "upgrade.installing": "Installing...",
   "upgrade.installIncomplete": "Installation incomplete, click to install",

+ 1 - 1
src/locale/zh-Hans.json

@@ -407,7 +407,7 @@
   "upgrade.version": "版本 {version}",
   "upgrade.download": "立即下载更新",
   "upgrade.downloading": "安装包下载中,请稍后",
-  "upgrade.downloadProgress": "{downloaded}M/{total}M",
+  "upgrade.downloadProgress": "{0}M/{1}M",
   "upgrade.install": "下载完成,立即安装",
   "upgrade.installing": "正在安装...",
   "upgrade.installIncomplete": "安装未完成,点击安装",

+ 3 - 71
src/pages/mine/mine.vue

@@ -21,6 +21,7 @@ import i18n from '@/locale/index'
 import { useUserStore } from '@/store/user'
 import { formatNumber } from '@/utils'
 import { toPage } from '@/utils/page'
+import { handleWhatsApp } from '@/utils/social'
 
 defineOptions({
   name: 'Mine', // 我的
@@ -69,20 +70,6 @@ const menuList = computed(() => {
   ]
 })
 
-function getPlusRuntime() {
-  const p = (globalThis as any)?.plus
-  return p?.runtime
-}
-
-function openH5WhatsApp(config: string, value: string = '') {
-  const phone = (value || '').replace(/\s+/g, '')
-  const url = config === 'activity_group'
-    ? `https://chat.whatsapp.com/${encodeURIComponent(value || '')}`
-    : `https://wa.me/${encodeURIComponent(phone)}`
-
-  if (typeof window !== 'undefined' && typeof window.open === 'function')
-    window.open(url, '_blank')
-}
 async function getConfig(code: string) {
   try {
     let value = ''
@@ -111,62 +98,7 @@ async function menuClick(item: any) {
   }
   else {
     const res = await getConfig(item.config)
-    openWhatsApp(item.config, res)
-  }
-}
-// 跳转whatsapp
-function openWhatsApp(config: string, value: string = '') {
-  const runtime = getPlusRuntime()
-  if (!runtime) {
-    openH5WhatsApp(config, value)
-    return
-  }
-
-  // 判断手机是否安装whatsapp
-  // pname:Android 需要查询的包名  action:ios 需要查询的 URL Scheme
-  const pname = 'com.whatsapp'
-
-  // installed ture:安装  false:未安装
-  const installed = runtime.isApplicationExist({
-    pname,
-    action: 'whatsapp://',
-  })
-
-  // whatsapp包名
-
-  // 判断手机系统,走不同方法
-  if ((globalThis as any)?.plus?.os?.name === 'Android') {
-    if (installed) {
-      // 手机已安装 直接跳转
-      if (config === 'live_chat') {
-        runtime.openURL(`whatsapp://send?phone=${value}`)
-      }
-      else if (config === 'activity_group') {
-        runtime.openURL(`https://chat.whatsapp.com/${value}`)
-      }
-    }
-    else {
-      // 手机未安装,跳转到手机商城并搜索whatsapp (国内目前搜不到)
-      ;(globalThis as any).plus.nativeUI.actionSheet(
-        {
-          title: '选择应用',
-          cancel: '取消',
-          buttons: [{ title: '应用市场' }],
-        },
-        ({ index }) => {
-          switch (index) {
-            case 1:
-              runtime.openURL(
-                `market://details?id=${pname}`,
-                () => {
-                  // 手机没有应用市场
-                  ;(globalThis as any).plus.nativeUI.alert('本机未安装指定的应用')
-                },
-              )
-          }
-        },
-      )
-    }
+    handleWhatsApp(item.config as 'live_chat' | 'activity_group', res)
   }
 }
 const walletInfo = ref<any>({})
@@ -207,7 +139,7 @@ onShow(() => {
 </script>
 
 <template>
-  <z-paging ref="paging" use-page-scroll refresher-only @refresh="handleRefresh">
+  <z-paging ref="paging" refresher-only use-page-scroll @refresh="handleRefresh">
     <view
       class="flex items-center justify-between bg-[rgba(var(--wot-color-theme-rgb),0.3)] pb-72rpx pl-24rpx pr-54rpx"
       :style="{ paddingTop: `${safeAreaInsets?.top + 24}px` }"

+ 3 - 109
src/pages/mine/share.vue

@@ -14,7 +14,7 @@ import { getUserInfoHook } from '@/hooks/usePageAuth'
 import { t } from '@/locale'
 import { useUserStore } from '@/store'
 import { goBack } from '@/utils/page'
-import { toast } from '@/utils/toast'
+import { handleSocialShare } from '@/utils/social'
 
 // 获取屏幕边界到安全区域距离
 const systemInfo = uni.getSystemInfoSync()
@@ -23,33 +23,6 @@ const safeAreaInsets = systemInfo.safeAreaInsets
 const userStore = useUserStore()
 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 qrcodeConfig = ref<any>({
@@ -111,89 +84,10 @@ function generateInviteShareLink() {
   }
 }
 
-// 检查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 } = 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({
-    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 (!getPlusRuntime()) {
-    openSocialApp(platform)
-    return
-  }
-
-  // 检查APP是否安装
-  if (!checkAppInstalled(platform)) {
-    toast.info(t('share.appNotInstalled'))
-    return
-  }
-
-  // 打开对应的社交媒体APP
-  openSocialApp(platform)
+  const shareData = generateInviteShareLink()
+  handleSocialShare(platform, shareData)
 }
 onLoad(() => {
   // 页面加载时的逻辑

+ 3 - 111
src/pages/productDetail/productDetail.vue

@@ -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
 }
 

+ 3 - 3
src/uni_modules/uni-upgrade-center-app/pages/upgrade-popup.vue

@@ -30,7 +30,7 @@
 								<progress class="progress" :percent="downLoadPercent" activeColor="#3DA7FF" show-info stroke-width="10" />
 								<view style="width: 100%; font-size: 28rpx; display: flex; justify-content: space-around">
 									<text>{{ $t('upgrade.downloading') }}</text>
-									<text>{{ $t('upgrade.downloadProgress', { downloaded: downloadedSize, total: packageFileSize }) }}</text>
+									<text>{{ $t('upgrade.downloadProgress', [downloadedSize, packageFileSize]) }}</text>
 								</view>
 							</view>
 
@@ -58,10 +58,10 @@
 							:disabled="installing"
 							@click="installPackage"
 						>
-							$t('upgrade.installIncomplete')
+								{{ $t('upgrade.installIncomplete') }}
 						</button>
 
-						<button v-else-if="installed && isWGT" class="content-button" style="border: none; color: #fff" plain @click="restart">$t('upgrade.restart')</button>
+						<button v-else-if="installed && isWGT" class="content-button" style="border: none; color: #fff" plain @click="restart">{{ $t('upgrade.restart') }}</button>
 					</template>
 				</view>
 			</view>

+ 149 - 0
src/utils/social.ts

@@ -0,0 +1,149 @@
+import { t } from '@/locale'
+import { toast } from '@/utils/toast'
+
+// 分享数据接口
+export interface ShareData {
+  url: string
+  text: string
+  title?: string
+}
+
+// 获取 plus runtime
+export function getPlusRuntime() {
+  const p = (globalThis as any)?.plus
+  return p?.runtime
+}
+
+// 检测 H5 是否支持原生分享
+export function isH5ShareSupported() {
+  return typeof navigator !== 'undefined' && typeof (navigator as any).share === 'function'
+}
+
+// 检查 APP 是否安装
+export 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,
+  })
+}
+
+// H5 模式下打开社交平台分享页面
+export function openH5ShareTarget(platform: string, shareData: ShareData) {
+  const { url, text } = shareData
+
+  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')
+}
+
+// APP 模式下打开社交 APP
+export function openSocialApp(platform: string, shareData: ShareData) {
+  const { url, text } = shareData
+  const runtime = getPlusRuntime()
+
+  if (!runtime) {
+    openH5ShareTarget(platform, shareData)
+    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',
+    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'))
+    })
+  }
+}
+
+// 统一分享处理方法(H5 直接跳转,APP 检查安装后跳转)
+export function handleSocialShare(platform: string, shareData: ShareData) {
+  // H5 模式下直接跳转到对应平台网页
+  if (!getPlusRuntime()) {
+    openH5ShareTarget(platform, shareData)
+    return
+  }
+
+  // APP 模式:检查 APP 是否安装
+  if (!checkAppInstalled(platform)) {
+    toast.info(t('share.appNotInstalled'))
+    return
+  }
+
+  // 打开对应的社交媒体 APP
+  openSocialApp(platform, shareData)
+}
+
+// H5 模式下打开 WhatsApp
+export function openH5WhatsApp(type: 'live_chat' | 'activity_group', value: string = '') {
+  const phone = (value || '').replace(/\s+/g, '')
+  const url = type === 'activity_group'
+    ? `https://chat.whatsapp.com/${encodeURIComponent(value || '')}`
+    : `https://wa.me/${encodeURIComponent(phone)}`
+
+  if (typeof window !== 'undefined' && typeof window.open === 'function')
+    window.open(url, '_blank')
+}
+
+// 统一 WhatsApp 跳转处理
+export function handleWhatsApp(type: 'live_chat' | 'activity_group', value: string = '') {
+  const runtime = getPlusRuntime()
+  // H5 模式下直接跳转网页
+  if (!runtime) {
+    openH5WhatsApp(type, value)
+    return
+  }
+
+  // APP 模式:检查 WhatsApp 是否安装
+  if (!checkAppInstalled('whatsapp')) {
+    toast.info(t('share.appNotInstalled'))
+    return
+  }
+
+  // 打开 WhatsApp
+  if (type === 'live_chat') {
+    runtime.openURL(`whatsapp://send?phone=${value}`)
+  }
+  else if (type === 'activity_group') {
+    runtime.openURL(`https://chat.whatsapp.com/${value}`)
+  }
+}