feat: add animated choice modes and bracket editor
Verify mini program and deploy preview / verify-deploy (push) Successful in 50s

This commit is contained in:
2026-09-19 04:11:21 +08:00
parent 90ac8b951f
commit 36aee09dfa
39 changed files with 1669 additions and 178 deletions
+48 -2
View File
@@ -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];