408249787@qq.com 6 päivää sitten
vanhempi
commit
a69cbb326e
2 muutettua tiedostoa jossa 31 lisäystä ja 4 poistoa
  1. 28 0
      .cool/utils/device.ts
  2. 3 4
      pages/programming/progress.uvue

+ 28 - 0
.cool/utils/device.ts

@@ -82,3 +82,31 @@ export const getDevicePixelRatio = (): number => {
 
 	return dpr;
 };
+/**
+ * 判断是否为平板(修复华为MatePad识别为phone问题)
+ * @returns true=平板 false=手机
+ */
+export const isTabletDevice = (): boolean => {
+	// 1. 获取设备基础信息
+	const devInfo = uni.getDeviceInfo();
+	const sysInfo = uni.getSystemInfoSync();
+	const model = devInfo.deviceModel.toLowerCase();
+	console.log(sysInfo)
+	// 2. 华为平板专属关键词(MatePad / MediaPad)
+	const isHuaweiPad = /matepad|mediapad/.test(model);
+	// 过滤华为折叠屏(Mate X/Xs/Xt等,避免大屏误判平板)
+	const isHuaweiFold = /mate x|mate xs|mate xt/.test(model);
+
+	// 3. 计算屏幕物理对角线英寸
+	const pxW = sysInfo.screenWidth;
+	const pxH = sysInfo.screenHeight;
+	const dpr = sysInfo.pixelRatio;
+	const inch = Math.sqrt(pxW ** 2 + pxH ** 2) / 160;
+	// 4. 复合判定规则
+	// 满足任意一条且不是折叠屏 → 平板
+	return !isHuaweiFold && (
+		devInfo.deviceType === 'pad'
+		|| isHuaweiPad
+		|| inch >= 7
+	);
+}

+ 3 - 4
pages/programming/progress.uvue

@@ -3,7 +3,7 @@ import Back from '@/components/back.uvue'
 import Loading from '@/components/loading.uvue'
 import { ref, onMounted, computed, watch, nextTick, onUnmounted } from 'vue'
 import { type SubjectCourseResult, fetchSubjectCourseApp, updateSubjectProgress } from '@/services/subject/course'
-import { router, user } from '@/.cool'
+import { router, user, isTabletDevice } from '@/.cool'
 
 const userInfo = computed(() => user.info.value?.userInfo)
 const course = ref<SubjectCourseResult>()
@@ -55,9 +55,8 @@ function handleClick(id: number) {
       });
       break
     case 4:
-      const res = uni.getDeviceInfo()
-      console.log(res)
-      if (res.deviceType === 'pad') {
+      const res = isTabletDevice()
+      if (res) {
         router.push({
           path: "/pages/programming/web-view",
           query: {