feat(用户管理): 添加用户列表排序功能并优化文档解析计数逻辑 (#85)
This commit is contained in:
parent
79360c48bd
commit
42ce701834
|
@ -11,9 +11,11 @@ def get_users():
|
||||||
page_size = int(request.args.get('size', 10))
|
page_size = int(request.args.get('size', 10))
|
||||||
username = request.args.get('username', '')
|
username = request.args.get('username', '')
|
||||||
email = request.args.get('email', '')
|
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({
|
return jsonify({
|
||||||
|
|
|
@ -392,8 +392,6 @@ def perform_parse(doc_id, doc_info, file_info, embedding_config):
|
||||||
|
|
||||||
chunk_count = 0
|
chunk_count = 0
|
||||||
chunk_ids_list = []
|
chunk_ids_list = []
|
||||||
middle_block_idx = 0 # 用于按顺序匹配 block_info_list
|
|
||||||
processed_text_chunks = 0 # 记录处理的文本块数量
|
|
||||||
|
|
||||||
for chunk_idx, chunk_data in enumerate(content_list):
|
for chunk_idx, chunk_data in enumerate(content_list):
|
||||||
page_idx = 0 # 默认页面索引
|
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 参数
|
es_client.index(index=index_name, id=chunk_id, document=es_doc) # 使用 document 参数
|
||||||
|
|
||||||
chunk_count += 1
|
chunk_count += 1
|
||||||
processed_text_chunks += 1
|
|
||||||
chunk_ids_list.append(chunk_id)
|
chunk_ids_list.append(chunk_id)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -553,7 +550,7 @@ def perform_parse(doc_id, doc_info, file_info, embedding_config):
|
||||||
# 记录图片信息,包括URL和位置信息
|
# 记录图片信息,包括URL和位置信息
|
||||||
image_info = {
|
image_info = {
|
||||||
"url": img_url,
|
"url": img_url,
|
||||||
"position": processed_text_chunks, # 使用当前处理的文本块数作为位置参考
|
"position": chunk_count, # 使用当前处理的文本块数作为位置参考
|
||||||
}
|
}
|
||||||
image_info_list.append(image_info)
|
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-ERROR] 上传图片 {img_path_abs} 失败: {e}")
|
||||||
|
|
||||||
# 打印匹配总结信息
|
# 打印匹配总结信息
|
||||||
print(f"[Parser-INFO] 共处理 {processed_text_chunks} 个文本块。")
|
print(f"[Parser-INFO] 共处理 {chunk_count} 个文本块。")
|
||||||
if middle_block_idx < len(block_info_list):
|
|
||||||
print(f"[Parser-WARNING] middle_data 中还有 {len(block_info_list) - middle_block_idx} 个提取的块信息未被使用。")
|
|
||||||
|
|
||||||
# 4. 更新文本块的图像信息
|
# 4. 更新文本块的图像信息
|
||||||
if image_info_list and chunk_ids_list:
|
if image_info_list and chunk_ids_list:
|
||||||
|
|
|
@ -4,7 +4,7 @@ from datetime import datetime
|
||||||
from utils import generate_uuid, encrypt_password
|
from utils import generate_uuid, encrypt_password
|
||||||
from database import DB_CONFIG
|
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:
|
try:
|
||||||
# 建立数据库连接
|
# 建立数据库连接
|
||||||
|
@ -24,10 +24,18 @@ def get_users_with_pagination(current_page, page_size, username='', email=''):
|
||||||
params.append(f"%{email}%")
|
params.append(f"%{email}%")
|
||||||
|
|
||||||
# 组合WHERE子句
|
# 组合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)
|
cursor.execute(count_sql, params)
|
||||||
total = cursor.fetchone()['total']
|
total = cursor.fetchone()['total']
|
||||||
|
|
||||||
|
@ -36,10 +44,10 @@ def get_users_with_pagination(current_page, page_size, username='', email=''):
|
||||||
|
|
||||||
# 执行分页查询
|
# 执行分页查询
|
||||||
query = f"""
|
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
|
FROM user
|
||||||
WHERE {where_sql}
|
{where_sql}
|
||||||
ORDER BY id DESC
|
{sort_clause}
|
||||||
LIMIT %s OFFSET %s
|
LIMIT %s OFFSET %s
|
||||||
"""
|
"""
|
||||||
cursor.execute(query, params + [page_size, offset])
|
cursor.execute(query, params + [page_size, offset])
|
||||||
|
|
|
@ -14,6 +14,10 @@ export interface TableRequestData {
|
||||||
username?: string
|
username?: string
|
||||||
/** 查询参数:邮箱 */
|
/** 查询参数:邮箱 */
|
||||||
email?: string
|
email?: string
|
||||||
|
/** 排序字段 */
|
||||||
|
sort_by: string
|
||||||
|
/** 排序方式 */
|
||||||
|
sort_order: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableData {
|
export interface TableData {
|
||||||
|
|
|
@ -393,7 +393,7 @@ onActivated(() => {
|
||||||
{{ (paginationData.currentPage - 1) * paginationData.pageSize + scope.$index + 1 }}
|
{{ (paginationData.currentPage - 1) * paginationData.pageSize + scope.$index + 1 }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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">
|
<el-table-column label="大小" align="center" width="120" sortable="custom">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
{{ formatFileSize(scope.row.size) }}
|
{{ formatFileSize(scope.row.size) }}
|
||||||
|
|
|
@ -156,6 +156,13 @@ const searchData = reactive({
|
||||||
email: ""
|
email: ""
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 排序状态
|
||||||
|
const sortData = reactive({
|
||||||
|
sortBy: "create_date",
|
||||||
|
sortOrder: "desc" // 默认排序顺序 (最新创建的在前)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// 存储多选的表格数据
|
// 存储多选的表格数据
|
||||||
const multipleSelection = ref<TableData[]>([])
|
const multipleSelection = ref<TableData[]>([])
|
||||||
|
|
||||||
|
@ -165,7 +172,9 @@ function getTableData() {
|
||||||
currentPage: paginationData.currentPage,
|
currentPage: paginationData.currentPage,
|
||||||
size: paginationData.pageSize,
|
size: paginationData.pageSize,
|
||||||
username: searchData.username,
|
username: searchData.username,
|
||||||
email: searchData.email
|
email: searchData.email,
|
||||||
|
sort_by: sortData.sortBy,
|
||||||
|
sort_order: sortData.sortOrder
|
||||||
}).then(({ data }) => {
|
}).then(({ data }) => {
|
||||||
paginationData.total = data.total
|
paginationData.total = data.total
|
||||||
tableData.value = data.list
|
tableData.value = data.list
|
||||||
|
@ -218,6 +227,25 @@ function handleBatchDelete() {
|
||||||
}
|
}
|
||||||
// #endregion
|
// #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 })
|
watch([() => paginationData.currentPage, () => paginationData.pageSize], getTableData, { immediate: true })
|
||||||
</script>
|
</script>
|
||||||
|
@ -259,12 +287,12 @@ watch([() => paginationData.currentPage, () => paginationData.pageSize], getTabl
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="table-wrapper">
|
<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 type="selection" width="50" align="center" />
|
||||||
<el-table-column prop="username" label="用户名" align="center" />
|
<el-table-column prop="username" label="用户名" align="center" sortable="custom" />
|
||||||
<el-table-column prop="email" label="邮箱" align="center" />
|
<el-table-column prop="email" label="邮箱" align="center" sortable="custom" />
|
||||||
<el-table-column prop="createTime" label="创建时间" align="center" />
|
<el-table-column prop="createTime" label="创建时间" align="center" sortable="custom" />
|
||||||
<el-table-column prop="updateTime" label="更新时间" align="center" />
|
<el-table-column prop="updateTime" label="更新时间" align="center" sortable="custom" />
|
||||||
<el-table-column fixed="right" label="操作" width="300" align="center">
|
<el-table-column fixed="right" label="操作" width="300" align="center">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button type="primary" text bg size="small" :icon="Edit" @click="handleUpdate(scope.row)">
|
<el-button type="primary" text bg size="small" :icon="Edit" @click="handleUpdate(scope.row)">
|
||||||
|
|
Loading…
Reference in New Issue