feat: add animated choice modes and bracket editor
Verify mini program and deploy preview / verify-deploy (push) Successful in 50s
Verify mini program and deploy preview / verify-deploy (push) Successful in 50s
This commit is contained in:
+28
-19
@@ -1,19 +1,28 @@
|
||||
.arena { min-height: 100vh; background: #fff8f2; }
|
||||
.topline { display: flex; align-items: center; justify-content: space-between; }
|
||||
.progress { margin-top: 20rpx; height: 10rpx; overflow: hidden; border-radius: 99rpx; background: #eee4dd; }
|
||||
.progress-in { height: 100%; border-radius: inherit; background: #ff6b35; transition: width .25s; }
|
||||
.question { margin: 54rpx 8rpx 34rpx; font-size: 52rpx; line-height: 1.18; font-weight: 900; }
|
||||
.pair { position: relative; }
|
||||
.choice { position: relative; min-height: 360rpx; padding: 34rpx; box-sizing: border-box; border-radius: 38rpx; color: #fff; box-shadow: 0 20rpx 50rpx rgba(80, 35, 18, .14); }
|
||||
.choice + .choice { margin-top: 24rpx; }
|
||||
.choice-a { background: #ff6b35; transform: rotate(-1deg); }
|
||||
.choice-b { background: #2766df; transform: rotate(1deg); }
|
||||
.choice:active { transform: scale(.975); }
|
||||
.choice-index { width: 54rpx; height: 54rpx; line-height: 54rpx; text-align: center; border: 2rpx solid rgba(255,255,255,.6); border-radius: 50%; font-size: 24rpx; font-weight: 800; }
|
||||
.food-mark { position: absolute; right: 34rpx; top: 24rpx; font-size: 92rpx; opacity: .8; transform: rotate(12deg); }
|
||||
.choice-name { margin-top: 72rpx; font-size: 60rpx; line-height: 1.12; font-weight: 900; }
|
||||
.tap-hint { margin-top: 54rpx; font-size: 24rpx; opacity: .75; }
|
||||
.versus { position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-8deg); width: 84rpx; height: 84rpx; line-height: 84rpx; text-align: center; color: #201d1b; background: #fff; border: 5rpx solid #201d1b; border-radius: 50%; font-size: 26rpx; font-weight: 900; }
|
||||
.round-note { margin: 38rpx 0; text-align: center; color: #8f827a; font-size: 24rpx; }
|
||||
.saving { position: fixed; left: 50%; bottom: 70rpx; transform: translateX(-50%); padding: 22rpx 34rpx; border-radius: 99rpx; background: #201d1b; color: #fff; font-size: 25rpx; }
|
||||
|
||||
.arena { height: 100vh; overflow: hidden; padding: 24rpx 28rpx; background: #fff; }
|
||||
.topline { display: flex; align-items: center; justify-content: space-between; font-size: 23rpx; font-weight: 800; }
|
||||
.progress { margin-top: 14rpx; height: 7rpx; overflow: hidden; background: #e8e8e8; }
|
||||
.progress-in { height: 100%; background: #111; transition: width .25s; }
|
||||
.mode-tabs { display: flex; width: 430rpx; height: 62rpx; margin: 24rpx auto; padding: 5rpx; border-radius: 10rpx; background: #f1f1f1; }
|
||||
.mode { flex: 1; display: grid; place-items: center; border-radius: 7rpx; color: #777; font-size: 23rpx; }
|
||||
.mode.active { background: #111; color: #fff; font-weight: 800; }
|
||||
.single-stage { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 16rpx; height: calc(100vh - 190rpx); max-height: 850rpx; }
|
||||
.choice { position: relative; display: flex; flex-direction: column; justify-content: center; min-width: 0; padding: 28rpx; color: #fff; transition: transform .2s cubic-bezier(.2,.9,.2,1), opacity .2s; }
|
||||
.choice:active { transform: scale(.94) rotate(-1deg); opacity: .8; }
|
||||
.choice-a { background: #f34b30; }
|
||||
.choice-b { background: #3564dd; }
|
||||
.choice-index { position: absolute; left: 24rpx; top: 24rpx; width: 48rpx; height: 48rpx; line-height: 48rpx; text-align: center; border: 2rpx solid rgba(255,255,255,.6); border-radius: 50%; font-size: 21rpx; }
|
||||
.choice-name { font-size: 45rpx; line-height: 1.1; font-weight: 950; word-break: break-all; }
|
||||
.tap-hint { position: absolute; left: 28rpx; bottom: 28rpx; font-size: 21rpx; opacity: .75; }
|
||||
.versus { position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%); display: grid; place-items: center; width: 66rpx; height: 66rpx; border: 5rpx solid #111; border-radius: 50%; background: #fff; font-size: 21rpx; font-weight: 950; }
|
||||
.swipe-stage { perspective: 1000rpx; }
|
||||
.swipe-stage .choice-a { transform: rotate(-2deg); transform-origin: bottom right; }
|
||||
.swipe-stage .choice-b { transform: rotate(2deg); transform-origin: bottom left; }
|
||||
.multi-stage { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 12rpx; height: calc(100vh - 190rpx); max-height: 850rpx; }
|
||||
.mini-match { position: relative; display: grid; grid-template-columns: 1fr 42rpx 1fr; align-items: stretch; min-height: 0; overflow: hidden; border: 2rpx solid #111; }
|
||||
.mini-choice { display: grid; place-items: center; padding: 16rpx; text-align: center; font-size: 27rpx; font-weight: 850; background: #fff; transition: .18s; }
|
||||
.mini-choice:active { color: #fff; background: #111; transform: scale(.95); }
|
||||
.mini-vs { display: grid; place-items: center; background: #111; color: #fff; font-size: 17rpx; font-weight: 900; }
|
||||
.mini-winner { grid-column: 1 / 4; display: flex; flex-direction: column; align-items: center; justify-content: center; animation: winner-in .35s cubic-bezier(.2,1.3,.4,1); background: #111; color: #fff; font-size: 34rpx; font-weight: 950; }
|
||||
.mini-winner text { margin-bottom: 10rpx; color: #d9ff54; font-size: 18rpx; letter-spacing: 4rpx; }
|
||||
.saving { position: fixed; z-index: 10; left: 50%; bottom: 50rpx; transform: translateX(-50%); padding: 20rpx 30rpx; border-radius: 99rpx; background: #111; color: #fff; font-size: 23rpx; }
|
||||
@keyframes winner-in { from { opacity: 0; transform: scale(.65) rotate(-4deg); } to { opacity: 1; transform: scale(1); } }
|
||||
|
||||
+48
-2
@@ -2,7 +2,7 @@ var api = require('../../utils/api');
|
||||
var bracket = require('../../utils/bracket');
|
||||
|
||||
Page({
|
||||
data: { loading: true, error: '', test: null, left: null, right: null, round: 1, progress: 0, completed: 0, totalDecisions: 0 },
|
||||
data: { loading: true, error: '', test: null, left: null, right: null, matches: [], mode: 'single', round: 1, progress: 0, completed: 0, totalDecisions: 0 },
|
||||
onLoad: function (options) {
|
||||
this.slug = options.slug;
|
||||
this.load();
|
||||
@@ -19,14 +19,26 @@ Page({
|
||||
},
|
||||
refreshPair: function () {
|
||||
var pair = bracket.current(this.state);
|
||||
if (this.visibleRound !== this.state.round) {
|
||||
this.visibleRound = this.state.round;
|
||||
this.multiOffset = 0;
|
||||
}
|
||||
var offset = this.multiOffset || 0;
|
||||
var matches = this.state.matches.slice(offset, offset + 4).map(function (match, index) {
|
||||
return { index: offset + index, left: match.left, right: match.right, winner: match.winner };
|
||||
});
|
||||
this.setData({
|
||||
left: pair && pair[0],
|
||||
right: pair && pair[1],
|
||||
matches: matches,
|
||||
round: this.state.round,
|
||||
completed: this.state.decisions.length,
|
||||
progress: Math.round(this.state.decisions.length / this.totalDecisions * 100)
|
||||
});
|
||||
},
|
||||
setMode: function (event) {
|
||||
this.setData({ mode: event.currentTarget.dataset.mode });
|
||||
},
|
||||
choose: function (event) {
|
||||
if (this.choosing) return;
|
||||
this.choosing = true;
|
||||
@@ -36,9 +48,43 @@ Page({
|
||||
if (finished) this.complete();
|
||||
else {
|
||||
this.refreshPair();
|
||||
this.choosing = false;
|
||||
var self = this;
|
||||
setTimeout(function () { self.choosing = false; }, 220);
|
||||
}
|
||||
},
|
||||
chooseMatch: function (event) {
|
||||
if (this.choosing) return;
|
||||
var matchIndex = Number(event.currentTarget.dataset.match);
|
||||
var side = event.currentTarget.dataset.side;
|
||||
var match = this.state.matches[matchIndex];
|
||||
if (!match || match.winner || !match.right) return;
|
||||
this.choosing = true;
|
||||
var winner = side === 'left' ? match.left : match.right;
|
||||
var beforeRound = this.state.round;
|
||||
var finished = bracket.chooseAt(this.state, matchIndex, winner);
|
||||
if (finished) this.complete();
|
||||
else {
|
||||
this.refreshPair();
|
||||
var self = this;
|
||||
setTimeout(function () {
|
||||
if (beforeRound === self.state.round) {
|
||||
var offset = self.multiOffset || 0;
|
||||
var block = self.state.matches.slice(offset, offset + 4);
|
||||
if (block.length && block.every(function (item) { return item.winner; })) self.multiOffset = offset + 4;
|
||||
}
|
||||
self.refreshPair();
|
||||
self.choosing = false;
|
||||
}, 360);
|
||||
}
|
||||
},
|
||||
touchStart: function (event) { this.touchX = event.touches[0].clientX; },
|
||||
touchEnd: function (event) {
|
||||
if (this.data.mode !== 'swipe' || this.touchX == null) return;
|
||||
var delta = event.changedTouches[0].clientX - this.touchX;
|
||||
this.touchX = null;
|
||||
if (Math.abs(delta) < 55) return;
|
||||
this.choose({ currentTarget: { dataset: { side: delta < 0 ? 'left' : 'right' } } });
|
||||
},
|
||||
complete: function () {
|
||||
var self = this;
|
||||
var champion = this.state.pool[0];
|
||||
|
||||
+18
-9
@@ -2,19 +2,28 @@
|
||||
<view xhs:if="{{loading}}" class="empty">正在抽签…</view>
|
||||
<view xhs:elif="{{error}}" class="empty">{{error}}</view>
|
||||
<block xhs:else>
|
||||
<view class="topline"><text class="pill">第 {{round}} 轮</text><text class="muted">{{progress}}%</text></view>
|
||||
<view class="topline"><text>第 {{round}} 轮</text><text class="muted">{{completed}} / {{totalDecisions}}</text></view>
|
||||
<view class="progress"><view class="progress-in" style="width: {{progress}}%"></view></view>
|
||||
<view class="question"><view>此刻只能留一个,</view><view>你会选谁?</view></view>
|
||||
<view class="pair">
|
||||
<view class="choice choice-a" data-side="left" bindtap="choose">
|
||||
<view class="choice-index">A</view><view class="food-mark">{{test.emoji}}</view><view class="choice-name">{{left.name}}</view><view class="tap-hint">点它晋级 ↗</view>
|
||||
</view>
|
||||
<view class="mode-tabs">
|
||||
<view class="mode {{mode === 'single' ? 'active' : ''}}" data-mode="single" bindtap="setMode">一对</view>
|
||||
<view class="mode {{mode === 'multi' ? 'active' : ''}}" data-mode="multi" bindtap="setMode">多对</view>
|
||||
<view class="mode {{mode === 'swipe' ? 'active' : ''}}" data-mode="swipe" bindtap="setMode">滑动</view>
|
||||
</view>
|
||||
<view xhs:if="{{mode !== 'multi'}}" class="single-stage {{mode === 'swipe' ? 'swipe-stage' : ''}}" bindtouchstart="touchStart" bindtouchend="touchEnd">
|
||||
<view class="choice choice-a" data-side="left" bindtap="choose"><view class="choice-index">A</view><view class="choice-name">{{left.name}}</view><view class="tap-hint">{{mode === 'swipe' ? '向左滑选它' : '点按晋级'}}</view></view>
|
||||
<view class="versus">VS</view>
|
||||
<view class="choice choice-b" data-side="right" bindtap="choose">
|
||||
<view class="choice-index">B</view><view class="food-mark">{{test.emoji}}</view><view class="choice-name">{{right.name}}</view><view class="tap-hint">点它晋级 ↗</view>
|
||||
<view class="choice choice-b" data-side="right" bindtap="choose"><view class="choice-index">B</view><view class="choice-name">{{right.name}}</view><view class="tap-hint">{{mode === 'swipe' ? '向右滑选它' : '点按晋级'}}</view></view>
|
||||
</view>
|
||||
<view xhs:else class="multi-stage">
|
||||
<view xhs:for="{{matches}}" xhs:key="index" class="mini-match {{item.winner ? 'resolved' : ''}}">
|
||||
<block xhs:if="{{item.winner}}"><view class="mini-winner"><text>晋级</text>{{item.winner.name}}</view></block>
|
||||
<block xhs:else>
|
||||
<view class="mini-choice" data-match="{{item.index}}" data-side="left" bindtap="chooseMatch">{{item.left.name}}</view>
|
||||
<view class="mini-vs">VS</view>
|
||||
<view class="mini-choice" data-match="{{item.index}}" data-side="right" bindtap="chooseMatch">{{item.right.name}}</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
<view class="round-note">已完成 {{completed}} / {{totalDecisions}} 次选择</view>
|
||||
<view xhs:if="{{submitting}}" class="saving">正在保存你的冠军…</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user