hookehuyr

feat(ActivitiesCover): 根据设备类型动态调整图片显示模式

添加设备类型检测功能,针对 iPad 类设备使用 widthFix 模式显示图片,普通设备使用 aspectFill 模式
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-19 20:20:21
* @LastEditTime: 2025-09-19 22:53:44
* @FilePath: /lls_program/src/pages/ActivitiesCover/index.vue
* @Description: 活动海报页面 - 展示活动信息并处理定位授权
-->
......@@ -11,7 +11,7 @@
<image
:src="defaultPoster"
class="background-image"
mode="scaleToFill"
:mode="imageDisplayMode"
/>
<!-- 分享按钮组件 -->
......@@ -132,7 +132,7 @@
</template>
<script setup>
import { ref, onMounted } from "vue"
import { ref, onMounted, computed } from "vue"
import Taro, { useLoad } from '@tarojs/taro'
import "./index.less"
import BottomNav from '../../components/BottomNav.vue'
......@@ -147,6 +147,46 @@ import { THEME_COLORS } from '@/utils/config';
// 默认海报图
const defaultPoster = 'https://cdn.ipadbiz.cn/lls_prog/images/welcome_8.jpg';
// 系统信息
const systemInfo = ref({});
/**
* 获取系统信息
*/
const getSystemInfo = () => {
try {
const info = Taro.getSystemInfoSync();
systemInfo.value = info;
} catch (error) {
console.error('获取系统信息失败:', error);
}
};
/**
* 检测是否为 iPad 类型设备
*/
const isTabletDevice = computed(() => {
if (!systemInfo.value.screenWidth) {
return false;
}
const { screenWidth, screenHeight } = systemInfo.value;
const screenRatio = screenWidth / screenHeight;
// iPad 类型设备通常屏幕比例在 0.7-0.8 之间(4:3 约为 0.75)
// 普通手机设备比例通常在 0.4-0.6 之间
return screenRatio > 0.65;
});
/**
* 计算图片显示模式
*/
const imageDisplayMode = computed(() => {
// iPad 类型设备使用 widthFix 模式,普通设备使用 aspectFill
return isTabletDevice.value ? 'widthFix' : 'aspectFill';
});
/**
* 活动海报页面组件
* 功能:展示活动信息、处理定位授权、跳转到活动页面
......@@ -908,6 +948,9 @@ useLoad((options) => {
// 页面挂载时检查定位授权状态
onMounted(async () => {
// 获取系统信息
getSystemInfo();
initPageData()
})
</script>
......