Init: 首次提交
This commit is contained in:
commit
fbbce125b7
|
|
@ -0,0 +1,8 @@
|
|||
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue,css,scss,sass,less,styl}]
|
||||
charset = utf-8
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
end_of_line = lf
|
||||
max_line_length = 100
|
||||
|
|
@ -0,0 +1 @@
|
|||
* text=auto eol=lf
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
coverage
|
||||
*.local
|
||||
|
||||
/cypress/videos/
|
||||
/cypress/screenshots/
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
*.tsbuildinfo
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"recommendations": [
|
||||
"Vue.volar",
|
||||
"dbaeumer.vscode-eslint",
|
||||
"EditorConfig.EditorConfig"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
# vue-project
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
|
||||
|
||||
## Type Support for `.vue` Imports in TS
|
||||
|
||||
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
|
||||
|
||||
## Customize configuration
|
||||
|
||||
See [Vite Configuration Reference](https://vite.dev/config/).
|
||||
|
||||
## Project Setup
|
||||
|
||||
```sh
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### Compile and Hot-Reload for Development
|
||||
|
||||
```sh
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
### Type-Check, Compile and Minify for Production
|
||||
|
||||
```sh
|
||||
pnpm build
|
||||
```
|
||||
|
||||
### Lint with [ESLint](https://eslint.org/)
|
||||
|
||||
```sh
|
||||
pnpm lint
|
||||
```
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import { globalIgnores } from 'eslint/config'
|
||||
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
|
||||
import pluginVue from 'eslint-plugin-vue'
|
||||
|
||||
// To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
|
||||
// import { configureVueProject } from '@vue/eslint-config-typescript'
|
||||
// configureVueProject({ scriptLangs: ['ts', 'tsx'] })
|
||||
// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup
|
||||
|
||||
export default defineConfigWithVueTs(
|
||||
{
|
||||
name: 'app/files-to-lint',
|
||||
files: ['**/*.{ts,mts,tsx,vue}'],
|
||||
},
|
||||
|
||||
globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),
|
||||
|
||||
pluginVue.configs['flat/essential'],
|
||||
vueTsConfigs.recommended,
|
||||
)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "vue-project",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "run-p type-check \"build-only {@}\" --",
|
||||
"preview": "vite preview",
|
||||
"build-only": "vite build",
|
||||
"type-check": "vue-tsc --build",
|
||||
"lint": "eslint . --fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/vite": "^4.1.13",
|
||||
"tailwindcss": "^4.1.13",
|
||||
"vue": "^3.5.18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node22": "^22.0.2",
|
||||
"@types/node": "^22.16.5",
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
"@vitejs/plugin-vue-jsx": "^5.0.1",
|
||||
"@vue/eslint-config-typescript": "^14.6.0",
|
||||
"@vue/tsconfig": "^0.7.0",
|
||||
"eslint": "^9.31.0",
|
||||
"eslint-plugin-vue": "~10.3.0",
|
||||
"jiti": "^2.4.2",
|
||||
"npm-run-all2": "^8.0.4",
|
||||
"typescript": "~5.8.0",
|
||||
"vite": "npm:rolldown-vite@latest",
|
||||
"vite-plugin-vue-devtools": "^8.0.0",
|
||||
"vue-tsc": "^3.0.4"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
|
|
@ -0,0 +1,442 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed, nextTick } from 'vue'
|
||||
|
||||
// 选项数据类型
|
||||
interface FoodOption {
|
||||
name: string
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
// 默认选项
|
||||
const defaultOptions: FoodOption[] = [
|
||||
{ name: '云吞面', enabled: true },
|
||||
{ name: '烧腊饭', enabled: true },
|
||||
{ name: '牛肉汤饭', enabled: true }
|
||||
]
|
||||
|
||||
// 响应式数据
|
||||
const options = ref<FoodOption[]>([])
|
||||
const newOption = ref('')
|
||||
const isSpinning = ref(false)
|
||||
const rotation = ref(0)
|
||||
const selectedIndex = ref(-1)
|
||||
const editingIndex = ref(-1)
|
||||
const editingValue = ref('')
|
||||
|
||||
// 计算属性
|
||||
const optionCount = computed(() => options.value.length)
|
||||
const enabledOptions = computed(() => options.value.filter(option => option.enabled))
|
||||
const enabledOptionCount = computed(() => enabledOptions.value.length)
|
||||
const anglePerOption = computed(() => 360 / optionCount.value)
|
||||
|
||||
// 从localStorage加载数据
|
||||
const loadOptions = () => {
|
||||
const saved = localStorage.getItem('foodOptions')
|
||||
if (saved) {
|
||||
try {
|
||||
options.value = JSON.parse(saved)
|
||||
} catch {
|
||||
options.value = [...defaultOptions]
|
||||
}
|
||||
} else {
|
||||
options.value = [...defaultOptions]
|
||||
}
|
||||
}
|
||||
|
||||
// 保存数据到localStorage
|
||||
const saveOptions = () => {
|
||||
localStorage.setItem('foodOptions', JSON.stringify(options.value))
|
||||
}
|
||||
|
||||
// 添加选项
|
||||
const addOption = () => {
|
||||
if (newOption.value.trim() && !options.value.some(option => option.name === newOption.value.trim())) {
|
||||
options.value.push({ name: newOption.value.trim(), enabled: true })
|
||||
newOption.value = ''
|
||||
saveOptions()
|
||||
}
|
||||
}
|
||||
|
||||
// 删除选项
|
||||
const removeOption = (index: number) => {
|
||||
options.value.splice(index, 1)
|
||||
saveOptions()
|
||||
}
|
||||
|
||||
// 切换选项启用/禁用状态
|
||||
const toggleOption = (index: number) => {
|
||||
options.value[index].enabled = !options.value[index].enabled
|
||||
saveOptions()
|
||||
}
|
||||
|
||||
// 开始编辑选项
|
||||
const startEdit = (index: number) => {
|
||||
editingIndex.value = index
|
||||
editingValue.value = options.value[index].name
|
||||
|
||||
// 下一个tick时聚焦输入框
|
||||
nextTick(() => {
|
||||
const editInput = document.querySelector('.edit-input') as HTMLInputElement
|
||||
if (editInput) {
|
||||
editInput.focus()
|
||||
editInput.select() // 选中所有文本
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 保存编辑
|
||||
const saveEdit = () => {
|
||||
if (editingIndex.value >= 0 && editingValue.value.trim()) {
|
||||
// 检查是否与其他选项重名
|
||||
const trimmedValue = editingValue.value.trim()
|
||||
const isDuplicate = options.value.some((option, index) =>
|
||||
index !== editingIndex.value && option.name === trimmedValue
|
||||
)
|
||||
|
||||
if (!isDuplicate) {
|
||||
options.value[editingIndex.value].name = trimmedValue
|
||||
saveOptions()
|
||||
}
|
||||
}
|
||||
cancelEdit()
|
||||
}
|
||||
|
||||
// 取消编辑
|
||||
const cancelEdit = () => {
|
||||
editingIndex.value = -1
|
||||
editingValue.value = ''
|
||||
}
|
||||
|
||||
// 开始转盘
|
||||
const startSpin = () => {
|
||||
if (isSpinning.value || enabledOptionCount.value === 0) return
|
||||
|
||||
isSpinning.value = true
|
||||
selectedIndex.value = -1
|
||||
|
||||
// 从启用的选项中随机选择
|
||||
const enabledIndices = options.value.map((option, index) => ({ option, index }))
|
||||
.filter(item => item.option.enabled)
|
||||
.map(item => item.index)
|
||||
|
||||
const randomEnabledIndex = Math.floor(Math.random() * enabledIndices.length)
|
||||
const selectedOptionIndex = enabledIndices[randomEnabledIndex]
|
||||
|
||||
// 简化逻辑:直接让转盘停在一个角度,使得指针指向选中扇形
|
||||
// 扇形中心角度 = (index + 0.5) * anglePerOption
|
||||
const targetSegmentCenterAngle = (selectedOptionIndex + 0.5) * anglePerOption.value
|
||||
|
||||
// 关键简化:让转盘的最终角度就是目标扇形的中心角度
|
||||
// 这样getPointerTargetIndex函数计算出的结果就应该是selectedOptionIndex
|
||||
const extraRotations = 5 + Math.random() * 3 // 5-8圈
|
||||
const finalRotation = extraRotations * 360 + targetSegmentCenterAngle
|
||||
|
||||
rotation.value = finalRotation
|
||||
|
||||
// 3秒后停止
|
||||
setTimeout(() => {
|
||||
isSpinning.value = false
|
||||
selectedIndex.value = selectedOptionIndex
|
||||
|
||||
// 调试:验证逻辑一致性
|
||||
const calculatedIndex = getPointerTargetIndex()
|
||||
console.log(`抽奖结果: ${selectedOptionIndex}, 指针计算结果: ${calculatedIndex}`)
|
||||
if (selectedOptionIndex !== calculatedIndex) {
|
||||
console.error('逻辑不一致!需要调整计算方法')
|
||||
}
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
|
||||
// 获取扇形背景色
|
||||
const getSegmentColor = (index: number) => {
|
||||
const colors = [
|
||||
'#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4',
|
||||
'#feca57', '#ff9ff3', '#54a0ff', '#5f27cd'
|
||||
]
|
||||
return colors[index % colors.length]
|
||||
}
|
||||
|
||||
// 创建SVG扇形路径
|
||||
const createSegmentPath = (index: number, radius: number = 150) => {
|
||||
const startAngle = index * anglePerOption.value
|
||||
const endAngle = (index + 1) * anglePerOption.value
|
||||
|
||||
// 关键问题:SVG中0度是右侧(3点方向),但我们希望0度在顶部(12点方向)
|
||||
// 所以我们需要-90度的偏移
|
||||
// 但是!我们的角度计算逻辑假设0度就在顶部
|
||||
// 这里可能是不一致的根源!
|
||||
|
||||
console.log(`扇形${index}: ${startAngle}° - ${endAngle}°`)
|
||||
|
||||
const startAngleRad = (startAngle - 90) * Math.PI / 180
|
||||
const endAngleRad = (endAngle - 90) * Math.PI / 180
|
||||
|
||||
const x1 = radius + radius * Math.cos(startAngleRad)
|
||||
const y1 = radius + radius * Math.sin(startAngleRad)
|
||||
const x2 = radius + radius * Math.cos(endAngleRad)
|
||||
const y2 = radius + radius * Math.sin(endAngleRad)
|
||||
|
||||
const largeArc = endAngle - startAngle > 180 ? 1 : 0
|
||||
|
||||
return `M ${radius} ${radius} L ${x1} ${y1} A ${radius} ${radius} 0 ${largeArc} 1 ${x2} ${y2} Z`
|
||||
}
|
||||
|
||||
// 计算文字位置
|
||||
const getTextPosition = (index: number, radius: number = 150) => {
|
||||
const angle = (index + 0.5) * anglePerOption.value
|
||||
const angleRad = (angle - 90) * Math.PI / 180
|
||||
const textRadius = radius * 0.7 // 文字距离中心的距离
|
||||
|
||||
const x = radius + textRadius * Math.cos(angleRad)
|
||||
const y = radius + textRadius * Math.sin(angleRad)
|
||||
|
||||
return { x, y, angle }
|
||||
}
|
||||
|
||||
// 根据当前角度计算指针实际指向哪个扇形
|
||||
const getPointerTargetIndex = () => {
|
||||
if (optionCount.value === 0) return -1
|
||||
|
||||
// 获取当前角度(0-360度范围)
|
||||
const currentAngle = ((rotation.value % 360) + 360) % 360
|
||||
|
||||
// 最简单的逻辑:直接用当前角度除以每扇形角度
|
||||
// 如果这个逻辑和抽奖结果不匹配,说明我们的角度设置有问题
|
||||
const targetIndex = Math.floor(currentAngle / anglePerOption.value) % optionCount.value
|
||||
|
||||
console.log(`当前角度: ${currentAngle}°, 计算得扇形: ${targetIndex}`)
|
||||
|
||||
return targetIndex
|
||||
}
|
||||
|
||||
// 组件挂载时加载数据
|
||||
onMounted(() => {
|
||||
loadOptions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-h-screen bg-gradient-to-br from-indigo-500 to-purple-600 p-5 md:p-5 font-sans">
|
||||
<header class="text-center text-white mb-10">
|
||||
<h1 class="text-3xl md:text-4xl lg:text-5xl font-bold mb-2 drop-shadow-lg">🎯 今天吃什么</h1>
|
||||
<p class="text-lg opacity-90">让转盘帮你决定今天的美食选择!</p>
|
||||
</header>
|
||||
|
||||
<main class="max-w-6xl mx-auto px-4 md:px-0 grid grid-cols-1 lg:grid-cols-2 gap-6 md:gap-10 items-start">
|
||||
<!-- 选项管理区域 -->
|
||||
<section class="bg-white p-8 rounded-3xl shadow-2xl">
|
||||
<h2 class="text-2xl font-semibold text-gray-800 mb-5">添加美食选项</h2>
|
||||
<div class="flex gap-3 mb-5">
|
||||
<input
|
||||
v-model="newOption"
|
||||
@keyup.enter="addOption"
|
||||
placeholder="输入美食名称..."
|
||||
class="flex-1 px-4 py-3 border-2 border-gray-200 rounded-xl text-base transition-colors focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
<button
|
||||
@click="addOption"
|
||||
class="px-6 py-3 bg-indigo-500 text-white rounded-xl text-base font-medium hover:bg-indigo-600 transition-colors"
|
||||
>
|
||||
添加
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-3">
|
||||
<div
|
||||
v-for="(option, index) in options"
|
||||
:key="index"
|
||||
class="flex justify-between items-center p-3 rounded-xl border transition-all"
|
||||
:class="option.enabled
|
||||
? 'bg-gray-50 border-gray-200'
|
||||
: 'bg-gray-100 border-gray-300 opacity-70'"
|
||||
>
|
||||
<!-- 编辑模式 -->
|
||||
<div v-if="editingIndex === index" class="flex-1 flex items-center">
|
||||
<input
|
||||
v-model="editingValue"
|
||||
@keyup.enter="saveEdit"
|
||||
@keyup.escape="cancelEdit"
|
||||
@blur="saveEdit"
|
||||
class="flex-1 px-3 py-1.5 border-2 border-indigo-500 rounded-lg text-sm font-medium bg-white outline-none transition-all focus:border-indigo-600 focus:shadow-sm focus:shadow-indigo-200"
|
||||
ref="editInput"
|
||||
autofocus
|
||||
/>
|
||||
</div>
|
||||
<!-- 显示模式 -->
|
||||
<span
|
||||
v-else
|
||||
class="font-medium transition-all cursor-pointer flex-1 flex items-center px-2 py-1 rounded-lg min-h-5 hover:bg-indigo-50"
|
||||
:class="option.enabled ? 'text-gray-800' : 'text-gray-500 line-through'"
|
||||
@click="startEdit(index)"
|
||||
title="点击编辑"
|
||||
>
|
||||
{{ option.name }}
|
||||
</span>
|
||||
|
||||
<div class="flex gap-2 items-center">
|
||||
<button
|
||||
@click="toggleOption(index)"
|
||||
class="w-7 h-7 rounded-full text-sm font-bold flex items-center justify-center transition-all"
|
||||
:class="option.enabled
|
||||
? 'bg-green-500 text-white hover:bg-green-600'
|
||||
: 'bg-red-500 text-white hover:bg-red-600'"
|
||||
:title="option.enabled ? '点击禁用' : '点击启用'"
|
||||
>
|
||||
{{ option.enabled ? '✓' : '✗' }}
|
||||
</button>
|
||||
<button
|
||||
@click="removeOption(index)"
|
||||
class="w-6 h-6 bg-red-500 text-white rounded-full text-base font-bold flex items-center justify-center hover:bg-red-600 transition-colors"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 转盘区域 -->
|
||||
<section class="flex flex-col items-center gap-6 md:gap-8">
|
||||
<div class="relative">
|
||||
<!-- SVG转盘 -->
|
||||
<svg
|
||||
width="320"
|
||||
height="320"
|
||||
class="w-64 h-64 md:w-80 md:h-80 drop-shadow-2xl transition-transform duration-[3000ms] ease-out"
|
||||
:style="{ transform: `rotate(${rotation}deg)` }"
|
||||
viewBox="0 0 300 300"
|
||||
>
|
||||
<!-- 转盘扇形 -->
|
||||
<g v-for="(option, index) in options" :key="index">
|
||||
<path
|
||||
:d="createSegmentPath(index, 150)"
|
||||
:fill="getSegmentColor(index)"
|
||||
:opacity="option.enabled ? 1 : 0.4"
|
||||
stroke="#fff"
|
||||
stroke-width="1"
|
||||
class="transition-opacity duration-300"
|
||||
/>
|
||||
|
||||
<!-- 文字 -->
|
||||
<text
|
||||
:x="getTextPosition(index, 150).x"
|
||||
:y="getTextPosition(index, 150).y"
|
||||
text-anchor="middle"
|
||||
dominant-baseline="central"
|
||||
:transform="`rotate(${getTextPosition(index, 150).angle}, ${getTextPosition(index, 150).x}, ${getTextPosition(index, 150).y})`"
|
||||
class="fill-white font-bold text-xs md:text-sm drop-shadow transition-all duration-300"
|
||||
:class="{ 'line-through opacity-60': !option.enabled }"
|
||||
style="text-shadow: 1px 1px 2px rgba(0,0,0,0.8);"
|
||||
>
|
||||
{{ option.name }}
|
||||
</text>
|
||||
|
||||
<!-- 调试:显示扇形索引和角度范围 -->
|
||||
<text
|
||||
:x="getTextPosition(index, 150).x"
|
||||
:y="getTextPosition(index, 150).y + 15"
|
||||
text-anchor="middle"
|
||||
dominant-baseline="central"
|
||||
:transform="`rotate(${getTextPosition(index, 150).angle}, ${getTextPosition(index, 150).x}, ${getTextPosition(index, 150).y + 15})`"
|
||||
class="fill-yellow-300 font-bold text-xs"
|
||||
style="text-shadow: 1px 1px 2px rgba(0,0,0,0.8);"
|
||||
>
|
||||
{{ index }}: {{ Math.round(index * anglePerOption) }}°-{{ Math.round((index + 1) * anglePerOption) }}°
|
||||
</text>
|
||||
</g>
|
||||
|
||||
<!-- 调试:角度刻度线 -->
|
||||
<g v-for="i in 12" :key="'tick-' + i">
|
||||
<line
|
||||
:x1="150"
|
||||
:y1="10"
|
||||
:x2="150"
|
||||
:y2="30"
|
||||
stroke="red"
|
||||
stroke-width="2"
|
||||
:transform="`rotate(${i * 30}, 150, 150)`"
|
||||
/>
|
||||
<text
|
||||
:x="150"
|
||||
:y="45"
|
||||
text-anchor="middle"
|
||||
dominant-baseline="central"
|
||||
:transform="`rotate(${i * 30}, 150, 150)`"
|
||||
class="fill-red-600 font-bold text-xs"
|
||||
>
|
||||
{{ i * 30 }}°
|
||||
</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
<!-- 指针 -->
|
||||
<div class="absolute top-0 left-1/2 transform -translate-x-1/2 -translate-y-2 w-0 h-0 border-l-4 border-r-4 border-t-8 border-l-transparent border-r-transparent border-t-red-500 z-10 drop-shadow-md"></div>
|
||||
</div>
|
||||
|
||||
<!-- 开始按钮 -->
|
||||
<button
|
||||
@click="startSpin"
|
||||
:disabled="isSpinning || enabledOptionCount === 0"
|
||||
class="px-10 py-4 rounded-full text-lg font-bold text-white transition-all duration-300 shadow-lg"
|
||||
:class="isSpinning || enabledOptionCount === 0
|
||||
? 'bg-gray-400 cursor-not-allowed opacity-60'
|
||||
: 'bg-gradient-to-r from-red-400 to-red-500 hover:-translate-y-1 hover:shadow-xl hover:shadow-red-200'"
|
||||
>
|
||||
{{ isSpinning ? '转盘中...' : enabledOptionCount === 0 ? '请至少启用一个选项' : '开始转盘' }}
|
||||
</button>
|
||||
|
||||
<!-- 启用选项统计 -->
|
||||
<div class="bg-white/90 px-5 py-2.5 rounded-full text-sm text-gray-600 font-medium shadow-lg">
|
||||
已启用选项:{{ enabledOptionCount }} / {{ optionCount }}
|
||||
</div>
|
||||
|
||||
<!-- 调试信息 (开发时可见) -->
|
||||
<div v-if="!isSpinning" class="text-center bg-white/80 p-3 rounded-lg text-xs text-gray-600 space-y-1">
|
||||
<div>总选项数: {{ optionCount }}</div>
|
||||
<div>每个扇形角度: {{ anglePerOption.toFixed(1) }}°</div>
|
||||
<div>当前旋转角度: {{ Math.round(rotation % 360) }}°</div>
|
||||
|
||||
<div class="border-t pt-2">
|
||||
<div class="font-semibold">指针实际指向:</div>
|
||||
<div>扇形索引: {{ getPointerTargetIndex() }}</div>
|
||||
<div v-if="getPointerTargetIndex() >= 0">
|
||||
选项名称: {{ options[getPointerTargetIndex()]?.name }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedIndex >= 0" class="border-t pt-2">
|
||||
<div class="font-semibold">抽奖结果:</div>
|
||||
<div>扇形索引: {{ selectedIndex }}</div>
|
||||
<div>选项名称: {{ options[selectedIndex]?.name }}</div>
|
||||
<div :class="selectedIndex === getPointerTargetIndex() ? 'text-green-600 font-bold' : 'text-red-600 font-bold'">
|
||||
{{ selectedIndex === getPointerTargetIndex() ? '✅ 指针对齐正确' : '❌ 指针对齐错误' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 显示所有扇形的角度范围 -->
|
||||
<div class="mt-2 text-xs border-t pt-2">
|
||||
<div class="font-semibold">扇形分布:</div>
|
||||
<div v-for="(option, index) in options" :key="index"
|
||||
:class="[
|
||||
index === selectedIndex ? 'font-bold text-blue-600' : '',
|
||||
index === getPointerTargetIndex() ? 'bg-yellow-200' : ''
|
||||
]">
|
||||
{{ index }}: {{ option.name }} ({{ Math.round(index * anglePerOption) }}° - {{ Math.round((index + 1) * anglePerOption) }}°)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 结果显示 -->
|
||||
<div
|
||||
v-if="selectedIndex >= 0 && !isSpinning"
|
||||
class="text-center bg-white p-6 rounded-2xl shadow-xl animate-pulse"
|
||||
>
|
||||
<h3 class="text-lg font-semibold text-gray-800 mb-2">🎉 今天吃:</h3>
|
||||
<div class="text-3xl font-bold text-red-500 drop-shadow-sm">{{ options[selectedIndex].name }}</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
@import "tailwindcss";
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import './main.css'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
||||
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
|
||||
"exclude": ["src/**/__tests__/*"],
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"extends": "@tsconfig/node22/tsconfig.json",
|
||||
"include": [
|
||||
"vite.config.*",
|
||||
"vitest.config.*",
|
||||
"cypress.config.*",
|
||||
"nightwatch.conf.*",
|
||||
"playwright.config.*",
|
||||
"eslint.config.*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"types": ["node"]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
vueJsx(),
|
||||
vueDevTools(),
|
||||
tailwindcss(),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
},
|
||||
},
|
||||
})
|
||||
Loading…
Reference in New Issue