update:增加主页app下载指定跳转应用商店
This commit is contained in:
parent
be7241de34
commit
aebdc075b0
@ -18,9 +18,13 @@
|
|||||||
>
|
>
|
||||||
免费开店
|
免费开店
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button :icon="Download" round size="large" @click="downAndroid">
|
<el-button round size="large" @click="jumpToAppStore">
|
||||||
Android版本下载
|
App下载
|
||||||
|
<el-icon style="margin-left: 0.5em;"><Download style="width: 2em; height: 2em;" /></el-icon>
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<!-- <el-button :icon="Download" round size="large" @click="jumpToAppStore">
|
||||||
|
Ios版本下载
|
||||||
|
</el-button> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -86,7 +90,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useTransition } from "@vueuse/core";
|
import { useTransition } from "@vueuse/core";
|
||||||
import { ref, onMounted, defineEmits, watch } from "vue";
|
import { ref, onMounted, watch } from "vue";
|
||||||
import { Promotion, Download } from "@element-plus/icons-vue";
|
import { Promotion, Download } from "@element-plus/icons-vue";
|
||||||
import {downloadApp} from '@/api/download.js';
|
import {downloadApp} from '@/api/download.js';
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
@ -117,6 +121,117 @@ const openRegisterForm = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 设备检测函数:解析userAgent判断系统和品牌
|
||||||
|
function detectDevice() {
|
||||||
|
const ua = navigator.userAgent.toLowerCase();
|
||||||
|
const device = {
|
||||||
|
isIOS: /iphone|ipad|ipod/.test(ua), // 判断是否为iOS设备
|
||||||
|
isAndroid: /android/.test(ua), // 判断是否为Android设备
|
||||||
|
brand: 'other' // 默认为其他品牌
|
||||||
|
};
|
||||||
|
|
||||||
|
// 细化判断Android设备的品牌
|
||||||
|
if (device.isAndroid) {
|
||||||
|
if (/mi|xiaomi/.test(ua)) {
|
||||||
|
device.brand = 'xiaomi'; // 小米
|
||||||
|
} else if (/huawei|honor/.test(ua)) {
|
||||||
|
device.brand = 'huawei'; // 华为/荣耀
|
||||||
|
} else if (/oppo/.test(ua)) {
|
||||||
|
device.brand = 'oppo'; // OPPO
|
||||||
|
} else if (/vivo/.test(ua)) {
|
||||||
|
device.brand = 'vivo'; // VIVO
|
||||||
|
} else if (/samsung/.test(ua)) {
|
||||||
|
device.brand = 'samsung'; // 三星
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 应用商店配置(需要替换为你自己的应用信息)
|
||||||
|
const appStoreConfig = {
|
||||||
|
// iOS App Store的应用ID(在App Store Connect中查看,示例为1234567890)
|
||||||
|
ios: '6751526968',
|
||||||
|
// Android各品牌应用商店的包名(应用的唯一标识,示例为com.example.xiaofa)
|
||||||
|
android: {
|
||||||
|
xiaomi: 'com.xiaofa.shopAdmin',
|
||||||
|
huawei: 'com.xiaofa.shopAdmin',
|
||||||
|
oppo: 'com.xiaofa.shopAdmin',
|
||||||
|
vivo: 'com.xiaofa.shopAdmin',
|
||||||
|
samsung: 'com.xiaofa.shopAdmin',
|
||||||
|
// 备用链接:其他品牌时跳转到小米应用商店网页版/应用宝/官网
|
||||||
|
other: 'https://app.mi.com/details?id=com.xiaofa.shopAdmin'
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 修改后的应用商店跳转逻辑
|
||||||
|
const jumpToAppStore = async () => {
|
||||||
|
try {
|
||||||
|
|
||||||
|
const device = detectDevice();
|
||||||
|
let targetUrl = '';
|
||||||
|
if (device.isIOS) {
|
||||||
|
// iOS:跳转到App Store(URL Scheme格式)
|
||||||
|
targetUrl = `itms-apps://itunes.apple.com/cn/app/id${appStoreConfig.ios}?mt=8`;
|
||||||
|
} else if (device.isAndroid) {
|
||||||
|
// Android:根据品牌跳转到对应应用商店
|
||||||
|
switch (device.brand) {
|
||||||
|
case 'xiaomi':
|
||||||
|
// 小米应用商店URL Scheme
|
||||||
|
targetUrl = `mimarket://details?id=${appStoreConfig.android.xiaomi}`;
|
||||||
|
break;
|
||||||
|
case 'huawei':
|
||||||
|
// 华为应用商店URL Scheme
|
||||||
|
targetUrl = `appmarket://details?id=${appStoreConfig.android.huawei}`;
|
||||||
|
break;
|
||||||
|
case 'oppo':
|
||||||
|
// OPPO应用商店URL Scheme
|
||||||
|
targetUrl = `oppomarket://details?id=${appStoreConfig.android.oppo}`;
|
||||||
|
break;
|
||||||
|
case 'vivo':
|
||||||
|
// VIVO应用商店URL Scheme
|
||||||
|
targetUrl = `vivomarket://details?id=${appStoreConfig.android.vivo}`;
|
||||||
|
break;
|
||||||
|
case 'samsung':
|
||||||
|
// 三星应用商店URL Scheme
|
||||||
|
targetUrl = `samsungapps://ProductDetail/${appStoreConfig.android.samsung}`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// 其他Android品牌:使用备用链接
|
||||||
|
targetUrl = appStoreConfig.android.other;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 非移动设备:直接下载
|
||||||
|
downAndroid()
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.href = targetUrl;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
// 检测是否还在当前页面(简单判断:如果URL没变化则认为跳转失败)
|
||||||
|
// console.log("检测是否还在当前页面:", window.location.href);
|
||||||
|
if (window.location.href.includes(window.location.host)) {
|
||||||
|
if (device.isIOS) {
|
||||||
|
// iOS跳转失败:跳转到App Store网页版
|
||||||
|
window.location.href = `https://apps.apple.com/cn/app/id${appStoreConfig.ios}`;
|
||||||
|
} else {
|
||||||
|
// Android跳转失败:跳转到兜底链接
|
||||||
|
downAndroid()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1000); // 1秒延迟,给应用商店跳转留时间
|
||||||
|
// }
|
||||||
|
} catch (error) {
|
||||||
|
console.error("获取应用信息失败", error);
|
||||||
|
// 异常处理:直接跳转到兜底链接
|
||||||
|
downAndroid()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const downAndroid = async () => {
|
const downAndroid = async () => {
|
||||||
try {
|
try {
|
||||||
// 用 await 等待 downloadApp 的 Promise 完成,直接拿到结果
|
// 用 await 等待 downloadApp 的 Promise 完成,直接拿到结果
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user