From 664352dea9250f6a3220348692689fdfdca5bf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E5=85=B8=E5=8D=93?= Date: Fri, 16 May 2025 09:28:44 +0800 Subject: [PATCH] =?UTF-8?q?flat:=20=E5=85=BC=E5=AE=B9=E5=B9=B3=E6=9D=BF?= =?UTF-8?q?=E3=80=81=E7=AD=89=E8=B6=85=E5=AE=BD=E5=B1=8F=E5=B9=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hook/useColumnCount.js | 29 ++++++++++++++++++++++++++++- index.html | 2 +- pages.json | 8 ++++---- pages/index/index.vue | 11 ++++++++--- unpackage/dist/build/.DS_Store | Bin 6148 -> 6148 bytes 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/hook/useColumnCount.js b/hook/useColumnCount.js index ecd80c9..7ed1c79 100644 --- a/hook/useColumnCount.js +++ b/hook/useColumnCount.js @@ -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 => 1,count=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 } } \ No newline at end of file diff --git a/index.html b/index.html index 182fac7..8f3b102 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@ -