Files
liteadmin/templates/task_list.html
T

357 lines
14 KiB
HTML

{% extends "base.html" %}
{% block title %}信息收集 - {{ site_name }}{% endblock %}
{% block content %}
<div class="page-title">
<h1>信息收集</h1>
<p>查看和管理班组任务</p>
</div>
<div style="display:flex; gap:8px; margin-bottom:16px; flex-wrap:wrap; align-items:center;">
<button class="btn btn-primary" onclick="showCreateModal()">+ 创建任务</button>
<div style="flex:1;"></div>
<button class="btn btn-sm" id="filterMyOnly" onclick="toggleFilter('my_only')">只看我创建的</button>
<button class="btn btn-sm" id="filterTodayOnly" onclick="toggleFilter('today_only')">只看今天创建的</button>
</div>
<div class="search-form" style="display:flex; gap:8px; margin-bottom:16px; flex-wrap:wrap; align-items:center;">
<input type="text" id="searchKeyword" class="form-control" style="width:200px;" placeholder="搜索任务名称..." value="{{ keyword }}">
<input type="date" id="searchDateFrom" class="form-control" style="width:150px;" value="{{ date_from }}">
<span style="color:var(--text-light);">~</span>
<input type="date" id="searchDateTo" class="form-control" style="width:150px;" value="{{ date_to }}">
<button class="btn btn-primary btn-sm" onclick="doSearch()">搜索</button>
<a href="/tasks/" class="btn btn-sm">重置</a>
</div>
<div class="card">
<div class="card-body" style="padding:0;">
<div id="taskListWrap">
<div class="empty-state">加载中...</div>
</div>
</div>
</div>
<div id="taskPagination"></div>
<!-- 创建任务弹窗 -->
<div id="createModal" style="display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); z-index:999; align-items:center; justify-content:center;">
<div style="background:#fff; border-radius:8px; width:480px; max-width:90%; padding:24px;">
<h3 style="margin-bottom:16px;">创建任务</h3>
<form id="createForm" method="post" action="/tasks/create/">
<div class="form-group">
<label>任务名称 <span style="color:var(--danger);">*</span></label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="form-group">
<label>任务简介</label>
<textarea name="description" class="form-control" style="min-height:80px;"></textarea>
</div>
<div id="createError" style="color:var(--danger); font-size:13px; margin-bottom:8px; display:none;"></div>
<div style="display:flex; gap:8px; justify-content:flex-end;">
<button type="button" class="btn" onclick="hideCreateModal()">取消</button>
<button type="submit" class="btn btn-primary">创建</button>
</div>
</form>
</div>
</div>
<!-- 修改任务弹窗 -->
<div id="editModal" style="display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); z-index:999; align-items:center; justify-content:center;">
<div style="background:#fff; border-radius:8px; width:480px; max-width:90%; padding:24px;">
<h3 style="margin-bottom:16px;">修改任务</h3>
<form id="editForm" method="post">
<div class="form-group">
<label>任务名称 <span style="color:var(--danger);">*</span></label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="form-group">
<label>任务简介</label>
<textarea name="description" class="form-control" style="min-height:80px;"></textarea>
</div>
<div id="editError" style="color:var(--danger); font-size:13px; margin-bottom:8px; display:none;"></div>
<div style="display:flex; gap:8px; justify-content:flex-end;">
<button type="button" class="btn" onclick="hideEditModal()">取消</button>
<button type="submit" class="btn btn-primary">保存</button>
</div>
</form>
</div>
</div>
<!-- 删除确认弹窗 -->
<div id="deleteModal" style="display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); z-index:999; align-items:center; justify-content:center;">
<div style="background:#fff; border-radius:8px; width:400px; max-width:90%; padding:24px;">
<h3 style="margin-bottom:12px;">确认删除</h3>
<p style="margin-bottom:16px; color:var(--text-light);">确定要删除任务 "<span id="deleteTaskName"></span>" 吗?此操作不可撤销。</p>
<form id="deleteForm" method="post">
<div style="display:flex; gap:8px; justify-content:flex-end;">
<button type="button" class="btn" onclick="hideDeleteModal()">取消</button>
<button type="submit" class="btn btn-danger">确认删除</button>
</div>
</form>
</div>
</div>
<script>
var CURRENT_PAGE = 1;
var FILTERS = {
my_only: '{{ my_only }}',
today_only: '{{ today_only }}',
};
function initFilterButtons() {
if (FILTERS.my_only === '1') document.getElementById('filterMyOnly').classList.add('btn-primary');
if (FILTERS.today_only === '1') document.getElementById('filterTodayOnly').classList.add('btn-primary');
}
function toggleFilter(key) {
FILTERS[key] = FILTERS[key] === '1' ? '' : '1';
CURRENT_PAGE = 1;
loadTaskList();
}
function doSearch() {
CURRENT_PAGE = 1;
loadTaskList();
}
function getSearchParams() {
var params = 'page=' + CURRENT_PAGE;
var keyword = document.getElementById('searchKeyword').value.trim();
var dateFrom = document.getElementById('searchDateFrom').value;
var dateTo = document.getElementById('searchDateTo').value;
if (keyword) params += '&keyword=' + encodeURIComponent(keyword);
if (dateFrom) params += '&date_from=' + encodeURIComponent(dateFrom);
if (dateTo) params += '&date_to=' + encodeURIComponent(dateTo);
if (FILTERS.my_only) params += '&my_only=1';
if (FILTERS.today_only) params += '&today_only=1';
return params;
}
function loadTaskList() {
var url = '/api/tasks/?' + getSearchParams();
var wrap = document.getElementById('taskListWrap');
wrap.innerHTML = '<div class="empty-state">加载中...</div>';
fetch(url)
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.error) {
wrap.innerHTML = '<div class="empty-state"><p style="color:var(--danger);">' + res.error + '</p></div>';
return;
}
renderTaskTable(res, wrap);
});
}
function renderTaskTable(res, wrap) {
if (!res.items || res.items.length === 0) {
wrap.innerHTML = '<div class="empty-state">暂无任务</div>';
document.getElementById('taskPagination').innerHTML = '';
return;
}
var html = '<div class="table-wrap"><table style="width:100%; border-collapse:collapse;">';
html += '<thead><tr style="background:#f8fafc; border-bottom:2px solid var(--border);">';
html += '<th style="padding:12px 16px; text-align:left; font-size:13px;">任务名称</th>';
html += '<th style="padding:12px 16px; text-align:left; font-size:13px;">创建时间</th>';
html += '<th style="padding:12px 16px; text-align:left; font-size:13px;">创建者</th>';
html += '<th style="padding:12px 16px; text-align:left; font-size:13px; min-width:220px;">快速提交</th>';
html += '<th style="padding:12px 16px; text-align:center; font-size:13px; width:150px;">操作</th>';
html += '</tr></thead><tbody>';
res.items.forEach(function(t) {
html += '<tr style="border-bottom:1px solid var(--border);">';
html += '<td style="padding:12px 16px;">';
html += '<a href="/tasks/' + t.id + '/" style="font-weight:500;">' + escapeHtml(t.name) + '</a>';
if (t.description) {
html += '<div style="font-size:13px; color:var(--text-light); margin-top:2px;">' + escapeHtml(t.description.substring(0, 60)) + '</div>';
}
html += '</td>';
html += '<td style="padding:12px 16px; font-size:13px; color:var(--text-light);">' + t.created_at + '</td>';
html += '<td style="padding:12px 16px; font-size:13px;">' + escapeHtml(t.creator_name) + '</td>';
html += '<td style="padding:8px 16px;">';
html += '<div style="display:flex; gap:6px;">';
html += '<input type="text" class="form-control quick-input" data-task-id="' + t.id + '" placeholder="输入信息..." style="flex:1; min-width:100px; padding:6px 10px; font-size:13px;">';
html += '<button class="btn btn-primary btn-sm" onclick="quickSubmit(this)" style="white-space:nowrap;">提交</button>';
html += '</div>';
html += '<div class="quick-msg" style="font-size:12px; color:var(--success); margin-top:2px; display:none;"></div>';
html += '</td>';
html += '<td style="padding:12px 16px; text-align:center; font-size:13px; white-space:nowrap;">';
if (t.creator_id === res.current_user_id) {
html += '<button class="btn btn-sm" onclick="showEditModal(' + t.id + ', \'' + escapeJs(t.name) + '\', \'' + escapeJs(t.description) + '\')" style="display:inline-block;">修改</button>';
html += '<button class="btn btn-sm btn-danger" onclick="showDeleteModal(' + t.id + ', \'' + escapeJs(t.name) + '\')" style="display:inline-block;">删除</button>';
}
html += '</td>';
html += '</tr>';
});
html += '</tbody></table></div>';
wrap.innerHTML = html;
if (res.total_pages > 1) {
var phtml = '<div class="pagination">';
if (res.has_prev) phtml += '<a href="javascript:void(0)" onclick="goTaskPage(' + res.prev_page + ')">上一页</a>';
else phtml += '<span class="disabled">上一页</span>';
for (var p = 1; p <= res.total_pages; p++) {
if (p === res.page) phtml += '<span class="active">' + p + '</span>';
else phtml += '<a href="javascript:void(0)" onclick="goTaskPage(' + p + ')">' + p + '</a>';
}
if (res.has_next) phtml += '<a href="javascript:void(0)" onclick="goTaskPage(' + res.next_page + ')">下一页</a>';
else phtml += '<span class="disabled">下一页</span>';
phtml += '</div>';
document.getElementById('taskPagination').innerHTML = phtml;
} else {
document.getElementById('taskPagination').innerHTML = '';
}
}
function goTaskPage(page) {
CURRENT_PAGE = page;
loadTaskList();
}
function escapeHtml(s) {
if (!s) return '';
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}
function escapeJs(s) {
if (!s) return '';
return s.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '');
}
function showCreateModal() {
document.getElementById('createModal').style.display = 'flex';
document.getElementById('createError').style.display = 'none';
}
function hideCreateModal() {
document.getElementById('createModal').style.display = 'none';
}
function showEditModal(id, name, description) {
var form = document.getElementById('editForm');
form.action = '/tasks/' + id + '/edit/';
form.querySelector('input[name="name"]').value = name;
form.querySelector('textarea[name="description"]').value = description;
document.getElementById('editError').style.display = 'none';
document.getElementById('editModal').style.display = 'flex';
}
function hideEditModal() {
document.getElementById('editModal').style.display = 'none';
}
function showDeleteModal(id, name) {
document.getElementById('deleteForm').action = '/tasks/' + id + '/delete/';
document.getElementById('deleteTaskName').textContent = name;
document.getElementById('deleteModal').style.display = 'flex';
}
function hideDeleteModal() {
document.getElementById('deleteModal').style.display = 'none';
}
function quickSubmit(btn) {
var div = btn.parentElement;
var input = div.querySelector('.quick-input');
var msg = div.parentElement.querySelector('.quick-msg');
var content = input.value.trim();
if (!content) { alert('请输入提交内容'); return; }
var taskId = input.getAttribute('data-task-id');
var data = new FormData();
data.append('content', content);
data.append('csrf_token', CSRF_TOKEN);
fetch('/tasks/' + taskId + '/submit/', { method: 'POST', body: data })
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.error) {
alert(res.error);
} else {
input.value = '';
msg.textContent = '提交成功!';
msg.style.display = 'block';
setTimeout(function() { msg.style.display = 'none'; }, 2000);
}
});
}
document.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
var input = e.target;
if (input.classList.contains('quick-input')) {
var btn = input.parentElement.querySelector('.btn');
if (btn) quickSubmit(btn);
}
}
});
document.getElementById('createForm').addEventListener('submit', function(e) {
e.preventDefault();
var form = this;
var data = new FormData(form);
data.append('csrf_token', CSRF_TOKEN);
fetch(form.action, { method: 'POST', body: data })
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.error) {
document.getElementById('createError').textContent = res.error;
document.getElementById('createError').style.display = 'block';
} else {
hideCreateModal();
form.reset();
loadTaskList();
}
});
});
document.getElementById('editForm').addEventListener('submit', function(e) {
e.preventDefault();
var form = this;
var data = new FormData(form);
data.append('csrf_token', CSRF_TOKEN);
fetch(form.action, { method: 'POST', body: data })
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.error) {
document.getElementById('editError').textContent = res.error;
document.getElementById('editError').style.display = 'block';
} else {
hideEditModal();
loadTaskList();
}
});
});
document.getElementById('deleteForm').addEventListener('submit', function(e) {
e.preventDefault();
var form = this;
var fd = new FormData();
fd.append('csrf_token', CSRF_TOKEN);
fetch(form.action, { method: 'POST', body: fd })
.then(function(r) { return r.json(); })
.then(function(res) {
if (res.error) {
alert(res.error);
} else {
hideDeleteModal();
loadTaskList();
}
});
});
document.querySelectorAll('#createModal, #editModal, #deleteModal').forEach(function(el) {
el.addEventListener('click', function(e) {
if (e.target === this) {
this.style.display = 'none';
}
});
});
document.addEventListener('DOMContentLoaded', function() {
initFilterButtons();
loadTaskList();
});
</script>
{% endblock %}