fix: 修复文件管理搜索不生效的问题

This commit is contained in:
Kerwin
2025-08-19 09:09:44 +08:00
parent cbf673126e
commit da3fc11b2e
6 changed files with 20 additions and 30 deletions

View File

@@ -104,7 +104,7 @@ func (r *FileRepositoryImpl) SearchFiles(search string, fileType, status string,
// 添加搜索条件 // 添加搜索条件
if search != "" { if search != "" {
query = query.Where("original_name LIKE ?", "%"+search+"%") query = query.Where("original_name LIKE ?", "%"+search+"%")
utils.Info("添加搜索条件: original_name LIKE '%%%s%%'", search) utils.Info("添加搜索条件: file_name LIKE '%%%s%%'", search)
} }
if fileType != "" { if fileType != "" {

View File

@@ -246,33 +246,23 @@ func (h *FileHandler) GetFileList(c *gin.Context) {
utils.Info("文件列表请求参数: page=%d, pageSize=%d, search='%s', fileType='%s', status='%s', userID=%d", utils.Info("文件列表请求参数: page=%d, pageSize=%d, search='%s', fileType='%s', status='%s', userID=%d",
req.Page, req.PageSize, req.Search, req.FileType, req.Status, req.UserID) req.Page, req.PageSize, req.Search, req.FileType, req.Status, req.UserID)
// 获取当前用户ID和角色 // 获取当前用户ID和角色(现在总是有认证)
userIDInterface, exists := c.Get("user_id") userID := c.GetUint("user_id")
roleInterface, _ := c.Get("role") role := c.GetString("role")
var userID uint utils.Info("GetFileList - 用户ID: %d, 角色: %s", userID, role)
var role string
if exists {
userID = userIDInterface.(uint)
}
if roleInterface != nil {
role = roleInterface.(string)
}
// 根据用户角色决定查询范围 // 根据用户角色决定查询范围
var files []entity.File var files []entity.File
var total int64 var total int64
var err error var err error
if exists && role == "admin" { if role == "admin" {
// 管理员可以查看所有文件 // 管理员可以查看所有文件
files, total, err = h.fileRepo.SearchFiles(req.Search, req.FileType, req.Status, req.UserID, req.Page, req.PageSize) files, total, err = h.fileRepo.SearchFiles(req.Search, req.FileType, req.Status, req.UserID, req.Page, req.PageSize)
} else if userID > 0 { } else {
// 普通用户只能查看自己的文件 // 普通用户只能查看自己的文件
files, total, err = h.fileRepo.SearchFiles(req.Search, req.FileType, req.Status, userID, req.Page, req.PageSize) files, total, err = h.fileRepo.SearchFiles(req.Search, req.FileType, req.Status, userID, req.Page, req.PageSize)
} else {
// 未登录用户只能查看公开文件
files, total, err = h.fileRepo.FindPublicFiles(req.Page, req.PageSize)
} }
if err != nil { if err != nil {

View File

@@ -244,7 +244,7 @@ func main() {
// 文件上传相关路由 // 文件上传相关路由
api.POST("/files/upload", middleware.AuthMiddleware(), fileHandler.UploadFile) api.POST("/files/upload", middleware.AuthMiddleware(), fileHandler.UploadFile)
api.GET("/files", fileHandler.GetFileList) api.GET("/files", middleware.AuthMiddleware(), fileHandler.GetFileList)
api.DELETE("/files", middleware.AuthMiddleware(), fileHandler.DeleteFiles) api.DELETE("/files", middleware.AuthMiddleware(), fileHandler.DeleteFiles)
api.PUT("/files", middleware.AuthMiddleware(), fileHandler.UpdateFile) api.PUT("/files", middleware.AuthMiddleware(), fileHandler.UpdateFile)
} }

View File

@@ -146,8 +146,8 @@ export const adminNewNavigationItems = [
key: 'system-config', key: 'system-config',
label: '系统配置', label: '系统配置',
icon: 'fas fa-cog', icon: 'fas fa-cog',
to: '/admin/system-config', to: '/admin/site-config',
active: (route: any) => route.path.startsWith('/admin/system-config'), active: (route: any) => route.path.startsWith('/admin/site-config'),
group: 'system' group: 'system'
}, },
{ {

View File

@@ -24,17 +24,17 @@
<!-- 搜索和筛选 --> <!-- 搜索和筛选 -->
<n-card> <n-card>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4"> <div class="flex flex-col md:flex-row gap-4">
<n-input v-model:value="searchQuery" placeholder="搜索账号..." clearable> <n-input v-model:value="searchQuery" placeholder="搜索账号..." clearable class="flex-1">
<template #prefix> <template #prefix>
<i class="fas fa-search"></i> <i class="fas fa-search"></i>
</template> </template>
</n-input> </n-input>
<n-select v-model:value="platform" placeholder="选择平台" :options="platformOptions" clearable <n-select v-model:value="platform" placeholder="选择平台" :options="platformOptions" clearable
@update:value="onPlatformChange" /> @update:value="onPlatformChange" class="w-full md:w-48" />
<n-button type="primary" @click="handleSearch"> <n-button type="primary" @click="handleSearch" class="w-full md:w-auto md:min-w-[100px]">
<template #icon> <template #icon>
<i class="fas fa-search"></i> <i class="fas fa-search"></i>
</template> </template>

View File

@@ -51,12 +51,12 @@
clearable clearable
/> />
<n-button type="primary" @click="handleSearch"> <n-button type="primary" @click="handleSearch" class="w-full md:w-auto md:min-w-[100px]">
<template #icon> <template #icon>
<i class="fas fa-search"></i> <i class="fas fa-search"></i>
</template> </template>
搜索 搜索
</n-button> </n-button>
</div> </div>
</n-card> </n-card>