feat(用户管理): 添加用户列表排序功能并优化文档解析计数逻辑 (#85)

This commit is contained in:
zstar 2025-05-14 10:57:12 +08:00 committed by GitHub
parent 79360c48bd
commit 42ce701834
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 58 additions and 21 deletions

View File

@ -11,9 +11,11 @@ def get_users():
page_size = int(request.args.get('size', 10))
username = request.args.get('username', '')
email = request.args.get('email', '')
sort_by = request.args.get("sort_by", "create_time")
sort_order = request.args.get("sort_order", "desc")
# 调用服务函数获取分页和筛选后的用户数据
users, total = get_users_with_pagination(current_page, page_size, username, email)
users, total = get_users_with_pagination(current_page, page_size, username, email, sort_by, sort_order)
# 返回符合前端期望格式的数据
return jsonify({

View File

@ -392,8 +392,6 @@ def perform_parse(doc_id, doc_info, file_info, embedding_config):
chunk_count = 0
chunk_ids_list = []
middle_block_idx = 0 # 用于按顺序匹配 block_info_list
processed_text_chunks = 0 # 记录处理的文本块数量
for chunk_idx, chunk_data in enumerate(content_list):
page_idx = 0 # 默认页面索引
@ -512,7 +510,6 @@ def perform_parse(doc_id, doc_info, file_info, embedding_config):
es_client.index(index=index_name, id=chunk_id, document=es_doc) # 使用 document 参数
chunk_count += 1
processed_text_chunks += 1
chunk_ids_list.append(chunk_id)
except Exception as e:
@ -553,7 +550,7 @@ def perform_parse(doc_id, doc_info, file_info, embedding_config):
# 记录图片信息包括URL和位置信息
image_info = {
"url": img_url,
"position": processed_text_chunks, # 使用当前处理的文本块数作为位置参考
"position": chunk_count, # 使用当前处理的文本块数作为位置参考
}
image_info_list.append(image_info)
@ -563,9 +560,7 @@ def perform_parse(doc_id, doc_info, file_info, embedding_config):
print(f"[Parser-ERROR] 上传图片 {img_path_abs} 失败: {e}")
# 打印匹配总结信息
print(f"[Parser-INFO] 共处理 {processed_text_chunks} 个文本块。")
if middle_block_idx < len(block_info_list):
print(f"[Parser-WARNING] middle_data 中还有 {len(block_info_list) - middle_block_idx} 个提取的块信息未被使用。")
print(f"[Parser-INFO] 共处理 {chunk_count} 个文本块。")
# 4. 更新文本块的图像信息
if image_info_list and chunk_ids_list:

View File

@ -4,7 +4,7 @@ from datetime import datetime
from utils import generate_uuid, encrypt_password
from database import DB_CONFIG
def get_users_with_pagination(current_page, page_size, username='', email=''):
def get_users_with_pagination(current_page, page_size, username='', email='', sort_by="create_time",sort_order="desc"):
"""查询用户信息,支持分页和条件筛选"""
try:
# 建立数据库连接
@ -24,10 +24,18 @@ def get_users_with_pagination(current_page, page_size, username='', email=''):
params.append(f"%{email}%")
# 组合WHERE子句
where_sql = " AND ".join(where_clauses) if where_clauses else "1=1"
where_sql = "WHERE " + (" AND ".join(where_clauses) if where_clauses else "1=1")
# 验证排序字段
valid_sort_fields = ["name", "size", "type", "create_time", "create_date"]
if sort_by not in valid_sort_fields:
sort_by = "create_time"
# 构建排序子句
sort_clause = f"ORDER BY {sort_by} {sort_order.upper()}"
# 查询总记录数
count_sql = f"SELECT COUNT(*) as total FROM user WHERE {where_sql}"
count_sql = f"SELECT COUNT(*) as total FROM user {where_sql}"
cursor.execute(count_sql, params)
total = cursor.fetchone()['total']
@ -36,10 +44,10 @@ def get_users_with_pagination(current_page, page_size, username='', email=''):
# 执行分页查询
query = f"""
SELECT id, nickname, email, create_date, update_date, status, is_superuser
SELECT id, nickname, email, create_date, update_date, status, is_superuser, create_date
FROM user
WHERE {where_sql}
ORDER BY id DESC
{where_sql}
{sort_clause}
LIMIT %s OFFSET %s
"""
cursor.execute(query, params + [page_size, offset])

View File

@ -14,6 +14,10 @@ export interface TableRequestData {
username?: string
/** 查询参数:邮箱 */
email?: string
/** 排序字段 */
sort_by: string
/** 排序方式 */
sort_order: string
}
export interface TableData {

View File

@ -393,7 +393,7 @@ onActivated(() => {
{{ (paginationData.currentPage - 1) * paginationData.pageSize + scope.$index + 1 }}
</template>
</el-table-column>
<el-table-column prop="name" label="文档名" align="center" sortable="custom" />
<el-table-column prop="name" label="文档名" align="center" sortable="custom"/>
<el-table-column label="大小" align="center" width="120" sortable="custom">
<template #default="scope">
{{ formatFileSize(scope.row.size) }}

View File

@ -156,6 +156,13 @@ const searchData = reactive({
email: ""
})
//
const sortData = reactive({
sortBy: "create_date",
sortOrder: "desc" // ()
})
//
const multipleSelection = ref<TableData[]>([])
@ -165,7 +172,9 @@ function getTableData() {
currentPage: paginationData.currentPage,
size: paginationData.pageSize,
username: searchData.username,
email: searchData.email
email: searchData.email,
sort_by: sortData.sortBy,
sort_order: sortData.sortOrder
}).then(({ data }) => {
paginationData.total = data.total
tableData.value = data.list
@ -218,6 +227,25 @@ function handleBatchDelete() {
}
// #endregion
/**
* @description 处理表格排序变化事件只允许正序和倒序切换
* @param {object} sortInfo 排序信息对象包含 prop order
* @param {string} sortInfo.prop 排序的字段名
* @param {string | null} sortInfo.order 排序的顺序 ('ascending', 'descending', null)
*/
function handleSortChange({ prop }: { prop: string, order: string | null }) {
//
if (sortData.sortBy === prop) {
//
sortData.sortOrder = sortData.sortOrder === "asc" ? "desc" : "asc"
} else {
//
sortData.sortBy = prop
sortData.sortOrder = "asc"
}
getTableData()
}
//
watch([() => paginationData.currentPage, () => paginationData.pageSize], getTableData, { immediate: true })
</script>
@ -259,12 +287,12 @@ watch([() => paginationData.currentPage, () => paginationData.pageSize], getTabl
</div>
</div>
<div class="table-wrapper">
<el-table :data="tableData" @selection-change="handleSelectionChange">
<el-table :data="tableData" @selection-change="handleSelectionChange" @sort-change="handleSortChange">
<el-table-column type="selection" width="50" align="center" />
<el-table-column prop="username" label="用户名" align="center" />
<el-table-column prop="email" label="邮箱" align="center" />
<el-table-column prop="createTime" label="创建时间" align="center" />
<el-table-column prop="updateTime" label="更新时间" align="center" />
<el-table-column prop="username" label="用户名" align="center" sortable="custom" />
<el-table-column prop="email" label="邮箱" align="center" sortable="custom" />
<el-table-column prop="createTime" label="创建时间" align="center" sortable="custom" />
<el-table-column prop="updateTime" label="更新时间" align="center" sortable="custom" />
<el-table-column fixed="right" label="操作" width="300" align="center">
<template #default="scope">
<el-button type="primary" text bg size="small" :icon="Edit" @click="handleUpdate(scope.row)">