feat: 下载

main
fadeaway 8 months ago
parent cd4487c102
commit b264af3265

@ -1,19 +1,31 @@
'use client'; 'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation'; import { useRouter } from 'next/navigation';
export default function EnterQueyueBtn() { export default function EnterQueyueBtn() {
const router = useRouter(); const router = useRouter();
const [opening, setOpening] = useState(false);
const handleEnterQueyue = () => { const handleEnterQueyue = () => {
if (opening) return;
setOpening(true);
const { searchParams } = new URL(window.location.href);
const songId = (searchParams as any)?.get('id');
const result = confirm('离开微信,打开第三方应用'); const result = confirm('离开微信,打开第三方应用');
if (result) { if (result) {
alert('打开应用无效跳转下载页'); window.location.href = `queyue://play/${songId}`; // 打开某手机上的某个app应用
window.location.href = 'queyue://'; // 打开某手机上的某个app应用
setTimeout(function () { setTimeout(function () {
// alert('打开应用无效跳转下载页');
router.push('/download'); router.push('/download');
}, 500); }, 2000);
setOpening(false);
} else {
setOpening(false);
} }
}; };
return ( return (
<button <button
className="w-[283px] h-[44px] flex items-center justify-center bg-[#B44343] font-medium text-[15px] rounded-full" className="w-[283px] h-[44px] flex items-center justify-center bg-[#B44343] font-medium text-[15px] rounded-full"

@ -3,7 +3,7 @@ import { useState, useEffect } from 'react';
import { Hosting } from '@/utils/ua'; import { Hosting } from '@/utils/ua';
export default function useUA() { export default function useUA() {
const [inWX, setInWX] = useState(true); const [inWX, setInWX] = useState(false);
useEffect(() => { useEffect(() => {
setInWX(Hosting.isWX(window?.navigator?.userAgent?.toLowerCase())); setInWX(Hosting.isWX(window?.navigator?.userAgent?.toLowerCase()));

@ -1,9 +1,75 @@
import { Hosting } from '@/utils/ua'; // 安卓包名
const APK_NAME = 'cn.luoo.indiemusic';
// 下载 export const isBuiltIn = () => {
export const download = () => {
const ua = window?.navigator?.userAgent?.toLowerCase(); const ua = window?.navigator?.userAgent?.toLowerCase();
if (!Hosting.isWX(ua)) { if (ua.match(/MicroMessenger/i)?.[0] === 'micromessenger') {
window.open('//cdn.indie.cn/release/queyue.apk', '__blank'); return 'weixin';
} else if (ua.match(/QQ/i)?.[0] === 'qq') {
return 'QQ';
} else if (ua.match(/Alipay/i)?.[0] === 'alipay') {
return 'alipay';
}
return false;
};
export const verifyBrand = () => {
const userAgent = window?.navigator?.userAgent?.toLowerCase();
const isIphone = userAgent.match(/(iphone|ipad|ipod)/i);
const isHuawei = userAgent.match(/huawei/i);
const isHonor = userAgent.match(/honor/i);
const isOppo = userAgent.match(/oppo/i);
const isOppoR15 = userAgent.match(/PACM00/i);
const isVivo = userAgent.match(/vivo/i);
const isXiaomi = userAgent.match(/mi\s/i);
const isXIAOMI = userAgent.match(/xiaomi/i);
const isXiaomi2s = userAgent.match(/mix\s/i);
const isRedmi = userAgent.match(/redmi/i);
if (isIphone) {
return 'iphone';
} else if (isHuawei || isHonor) {
return 'huawei';
} else if (isOppo || isOppoR15) {
return 'oppo';
} else if (isVivo) {
return 'vivo';
} else if (isXiaomi || isRedmi || isXiaomi2s || isXIAOMI) {
return 'xiaomi';
} else {
return 'other';
}
};
export const download = () => {
if (isBuiltIn()) {
// 内置浏览器 可加提示使其打开手机自带浏览器
return;
}
const iosLinkUrl = ''; // TODO:
const androidLinkurl = '//cdn.indie.cn/release/queyue.apk';
const huaweiUrl = `appmarket://details?id=${APK_NAME}`;
const oppoUrl = `oppomarket://details?packagename=${APK_NAME}`;
const vivoUrl = `vivomarket://details?id=${APK_NAME}`;
const xiaomiUrl = `mimarket://details?id=${APK_NAME}`;
switch (verifyBrand()) {
case 'iphone':
window.location.href = iosLinkUrl;
break;
case 'xiaomi':
window.location.href = xiaomiUrl;
break;
case 'huawei':
window.location.href = huaweiUrl;
break;
case 'vivo':
window.location.href = vivoUrl;
break;
case 'oppo':
window.location.href = oppoUrl;
break;
default:
window.location.href = androidLinkurl;
break;
} }
}; };

Loading…
Cancel
Save