Skip to content

Commit c94f6fa

Browse files
committed
fix: fix mobile devices bugs
1 parent c4a0e55 commit c94f6fa

8 files changed

Lines changed: 62 additions & 37 deletions

File tree

src/client/components/download-button.vue

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,42 @@ import { ReleasesConfig } from '@client/utils/data.config';
88
import { ElMessage } from 'element-plus';
99
1010
@Options({
11-
components: {
12-
13-
},
11+
components: {},
1412
})
1513
export default class DownloadButton extends Vue {
1614
@Prop({ type: String, required: true }) platform!: string;
1715
@Prop({ type: String, required: true }) arch!: string;
1816
@Prop({ type: Boolean, default: false }) isHome: Boolean;
1917
@Prop({ type: String, required: true }) version!: string;
2018
19+
// 检测是否为移动设备
20+
get isMobileDevice(): boolean {
21+
if (typeof navigator === 'undefined') return false;
22+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
23+
}
24+
2125
get isSupportedPlatform(): boolean {
26+
// 只有在主页时才考虑移动设备检测
27+
if (this.isHome && this.isMobileDevice) {
28+
return false;
29+
}
2230
return this.platform === 'windows' || this.platform === 'mac';
2331
}
2432
2533
get isUnsupportedPlatform(): boolean {
34+
// 只有在主页时才考虑移动设备,releases页面按正常平台逻辑
35+
if (this.isHome && this.isMobileDevice) {
36+
return true;
37+
}
2638
return this.platform !== 'windows' && this.platform !== 'mac';
2739
}
2840
2941
get platformName(): string {
42+
// 只有在主页时才显示移动设备名称
43+
if (this.isHome && this.isMobileDevice) {
44+
return '移动设备';
45+
}
46+
3047
// 确保服务端和客户端返回一致的平台名称
3148
switch (this.platform) {
3249
case 'mac':
@@ -39,6 +56,11 @@ export default class DownloadButton extends Vue {
3956
}
4057
4158
get platformImage(): string {
59+
// 只有在主页时,移动设备才显示通用下载图标
60+
if (this.isHome && this.isMobileDevice) {
61+
return download;
62+
}
63+
4264
switch (this.platform) {
4365
case 'windows':
4466
return windows;
@@ -50,9 +72,13 @@ export default class DownloadButton extends Vue {
5072
}
5173
5274
private handleDownload() {
75+
if (this.isMobileDevice) {
76+
this.$router.push({ name: 'Releases' });
77+
return;
78+
}
5379
const releasesConfig = new ReleasesConfig(this.version);
5480
let downloadLink = releasesConfig.downloadSingleSystemLink(this.platform, this.arch);
55-
ElMessage('下载开始,请稍后...');
81+
ElMessage('下载开始,请稍候...');
5682
window.open(downloadLink, '_parent');
5783
}
5884
}

src/client/components/guide.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class Guide extends Vue {
4444
});
4545
},
4646
{
47-
threshold: 0.5,
47+
threshold: 0.2,
4848
},
4949
);
5050

src/client/components/release-item.vue

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,21 @@ export default class ReleaseItem extends Vue {
2828
}
2929
}
3030
31+
// 移动端主流架构配置
32+
get mobileMainstreamArch(): string {
33+
switch (this.platform) {
34+
case 'windows':
35+
return 'x64';
36+
case 'mac':
37+
return 'arm64';
38+
default:
39+
return 'x64';
40+
}
41+
}
42+
3143
// 使用默认架构避免SSR不匹配
3244
get defaultArch(): string {
33-
return 'x64'; // 默认使用 x64,在客户端会动态更新
45+
return this.mobileMainstreamArch;
3446
}
3547
3648
get downloadLink(): string {
@@ -74,13 +86,13 @@ export default class ReleaseItem extends Vue {
7486
}
7587
}
7688
77-
// SSR 安全的描述文本
89+
// SSR 安全的描述文本 - 移动端显示主流架构
7890
get staticAsideDesc(): string | null {
7991
switch (this.platform) {
8092
case 'windows':
8193
return `version ${this.version} for x64`;
8294
case 'mac':
83-
return `version ${this.version} for Intel Chip`;
95+
return `version ${this.version} for Apple Silicon`;
8496
default:
8597
return null;
8698
}
@@ -92,15 +104,23 @@ export default class ReleaseItem extends Vue {
92104
93105
mounted() {
94106
// 在客户端更新架构信息
95-
this.clientArch = platformUtil.getArchitecture();
107+
const detectedArch = platformUtil.getArchitecture();
108+
// 如果是移动端访问,使用主流架构而不是检测到的架构
109+
this.clientArch = this.isMobileDevice() ? this.mobileMainstreamArch : detectedArch;
96110
this.isClientMounted = true;
97111
}
98112
113+
// 检测是否为移动设备
114+
private isMobileDevice(): boolean {
115+
if (typeof navigator === 'undefined') return false;
116+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
117+
}
118+
99119
get dynamicAsideDesc(): string | null {
100120
const arch = this.clientArch;
101121
switch (this.platform) {
102122
case 'windows':
103-
return `version ${this.version} for ${arch == 'arm64' ? 'Arm64' : arch}`;
123+
return `version ${this.version} for ${arch == 'arm64' ? 'Arm64' : 'x64'}`;
104124
case 'mac':
105125
if (arch == 'arm64') {
106126
return `version ${this.version} for Apple Silicon`;
@@ -118,7 +138,7 @@ export default class ReleaseItem extends Vue {
118138
119139
private handleDownload(link: string) {
120140
console.log('Download link:', link);
121-
ElMessage('下载开始,请稍后...');
141+
ElMessage('下载开始,请稍候...');
122142
window.open(link, '_parent');
123143
}
124144
}

src/client/main.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,7 @@ export function mainEntry({
4545
}
4646
});
4747

48-
// 添加路由守卫:检测平台并重定向
49-
router.beforeEach((to, from, next) => {
50-
if (isClient) {
51-
if (to.path === '/' && (!from.name || from.path === '/')) {
52-
try {
53-
const os = getOperatingSystem();
54-
const isSupportedPlatform = isMac() || isWindows();
55-
56-
// 如果不是 Windows 或 macOS,重定向到 releases 页面
57-
if (!isSupportedPlatform) {
58-
console.log(`检测到平台: ${os},重定向到 releases 页面`);
59-
return next('/releases');
60-
}
61-
} catch (error) {
62-
console.error('平台检测失败:', error);
63-
}
64-
}
65-
}
66-
67-
// 继续正常的路由导航
68-
next();
69-
});
48+
// 路由守卫已移至服务端中间件处理
7049

7150
router.beforeResolve(async (to, from, next) => {
7251
const component = to.matched[0].components.default;

src/client/modules/home/home-display.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export default class HomeDisplay extends Vue {
200200
<div class="content-main-tools" v-if="!isMobile">
201201
<p v-if="isSupportedPlatform">版本 {{ version }},发布于 {{ releasesTime }}</p>
202202
<p>访问 <a :href="getLinks().algoUX" target="_blank">algoUX</a>,探索更多编程与算竞工具链产品</p>
203-
<p>访问<a :href="getLinks().oldWebsite" class="old-web" target="_blank">旧版网站</a></p>
203+
<p>访问 <a :href="getLinks().oldWebsite" class="old-web" target="_blank">旧版网站</a></p>
204204
</div>
205205
</main>
206206
<svg

src/client/modules/home/home.view.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { GetReleasesDTO } from '@common/modules/releases/releases.dto';
2828
@RenderMethod(RenderMethodKind.SSR)
2929
export default class Home extends Vue {
3030
homeState: GetReleasesDTO = {
31-
version: '1.0.0-beta.1', // 默认版本,避免空字符串
31+
version: '',
3232
releaseDate: '',
3333
url: '',
3434
releasesInfo: {} as any,

src/client/modules/releases/releases.view.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { GetReleasesDTO } from '@common/modules/releases/releases.dto';
1717
@RenderMethod(RenderMethodKind.SSR)
1818
export default class Releases extends Vue {
1919
releasesState: GetReleasesDTO = {
20-
version: '1.0.0-beta.1', // 默认版本,避免空字符串
20+
version: '', // 默认版本,避免空字符串
2121
url: '',
2222
releaseDate: '',
2323
releasesInfo: {} as any,

src/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class OurApp extends App {
3333
'!./common/api/**',
3434
];
3535

36-
protected hostname = process.env.HOST || '127.0.0.1';
36+
protected hostname = process.env.HOST || '0.0.0.0';
3737

3838
protected port = parseInt(process.env.PORT) || 3000;
3939

0 commit comments

Comments
 (0)