feat: 翻译记录添加不共享开关功能
- Translation 模型新增 no_share 字段 - 管理后台翻译记录页面添加共享状态列和切换按钮 - 不共享的翻译不会被其他用户使用缓存 - 缓存匹配时检查是否有 no_share 标记
This commit is contained in:
@@ -69,13 +69,14 @@
|
||||
<th>大小</th>
|
||||
<th>状态</th>
|
||||
<th>缓存</th>
|
||||
<th>共享</th>
|
||||
<th>时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for t in translations.items %}
|
||||
<tr>
|
||||
<tr id="trans-row-{{ t.id }}">
|
||||
<td>{{ t.id }}</td>
|
||||
<td>{{ t.original_filename[:25] }}{% if t.original_filename|length > 25 %}...{% endif %}</td>
|
||||
<td>{% if t.user_id %}ID:{{ t.user_id }}{% else %}访客{% endif %}</td>
|
||||
@@ -87,14 +88,26 @@
|
||||
</span>
|
||||
</td>
|
||||
<td>{% if t.from_cache %}<i class="bi bi-check-circle text-success"></i>{% else %}-{% endif %}</td>
|
||||
<td>
|
||||
{% if t.no_share %}
|
||||
<span class="badge bg-secondary" id="share-badge-{{ t.id }}">不共享</span>
|
||||
{% else %}
|
||||
<span class="badge bg-success" id="share-badge-{{ t.id }}">共享</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ t.created_at.strftime('%m-%d %H:%M') }}</td>
|
||||
<td>
|
||||
<a href="{{ url_for('admin.translation_detail', trans_id=t.id) }}" class="btn btn-sm btn-outline-primary"><i class="bi bi-eye"></i></a>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteTrans({{ t.id }})"><i class="bi bi-trash"></i></button>
|
||||
<div class="d-flex gap-1">
|
||||
<button class="btn btn-sm btn-outline-{% if t.no_share %}success{% else %}warning{% endif %}" onclick="toggleShare({{ t.id }})" title="切换共享状态">
|
||||
<i class="bi bi-share{% if t.no_share %}-fill{% endif %}"></i>
|
||||
</button>
|
||||
<a href="{{ url_for('admin.translation_detail', trans_id=t.id) }}" class="btn btn-sm btn-outline-primary"><i class="bi bi-eye"></i></a>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteTrans({{ t.id }})"><i class="bi bi-trash"></i></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="9" class="text-center text-muted py-4">暂无数据</td></tr>
|
||||
<tr><td colspan="10" class="text-center text-muted py-4">暂无数据</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -122,6 +135,26 @@
|
||||
.then(r => r.json())
|
||||
.then(d => { if (d.success) location.reload(); });
|
||||
}
|
||||
|
||||
function toggleShare(id) {
|
||||
fetch(`/admin/translation/${id}/toggle-share`, { method: 'POST' })
|
||||
.then(r => r.json())
|
||||
.then(d => {
|
||||
if (d.success) {
|
||||
// 更新显示状态
|
||||
const badge = document.getElementById(`share-badge-${id}`);
|
||||
if (d.no_share) {
|
||||
badge.className = 'badge bg-secondary';
|
||||
badge.textContent = '不共享';
|
||||
} else {
|
||||
badge.className = 'badge bg-success';
|
||||
badge.textContent = '共享';
|
||||
}
|
||||
// 更新按钮样式
|
||||
location.reload(); // 简化处理,刷新页面
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user