Skip to content

Commit ca1d262

Browse files
committed
fix:增加奇遇详情对游戏内嵌页的适配
1 parent 979d479 commit ca1d262

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

src/views/adventure/Adventure.vue

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@
1717

1818
<script>
1919
import Nav from "@/components/Nav_v5.vue";
20+
import { getSerendipityAchievementId } from "@/service/adventure/adventure";
2021
import { __imgPath, __dataPath } from "@/utils/config";
22+
23+
24+
// ⚠️ 请不要删除
25+
// 以下处理奇遇详情页对游戏内嵌的适配
26+
// PC:在低版本 Chrome 中跳转到经典页面(用于PC游戏插件拉起)
27+
// 无界:在游戏内嵌 WebView 中跳转到无界专属页面(用于游戏内嵌拉起)
28+
const LEGACY_CHROME_MAX_VERSION = 76;
29+
const LEGACY_PAGE_URL = "https://page.j3cx.com/";
30+
const MOBILE_GAME_PAGE_URL = "https://www.jx3box.com/wujie/cj/view/";
31+
2132
export default {
2233
name: "App",
2334
provide: {
@@ -28,11 +39,96 @@ export default {
2839
data: function () {
2940
return {
3041
navStatusClass: "is-regular",
42+
isRedirectingLegacyPage: false,
3143
};
3244
},
45+
watch: {
46+
$route: {
47+
immediate: true,
48+
handler() {
49+
this.redirectLegacyChromeAdventure();
50+
},
51+
},
52+
},
3353
mounted() { },
3454
computed: {},
3555
methods: {
56+
getChromeVersion() {
57+
if (typeof window === "undefined" || !window.navigator) return null;
58+
const ua = window.navigator.userAgent || "";
59+
const matched = ua.match(/Chrome\/(\d+)/i);
60+
if (!matched) return null;
61+
return Number(matched[1]);
62+
},
63+
isLegacyChrome() {
64+
const chromeVersion = this.getChromeVersion();
65+
return Number.isFinite(chromeVersion) && chromeVersion <= LEGACY_CHROME_MAX_VERSION;
66+
},
67+
isMobileGameWebView() {
68+
if (typeof window === "undefined" || !window.navigator) return false;
69+
70+
const ua = window.navigator.userAgent || "";
71+
const isAndroidWebView = /Android/i.test(ua) && /;\s*wv\)/i.test(ua);
72+
const isIPhoneWebView = /iPhone/i.test(ua) && !/Safari\//i.test(ua);
73+
74+
return isAndroidWebView || isIPhoneWebView;
75+
},
76+
isAdventureDetailRoute() {
77+
return this.$route?.name === "single" && !!this.$route?.params?.id;
78+
},
79+
shouldUseClassicPage() {
80+
if (typeof window === "undefined") return false;
81+
82+
const hostname = window.location.hostname || "";
83+
const searchParams = new URLSearchParams(window.location.search || "");
84+
const client = String(searchParams.get("client") || "").toLowerCase();
85+
86+
return hostname.includes("origin") || client.includes("origin");
87+
},
88+
buildLegacyPageUrl(achievementId) {
89+
const target = new URL(LEGACY_PAGE_URL);
90+
target.searchParams.set("type", "achievement");
91+
target.searchParams.set("id", achievementId);
92+
93+
if (this.shouldUseClassicPage()) {
94+
target.searchParams.set("L", "classic_yq");
95+
}
96+
97+
return target.toString();
98+
},
99+
buildMobileGamePageUrl(achievementId) {
100+
return `${MOBILE_GAME_PAGE_URL}${achievementId}`;
101+
},
102+
async redirectLegacyChromeAdventure() {
103+
if (this.isRedirectingLegacyPage) return;
104+
if (!this.isAdventureDetailRoute()) return;
105+
106+
const shouldRedirectToMobileGamePage = this.isMobileGameWebView();
107+
const shouldRedirectToLegacyPage = this.isLegacyChrome();
108+
if (!shouldRedirectToMobileGamePage && !shouldRedirectToLegacyPage) return;
109+
110+
const adventureId = this.$route.params.id;
111+
if (!adventureId) return;
112+
113+
this.isRedirectingLegacyPage = true;
114+
115+
try {
116+
const res = await getSerendipityAchievementId(adventureId, {
117+
client: this.$store.state.client,
118+
});
119+
const achievementId = res.data?.achievement_id;
120+
if (!achievementId) return;
121+
122+
const targetUrl = shouldRedirectToMobileGamePage
123+
? this.buildMobileGamePageUrl(achievementId)
124+
: this.buildLegacyPageUrl(achievementId);
125+
window.location.replace(targetUrl);
126+
} catch (error) {
127+
console.error("低版本 Chrome 奇遇页跳转失败", error);
128+
} finally {
129+
this.isRedirectingLegacyPage = false;
130+
}
131+
},
36132
statusChange(navStatusClass) {
37133
this.navStatusClass = navStatusClass;
38134
},

0 commit comments

Comments
 (0)