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
+18
View File
@@ -0,0 +1,18 @@
.discover { padding: 28rpx 18rpx 180rpx; background: #fff; }
.heading { font-size: 46rpx; font-weight: 950; }
.subheading { margin: 10rpx 0 34rpx; color: #777; font-size: 24rpx; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12rpx; }
.result-card { overflow: hidden; border: 1rpx solid #eee; background: #fff; }
.result-card image { display: block; width: 100%; height: 290rpx; }
.result-copy { padding: 16rpx; }
.result-copy text { color: #777; font-size: 21rpx; }
.result-copy view { margin-top: 6rpx; font-size: 31rpx; font-weight: 900; }
.bottom-nav { position: fixed; z-index: 20; left: 28rpx; right: 28rpx; bottom: calc(24rpx + env(safe-area-inset-bottom)); display: flex; height: 104rpx; padding: 0 18rpx; border-radius: 20rpx; background: #080808; box-shadow: 0 18rpx 50rpx rgba(0,0,0,.22); }
.nav-item { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #888; font-size: 18rpx; }
.nav-item.active { color: #fff; }
.nav-item.active:before { content: ''; position: absolute; top: -25rpx; width: 94rpx; height: 94rpx; border: 14rpx solid #fff; border-radius: 50%; background: #080808; }
.nav-icon { z-index: 1; width: 26rpx; height: 26rpx; margin-bottom: 7rpx; border: 5rpx solid currentColor; }
.home-icon { transform: rotate(45deg); border-radius: 5rpx; }
.discover-icon { border-radius: 50%; border-width: 6rpx 2rpx; }
.me-icon { border-radius: 50%; }
.nav-item text { z-index: 1; }
+16
View File
@@ -0,0 +1,16 @@
var api = require('../../utils/api');
Page({
data: { results: [], loading: true, error: '' },
onLoad: function () { this.load(); },
load: function () {
var self = this;
api.request('/api/v1/results/discover').then(function (results) {
self.setData({ results: results, loading: false, error: '' });
}).catch(function (error) {
self.setData({ loading: false, error: error.message || '加载失败' });
});
},
openHome: function () { xhs.redirectTo({ url: '/pages/index/index' }); },
openMe: function () { xhs.redirectTo({ url: '/pages/me/me' }); }
});
+1
View File
@@ -0,0 +1 @@
{ "navigationBarTitleText": "大家的选择" }
+18
View File
@@ -0,0 +1,18 @@
<view class="page discover">
<view class="heading">大家最近选了什么</view>
<view class="subheading">看看同频的人把谁送到了最后</view>
<view xhs:if="{{loading}}" class="empty">正在收集答案…</view>
<view xhs:elif="{{error}}" class="empty">{{error}}</view>
<view xhs:elif="{{!results.length}}" class="empty">还没有公开结果</view>
<view xhs:else class="result-grid">
<view xhs:for="{{results}}" xhs:key="id" class="result-card">
<image src="/assets/test-covers/{{item.test_slug}}.jpg" mode="aspectFill" />
<view class="result-copy"><text>{{item.test_title}}</text><view>{{item.champion_name}}</view></view>
</view>
</view>
<view class="bottom-nav">
<view class="nav-item" bindtap="openHome"><view class="nav-icon home-icon"></view><text>测试</text></view>
<view class="nav-item active"><view class="nav-icon discover-icon"></view><text>发现</text></view>
<view class="nav-item" bindtap="openMe"><view class="nav-icon me-icon"></view><text>我的</text></view>
</view>
</view>
+27 -22
View File
@@ -1,23 +1,28 @@
.home { padding-bottom: 70rpx; }
.hero { position: relative; overflow: hidden; background: #ff6b35; color: #fff; border-radius: 36rpx; padding: 40rpx 34rpx 34rpx; box-shadow: 0 18rpx 50rpx rgba(168, 65, 25, .18); }
.hero-row { display: flex; justify-content: space-between; align-items: flex-start; }
.eyebrow { font-size: 21rpx; letter-spacing: 4rpx; opacity: .8; }
.title { width: 480rpx; margin-top: 18rpx; font-size: 58rpx; line-height: 1.05; font-weight: 900; }
.hero-copy { margin-top: 42rpx; width: 480rpx; font-size: 27rpx; line-height: 1.6; opacity: .92; }
.me-button { margin: 0; padding: 0 24rpx; min-width: 0; height: 64rpx; line-height: 64rpx; font-size: 25rpx; border-radius: 999rpx; background: rgba(255,255,255,.2); color: #fff; }
.hero-stickers { margin-top: 30rpx; display: flex; justify-content: space-between; font-size: 30rpx; font-weight: 800; }
.section-head { display: flex; justify-content: space-between; margin: 48rpx 6rpx 24rpx; font-size: 30rpx; font-weight: 800; }
.section-head .muted { font-size: 24rpx; font-weight: 500; }
.waterfall { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-gap: 22rpx; align-items: start; }
.test-card { overflow: hidden; background: #fff; border-radius: 28rpx; box-shadow: 0 9rpx 30rpx rgba(62, 42, 30, .08); }
.test-card:active { transform: scale(.98); }
.card-art { position: relative; height: 250rpx; overflow: hidden; }
.card-1 .card-art { height: 310rpx; }
.card-number { position: absolute; left: 20rpx; top: 18rpx; color: rgba(255,255,255,.8); font-size: 22rpx; font-weight: 800; }
.card-emoji { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%) rotate(-8deg); font-size: 112rpx; }
.card-body { padding: 24rpx; }
.card-title { font-size: 30rpx; font-weight: 900; }
.card-copy { margin-top: 12rpx; color: #746a63; font-size: 23rpx; line-height: 1.45; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.card-meta { margin-top: 22rpx; display: flex; justify-content: space-between; color: #9a8e86; font-size: 20rpx; }
.home { padding: 22rpx 18rpx 180rpx; background: #fff; }
.mast { display: flex; align-items: center; gap: 16rpx; padding: 8rpx 4rpx 22rpx; }
.logo-mark { position: relative; display: grid; place-items: center; width: 72rpx; height: 58rpx; overflow: hidden; background: #111; color: #fff; font-size: 24rpx; font-weight: 950; letter-spacing: -2rpx; }
.logo-cut { position: absolute; left: 25rpx; top: -18rpx; width: 28rpx; height: 28rpx; border: 8rpx solid #fff; border-radius: 50%; }
.logo-word { font-size: 31rpx; font-weight: 950; letter-spacing: 2rpx; }
.search { display: flex; align-items: center; height: 72rpx; margin-bottom: 20rpx; padding: 0 24rpx; background: #f3f3f3; border-radius: 8rpx; }
.search-icon { margin-right: 14rpx; font-size: 38rpx; transform: rotate(-20deg); }
.search input { flex: 1; font-size: 27rpx; }
.waterfall { column-count: 2; column-gap: 10rpx; }
.test-card { display: inline-block; width: 100%; margin: 0 0 18rpx; overflow: hidden; break-inside: avoid; background: #fff; }
.test-card:active { opacity: .78; transform: scale(.985); }
.card-art { display: block; width: 100%; height: 360rpx; background: #eee; }
.card-1 .card-art { height: 430rpx; }
.card-2 .card-art { height: 390rpx; }
.card-body { padding: 16rpx 8rpx 10rpx; }
.card-title { font-size: 28rpx; font-weight: 850; }
.card-copy { margin-top: 8rpx; color: #555; font-size: 22rpx; line-height: 1.42; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.card-meta { margin-top: 12rpx; display: flex; justify-content: space-between; color: #999; font-size: 19rpx; }
.retry { margin-top: 24rpx; width: 240rpx; font-size: 24rpx; }
.bottom-nav { position: fixed; z-index: 20; left: 28rpx; right: 28rpx; bottom: calc(24rpx + env(safe-area-inset-bottom)); display: flex; height: 104rpx; padding: 0 18rpx; border-radius: 20rpx; background: #080808; box-shadow: 0 18rpx 50rpx rgba(0,0,0,.22); }
.nav-item { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #888; font-size: 18rpx; }
.nav-item.active { color: #fff; }
.nav-item.active:before { content: ''; position: absolute; top: -25rpx; width: 94rpx; height: 94rpx; border: 14rpx solid #fff; border-radius: 50%; background: #080808; }
.nav-icon { z-index: 1; width: 26rpx; height: 26rpx; margin-bottom: 7rpx; border: 5rpx solid currentColor; }
.home-icon { transform: rotate(45deg); border-radius: 5rpx; }
.discover-icon { border-radius: 50%; border-width: 6rpx 2rpx; }
.me-icon { border-radius: 50%; }
.nav-item text { z-index: 1; }
+10 -2
View File
@@ -1,13 +1,13 @@
var api = require('../../utils/api');
Page({
data: { tests: [], loading: true, error: '' },
data: { tests: [], visibleTests: [], keyword: '', loading: true, error: '' },
onLoad: function () { this.loadTests(); },
onPullDownRefresh: function () { this.loadTests(true); },
loadTests: function (refreshing) {
var self = this;
api.request('/api/v1/tests').then(function (tests) {
self.setData({ tests: tests, loading: false, error: '' });
self.setData({ tests: tests, visibleTests: tests, loading: false, error: '' });
}).catch(function (error) {
self.setData({ loading: false, error: error.message || '加载失败' });
}).then(function () {
@@ -19,5 +19,13 @@ Page({
openTest: function (event) {
xhs.navigateTo({ url: '/pages/test/test?slug=' + event.currentTarget.dataset.slug });
},
search: function (event) {
var keyword = (event.detail.value || '').trim().toLowerCase();
var visible = this.data.tests.filter(function (item) {
return (item.title + ' ' + item.subtitle).toLowerCase().indexOf(keyword) >= 0;
});
this.setData({ keyword: keyword, visibleTests: visible });
},
openDiscover: function () { xhs.navigateTo({ url: '/pages/discover/discover' }); },
openMe: function () { xhs.navigateTo({ url: '/pages/me/me' }); }
});
+10 -18
View File
@@ -1,29 +1,21 @@
<view class="page home">
<view class="hero">
<view class="hero-row">
<view>
<view class="eyebrow">TASTE LAB · 01</view>
<view class="title">今天,认真选一个。</view>
</view>
<button class="me-button" bindtap="openMe">我的</button>
</view>
<view class="hero-copy">没有“都可以”。每轮只选一个,让你的偏爱一路赢到底。</view>
<view class="hero-stickers"><text>✦</text><text>二选一</text><text>↗</text></view>
</view>
<view class="section-head"><text>全部测试</text><text class="muted">{{tests.length}} 个题库</text></view>
<view class="mast"><view class="logo-mark"><view class="logo-cut"></view><text>PK</text></view><view class="logo-word">偏爱研究所</view></view>
<view class="search"><text class="search-icon">⌕</text><input placeholder="搜索测试" bindinput="search" value="{{keyword}}" /></view>
<view xhs:if="{{loading}}" class="empty">正在摆好擂台…</view>
<view xhs:elif="{{error}}" class="empty">{{error}}<button class="retry" bindtap="loadTests">再试一次</button></view>
<view xhs:else class="waterfall">
<view xhs:for="{{tests}}" xhs:key="slug" class="test-card card-{{index % 3}}" data-slug="{{item.slug}}" bindtap="openTest">
<view class="card-art" style="background: {{item.accent}}">
<text class="card-number">0{{index + 1}}</text><text class="card-emoji">{{item.emoji}}</text>
</view>
<view xhs:for="{{visibleTests}}" xhs:key="slug" class="test-card card-{{index % 3}}" data-slug="{{item.slug}}" bindtap="openTest">
<image class="card-art" src="/assets/test-covers/{{item.slug}}.jpg" mode="aspectFill" />
<view class="card-body">
<view class="card-title">{{item.title}}</view>
<view class="card-copy">{{item.subtitle}}</view>
<view class="card-meta"><text>{{item.candidate_count}} 强</text><text>{{item.run_count}} 人完成 →</text></view>
<view class="card-meta"><text>{{item.candidate_count}} 强</text><text>{{item.run_count}} 人完成</text></view>
</view>
</view>
</view>
<view class="bottom-nav">
<view class="nav-item active"><view class="nav-icon home-icon"></view><text>测试</text></view>
<view class="nav-item" bindtap="openDiscover"><view class="nav-icon discover-icon"></view><text>发现</text></view>
<view class="nav-item" bindtap="openMe"><view class="nav-icon me-icon"></view><text>我的</text></view>
</view>
</view>
+10 -1
View File
@@ -13,4 +13,13 @@
.result-test { color: #887c74; font-size: 22rpx; }
.result-champion { margin-top: 6rpx; font-size: 34rpx; font-weight: 900; }
.arrow { font-size: 34rpx; }
.profile { padding-bottom: 180rpx; }
.bottom-nav { position: fixed; z-index: 20; left: 28rpx; right: 28rpx; bottom: calc(24rpx + env(safe-area-inset-bottom)); display: flex; height: 104rpx; padding: 0 18rpx; border-radius: 20rpx; background: #080808; box-shadow: 0 18rpx 50rpx rgba(0,0,0,.22); }
.nav-item { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #888; font-size: 18rpx; }
.nav-item.active { color: #fff; }
.nav-item.active:before { content: ''; position: absolute; top: -25rpx; width: 94rpx; height: 94rpx; border: 14rpx solid #fff; border-radius: 50%; background: #080808; }
.nav-icon { z-index: 1; width: 26rpx; height: 26rpx; margin-bottom: 7rpx; border: 5rpx solid currentColor; }
.home-icon { transform: rotate(45deg); border-radius: 5rpx; }
.discover-icon { border-radius: 50%; border-width: 6rpx 2rpx; }
.me-icon { border-radius: 50%; }
.nav-item text { z-index: 1; }
+3 -2
View File
@@ -19,6 +19,7 @@ Page({
api.request('/api/v1/me/link-code', { method: 'POST' }).then(function (data) {
self.setData({ linkCode: data.code });
}).catch(function (error) { xhs.showToast({ title: error.message || '生成失败', icon: 'none' }); });
}
},
openHome: function () { xhs.redirectTo({ url: '/pages/index/index' }); },
openDiscover: function () { xhs.redirectTo({ url: '/pages/discover/discover' }); }
});
+5 -1
View File
@@ -15,5 +15,9 @@
<view class="medal">#1</view><view class="result-main"><view class="result-test">{{item.test_title}}</view><view class="result-champion">{{item.champion_name}}</view></view><view class="arrow">→</view>
</view>
</view>
<view class="bottom-nav">
<view class="nav-item" bindtap="openHome"><view class="nav-icon home-icon"></view><text>测试</text></view>
<view class="nav-item" bindtap="openDiscover"><view class="nav-icon discover-icon"></view><text>发现</text></view>
<view class="nav-item active"><view class="nav-icon me-icon"></view><text>我的</text></view>
</view>
</view>
+24 -16
View File
@@ -1,16 +1,24 @@
.result-kicker { text-align: center; color: #ff6b35; font-size: 22rpx; letter-spacing: 6rpx; font-weight: 800; }
.result-title { margin: 14rpx 0 28rpx; text-align: center; font-size: 46rpx; font-weight: 900; }
.champion { position: relative; overflow: hidden; padding: 54rpx 36rpx; text-align: center; border-radius: 36rpx; background: #25211f; color: #fff; }
.crown { position: absolute; right: 24rpx; top: 2rpx; color: #ffe568; font-size: 100rpx; transform: rotate(13deg); }
.test-name { opacity: .62; font-size: 24rpx; }
.champion-name { margin-top: 18rpx; font-size: 70rpx; line-height: 1.15; font-weight: 900; }
.runner { margin-top: 22rpx; color: #e5dcd6; font-size: 23rpx; }
.poster-head { display: flex; justify-content: space-between; margin: 46rpx 4rpx 20rpx; font-size: 30rpx; font-weight: 900; }
.poster-head .muted { font-size: 23rpx; font-weight: 500; }
.poster { width: 100%; height: 925rpx; border-radius: 30rpx; box-shadow: 0 16rpx 40rpx rgba(50,30,20,.12); }
.theme-scroll { margin-top: 26rpx; white-space: nowrap; }
.theme-row { display: flex; }
.theme-chip { flex: none; margin: 0 14rpx 0 0; padding: 0 28rpx; height: 68rpx; line-height: 68rpx; border-radius: 99rpx; background: #fff; color: #6d625b; font-size: 23rpx; }
.theme-chip.active { background: #25211f; color: #fff; }
.sticker-row { display: flex; justify-content: space-between; margin-top: 26rpx; padding: 26rpx; border-radius: 24rpx; background: #fff; font-size: 25rpx; }
.save, .again { margin-top: 22rpx; font-size: 28rpx; }
.editor { min-height: 100vh; padding: 20rpx 22rpx 40rpx; background: #151515; color: #fff; }
.editor-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18rpx; }
.editor-head text { font-size: 31rpx; font-weight: 900; }
.editor-head view view { margin-top: 4rpx; color: #888; font-size: 19rpx; }
.export { margin: 0; padding: 0 30rpx; min-width: 0; height: 64rpx; line-height: 64rpx; border-radius: 99rpx; background: #ff3156; color: #fff; font-size: 23rpx; font-weight: 800; }
.poster { width: 100%; height: 880rpx; background: #242424; }
.strip, .media-strip, .tool-strip { white-space: nowrap; }
.strip-row, .media-row, .tool-row { display: flex; align-items: center; }
.strip { margin-top: 18rpx; }
.chip { flex: none; margin-right: 10rpx; padding: 0 22rpx; min-width: 0; height: 54rpx; line-height: 54rpx; border-radius: 8rpx; background: #292929; color: #aaa; font-size: 20rpx; }
.chip.active { background: #fff; color: #111; }
.media-strip { margin-top: 22rpx; }
.media-thumb, .add-media { flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 112rpx; height: 112rpx; margin-right: 12rpx; border: 2rpx solid #444; border-radius: 10rpx; background: #252525; color: #fff; font-size: 20rpx; }
.bracket-thumb { border-color: #fff; background: #f3eadf; color: #111; font-weight: 800; }
.add-media text { margin-top: 5rpx; color: #999; font-size: 16rpx; }
.tool-strip { margin-top: 25rpx; }
.tool { flex: none; width: 104rpx; text-align: center; color: #888; font-size: 19rpx; }
.tool.active { color: #fff; }
.tool-icon { display: grid; place-items: center; width: 50rpx; height: 50rpx; margin: 0 auto 9rpx; border: 3rpx solid currentColor; border-radius: 12rpx; font-size: 18rpx; }
.tool-panel { display: flex; margin-top: 22rpx; padding: 18rpx; overflow: hidden; background: #222; }
.theme-chip { flex: 1; margin: 0 5rpx; padding: 0; height: 58rpx; line-height: 58rpx; border-radius: 6rpx; background: #333; color: #aaa; font-size: 19rpx; }
.theme-chip.active { background: #fff; color: #111; }
.setting-row { display: flex; width: 100%; justify-content: space-between; font-size: 22rpx; }
.hint { color: #777; font-size: 20rpx; }
+86 -14
View File
@@ -1,4 +1,5 @@
var api = require('../../utils/api');
var posterEditor = require('../../vendor/poster-editor.cjs');
var THEMES = {
celebration: { bg: '#ff6b35', ink: '#fffaf4', card: '#25211f', accent: '#ffe568', label: '庆祝派对' },
@@ -16,9 +17,20 @@ Page({
{ name: 'sticker', label: '贴纸手账' }
],
sticker: true,
bracketLayout: 'symmetric',
bracketView: 'overview',
activeTool: 'filter',
backgroundPath: '',
tools: [
{ name: 'filter', label: '滤镜' }, { name: 'text', label: '文字' },
{ name: 'sticker', label: '贴纸' }, { name: 'crop', label: '裁剪' },
{ name: 'adjust', label: '调整' }, { name: 'layout', label: '布局' },
{ name: 'brush', label: '画笔' }
],
saving: false
},
onLoad: function (options) {
this.posterDocument = posterEditor.createDocument({ id: 'run-' + options.id, seed: options.id, width: 750, height: 1000, meta: { sourceType: 'pk-run', sourceId: options.id } });
var cached = xhs.getStorageSync('pk_last_result');
this.runId = options.id;
if (cached && cached.id === options.id) this.setData({ result: cached });
@@ -36,35 +48,45 @@ Page({
this.drawPoster();
},
toggleSticker: function () { this.setData({ sticker: !this.data.sticker }); this.drawPoster(); },
pickBracketLayout: function (event) { this.setData({ bracketLayout: event.currentTarget.dataset.layout }); this.drawPoster(); },
pickBracketView: function (event) { this.setData({ bracketView: event.currentTarget.dataset.view }); this.drawPoster(); },
pickTool: function (event) { this.setData({ activeTool: event.currentTarget.dataset.tool }); },
chooseBackground: function () {
var self = this;
xhs.chooseImage({
count: 1,
success: function (result) {
var path = result.tempFilePaths && result.tempFilePaths[0];
if (path) { self.setData({ backgroundPath: path }); self.drawPoster(); }
}
});
},
drawPoster: function () {
var result = this.data.result;
if (!result) return;
var theme = THEMES[this.data.template];
var isCelebration = this.data.template === 'celebration';
var showSticker = this.data.sticker;
var layout = this.data.bracketLayout;
var view = this.data.bracketView;
var backgroundPath = this.data.backgroundPath;
xhs.createSelectorQuery().select('.poster').boundingClientRect(function (rect) {
var ctx = xhs.createCanvasContext('poster');
if (rect) ctx.scale(rect.width / 750, rect.height / 1000);
ctx.setFillStyle(theme.bg); ctx.fillRect(0, 0, 750, 1000);
if (backgroundPath) {
ctx.drawImage(backgroundPath, 0, 0, 750, 1000);
ctx.setGlobalAlpha(.82); ctx.setFillStyle(theme.bg); ctx.fillRect(0, 0, 750, 1000); ctx.setGlobalAlpha(1);
}
ctx.setFillStyle(theme.ink); ctx.setFontSize(24); ctx.fillText('PK 研究所 / MY PICK', 54, 72);
ctx.setFontSize(58); ctx.fillText('我的冠军是', 54, 156);
ctx.setFillStyle(theme.card); ctx.fillRect(46, 205, 658, 440);
ctx.setFillStyle(theme.card); ctx.fillRect(30, 190, 690, 610);
ctx.setFillStyle(isCelebration ? '#fffaf4' : theme.ink);
ctx.setFontSize(26); ctx.fillText(result.test_title, 84, 270);
ctx.setFontSize(result.champion_name.length > 7 ? 62 : 82);
ctx.fillText(result.champion_name, 84, 405);
ctx.setFillStyle(theme.accent); ctx.fillRect(84, 440, Math.min(500, result.champion_name.length * 80), 18);
ctx.setFillStyle(isCelebration ? '#fffaf4' : theme.ink);
ctx.setFontSize(24); ctx.fillText('一路二选一,它赢到了最后。', 84, 525);
var ranking = result.ranking_names || [];
ctx.setFillStyle(theme.ink); ctx.setFontSize(25); ctx.fillText('我的 TOP 4', 54, 720);
for (var i = 0; i < Math.min(4, ranking.length); i += 1) {
ctx.setFontSize(26); ctx.fillText((i + 1) + '. ' + ranking[i], 64, 774 + i * 48);
}
ctx.setFontSize(22); ctx.fillText(result.test_title, 54, 235);
drawBracket(ctx, result, layout, view, theme, isCelebration);
if (showSticker) {
ctx.setFillStyle(theme.accent); ctx.beginPath(); ctx.arc(645, 125, 58, 0, Math.PI * 2); ctx.fill();
ctx.setFillStyle(theme.card); ctx.setFontSize(28); ctx.fillText('WIN!', 607, 134);
ctx.setFontSize(52); ctx.fillText('✦', 640, 700); ctx.fillText('♡', 550, 900);
ctx.setFillStyle(theme.card); ctx.setFontSize(24); ctx.fillText('WIN', 615, 134);
}
ctx.setFillStyle(theme.ink); ctx.setFontSize(20); ctx.fillText('长按保存,把答案分享给同频的人', 54, 956);
ctx.draw();
@@ -88,3 +110,53 @@ Page({
},
replay: function () { xhs.redirectTo({ url: '/pages/test/test?slug=' + this.data.result.test_slug }); }
});
function drawBracket(ctx, result, layout, view, theme, isCelebration) {
var decisions = result.decisions || [];
var names = result.candidate_names || {};
if (!decisions.length) {
ctx.setFillStyle(isCelebration ? '#fffaf4' : theme.ink);
ctx.setFontSize(72);
ctx.fillText(result.champion_name, 70, 480);
return;
}
var maxRound = decisions.reduce(function (max, item) { return Math.max(max, item.round); }, 1);
var minimumRound = view === 'final' ? maxRound : view === 'top8' ? Math.max(1, maxRound - 2) : view === 'top16' ? Math.max(1, maxRound - 3) : 1;
var visible = decisions.filter(function (item) { return item.round >= minimumRound; });
if (view === 'left' || view === 'right') {
visible = visible.filter(function (item, index) { return item.round === maxRound || index % 2 === (view === 'left' ? 0 : 1); });
}
var grouped = {};
visible.forEach(function (item) { (grouped[item.round] || (grouped[item.round] = [])).push(item); });
var positions = {};
Object.keys(grouped).forEach(function (roundKey) {
var round = Number(roundKey), items = grouped[round], count = items.length;
items.forEach(function (item, index) {
var centered = layout === 'symmetric';
var side = centered && round < maxRound && index % 2 ? 1 : -1;
var depth = maxRound - round;
var x = centered ? 375 + side * Math.min(250, 82 + depth * 68) : 64 + (round - minimumRound) * (590 / Math.max(1, maxRound - minimumRound));
var y = 300 + (index + 1) * (440 / (count + 1));
positions[item.winner_id + ':' + item.round] = { x: x, y: y, side: side, item: item };
});
});
ctx.setLineWidth(3);
ctx.setStrokeStyle(theme.accent);
Object.keys(positions).forEach(function (key) {
var pos = positions[key], parent = null;
visible.forEach(function (candidate) {
if (!parent && candidate.round > pos.item.round && (candidate.left_id === pos.item.winner_id || candidate.right_id === pos.item.winner_id)) parent = positions[candidate.winner_id + ':' + candidate.round];
});
if (parent) {
ctx.beginPath(); ctx.moveTo(pos.x, pos.y); ctx.lineTo((pos.x + parent.x) / 2, pos.y); ctx.lineTo((pos.x + parent.x) / 2, parent.y); ctx.lineTo(parent.x, parent.y); ctx.stroke();
}
});
Object.keys(positions).forEach(function (key) {
var pos = positions[key], label = names[pos.item.winner_id] || result.champion_name;
ctx.setFillStyle(pos.item.round === maxRound ? theme.accent : theme.bg);
ctx.fillRect(pos.x - 58, pos.y - 21, 116, 42);
ctx.setFillStyle(theme.ink); ctx.setFontSize(label.length > 6 ? 14 : 17);
ctx.fillText(label.slice(0, 8), pos.x - 48, pos.y + 6);
});
ctx.setFillStyle(theme.ink); ctx.setFontSize(24); ctx.fillText('冠军 ' + result.champion_name, 54, 850);
}
+16 -13
View File
@@ -1,15 +1,18 @@
<view class="page result-page" xhs:if="{{result}}">
<view class="result-kicker">FINAL ANSWER</view>
<view class="result-title">你的冠军诞生了!</view>
<view class="champion"><view class="crown">♛</view><view class="test-name">{{result.test_title}}</view><view class="champion-name">{{result.champion_name}}</view><view class="runner" xhs:if="{{result.runner_up_name}}">决赛击败 {{result.runner_up_name}}</view></view>
<view class="poster-head"><text>分享卡片</text><text class="muted">3 款模板任选</text></view>
<view class="page editor" xhs:if="{{result}}">
<view class="editor-head"><view><text>分享图编辑器</text><view>{{result.test_title}} · {{result.champion_name}}</view></view><button class="export" loading="{{saving}}" bindtap="savePoster">导出</button></view>
<canvas canvas-id="poster" class="poster"></canvas>
<scroll-view scroll-x class="theme-scroll">
<view class="theme-row">
<button xhs:for="{{themeList}}" xhs:key="name" class="theme-chip {{template === item.name ? 'active' : ''}}" data-name="{{item.name}}" bindtap="pickTemplate">{{item.label}}</button>
</view>
</scroll-view>
<view class="sticker-row" bindtap="toggleSticker"><text>添加手绘贴纸</text><text>{{sticker ? '已开启 ✓' : '关闭'}}</text></view>
<button class="primary save" loading="{{saving}}" bindtap="savePoster">保存分享图</button>
<button class="secondary again" bindtap="replay">再测一次</button>
<scroll-view scroll-x class="strip"><view class="strip-row">
<button class="chip {{bracketLayout === 'symmetric' ? 'active' : ''}}" data-layout="symmetric" bindtap="pickBracketLayout">对称图</button>
<button class="chip {{bracketLayout === 'single' ? 'active' : ''}}" data-layout="single" bindtap="pickBracketLayout">单边图</button>
<button class="chip {{bracketView === 'overview' ? 'active' : ''}}" data-view="overview" bindtap="pickBracketView">总览</button>
<button class="chip" data-view="left" bindtap="pickBracketView">左半区</button><button class="chip" data-view="right" bindtap="pickBracketView">右半区</button>
<button class="chip" data-view="top16" bindtap="pickBracketView">16 强</button><button class="chip" data-view="top8" bindtap="pickBracketView">8 强</button><button class="chip" data-view="final" bindtap="pickBracketView">决赛</button>
</view></scroll-view>
<scroll-view scroll-x class="media-strip"><view class="media-row"><view class="media-thumb bracket-thumb">晋级图</view><button class="add-media" bindtap="chooseBackground">+<text>添加底图</text></button></view></scroll-view>
<scroll-view scroll-x class="tool-strip"><view class="tool-row">
<view xhs:for="{{tools}}" xhs:key="name" class="tool {{activeTool === item.name ? 'active' : ''}}" data-tool="{{item.name}}" bindtap="pickTool"><view class="tool-icon">{{index + 1}}</view><text>{{item.label}}</text></view>
</view></scroll-view>
<view class="tool-panel" xhs:if="{{activeTool === 'filter'}}"><button xhs:for="{{themeList}}" xhs:key="name" class="theme-chip {{template === item.name ? 'active' : ''}}" data-name="{{item.name}}" bindtap="pickTemplate">{{item.label}}</button></view>
<view class="tool-panel" xhs:elif="{{activeTool === 'sticker'}}"><view class="setting-row" bindtap="toggleSticker"><text>装饰贴纸</text><text>{{sticker ? '已开启' : '关闭'}}</text></view></view>
<view class="tool-panel hint" xhs:else>此工具将由 @entroia/poster-editor 的图层绑定驱动</view>
</view>
+28 -19
View File
@@ -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
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];
+18 -9
View File
@@ -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>