diff --git a/__test__/ElementPosition.test.ts b/__test__/ElementPosition.test.ts new file mode 100644 index 0000000..6bedc6e --- /dev/null +++ b/__test__/ElementPosition.test.ts @@ -0,0 +1,19 @@ +import { describe, it, expect } from 'vitest' +import { useElementPosition } from '@/hooks/useElement' + +describe('useElementPosition', () => { + it('works for totalCount = 40 without throwing', () => { + const element = {} as any + const count = 10 + const totalCount = 40 + const cardSize = { width: 140, height: 200 } + const windowSize = { width: 800, height: 600 } + const cardIndex = 0 + + const result = useElementPosition(element, count, totalCount, cardSize, windowSize, cardIndex) + expect(result).toHaveProperty('xTable') + expect(result).toHaveProperty('yTable') + expect(result).toHaveProperty('scale') + expect(typeof result.scale).toBe('number') + }) +}) \ No newline at end of file diff --git a/package.json b/package.json index bf9f6ab..7aeded9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "log-lottery", "private": true, - "version": "0.6.0-3", + "version": "0.6.0-4", "type": "module", "license": "MIT", "scripts": { diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 94aa331..7155bd3 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -77,7 +77,7 @@ checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" [[package]] name = "app" -version = "0.6.0-3" +version = "0.6.0-4" dependencies = [ "log", "serde", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 4f386ea..f02c704 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.6.0-3" +version = "0.6.0-4" description = "A Tauri App" authors = [ "you" ] license = "" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5adb8d5..3e63187 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "log-lottery", - "version": "0.6.0-3", + "version": "0.6.0-4", "identifier": "to2026.xyz", "build": { "frontendDist": "../dist", diff --git a/src/constant/config.ts b/src/constant/config.ts index 657f857..2d4e625 100644 --- a/src/constant/config.ts +++ b/src/constant/config.ts @@ -1,2 +1,2 @@ -export const SINGLE_TIME_MAX_PERSON_COUNT = 30 +export const SINGLE_TIME_MAX_PERSON_COUNT = 40 export const CONFETTI_FIRE_MAX_COUNT = 12 diff --git a/src/hooks/useElement/index.ts b/src/hooks/useElement/index.ts index 043a356..ba42343 100644 --- a/src/hooks/useElement/index.ts +++ b/src/hooks/useElement/index.ts @@ -262,6 +262,16 @@ const cardRule: CardRule = { /** * @description 设置抽中卡片的位置 */ +function createRuleForCount(count: number) { + // 动态生成规则:行数在 3-5 之间,尽可能均匀分配 + const len = Math.min(5, Math.max(3, Math.ceil(count / 10))) + const base = Math.floor(count / len) + let rem = count % len + const rule = Array.from({ length: len }).fill(0).map(() => base + (rem > 0 ? (rem--, 1) : 0)) + const scale = Math.max(0.9, 1.2 - (len - 3) * 0.1) + return { maxLine: Math.min(10, Math.ceil(count / len)), scale, rule, length: len } +} + export function useElementPosition( element: any, count: number, @@ -280,7 +290,8 @@ export function useElementPosition( x: 0, y: windowSize.height / 2, } - const { scale, rule, length } = cardRule[totalCount] + const ruleObj = cardRule[totalCount] ?? createRuleForCount(totalCount) + const { scale, rule, length } = ruleObj // 计算缩放后的卡片尺寸 const scaledCardWidth = cardSize.width * scale const scaledCardHeight = cardSize.height * scale @@ -311,7 +322,7 @@ export function useElementPosition( // 修改此处逻辑,确保当length=2时,两行围绕中心点对称分布 centerPosition.y = windowSize.height / 2 - totalHeight / 2 - yTable = centerPosition.y + currentRow * verticalSpacing + centerYOffset + scaledCardHeight / 2 // 添加卡片高度的一半作为修正 + yTable = centerPosition.y + currentRow * verticalSpacing + centerYOffset // 添加卡片高度的一半作为修正 // 计算当前行的水平居中偏移 const horizontalSpacing = scaledCardWidth * 1.2 // 水平间距基于缩放后的宽度 const rowWidth = (cardsInCurrentRow - 1) * horizontalSpacing diff --git a/src/style/style.scss b/src/style/style.scss index 342e40a..16a4f96 100644 --- a/src/style/style.scss +++ b/src/style/style.scss @@ -111,4 +111,4 @@ height: 240px !important; object-fit: cover; } -} \ No newline at end of file +} diff --git a/static/images/config-view.png b/static/images/config-view.png index 6cb03bb..c2d53c9 100644 Binary files a/static/images/config-view.png and b/static/images/config-view.png differ diff --git a/static/images/config_personall.png b/static/images/config_personall.png index 552095d..a7a1d05 100644 Binary files a/static/images/config_personall.png and b/static/images/config_personall.png differ diff --git a/static/images/config_prize.png b/static/images/config_prize.png index be51c8f..746e5f9 100644 Binary files a/static/images/config_prize.png and b/static/images/config_prize.png differ diff --git a/static/images/home.png b/static/images/home.png index f9054a1..df782fb 100644 Binary files a/static/images/home.png and b/static/images/home.png differ diff --git a/static/images/home_prizelist.png b/static/images/home_prizelist.png index 6553de2..01e43a1 100644 Binary files a/static/images/home_prizelist.png and b/static/images/home_prizelist.png differ