diff --git a/src/pages/Home/components/DownloadButton.vue b/src/pages/Home/components/DownloadButton.vue index 07d73ab..abe0939 100644 --- a/src/pages/Home/components/DownloadButton.vue +++ b/src/pages/Home/components/DownloadButton.vue @@ -8,7 +8,6 @@ target="_blank" :aria-label="mainButton.label" class="flex h-full w-full items-center justify-center transition-transform hover:brightness-110 active:scale-95" - @click.prevent="handleDownload(mainButton)" > @@ -16,8 +15,8 @@ v-else :id="mainButton?.id" :aria-label="mainButton?.label" + @click="handleDownload(mainButton.key)" class="flex h-full w-full cursor-pointer items-center justify-center transition-transform hover:brightness-110 active:scale-95" - @click="handleDownload(mainButton)" > @@ -37,7 +36,6 @@ target="_blank" :aria-label="item.label" class="transition-transform hover:brightness-110 active:scale-95" - @click.prevent="handleDownload(item)" > @@ -45,8 +43,8 @@ v-else :id="item.id" :aria-label="item.label" + @click="handleDownload(item.key)" class="cursor-pointer transition-transform hover:brightness-110 active:scale-95" - @click="handleDownload(item)" > @@ -68,9 +66,9 @@ import AndroidIcon from './AndroidIcon.svg?component' import request from '@/utils/request' import {computed, ref, onMounted} from "vue"; -import {getAllQueryString} from "../../../utils/url-utils"; -import AdjustUtil from "../../../utils/adjust"; +import {getAllQueryString} from "@/utils/url-utils.ts"; +const downLoadWin = ref('') const currentPlatform = ref('win') onMounted(() => { @@ -103,41 +101,44 @@ onMounted(() => { console.log('Detected Platform:', currentPlatform.value); }); -const handleDownload = (item: any) => { - console.log('Downloading:', item.label, item.link); - // 记录点击事件(通过 key 自动映射令牌) - AdjustUtil.trackEvent(item.key); +// request.get('/api/v1/common/client/download', { +// invite_code: getAllQueryString('ic'), +// platform: 'windows', +// }).then((res: any) => { +// downLoadWin.value = res.url +// }) - if (item.key === 'win') { - // Windows 平台:点击时请求下载地址 - request.get('/api/v1/common/client/download', { - invite_code: getAllQueryString('ic'), - platform: 'windows', - }).then((res: any) => { - if (res.url) { - window.open(res.url, '_blank'); - } - }).catch((err: any) => { - console.error('Failed to fetch windows download link:', err); - }); - } else if (item.link) { - // 其他平台:直接打开链接 - window.open(item.link, '_blank'); +const handleDownload = async (key: string) => { + const platformMap: Record = { + win: 'windows', + mac: 'mac', + android: 'android', + ios: 'ios', } -}; + const platform = platformMap[key] || 'windows' -const allDownloadOptions = computed(() => { - const androidLink = currentPlatform.value === 'android' - ? AdjustUtil.getDecoratedLink() - : 'https://api.hifast.biz/v1/common/client/download/file/Hi%E5%BF%ABVPN-android-1.0.0.apk' + try { + const res: any = await request.get('/api/v1/common/client/download', { + invite_code: getAllQueryString('ic'), + platform: platform, + }) + if (res.url) { + if (key === 'win') { + downLoadWin.value = res.url + } + window.open(res.url, '_blank') + } + } catch (error) { + console.error('Download fetch failed', error) + } +} - return [ - { key: 'win', mainIcon: Icon1, secondaryIcon: WinIcon, link: '', label: 'Windows', id: 'downloadButton_win' }, - { key: 'mac', mainIcon: Icon3, secondaryIcon: MacIcon, label: 'macOS', link: AdjustUtil.getDecoratedLink() }, - { key: 'ios', mainIcon: Icon2, secondaryIcon: AppleIcon, label: 'iOS', link: AdjustUtil.getDecoratedLink() }, - { key: 'android', mainIcon: Icon4, secondaryIcon: AndroidIcon, label: 'Android', link: androidLink }, - ] -}) +const allDownloadOptions = computed(() => [ + { key: 'win', mainIcon: Icon1, secondaryIcon: WinIcon, link: downLoadWin.value, label: 'Windows', id: 'downloadButton_win' }, + { key: 'mac', mainIcon: Icon3, secondaryIcon: MacIcon, label: 'macOS', id: 'downloadButton_mac' }, + { key: 'ios', mainIcon: Icon2, secondaryIcon: AppleIcon, label: 'iOS', id: 'downloadButton_apple' }, + { key: 'android', mainIcon: Icon4, secondaryIcon: AndroidIcon, label: 'Android', id: 'downloadButton_android' }, +]) const mainButton = computed(() => { return allDownloadOptions.value.find(opt => opt.key === currentPlatform.value) || allDownloadOptions.value[0] @@ -147,3 +148,4 @@ const otherButtons = computed(() => { return allDownloadOptions.value.filter(opt => opt.key !== currentPlatform.value) }) +