update:增加主页app下载指定跳转应用商店

This commit is contained in:
hufflzp 2025-12-19 17:16:40 +08:00
parent be7241de34
commit aebdc075b0

View File

@ -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 StoreIDApp Store Connect1234567890
ios: '6751526968',
// Androidcom.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) {
// iOSApp StoreURL 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':
// OPPOURL Scheme
targetUrl = `oppomarket://details?id=${appStoreConfig.android.oppo}`;
break;
case 'vivo':
// VIVOURL 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) {
// iOSApp 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