htc 1 день назад
Родитель
Сommit
6153a762e7
1 измененных файлов с 27 добавлено и 0 удалено
  1. 27 0
      utils/platform.js

+ 27 - 0
utils/platform.js

@@ -0,0 +1,27 @@
+/**
+ * 获取当前运行平台信息
+ * @returns {{isPC: boolean, isMobile: boolean, platform: string}}
+ */
+export function getPlatformInfo() {
+	try {
+		const info = uni.getSystemInfoSync();
+		const platform = info.platform.toLowerCase();
+		
+		const isPC = platform === 'windows' || platform === 'mac';
+		const isMobile = platform === 'ios' || platform === 'android';
+		
+		return {
+			isPC,
+			isMobile,
+			platform
+		};
+	} catch (e) {
+		// 发生错误时,默认返回移动端信息或错误状态
+		console.error('getPlatformInfo error:', e);
+		return {
+			isPC: false,
+			isMobile: true, // 默认或降级处理
+			platform: 'unknown'
+		};
+	}
+}