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 != "" {
query = query.Where("original_name LIKE ?", "%"+search+"%")
utils.Info("添加搜索条件: original_name LIKE '%%%s%%'", search)
utils.Info("添加搜索条件: file_name LIKE '%%%s%%'", search)
}
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",
req.Page, req.PageSize, req.Search, req.FileType, req.Status, req.UserID)
// 获取当前用户ID和角色
userIDInterface, exists := c.Get("user_id")
roleInterface, _ := c.Get("role")
// 获取当前用户ID和角色(现在总是有认证)
userID := c.GetUint("user_id")
role := c.GetString("role")
var userID uint
var role string
if exists {
userID = userIDInterface.(uint)
}
if roleInterface != nil {
role = roleInterface.(string)
}
utils.Info("GetFileList - 用户ID: %d, 角色: %s", userID, role)
// 根据用户角色决定查询范围
var files []entity.File
var total int64
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)
} else if userID > 0 {
} else {
// 普通用户只能查看自己的文件
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 {

View File

@@ -244,7 +244,7 @@ func main() {
// 文件上传相关路由
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.PUT("/files", middleware.AuthMiddleware(), fileHandler.UpdateFile)
}

View File

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

View File

@@ -24,17 +24,17 @@
<!-- 搜索和筛选 -->
<n-card>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<n-input v-model:value="searchQuery" placeholder="搜索账号..." clearable>
<div class="flex flex-col md:flex-row gap-4">
<n-input v-model:value="searchQuery" placeholder="搜索账号..." clearable class="flex-1">
<template #prefix>
<i class="fas fa-search"></i>
</template>
</n-input>
<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>
<i class="fas fa-search"></i>
</template>

View File

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