增加小程序,修改游戏前端

This commit is contained in:
2026-02-04 17:29:51 +08:00
parent de17737ca1
commit 8c677908d7
835 changed files with 283328 additions and 2165 deletions

View File

@@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "谁去拿外卖"
}

View File

@@ -0,0 +1,84 @@
Page({
data: {
names: [] as string[],
newName: '',
result: '',
isRolling: false
},
onLoad() {
// Initialize with some default placeholder data optionally, or keep empty
// this.setData({ names: ['张三', '李四', '王五'] });
},
onInput(e: any) {
this.setData({ newName: e.detail.value });
},
addName() {
const name = this.data.newName.trim();
if (!name) {
wx.showToast({ title: '请输入名字', icon: 'none' });
return;
}
// Check duplication
if (this.data.names.includes(name)) {
wx.showToast({ title: '名字已存在', icon: 'none' });
return;
}
const names = [...this.data.names, name];
this.setData({ names, newName: '' });
},
removeName(e: any) {
if (this.data.isRolling) return;
const index = e.currentTarget.dataset.index;
const names = [...this.data.names];
names.splice(index, 1);
this.setData({ names });
// If deleted the current result, clear result
if (this.data.names.indexOf(this.data.result) === -1) {
// actually result is a string copy, but if logic requires reset:
// this.setData({ result: '' });
}
},
startDraw() {
if (this.data.isRolling) return;
const names = this.data.names;
if (names.length < 2) {
wx.showToast({ title: '至少需要两个人才能抽取哦', icon: 'none' });
return;
}
this.setData({ isRolling: true, result: '' });
let count = 0;
// Speed up first then slow down? Or simple uniform interval.
// Let's do a simple one first.
let baseInterval = 50;
let totalRolls = 30;
const roll = () => {
const randomIndex = Math.floor(Math.random() * names.length);
this.setData({ result: names[randomIndex] });
count++;
if (count < totalRolls) {
// dynamic interval could be fun, but keeping it simple for now
setTimeout(roll, baseInterval + (count * 5)); // slowing down
} else {
this.setData({ isRolling: false });
wx.vibrateShort({ type: 'heavy' });
}
};
roll();
}
});

View File

@@ -0,0 +1,33 @@
<view class="container">
<view class="header-tip">
<text>输入名字,看看今天谁是天选打工人</text>
</view>
<view class="input-area">
<input class="input" placeholder="输入名字 (如: 小明)" value="{{newName}}" bindinput="onInput" bindconfirm="addName" />
<view class="btn-add" bindtap="addName">添加</view>
</view>
<scroll-view scroll-y class="list-area">
<view class="name-list">
<block wx:for="{{names}}" wx:key="*this">
<view class="name-item">
<text class="name-text">{{item}}</text>
<view class="btn-delete" bindtap="removeName" data-index="{{index}}">×</view>
</view>
</block>
<view wx:if="{{names.length === 0}}" class="empty-tip">
<text>还没有候选人,快去添加吧</text>
</view>
</view>
</scroll-view>
<view class="result-area">
<view class="result-box {{isRolling ? 'rolling' : ''}}">
<text class="result-text">{{result || '?'}}</text>
</view>
<button class="btn-start" bindtap="startDraw" disabled="{{isRolling || names.length < 2}}">
{{isRolling ? '随机抽取中...' : '开始抽取'}}
</button>
</view>
</view>

View File

@@ -0,0 +1,155 @@
page {
background-color: #f6f7f9;
height: 100%;
}
.container {
display: flex;
flex-direction: column;
height: 100vh;
padding: 20px;
box-sizing: border-box;
}
.header-tip {
text-align: center;
margin-bottom: 20px;
color: #666;
font-size: 14px;
}
.input-area {
display: flex;
margin-bottom: 20px;
background: #fff;
border-radius: 50px;
padding: 5px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.input {
flex: 1;
height: 40px;
padding: 0 20px;
font-size: 16px;
}
.btn-add {
width: 80px;
height: 40px;
line-height: 40px;
text-align: center;
background: #9c27b0;
color: #fff;
border-radius: 40px;
font-size: 14px;
font-weight: bold;
}
.list-area {
flex: 1;
background: #fff;
border-radius: 12px;
padding: 10px;
margin-bottom: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
overflow: hidden;
}
.name-list {
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 10px;
}
.name-item {
background: #f3e5f5;
color: #4a148c;
padding: 8px 16px;
border-radius: 20px;
font-size: 14px;
display: flex;
align-items: center;
position: relative;
}
.name-text {
margin-right: 15px;
}
.btn-delete {
width: 20px;
height: 20px;
line-height: 18px;
text-align: center;
border-radius: 50%;
background: rgba(0,0,0,0.1);
color: #4a148c;
font-size: 16px;
position: absolute;
right: 5px;
top: 50%;
transform: translateY(-50%);
}
.empty-tip {
width: 100%;
text-align: center;
color: #999;
padding-top: 50px;
}
.result-area {
height: 200px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.result-box {
width: 120px;
height: 120px;
border-radius: 50%;
background: #fff;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
border: 5px solid #e1bee7;
box-shadow: 0 4px 15px rgba(156, 39, 176, 0.2);
transition: all 0.1s;
}
.result-box.rolling {
transform: scale(1.1);
border-color: #9c27b0;
}
.result-text {
font-size: 24px;
font-weight: bold;
color: #333;
/* Prevent long names from overflowing */
max-width: 90%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.btn-start {
width: 80% !important;
background: linear-gradient(135deg, #ab47bc 0%, #8e24aa 100%);
color: #fff;
border-radius: 30px;
padding: 12px 0;
font-size: 18px;
box-shadow: 0 4px 15px rgba(142, 36, 170, 0.4);
}
.btn-start[disabled] {
opacity: 0.7;
background: #ccc;
box-shadow: none;
}