feat: SSR 抽奖帖发帖与开奖

compose 支持 lottery;详情抽奖卡可开奖并展示中奖名单。同步勾选已落地的 health/robots/sitemap/uploads/限流清单项。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-30 03:30:57 +08:00
parent b5aee606fb
commit e06c54870c
9 changed files with 176 additions and 13 deletions

View File

@@ -16,7 +16,7 @@
</select>
</label>
{{if .IsEdit}}
<p class="j13-muted">类型:{{if eq .PostType "poll"}}投票{{else if eq .PostType "question"}}问答{{else if eq .PostType "bounty"}}悬赏{{else}}普通讨论{{end}}(不可更改)</p>
<p class="j13-muted">类型:{{if eq .PostType "poll"}}投票{{else if eq .PostType "question"}}问答{{else if eq .PostType "bounty"}}悬赏{{else if eq .PostType "lottery"}}抽奖{{else}}普通讨论{{end}}(不可更改)</p>
<input type="hidden" name="post_type" value="{{.PostType}}"/>
{{else}}
<label>类型
@@ -25,6 +25,7 @@
<option value="question"{{if eq .PostType "question"}} selected{{end}}>问答</option>
<option value="poll"{{if eq .PostType "poll"}} selected{{end}}>投票</option>
<option value="bounty"{{if eq .PostType "bounty"}} selected{{end}}>悬赏</option>
<option value="lottery"{{if eq .PostType "lottery"}} selected{{end}}>抽奖</option>
</select>
</label>
<p class="j13-muted" id="compose-question-hint"{{if ne .PostType "question"}} hidden{{end}}>问答帖无额外字段;解决状态可在帖详情由作者或管理员切换。</p>
@@ -48,6 +49,13 @@
<input name="bounty_points" type="number" min="1" value="{{.BountyPoints}}"/>
</label>
</fieldset>
<fieldset class="j13-lottery-fields" id="compose-lottery-fields"{{if ne .PostType "lottery"}} hidden{{end}}>
<legend>抽奖设置</legend>
<p class="j13-muted">参与者:已发布评论且非楼主(按用户去重)。人数足够后可由作者或管理员开奖。</p>
<label>中奖人数
<input name="lottery_winner_count" type="number" min="1" max="20" value="{{.LotteryWinners}}"/>
</label>
</fieldset>
{{end}}
<label>标题
<input name="title" required maxlength="{{.TitleMax}}" value="{{.Title}}"/>
@@ -79,11 +87,13 @@
var sel = document.getElementById('compose-post-type');
var box = document.getElementById('compose-poll-fields');
var bounty = document.getElementById('compose-bounty-fields');
var lottery = document.getElementById('compose-lottery-fields');
var qHint = document.getElementById('compose-question-hint');
if (!sel) return;
function sync() {
if (box) box.hidden = sel.value !== 'poll';
if (bounty) bounty.hidden = sel.value !== 'bounty';
if (lottery) lottery.hidden = sel.value !== 'lottery';
if (qHint) qHint.hidden = sel.value !== 'question';
}
sel.addEventListener('change', sync);

View File

@@ -121,6 +121,27 @@
{{end}}
</section>
{{end}}
{{if .Lottery}}
<section class="j13-lottery" aria-label="抽奖">
<h2 class="j13-lottery__title">抽奖</h2>
<p class="j13-muted">
中奖 {{.Lottery.WinnerCount}} 人 · 参与 {{.Lottery.ParticipantCount}} 人 · {{.Lottery.StatusLabel}}
</p>
{{if .Lottery.CanDraw}}
<form method="post" action="/post/{{.PostID}}/lottery/draw" class="j13-inline-form" onsubmit="return confirm('确认开奖?人数不足会失败。');">
<input type="hidden" name="_csrf" value="{{.CSRF}}"/>
<button type="submit">开奖</button>
</form>
{{end}}
{{if .Lottery.Winners}}
<ul class="j13-lottery__winners">
{{range .Lottery.Winners}}
<li>{{if .UserID}}<a href="/user/{{.UserID}}">{{.Name}}</a>{{else}}{{.Name}}{{end}}</li>
{{end}}
</ul>
{{end}}
</section>
{{end}}
{{if .Poll}}
<section class="j13-poll" aria-label="投票">
<h2 class="j13-poll__title">投票</h2>