feat: SSR 问答帖发帖与解决状态切换

compose 支持 question;详情徽章并由作者/管理员切换。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-30 02:04:56 +08:00
parent 92b68b9eef
commit 303755b47a
9 changed files with 71 additions and 11 deletions

View File

@@ -16,15 +16,17 @@
</select>
</label>
{{if .IsEdit}}
<p class="j13-muted">类型:{{if eq .PostType "poll"}}投票{{else}}普通讨论{{end}}(不可更改)</p>
<p class="j13-muted">类型:{{if eq .PostType "poll"}}投票{{else if eq .PostType "question"}}问答{{else}}普通讨论{{end}}(不可更改)</p>
<input type="hidden" name="post_type" value="{{.PostType}}"/>
{{else}}
<label>类型
<select name="post_type" id="compose-post-type">
<option value="normal"{{if ne .PostType "poll"}} selected{{end}}>普通讨论</option>
<option value="normal"{{if or (eq .PostType "normal") (eq .PostType "")}} selected{{end}}>普通讨论</option>
<option value="question"{{if eq .PostType "question"}} selected{{end}}>问答</option>
<option value="poll"{{if eq .PostType "poll"}} selected{{end}}>投票</option>
</select>
</label>
<p class="j13-muted" id="compose-question-hint"{{if ne .PostType "question"}} hidden{{end}}>问答帖无额外字段;解决状态可在帖详情由作者或管理员切换。</p>
<fieldset class="j13-poll-fields" id="compose-poll-fields"{{if ne .PostType "poll"}} hidden{{end}}>
<legend>投票设置</legend>
<label class="j13-check"><input type="checkbox" name="poll_multi" value="1"{{if .PollMulti}} checked{{end}}/> 允许多选</label>
@@ -68,8 +70,12 @@
(function () {
var sel = document.getElementById('compose-post-type');
var box = document.getElementById('compose-poll-fields');
if (!sel || !box) return;
function sync() { box.hidden = sel.value !== 'poll'; }
var qHint = document.getElementById('compose-question-hint');
if (!sel) return;
function sync() {
if (box) box.hidden = sel.value !== 'poll';
if (qHint) qHint.hidden = sel.value !== 'question';
}
sel.addEventListener('change', sync);
sync();
})();

View File

@@ -14,6 +14,9 @@
{{if .EditLocked}}<span class="j13-tag">禁编</span>{{end}}
{{if .CommentsLocked}}<span class="j13-tag">已结贴</span>{{end}}
{{if .PostTypeLabel}}<span class="j13-tag">{{.PostTypeLabel}}</span>{{end}}
{{if .IsQuestion}}
{{if .QuestionResolved}}<span class="j13-tag j13-tag--resolved">已解决</span>{{else}}<span class="j13-tag j13-tag--unresolved">未解决</span>{{end}}
{{end}}
{{if .BoardName}}<a class="j13-tag" href="/board/{{.BoardID}}">{{.BoardName}}</a>{{end}}
{{if .AuthorID}}<a href="/user/{{.AuthorID}}">{{.AuthorName}}</a>{{else}}<span>{{.AuthorName}}</span>{{end}}
<span>{{.CreatedLabel}}</span>
@@ -21,6 +24,18 @@
</div>
{{if .LoggedIn}}
<div class="j13-post__actions">
{{if .CanToggleQuestion}}
<form method="post" action="/post/{{.PostID}}/question/resolve" class="j13-inline-form">
<input type="hidden" name="_csrf" value="{{.CSRF}}"/>
{{if .QuestionResolved}}
<input type="hidden" name="resolved" value="0"/>
<button type="submit" class="j13-btn-secondary">标为未解决</button>
{{else}}
<input type="hidden" name="resolved" value="1"/>
<button type="submit">标为已解决</button>
{{end}}
</form>
{{end}}
<form method="post" action="/post/{{.PostID}}/like" class="j13-inline-form">
<input type="hidden" name="_csrf" value="{{.CSRF}}"/>
<button type="submit">{{if .Liked}}取消赞{{else}}赞{{end}} ({{.LikeCount}})</button>