完善老师页面,数据管理增加按key筛查
This commit is contained in:
@@ -69,12 +69,18 @@
|
||||
<div class="main-content">
|
||||
<div class="container">
|
||||
<h2>数据管理</h2>
|
||||
{% if is_admin %}
|
||||
<p class="muted">仅管理员可见。可查看、编辑、删除所有记录。</p>
|
||||
{% else %}
|
||||
<p class="muted">可查看本人及所管理 Key 的上传数据。</p>
|
||||
{% endif %}
|
||||
|
||||
<!-- 搜索功能区域 -->
|
||||
<div class="search-container">
|
||||
<div class="search-controls">
|
||||
<input type="text" id="searchQuery" class="search-input" placeholder="请输入搜索关键词...">
|
||||
<select id="keyFilter" class="search-input"></select>
|
||||
<button class="btn" onclick="clearKeyFilter()">清空Key筛查</button>
|
||||
<button class="btn btn-primary" onclick="performSearch('exact')">关键词搜索</button>
|
||||
<button class="btn btn-secondary" onclick="performSearch('fuzzy')">模糊搜索</button>
|
||||
<button class="btn" onclick="loadAllData()">显示全部</button>
|
||||
@@ -146,6 +152,7 @@ function getCookie(name) {
|
||||
|
||||
// DOM元素引用
|
||||
const searchQueryInput = document.getElementById('searchQuery');
|
||||
const keyFilterSelect = document.getElementById('keyFilter');
|
||||
const searchResultDiv = document.getElementById('searchResult');
|
||||
const searchStatus = document.getElementById('searchStatus');
|
||||
const searchCount = document.getElementById('searchCount');
|
||||
@@ -174,6 +181,7 @@ let allDataCache = []; // 缓存所有数据,避免重复请求
|
||||
let currentSearchQuery = ''; // 记录当前搜索查询
|
||||
let isFuzzySearch = false; // 记录当前是否为模糊搜索
|
||||
let isDeleting = false; // 标记是否正在删除
|
||||
let currentKeyFilter = '';
|
||||
|
||||
// 图片缩放相关变量
|
||||
let currentScale = 1;
|
||||
@@ -193,6 +201,11 @@ async function performSearch(type) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentKeyFilter) {
|
||||
currentKeyFilter = '';
|
||||
if (keyFilterSelect) keyFilterSelect.value = '';
|
||||
}
|
||||
|
||||
currentSearchQuery = query;
|
||||
isFuzzySearch = type === 'fuzzy';
|
||||
showSearchLoading();
|
||||
@@ -257,6 +270,17 @@ async function loadAllData() {
|
||||
showSearchLoading();
|
||||
|
||||
try {
|
||||
if (currentKeyFilter) {
|
||||
const response = await fetch(`/elastic/filter-by-key/?key=${encodeURIComponent(currentKeyFilter)}`);
|
||||
const data = await response.json();
|
||||
if (data.status === 'success') {
|
||||
displayAllData(data.data || [], currentKeyFilter);
|
||||
} else {
|
||||
showSearchMessage(`加载数据失败: ${data.message || '未知错误'}`, 'error');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果已有缓存,直接使用
|
||||
if (allDataCache.length > 0) {
|
||||
displayAllData(allDataCache);
|
||||
@@ -279,10 +303,10 @@ async function loadAllData() {
|
||||
}
|
||||
|
||||
// 显示所有数据
|
||||
function displayAllData(data) {
|
||||
function displayAllData(data, key) {
|
||||
searchResultDiv.style.display = 'block';
|
||||
searchResultDiv.className = 'search-result';
|
||||
searchStatus.textContent = '显示全部数据';
|
||||
searchStatus.textContent = key ? `按Key筛查:${key}` : '显示全部数据';
|
||||
searchCount.textContent = `共 ${data.length} 条记录`;
|
||||
|
||||
renderTable(data);
|
||||
@@ -294,7 +318,11 @@ function clearSearch() {
|
||||
searchResultDiv.style.display = 'none';
|
||||
currentSearchQuery = '';
|
||||
|
||||
// 如果有缓存数据,显示全部
|
||||
if (currentKeyFilter) {
|
||||
loadAllData();
|
||||
return;
|
||||
}
|
||||
|
||||
if (allDataCache.length > 0) {
|
||||
renderTable(allDataCache);
|
||||
} else {
|
||||
@@ -303,6 +331,34 @@ function clearSearch() {
|
||||
}
|
||||
}
|
||||
|
||||
async function initKeyFilter() {
|
||||
if (!keyFilterSelect) return;
|
||||
keyFilterSelect.innerHTML = '<option value="">全部Key</option>';
|
||||
try {
|
||||
const resp = await fetch('/elastic/keys-for-filter/', { credentials: 'same-origin' });
|
||||
const data = await resp.json();
|
||||
if (data.status !== 'success') return;
|
||||
const keys = data.data || [];
|
||||
keys.forEach(k => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = String(k || '');
|
||||
opt.textContent = String(k || '');
|
||||
keyFilterSelect.appendChild(opt);
|
||||
});
|
||||
} catch (e) {
|
||||
}
|
||||
keyFilterSelect.addEventListener('change', () => {
|
||||
currentKeyFilter = (keyFilterSelect.value || '').trim();
|
||||
loadAllData();
|
||||
});
|
||||
}
|
||||
|
||||
function clearKeyFilter() {
|
||||
currentKeyFilter = '';
|
||||
if (keyFilterSelect) keyFilterSelect.value = '';
|
||||
loadAllData();
|
||||
}
|
||||
|
||||
// 渲染表格
|
||||
function renderTable(data) {
|
||||
tableBody.innerHTML = '';
|
||||
@@ -610,6 +666,7 @@ async function doDelete(id){
|
||||
|
||||
// 页面加载时自动加载所有数据
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
initKeyFilter();
|
||||
loadAllData();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user