|
|
@@ -9,7 +9,7 @@
|
|
|
</el-carousel>
|
|
|
<!-- 标签与商品名 -->
|
|
|
<div class="tag-bar">
|
|
|
- <span class="tag tag-subsidy" v-if="spuInfo.hot_flag==1">热门商品</span>
|
|
|
+ <span class="tag tag-subsidy" v-if="spuInfo.hot_flag == 1">热门商品</span>
|
|
|
<span class="tag tag-flash" v-if="spuInfo.freeShipment">包邮</span>
|
|
|
<span class="product-name">{{ spuInfo.title }}</span>
|
|
|
</div>
|
|
|
@@ -64,6 +64,7 @@ export default {
|
|
|
data() {
|
|
|
return {
|
|
|
androidLinkurl: "",
|
|
|
+ iosLinkurl: "https://apps.apple.com/cn/app/6769659397",
|
|
|
spuInfo: {},
|
|
|
query: {
|
|
|
platform: "",
|
|
|
@@ -88,7 +89,9 @@ export default {
|
|
|
},
|
|
|
getAppdownloadUrl() {
|
|
|
getAppLatestVersion().then(res => {
|
|
|
- this.androidLinkurl = res.data.downloadUrl
|
|
|
+ const data = res.data || {}
|
|
|
+ this.androidLinkurl = data.downloadUrl || this.androidLinkurl
|
|
|
+ this.iosLinkurl = data.iosDownloadUrl || data.iosUrl || data.iosLinkurl || data.appStoreUrl || data.appstoreUrl || data.downloadUrlIos || this.iosLinkurl
|
|
|
})
|
|
|
},
|
|
|
getgoodDetail() {
|
|
|
@@ -100,73 +103,76 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
openAPP() {
|
|
|
- const that = this;
|
|
|
- // 1. 解析用户代理,判断设备类型
|
|
|
- const ua = navigator.userAgent;
|
|
|
- const isAndroid = ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1; // 安卓终端
|
|
|
- // 新增:标记是否已唤起APP(核心修复)
|
|
|
+ const ua = navigator.userAgent || "";
|
|
|
+ const isAndroid = /Android|Adr/i.test(ua);
|
|
|
+ const isIOS = /iPhone|iPad|iPod/i.test(ua) || (ua.indexOf("Macintosh") > -1 && navigator.maxTouchPoints > 1);
|
|
|
+ const androidSchemeUrl = "com.benefit.workbox://promotion-goods" + location.search;
|
|
|
+ const iosSchemeUrl = "https://7a9380b8150abc3e955eba4699371ae1.share2dlink.com/" + location.search;
|
|
|
+ const schemeUrl = isIOS ? iosSchemeUrl : androidSchemeUrl;
|
|
|
+ const fallbackUrl = isIOS ? this.iosLinkurl : this.androidLinkurl;
|
|
|
+ const loadStartTime = new Date().getTime();
|
|
|
let isAppInvoked = false;
|
|
|
|
|
|
- // 2. 安卓端唤醒逻辑(核心优化)
|
|
|
+ const cleanup = () => {
|
|
|
+ document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
|
+ window.removeEventListener('pagehide', onPageHide);
|
|
|
+ };
|
|
|
+ const onPageHide = () => {
|
|
|
+ isAppInvoked = true;
|
|
|
+ cleanup();
|
|
|
+ };
|
|
|
+ const onVisibilityChange = () => {
|
|
|
+ if (document.hidden) {
|
|
|
+ onPageHide();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const openFallback = () => {
|
|
|
+ if (fallbackUrl && fallbackUrl.trim()) {
|
|
|
+ const a = document.createElement('a');
|
|
|
+ a.target = '_blank';
|
|
|
+ a.href = fallbackUrl;
|
|
|
+ a.click();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$message({
|
|
|
+ message: isIOS ? 'iOS download link is not configured' : 'Android download link is not configured',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ };
|
|
|
+
|
|
|
+ if (!isAndroid && !isIOS) {
|
|
|
+ this.$message({
|
|
|
+ message: 'Please open on Android or iOS mobile device',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ document.addEventListener('visibilitychange', onVisibilityChange);
|
|
|
+ window.addEventListener('pagehide', onPageHide);
|
|
|
+
|
|
|
if (isAndroid) {
|
|
|
- // 记录唤醒开始时间
|
|
|
- const loadStartTime = new Date().getTime();
|
|
|
- // APP Scheme 唤起链接(带参数)
|
|
|
- const schemeUrl = "com.benefit.workbox://promotion-goods" + location.search;
|
|
|
-
|
|
|
- // ========== 关键优化1:监听页面隐藏事件(唤起APP会触发) ==========
|
|
|
- // 当页面被隐藏(切换到APP),标记为已唤起
|
|
|
- const onPageHide = () => {
|
|
|
- isAppInvoked = true;
|
|
|
- // 移除监听,避免重复触发
|
|
|
- document.removeEventListener('visibilitychange', onPageHide);
|
|
|
- window.removeEventListener('pagehide', onPageHide);
|
|
|
- };
|
|
|
- // 监听页面隐藏(兼容不同浏览器)
|
|
|
- document.addEventListener('visibilitychange', onPageHide);
|
|
|
- window.addEventListener('pagehide', onPageHide);
|
|
|
-
|
|
|
- // ========== 关键优化2:简化唤起方式(避免重复触发) ==========
|
|
|
- // 仅用iframe唤起(去掉location.href兜底,减少误触发)
|
|
|
const iframe = document.createElement('iframe');
|
|
|
iframe.style.display = 'none';
|
|
|
iframe.src = schemeUrl;
|
|
|
document.body.appendChild(iframe);
|
|
|
- // 用完销毁iframe
|
|
|
setTimeout(() => {
|
|
|
- document.body.removeChild(iframe);
|
|
|
- }, 2000);
|
|
|
-
|
|
|
- // ========== 关键优化3:精准检测唤起状态 ==========
|
|
|
- setTimeout(() => {
|
|
|
- const currentTime = new Date().getTime();
|
|
|
- const timeDiff = currentTime - loadStartTime;
|
|
|
-
|
|
|
- // 只有「未标记唤起」且「时间差小于阈值」,才跳转下载
|
|
|
- if (!isAppInvoked && timeDiff < 5000) { // 阈值从10000缩短到5000,更精准
|
|
|
- // 校验下载链接是否有效,避免报错
|
|
|
- if (that.androidLinkurl && that.androidLinkurl.trim()) {
|
|
|
- const a = document.createElement('a');
|
|
|
- a.target = '_blank';
|
|
|
- a.href = that.androidLinkurl;
|
|
|
- a.click();
|
|
|
- } else {
|
|
|
- console.error('安卓下载链接未配置');
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 唤起成功,清空标记
|
|
|
- isAppInvoked = false;
|
|
|
- // 移除监听
|
|
|
- document.removeEventListener('visibilitychange', onPageHide);
|
|
|
- window.removeEventListener('pagehide', onPageHide);
|
|
|
+ if (iframe.parentNode) {
|
|
|
+ document.body.removeChild(iframe);
|
|
|
}
|
|
|
- }, 2000); // 检测延迟从1000延长到2000,给APP唤起足够时间
|
|
|
+ }, 2000);
|
|
|
} else {
|
|
|
- this.$message({
|
|
|
- message: '暂不支持苹果端,请在安卓端打开',
|
|
|
- type: 'warning'
|
|
|
- })
|
|
|
+ window.location.href = schemeUrl;
|
|
|
}
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ const timeDiff = new Date().getTime() - loadStartTime;
|
|
|
+ if (!isAppInvoked && timeDiff < 5000) {
|
|
|
+ openFallback();
|
|
|
+ }
|
|
|
+ cleanup();
|
|
|
+ }, 2000);
|
|
|
},
|
|
|
GetQueryString(name) {
|
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|