75 lines
2.7 KiB
HTML
75 lines
2.7 KiB
HTML
{% extends "base.html" %}
|
||
{% block title %}发布话题 - 论坛{% endblock %}
|
||
{% block content %}
|
||
<div class="page-title">
|
||
<h1>发布新话题</h1>
|
||
<p>支持 Markdown 语法(表格、代码块、图片等)</p>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<div class="card-body">
|
||
<div id="error-box" style="display:none;" class="alert alert-danger"></div>
|
||
<form id="topic-form">
|
||
<div class="form-group">
|
||
<label for="title">标题</label>
|
||
<input type="text" id="title" name="title" class="form-control" required placeholder="请输入话题标题">
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="category">分类</label>
|
||
<select id="category" name="category" class="form-control"></select>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="content">内容(支持 Markdown)</label>
|
||
<textarea id="content" name="content" class="form-control" rows="12" required placeholder="支持 Markdown 语法:标题、表格、代码块、图片、链接..."></textarea>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="file_upload">上传文件(可选,支持 .docx / .xlsx)</label>
|
||
<input type="file" id="file_upload" name="file_upload" class="form-control" accept=".docx,.xlsx">
|
||
<div style="font-size:12px;color:var(--text-light);margin-top:4px;">
|
||
上传后自动解析文字、图片和表格到内容中
|
||
</div>
|
||
</div>
|
||
<button type="submit" class="btn btn-primary">发布话题</button>
|
||
<a href="/forum/" class="btn">取消</a>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
(async function() {
|
||
var catRes = await fetch('/api/forum/categories/');
|
||
var catData = await catRes.json();
|
||
if (catData.success) {
|
||
var sel = document.getElementById('category');
|
||
sel.innerHTML = catData.categories.map(function(c) {
|
||
return '<option value="' + c.value + '">' + c.label + '</option>';
|
||
}).join('');
|
||
}
|
||
|
||
document.getElementById('topic-form').addEventListener('submit', async function(e) {
|
||
e.preventDefault();
|
||
var fd = new FormData(this);
|
||
fd.append('csrf_token', CSRF_TOKEN);
|
||
var res = await fetch('/forum/new/', { method: 'POST', body: fd });
|
||
var data = await res.json();
|
||
if (data.success) {
|
||
window.location.href = '/forum/' + data.id + '/';
|
||
} else {
|
||
var box = document.getElementById('error-box');
|
||
box.textContent = data.error || '发布失败';
|
||
box.style.display = 'block';
|
||
}
|
||
});
|
||
|
||
document.getElementById('file_upload').addEventListener('change', function(e) {
|
||
var file = e.target.files[0];
|
||
if (!file) return;
|
||
parseUploadedFile(file, function(markdown) {
|
||
var ta = document.getElementById('content');
|
||
ta.value = ta.value + '\n\n' + markdown;
|
||
});
|
||
});
|
||
})();
|
||
</script>
|
||
{% endblock %}
|