flat: 兼容平板、等超宽屏幕

This commit is contained in:
史典卓
2025-05-16 09:28:44 +08:00
parent 13e6fd614e
commit 664352dea9
5 changed files with 41 additions and 9 deletions

View File

@@ -8,13 +8,39 @@ import {
export function useColumnCount(onChange = () => {}) {
const columnCount = ref(0)
const columnSpace = ref(2)
// const calcColumn = () => {
// const width = uni.getSystemInfoSync().windowWidth
// console.log(width)
// const count = Math.min(5, Math.floor(width / 375) + 1)
// if (count !== columnCount.value) {
// columnCount.value = count < 2 ? 2 : count
// }
// }
const calcColumn = () => {
const width = uni.getSystemInfoSync().windowWidth
const count = Math.min(5, Math.floor(width / 375) + 1)
let count = 2
if (width >= 1000) {
count = 5
} else if (width >= 750) {
count = 4
} else if (width >= 500) {
count = 3
} else {
count = 2
}
if (count !== columnCount.value) {
columnCount.value = count
}
// 计算间距count=2 => 1count=5 => 2中间线性插值
const spacing = 2 - (count - 2) * (1 / 3)
// console.log('列数:', count, '间距:', spacing.toFixed(2))
columnSpace.value = spacing
}
onMounted(() => {
@@ -40,5 +66,6 @@ export function useColumnCount(onChange = () => {}) {
return {
columnCount,
columnSpace
}
}