mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
完成媒体管理模块
This commit is contained in:
+1
-2
@@ -20,11 +20,9 @@ import top.xyquan.ecomdmbbackend.utils.JwtUtils;
|
||||
@EnableWebSecurity
|
||||
public class SecurityConfig {
|
||||
|
||||
private final JwtUtils jwtUtils;
|
||||
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
||||
|
||||
public SecurityConfig(JwtUtils jwtUtils, JwtAuthenticationFilter jwtAuthenticationFilter) {
|
||||
this.jwtUtils = jwtUtils;
|
||||
this.jwtAuthenticationFilter = jwtAuthenticationFilter;
|
||||
}
|
||||
|
||||
@@ -40,6 +38,7 @@ public class SecurityConfig {
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/auth/**").permitAll()
|
||||
.requestMatchers("/uploads/**").permitAll() // 允许直接访问上传的文件
|
||||
.requestMatchers("/doc.html", "/webjars/**", "/v3/api-docs/**", "/swagger-resources/**",
|
||||
"/swagger-ui/**", "/swagger-ui.html")
|
||||
.permitAll()
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
.addResourceLocations("classpath:/static/");
|
||||
|
||||
// 配置上传文件访问 - 使用绝对路径
|
||||
registry.addResourceHandler("/static/uploads/**")
|
||||
.addResourceLocations("file:./static/uploads/");
|
||||
registry.addResourceHandler("/uploads/**")
|
||||
.addResourceLocations("file:./uploads/");
|
||||
|
||||
// 配置Swagger UI资源
|
||||
registry.addResourceHandler("/swagger-ui/**")
|
||||
|
||||
+3
-3
@@ -19,8 +19,8 @@ public class CreateProductDTO {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 主图URL
|
||||
* 主图图片ID
|
||||
*/
|
||||
@Schema(description = "主图URL", example = "https://example.com/product.jpg")
|
||||
private String mainImage;
|
||||
@Schema(description = "主图图片ID", example = "1")
|
||||
private Long mainImageId;
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,10 +34,10 @@ public class UpdateProductDTO {
|
||||
private String skuCode;
|
||||
|
||||
/**
|
||||
* 主图URL
|
||||
* 主图图片ID
|
||||
*/
|
||||
@Schema(description = "主图URL", example = "https://example.com/product.jpg")
|
||||
private String mainImage;
|
||||
@Schema(description = "主图图片ID", example = "1")
|
||||
private Long mainImageId;
|
||||
|
||||
/**
|
||||
* 成本价
|
||||
|
||||
+3
-3
@@ -19,10 +19,10 @@ public class CreateShopDTO {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* logo URL
|
||||
* logo图片ID
|
||||
*/
|
||||
@Schema(description = "logo URL", example = "https://example.com/logo.jpg")
|
||||
private String logo;
|
||||
@Schema(description = "logo图片ID", example = "1")
|
||||
private Long logoImageId;
|
||||
|
||||
/**
|
||||
* 平台(如淘宝、京东、拼多多)
|
||||
|
||||
+3
-3
@@ -19,10 +19,10 @@ public class UpdateShopDTO {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* logo URL
|
||||
* logo图片ID
|
||||
*/
|
||||
@Schema(description = "logo URL", example = "https://example.com/logo.jpg")
|
||||
private String logo;
|
||||
@Schema(description = "logo图片ID", example = "1")
|
||||
private Long logoImageId;
|
||||
|
||||
/**
|
||||
* 平台(如淘宝、京东、拼多多)
|
||||
|
||||
+7
-1
@@ -33,11 +33,17 @@ public class ProductPO {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 主图URL
|
||||
* 主图URL(冗余字段)
|
||||
*/
|
||||
@TableField("main_image")
|
||||
private String mainImage;
|
||||
|
||||
/**
|
||||
* 主图图片ID
|
||||
*/
|
||||
@TableField("main_image_id")
|
||||
private Long mainImageId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
+7
-1
@@ -33,11 +33,17 @@ public class ShopPO {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* logo URL
|
||||
* logo URL(冗余字段)
|
||||
*/
|
||||
@TableField("logo")
|
||||
private String logo;
|
||||
|
||||
/**
|
||||
* logo图片ID
|
||||
*/
|
||||
@TableField("logo_image_id")
|
||||
private Long logoImageId;
|
||||
|
||||
/**
|
||||
* 平台(如淘宝、京东、拼多多)
|
||||
*/
|
||||
|
||||
+23
-1
@@ -17,6 +17,8 @@ import top.xyquan.ecomdmbbackend.modules.ec.model.dto.product.UpdateProductDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -30,9 +32,11 @@ import java.util.stream.Collectors;
|
||||
public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> implements ProductService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final MediaImageService mediaImageService;
|
||||
|
||||
public ProductServiceImpl(CurrentUserContext currentUserContext) {
|
||||
public ProductServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.mediaImageService = mediaImageService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,6 +62,15 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
// 设置公司ID
|
||||
product.setCompanyId(companyId);
|
||||
|
||||
// 处理主图图片关联
|
||||
if (createProductDTO.getMainImageId() != null) {
|
||||
MediaImageVO mainImage = mediaImageService.getImageById(createProductDTO.getMainImageId());
|
||||
if (mainImage != null) {
|
||||
product.setMainImageId(createProductDTO.getMainImageId());
|
||||
product.setMainImage(mainImage.getUrl()); // 设置冗余字段
|
||||
}
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
product.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
@@ -97,6 +110,15 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
product.setId(id);
|
||||
product.setCompanyId(companyId);
|
||||
|
||||
// 处理主图图片关联
|
||||
if (updateProductDTO.getMainImageId() != null) {
|
||||
MediaImageVO mainImage = mediaImageService.getImageById(updateProductDTO.getMainImageId());
|
||||
if (mainImage != null) {
|
||||
product.setMainImageId(updateProductDTO.getMainImageId());
|
||||
product.setMainImage(mainImage.getUrl()); // 设置冗余字段
|
||||
}
|
||||
}
|
||||
|
||||
// 设置更新人ID
|
||||
product.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
|
||||
+23
-1
@@ -17,6 +17,8 @@ import top.xyquan.ecomdmbbackend.modules.ec.model.dto.shop.UpdateShopDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.model.vo.ShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -30,9 +32,11 @@ import java.util.stream.Collectors;
|
||||
public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements ShopService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final MediaImageService mediaImageService;
|
||||
|
||||
public ShopServiceImpl(CurrentUserContext currentUserContext) {
|
||||
public ShopServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.mediaImageService = mediaImageService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +61,15 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
// 设置公司ID
|
||||
shop.setCompanyId(companyId);
|
||||
|
||||
// 处理logo图片关联
|
||||
if (createShopDTO.getLogoImageId() != null) {
|
||||
MediaImageVO logoImage = mediaImageService.getImageById(createShopDTO.getLogoImageId());
|
||||
if (logoImage != null) {
|
||||
shop.setLogoImageId(createShopDTO.getLogoImageId());
|
||||
shop.setLogo(logoImage.getUrl()); // 设置冗余字段
|
||||
}
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
shop.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
@@ -95,6 +108,15 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
shop.setId(id);
|
||||
shop.setCompanyId(companyId);
|
||||
|
||||
// 处理logo图片关联
|
||||
if (updateShopDTO.getLogoImageId() != null) {
|
||||
MediaImageVO logoImage = mediaImageService.getImageById(updateShopDTO.getLogoImageId());
|
||||
if (logoImage != null) {
|
||||
shop.setLogoImageId(updateShopDTO.getLogoImageId());
|
||||
shop.setLogo(logoImage.getUrl()); // 设置冗余字段
|
||||
}
|
||||
}
|
||||
|
||||
// 设置更新人ID
|
||||
shop.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
|
||||
+11
@@ -6,7 +6,10 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaFileFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.UpdateFileDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaFileVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.service.MediaFileService;
|
||||
@@ -87,4 +90,12 @@ public class MediaFileController {
|
||||
List<MediaFileVO> mediaFileVOList = mediaFileService.getFilesByHashes(fileHashes);
|
||||
return ApiResponse.success(mediaFileVOList);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取文件列表", description = "分页获取文件列表,支持条件过滤")
|
||||
@PostMapping("/page")
|
||||
public ApiResponse<PageResultVO<MediaFileVO>> getFilePage(
|
||||
@Valid @RequestBody PageQueryDTO<MediaFileFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<MediaFileVO> result = mediaFileService.getFilePage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -6,7 +6,10 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaImageFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.UpdateImageDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
|
||||
@@ -100,4 +103,12 @@ public class MediaImageController {
|
||||
List<MediaImageVO> mediaImageVOList = mediaImageService.getImagesByHashes(fileHashes);
|
||||
return ApiResponse.success(mediaImageVOList);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取图片列表", description = "分页获取图片列表,支持条件过滤")
|
||||
@PostMapping("/page")
|
||||
public ApiResponse<PageResultVO<MediaImageVO>> getImagePage(
|
||||
@Valid @RequestBody PageQueryDTO<MediaImageFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<MediaImageVO> result = mediaImageService.getImagePage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
}
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.media.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 文件过滤条件DTO
|
||||
*/
|
||||
@Data
|
||||
public class MediaFileFilterDTO {
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String filename;
|
||||
|
||||
/**
|
||||
* 文件类型
|
||||
*/
|
||||
private String fileType;
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
private String tags;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.media.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 图片过滤条件DTO
|
||||
*/
|
||||
@Data
|
||||
public class MediaImageFilterDTO {
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String filename;
|
||||
|
||||
/**
|
||||
* 图片分类
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
private String tags;
|
||||
}
|
||||
+8
@@ -1,6 +1,9 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.media.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaFileFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.UpdateFileDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaFileVO;
|
||||
|
||||
@@ -40,4 +43,9 @@ public interface MediaFileService {
|
||||
* 根据文件哈希列表批量查询文件信息
|
||||
*/
|
||||
List<MediaFileVO> getFilesByHashes(List<String> fileHashes);
|
||||
|
||||
/**
|
||||
* 分页获取文件列表
|
||||
*/
|
||||
PageResultVO<MediaFileVO> getFilePage(PageQueryDTO<MediaFileFilterDTO> pageQueryDTO);
|
||||
}
|
||||
|
||||
+13
@@ -1,6 +1,9 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.media.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaImageFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.UpdateImageDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
|
||||
@@ -31,6 +34,11 @@ public interface MediaImageService {
|
||||
*/
|
||||
void deleteImage(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID查询图片信息
|
||||
*/
|
||||
MediaImageVO getImageById(Long id);
|
||||
|
||||
/**
|
||||
* 根据文件哈希查询图片信息
|
||||
*/
|
||||
@@ -40,4 +48,9 @@ public interface MediaImageService {
|
||||
* 根据文件哈希列表批量查询图片信息
|
||||
*/
|
||||
List<MediaImageVO> getImagesByHashes(List<String> fileHashes);
|
||||
|
||||
/**
|
||||
* 分页获取图片列表
|
||||
*/
|
||||
PageResultVO<MediaImageVO> getImagePage(PageQueryDTO<MediaImageFilterDTO> pageQueryDTO);
|
||||
}
|
||||
|
||||
+48
@@ -13,6 +13,12 @@ import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaFileVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.service.MediaFileService;
|
||||
import top.xyquan.ecomdmbbackend.utils.FileUploadUtils;
|
||||
import top.xyquan.ecomdmbbackend.utils.FileHashUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaFileFilterDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -192,6 +198,48 @@ public class MediaFileServiceImpl extends ServiceImpl<MediaFileMapper, MediaFile
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<MediaFileVO> getFilePage(PageQueryDTO<MediaFileFilterDTO> pageQueryDTO) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 创建分页对象
|
||||
Page<MediaFilePO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<MediaFilePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MediaFilePO::getCompanyId, companyId)
|
||||
.isNull(MediaFilePO::getDeleteTime);
|
||||
|
||||
// 添加过滤条件
|
||||
MediaFileFilterDTO filter = pageQueryDTO.getFilters();
|
||||
if (filter != null) {
|
||||
if (filter.getFilename() != null && !filter.getFilename().trim().isEmpty()) {
|
||||
wrapper.like(MediaFilePO::getFilename, filter.getFilename());
|
||||
}
|
||||
if (filter.getFileType() != null && !filter.getFileType().trim().isEmpty()) {
|
||||
wrapper.eq(MediaFilePO::getFileType, filter.getFileType());
|
||||
}
|
||||
if (filter.getTags() != null && !filter.getTags().trim().isEmpty()) {
|
||||
wrapper.like(MediaFilePO::getTags, filter.getTags());
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
wrapper.orderByDesc(MediaFilePO::getUploadTime);
|
||||
|
||||
// 执行分页查询
|
||||
IPage<MediaFilePO> pageResult = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<MediaFileVO> voList = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建分页结果
|
||||
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
|
||||
+57
@@ -13,6 +13,12 @@ import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
|
||||
import top.xyquan.ecomdmbbackend.utils.FileUploadUtils;
|
||||
import top.xyquan.ecomdmbbackend.utils.FileHashUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaImageFilterDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -141,6 +147,15 @@ public class MediaImageServiceImpl extends ServiceImpl<MediaImageMapper, MediaIm
|
||||
return convertToVO(updatedImage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaImageVO getImageById(Long id) {
|
||||
MediaImagePO mediaImage = this.getById(id);
|
||||
if (mediaImage == null) {
|
||||
return null;
|
||||
}
|
||||
return convertToVO(mediaImage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteImage(Long id) {
|
||||
// 从token中获取公司ID
|
||||
@@ -197,6 +212,48 @@ public class MediaImageServiceImpl extends ServiceImpl<MediaImageMapper, MediaIm
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<MediaImageVO> getImagePage(PageQueryDTO<MediaImageFilterDTO> pageQueryDTO) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 创建分页对象
|
||||
Page<MediaImagePO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<MediaImagePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MediaImagePO::getCompanyId, companyId)
|
||||
.isNull(MediaImagePO::getDeleteTime);
|
||||
|
||||
// 添加过滤条件
|
||||
MediaImageFilterDTO filter = pageQueryDTO.getFilters();
|
||||
if (filter != null) {
|
||||
if (filter.getFilename() != null && !filter.getFilename().trim().isEmpty()) {
|
||||
wrapper.like(MediaImagePO::getFilename, filter.getFilename());
|
||||
}
|
||||
if (filter.getType() != null && !filter.getType().trim().isEmpty()) {
|
||||
wrapper.eq(MediaImagePO::getType, filter.getType());
|
||||
}
|
||||
if (filter.getTags() != null && !filter.getTags().trim().isEmpty()) {
|
||||
wrapper.like(MediaImagePO::getTags, filter.getTags());
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
wrapper.orderByDesc(MediaImagePO::getUploadTime);
|
||||
|
||||
// 执行分页查询
|
||||
IPage<MediaImagePO> pageResult = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<MediaImageVO> voList = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建分页结果
|
||||
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
|
||||
+3
-3
@@ -45,10 +45,10 @@ public class CreateCompanyDTO {
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* logo
|
||||
* logo图片ID
|
||||
*/
|
||||
@Schema(description = "公司logo", example = "https://example.com/logo.png")
|
||||
private String logo;
|
||||
@Schema(description = "logo图片ID", example = "1")
|
||||
private Long logoImageId;
|
||||
|
||||
/**
|
||||
* 状态 (0-禁用 1-正常)
|
||||
|
||||
+3
-3
@@ -45,10 +45,10 @@ public class UpdateCompanyDTO {
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* logo
|
||||
* logo图片ID
|
||||
*/
|
||||
@Schema(description = "公司logo", example = "https://example.com/logo.png")
|
||||
private String logo;
|
||||
@Schema(description = "logo图片ID", example = "1")
|
||||
private Long logoImageId;
|
||||
|
||||
/**
|
||||
* 状态 (0-禁用 1-正常)
|
||||
|
||||
+7
-1
@@ -57,11 +57,17 @@ public class CompanyPO {
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* logo
|
||||
* logo URL(冗余字段)
|
||||
*/
|
||||
@TableField("logo")
|
||||
private String logo;
|
||||
|
||||
/**
|
||||
* logo图片ID
|
||||
*/
|
||||
@TableField("logo_image_id")
|
||||
private Long logoImageId;
|
||||
|
||||
/**
|
||||
* 状态 (0-禁用 1-正常)
|
||||
*/
|
||||
|
||||
+23
-1
@@ -17,6 +17,8 @@ import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.CompanyFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.model.po.CompanyPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.model.vo.CompanyVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.service.CompanyService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -30,9 +32,11 @@ import java.util.stream.Collectors;
|
||||
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> implements CompanyService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final MediaImageService mediaImageService;
|
||||
|
||||
public CompanyServiceImpl(CurrentUserContext currentUserContext) {
|
||||
public CompanyServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.mediaImageService = mediaImageService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,6 +52,15 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
CompanyPO company = new CompanyPO();
|
||||
BeanUtils.copyProperties(createCompanyDTO, company);
|
||||
|
||||
// 处理logo图片ID
|
||||
if (createCompanyDTO.getLogoImageId() != null) {
|
||||
MediaImageVO logoImage = mediaImageService.getImageById(createCompanyDTO.getLogoImageId());
|
||||
if (logoImage != null) {
|
||||
company.setLogoImageId(createCompanyDTO.getLogoImageId());
|
||||
company.setLogo(logoImage.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
if (company.getStatus() == null) {
|
||||
company.setStatus(1);
|
||||
@@ -83,6 +96,15 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
CompanyPO company = new CompanyPO();
|
||||
BeanUtils.copyProperties(updateCompanyDTO, company);
|
||||
|
||||
// 处理logo图片ID
|
||||
if (updateCompanyDTO.getLogoImageId() != null) {
|
||||
MediaImageVO logoImage = mediaImageService.getImageById(updateCompanyDTO.getLogoImageId());
|
||||
if (logoImage != null) {
|
||||
company.setLogoImageId(updateCompanyDTO.getLogoImageId());
|
||||
company.setLogo(logoImage.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
// 设置更新人ID
|
||||
company.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
|
||||
+2
-2
@@ -15,9 +15,9 @@ public class UpdateUserInfoDTO {
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 头像路径
|
||||
* 头像图片ID
|
||||
*/
|
||||
private String avatar;
|
||||
private Long avatarImageId;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
|
||||
+7
-1
@@ -63,11 +63,17 @@ public class UserPO {
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 头像路径
|
||||
* 头像路径(冗余字段)
|
||||
*/
|
||||
@TableField("avatar")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 头像图片ID
|
||||
*/
|
||||
@TableField("avatar_image_id")
|
||||
private Long avatarImageId;
|
||||
|
||||
/**
|
||||
* 关联角色(user-普通账户 admin-公司管理员账户 super-超管账户)
|
||||
*/
|
||||
|
||||
+1
-1
@@ -187,7 +187,7 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||
}
|
||||
|
||||
// 获取岗位的所有菜单权限
|
||||
List<PositionMenuVO> positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId);
|
||||
// List<PositionMenuVO> positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId);
|
||||
|
||||
// 这里应该根据菜单ID查询对应的权限码列表
|
||||
// 简化实现:返回空列表
|
||||
|
||||
+14
-3
@@ -16,6 +16,8 @@ import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.UserService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
import top.xyquan.ecomdmbbackend.utils.JwtUtils;
|
||||
import top.xyquan.ecomdmbbackend.utils.SecurityUtils;
|
||||
import top.xyquan.ecomdmbbackend.utils.TokenPayload;
|
||||
@@ -30,10 +32,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtUtils jwtUtils;
|
||||
private final MediaImageService mediaImageService;
|
||||
|
||||
public UserServiceImpl(PasswordEncoder passwordEncoder, JwtUtils jwtUtils) {
|
||||
public UserServiceImpl(PasswordEncoder passwordEncoder, JwtUtils jwtUtils, MediaImageService mediaImageService) {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.jwtUtils = jwtUtils;
|
||||
this.mediaImageService = mediaImageService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,9 +166,16 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
if (StringUtils.hasText(updateUserInfoDTO.getRealName())) {
|
||||
user.setRealName(updateUserInfoDTO.getRealName());
|
||||
}
|
||||
if (StringUtils.hasText(updateUserInfoDTO.getAvatar())) {
|
||||
user.setAvatar(updateUserInfoDTO.getAvatar());
|
||||
|
||||
// 处理头像图片ID
|
||||
if (updateUserInfoDTO.getAvatarImageId() != null) {
|
||||
MediaImageVO avatarImage = mediaImageService.getImageById(updateUserInfoDTO.getAvatarImageId());
|
||||
if (avatarImage != null) {
|
||||
user.setAvatarImageId(updateUserInfoDTO.getAvatarImageId());
|
||||
user.setAvatar(avatarImage.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(updateUserInfoDTO.getPhone())) {
|
||||
user.setPhone(updateUserInfoDTO.getPhone());
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ CREATE TABLE `ec_shop` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '店铺ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '所属公司ID',
|
||||
`name` VARCHAR(200) NOT NULL COMMENT '店铺名称',
|
||||
`logo` varchar(255) DEFAULT NULL COMMENT 'logo URL',
|
||||
`logo` varchar(255) DEFAULT NULL COMMENT 'logo URL(冗余字段)',
|
||||
`logo_image_id` BIGINT UNSIGNED DEFAULT NULL COMMENT 'logo图片ID',
|
||||
`platform` VARCHAR(50) DEFAULT NULL COMMENT '平台(如淘宝、京东、拼多多)',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
@@ -13,10 +14,12 @@ CREATE TABLE `ec_shop` (
|
||||
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `fk_ec_shop_logo_image` (`logo_image_id`),
|
||||
KEY `fk_ec_shop_creator` (`create_by`),
|
||||
KEY `fk_ec_shop_updater` (`update_by`),
|
||||
KEY `fk_ec_shop_deleter` (`delete_by`),
|
||||
CONSTRAINT `fk_ec_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_logo_image` FOREIGN KEY (`logo_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
@@ -27,7 +30,8 @@ CREATE TABLE `ec_product` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '商品ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`name` VARCHAR(255) NOT NULL COMMENT '商品名称',
|
||||
`main_image` VARCHAR(500) DEFAULT NULL COMMENT '主图URL',
|
||||
`main_image` VARCHAR(500) DEFAULT NULL COMMENT '主图URL(冗余字段)',
|
||||
`main_image_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '主图图片ID',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
|
||||
@@ -36,10 +40,12 @@ CREATE TABLE `ec_product` (
|
||||
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `fk_ec_product_main_image` (`main_image_id`),
|
||||
KEY `fk_ec_product_creator` (`create_by`),
|
||||
KEY `fk_ec_product_updater` (`update_by`),
|
||||
KEY `fk_ec_product_deleter` (`delete_by`),
|
||||
CONSTRAINT `fk_ec_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_main_image` FOREIGN KEY (`main_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
|
||||
@@ -6,7 +6,8 @@ CREATE TABLE `org_company` (
|
||||
`contact_person` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '联系人',
|
||||
`contact_phone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '联系电话',
|
||||
`email` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '邮箱',
|
||||
`logo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT 'logo',
|
||||
`logo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT 'logo URL(冗余字段)',
|
||||
`logo_image_id` bigint unsigned DEFAULT NULL COMMENT 'logo图片ID',
|
||||
`status` int NOT NULL DEFAULT '1' COMMENT '状态 (0-禁用 1-正常)',
|
||||
`expire_time` timestamp NULL DEFAULT NULL COMMENT '订阅到期时间',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
@@ -16,8 +17,10 @@ CREATE TABLE `org_company` (
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `fk_org_company_creator` (`create_by`) USING BTREE,
|
||||
KEY `fk_org_company_updater` (`update_by`) USING BTREE,
|
||||
KEY `fk_org_company_logo_image` (`logo_image_id`) USING BTREE,
|
||||
CONSTRAINT `fk_org_company_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_company_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
CONSTRAINT `fk_org_company_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_company_logo_image` FOREIGN KEY (`logo_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-公司表';
|
||||
|
||||
CREATE TABLE `org_company_menu` (
|
||||
|
||||
@@ -7,7 +7,8 @@ CREATE TABLE `sys_user` (
|
||||
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '登录密码',
|
||||
`phone` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '手机号码',
|
||||
`real_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户名称',
|
||||
`avatar` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '头像路径',
|
||||
`avatar` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '头像路径(冗余字段)',
|
||||
`avatar_image_id` bigint unsigned DEFAULT NULL COMMENT '头像图片ID',
|
||||
`role` enum('user','admin','super') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT 'user' COMMENT '关联角色(user-普通账户 admin-公司管理员 super-超管账户)',
|
||||
`pwd_security_level` tinyint unsigned DEFAULT NULL COMMENT '密码安全级别(0-初始 1-很弱 2-弱 3-安全 4-很安全)',
|
||||
`pwd_update_time` timestamp NULL DEFAULT NULL COMMENT '密码最后更新时间',
|
||||
@@ -29,9 +30,11 @@ CREATE TABLE `sys_user` (
|
||||
KEY `fk_user_company` (`company_id`) USING BTREE,
|
||||
KEY `fk_user_department` (`department_id`) USING BTREE,
|
||||
KEY `fk_user_position` (`position_id`) USING BTREE,
|
||||
KEY `fk_user_avatar_image` (`avatar_image_id`) USING BTREE,
|
||||
CONSTRAINT `fk_user_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_user_department` FOREIGN KEY (`department_id`) REFERENCES `org_department` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_user_position` FOREIGN KEY (`position_id`) REFERENCES `org_position` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
CONSTRAINT `fk_user_position` FOREIGN KEY (`position_id`) REFERENCES `org_position` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_user_avatar_image` FOREIGN KEY (`avatar_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-用户表';
|
||||
|
||||
CREATE TABLE `sys_menu` (
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 297 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 110 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 323 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 362 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
@@ -0,0 +1,110 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
import type { MediaFileDTO, MediaFileVO, MediaImageDTO, MediaImageVO } from './types';
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
/**
|
||||
* 文件管理相关API
|
||||
*/
|
||||
|
||||
// 文件上传
|
||||
export async function uploadFileApi(file: File) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return requestClient.post<MediaFileVO.MediaFileInfoVO>('/media/file/upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 批量文件上传
|
||||
export async function batchUploadFilesApi(files: File[]) {
|
||||
const formData = new FormData();
|
||||
files.forEach(file => {
|
||||
formData.append('files', file);
|
||||
});
|
||||
return requestClient.post<MediaFileVO.MediaFileInfoVO[]>('/media/file/batch-upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 更新文件信息
|
||||
export async function updateFileApi(data: MediaFileDTO.UpdateFileDTO) {
|
||||
return requestClient.put<MediaFileVO.MediaFileInfoVO>('/media/file/update', data);
|
||||
}
|
||||
|
||||
// 删除文件
|
||||
export async function deleteFileApi(id: number) {
|
||||
return requestClient.delete(`/media/file/delete/${id}`);
|
||||
}
|
||||
|
||||
// 根据哈希查询文件
|
||||
export async function getFileByHashApi(fileHash: string) {
|
||||
return requestClient.get<MediaFileVO.MediaFileInfoVO>(`/media/file/hash/${fileHash}`);
|
||||
}
|
||||
|
||||
// 批量根据哈希查询文件
|
||||
export async function getFilesByHashesApi(fileHashes: string[]) {
|
||||
return requestClient.post<MediaFileVO.MediaFileInfoVO[]>('/media/file/batch-hash', fileHashes);
|
||||
}
|
||||
|
||||
// 分页获取文件列表
|
||||
export async function getFilePageApi(params: PageQueryDTO<MediaFileDTO.MediaFileFilterDTO>) {
|
||||
return requestClient.post<PageResultVO<MediaFileVO.MediaFileInfoVO>>('/media/file/page', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片管理相关API
|
||||
*/
|
||||
|
||||
// 图片上传
|
||||
export async function uploadImageApi(file: File) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return requestClient.post<MediaImageVO.MediaImageInfoVO>('/media/image/upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 批量图片上传
|
||||
export async function batchUploadImagesApi(files: File[]) {
|
||||
const formData = new FormData();
|
||||
files.forEach(file => {
|
||||
formData.append('files', file);
|
||||
});
|
||||
return requestClient.post<MediaImageVO.MediaImageInfoVO[]>('/media/image/batch-upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 更新图片信息
|
||||
export async function updateImageApi(data: MediaImageDTO.UpdateImageDTO) {
|
||||
return requestClient.put<MediaImageVO.MediaImageInfoVO>('/media/image/update', data);
|
||||
}
|
||||
|
||||
// 删除图片
|
||||
export async function deleteImageApi(id: number) {
|
||||
return requestClient.delete(`/media/image/delete/${id}`);
|
||||
}
|
||||
|
||||
// 根据哈希查询图片
|
||||
export async function getImageByHashApi(fileHash: string) {
|
||||
return requestClient.get<MediaImageVO.MediaImageInfoVO>(`/media/image/hash/${fileHash}`);
|
||||
}
|
||||
|
||||
// 批量根据哈希查询图片
|
||||
export async function getImagesByHashesApi(fileHashes: string[]) {
|
||||
return requestClient.post<MediaImageVO.MediaImageInfoVO[]>('/media/image/batch-hash', fileHashes);
|
||||
}
|
||||
|
||||
// 分页获取图片列表
|
||||
export async function getImagePageApi(params: PageQueryDTO<MediaImageDTO.MediaImageFilterDTO>) {
|
||||
return requestClient.post<PageResultVO<MediaImageVO.MediaImageInfoVO>>('/media/image/page', params);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 媒体文件相关类型定义
|
||||
*/
|
||||
|
||||
export namespace MediaFileVO {
|
||||
export interface MediaFileInfoVO {
|
||||
id: number;
|
||||
companyId: number;
|
||||
url: string;
|
||||
filename: string;
|
||||
fileType: string;
|
||||
fileHash: string;
|
||||
tags: string;
|
||||
remark: string;
|
||||
uploadBy: number;
|
||||
uploadTime: string;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace MediaImageVO {
|
||||
export interface MediaImageInfoVO {
|
||||
id: number;
|
||||
companyId: number;
|
||||
url: string;
|
||||
filename: string;
|
||||
type: string;
|
||||
fileHash: string;
|
||||
tags: string;
|
||||
remark: string;
|
||||
uploadBy: number;
|
||||
uploadTime: string;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace MediaFileDTO {
|
||||
export interface UpdateFileDTO {
|
||||
id: number;
|
||||
fileType?: string;
|
||||
tags?: string;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export interface MediaFileFilterDTO {
|
||||
filename?: string;
|
||||
fileType?: string;
|
||||
tags?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace MediaImageDTO {
|
||||
export interface UpdateImageDTO {
|
||||
id: number;
|
||||
type?: string;
|
||||
tags?: string;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export interface MediaImageFilterDTO {
|
||||
filename?: string;
|
||||
type?: string;
|
||||
tags?: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
meta: {
|
||||
icon: 'lucide:folder-open',
|
||||
order: 300,
|
||||
title: '媒体管理',
|
||||
},
|
||||
name: 'Media',
|
||||
path: '/media',
|
||||
children: [
|
||||
{
|
||||
name: 'FileRepository',
|
||||
path: '/media/file-repository',
|
||||
component: () => import('#/views/media/file-repository/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:folder',
|
||||
title: '文件仓库',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'ImageRepository',
|
||||
path: '/media/image-repository',
|
||||
component: () => import('#/views/media/image-repository/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:image',
|
||||
title: '图片仓库',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
@@ -0,0 +1,459 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Select,
|
||||
Table,
|
||||
Upload,
|
||||
message,
|
||||
Tag,
|
||||
Space,
|
||||
Popconfirm,
|
||||
Tooltip
|
||||
} from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
// 创建图标组件
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
const DeleteIcon = createIconifyIcon('lucide:trash-2');
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
const EyeIcon = createIconifyIcon('lucide:eye');
|
||||
|
||||
import {
|
||||
uploadFileApi,
|
||||
batchUploadFilesApi,
|
||||
updateFileApi,
|
||||
deleteFileApi,
|
||||
getFilePageApi,
|
||||
type MediaFileVO,
|
||||
type MediaFileDTO
|
||||
} from '#/api/media';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
defineOptions({ name: 'FileRepository' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const fileList = ref<MediaFileVO.MediaFileInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const modalVisible = ref(false);
|
||||
const modalTitle = ref('');
|
||||
const isEdit = ref(false);
|
||||
const currentFileId = ref<number | null>(null);
|
||||
const formRef = ref();
|
||||
const uploadLoading = ref(false);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
filename: '',
|
||||
fileType: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<MediaFileDTO.UpdateFileDTO>({
|
||||
id: 0,
|
||||
fileType: '',
|
||||
tags: '',
|
||||
remark: '',
|
||||
});
|
||||
|
||||
// 文件类型选项
|
||||
const fileTypeOptions = [
|
||||
{ label: 'PDF', value: 'PDF' },
|
||||
{ label: 'CAD', value: 'CAD' },
|
||||
{ label: 'Excel', value: 'Excel' },
|
||||
{ label: 'Word', value: 'Word' },
|
||||
{ label: 'PPT', value: 'PPT' },
|
||||
{ label: '图片', value: '图片' },
|
||||
{ label: '视频', value: '视频' },
|
||||
{ label: '音频', value: '音频' },
|
||||
{ label: '压缩包', value: '压缩包' },
|
||||
{ label: '其他', value: '其他' },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '文件名',
|
||||
dataIndex: 'filename',
|
||||
key: 'filename',
|
||||
width: 300,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; align-items: center; gap: 8px;' }, [
|
||||
h('span', { style: 'font-weight: 500;' }, record.filename),
|
||||
h(Tag, { color: 'blue', size: 'small' }, () => record.fileType || '未知'),
|
||||
]);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '文件类型',
|
||||
dataIndex: 'fileType',
|
||||
key: 'fileType',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
return h(Tag, { color: 'blue' }, () => record.fileType || '未知');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
dataIndex: 'tags',
|
||||
key: 'tags',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
if (!record.tags) return h('span', { style: 'color: #999;' }, '无标签');
|
||||
const tags = record.tags.split(',').filter(tag => tag.trim());
|
||||
return h('div', { style: 'display: flex; flex-wrap: wrap; gap: 4px;' },
|
||||
tags.map(tag => h(Tag, { color: 'green', size: 'small' }, () => tag.trim()))
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
if (!record.remark) return h('span', { style: 'color: #999;' }, '无描述');
|
||||
return h(Tooltip, { title: record.remark }, {
|
||||
default: () => h('span', {
|
||||
style: 'display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'
|
||||
}, record.remark)
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '上传时间',
|
||||
dataIndex: 'uploadTime',
|
||||
key: 'uploadTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Tooltip, { title: '预览' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handlePreview(record),
|
||||
}, {
|
||||
default: () => h(EyeIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '下载' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handleDownload(record),
|
||||
}, {
|
||||
default: () => h(DownloadIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '编辑' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, {
|
||||
default: () => h(EditIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '删除' }, {
|
||||
default: () => h(Popconfirm, {
|
||||
title: '确定要删除这个文件吗?',
|
||||
onConfirm: () => handleDelete(record.id),
|
||||
}, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
danger: true,
|
||||
}, {
|
||||
default: () => h(DeleteIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
})
|
||||
}),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 计算属性 - 由于使用后端分页,不再需要前端过滤
|
||||
const filteredFileList = computed(() => fileList.value);
|
||||
|
||||
// 方法
|
||||
const loadFileList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<MediaFileDTO.MediaFileFilterDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
filename: searchForm.value.filename || undefined,
|
||||
fileType: searchForm.value.fileType || undefined,
|
||||
}
|
||||
};
|
||||
|
||||
const response = await getFilePageApi(params);
|
||||
fileList.value = response.records;
|
||||
total.value = response.total;
|
||||
} catch (error) {
|
||||
message.error('加载文件列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSearch = () => {
|
||||
current.value = 1;
|
||||
loadFileList();
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
searchForm.value = {
|
||||
filename: '',
|
||||
fileType: undefined,
|
||||
};
|
||||
handleSearch();
|
||||
};
|
||||
|
||||
const handleUpload = async (file: File) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await uploadFileApi(file);
|
||||
message.success('文件上传成功');
|
||||
loadFileList();
|
||||
} catch (error) {
|
||||
message.error('文件上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleBatchUpload = async (files: File[]) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await batchUploadFilesApi(files);
|
||||
message.success(`成功上传 ${files.length} 个文件`);
|
||||
loadFileList();
|
||||
} catch (error) {
|
||||
message.error('批量上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = (record: MediaFileVO.MediaFileInfoVO) => {
|
||||
isEdit.value = true;
|
||||
modalTitle.value = '编辑文件信息';
|
||||
currentFileId.value = record.id;
|
||||
formData.value = {
|
||||
id: record.id,
|
||||
fileType: record.fileType,
|
||||
tags: record.tags,
|
||||
remark: record.remark,
|
||||
};
|
||||
modalVisible.value = true;
|
||||
};
|
||||
|
||||
const handlePreview = (record: MediaFileVO.MediaFileInfoVO) => {
|
||||
window.open(record.url, '_blank');
|
||||
};
|
||||
|
||||
const handleDownload = (record: MediaFileVO.MediaFileInfoVO) => {
|
||||
const link = document.createElement('a');
|
||||
link.href = record.url;
|
||||
link.download = record.filename;
|
||||
link.click();
|
||||
};
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
await deleteFileApi(id);
|
||||
message.success('删除成功');
|
||||
loadFileList();
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
await updateFileApi(formData.value);
|
||||
message.success('更新成功');
|
||||
modalVisible.value = false;
|
||||
loadFileList();
|
||||
} catch (error) {
|
||||
message.error('更新失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false;
|
||||
formData.value = {
|
||||
id: 0,
|
||||
fileType: '',
|
||||
tags: '',
|
||||
remark: '',
|
||||
};
|
||||
};
|
||||
|
||||
// 上传配置
|
||||
const uploadProps = {
|
||||
multiple: true,
|
||||
showUploadList: false,
|
||||
beforeUpload: (file: any) => {
|
||||
const isValidSize = file.size / 1024 / 1024 < 100; // 100MB
|
||||
if (!isValidSize) {
|
||||
message.error('文件大小不能超过 100MB');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
customRequest: (options: any) => {
|
||||
const { file } = options;
|
||||
if (Array.isArray(file)) {
|
||||
handleBatchUpload(file);
|
||||
} else {
|
||||
handleUpload(file);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// 初始化
|
||||
loadFileList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<template #title>文件仓库</template>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<div class="mb-4 p-4 bg-white rounded-lg shadow-sm">
|
||||
<Form :model="searchForm" layout="inline">
|
||||
<Form.Item label="文件名">
|
||||
<Input
|
||||
v-model:value="searchForm.filename"
|
||||
placeholder="请输入文件名"
|
||||
style="width: 200px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="文件类型">
|
||||
<Select
|
||||
v-model:value="searchForm.fileType"
|
||||
placeholder="请选择文件类型"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in fileTypeOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 操作区域 -->
|
||||
<div class="mb-4 flex justify-between items-center">
|
||||
<div class="flex items-center gap-4">
|
||||
<Upload v-bind="uploadProps">
|
||||
<Button type="primary" :loading="uploadLoading">
|
||||
<UploadIcon class="w-4 h-4 mr-2" />
|
||||
上传文件
|
||||
</Button>
|
||||
</Upload>
|
||||
<span class="text-gray-500">支持批量上传,单个文件最大100MB</span>
|
||||
</div>
|
||||
<div class="text-gray-500">
|
||||
共 {{ total }} 个文件
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 文件列表 -->
|
||||
<div class="bg-white rounded-lg shadow-sm">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="filteredFileList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
:scroll="{ x: 1200 }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<Modal
|
||||
v-model:open="modalVisible"
|
||||
:title="modalTitle"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="文件类型" name="fileType">
|
||||
<Select v-model:value="formData.fileType" placeholder="请选择文件类型">
|
||||
<Select.Option
|
||||
v-for="option in fileTypeOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="标签" name="tags">
|
||||
<Input
|
||||
v-model:value="formData.tags"
|
||||
placeholder="请输入标签,多个标签用逗号分隔"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="描述" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入文件描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ant-upload-list {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
<script lang="ts" setup>
|
||||
import { Card, Image, Tag, Button, Space, Popconfirm } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import type { MediaImageVO } from '#/api/media';
|
||||
|
||||
// 创建图标组件
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
interface Props {
|
||||
image: MediaImageVO.MediaImageInfoVO;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'download', image: MediaImageVO.MediaImageInfoVO): void;
|
||||
(e: 'edit', image: MediaImageVO.MediaImageInfoVO): void;
|
||||
(e: 'delete', id: number): void;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const handleDownload = (image: MediaImageVO.MediaImageInfoVO) => {
|
||||
emit('download', image);
|
||||
};
|
||||
|
||||
const handleEdit = (image: MediaImageVO.MediaImageInfoVO) => {
|
||||
emit('edit', image);
|
||||
};
|
||||
|
||||
const handleDelete = (id: number) => {
|
||||
emit('delete', id);
|
||||
};
|
||||
|
||||
const getTagColor = (type: string | undefined) => {
|
||||
switch (type) {
|
||||
case '设计图':
|
||||
return 'blue';
|
||||
case '实物图':
|
||||
return 'green';
|
||||
case '细节图':
|
||||
return 'orange';
|
||||
case '工艺图':
|
||||
return 'purple';
|
||||
default:
|
||||
return '#006BE6';
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card
|
||||
hoverable
|
||||
:body-style="{ padding: '8px' }"
|
||||
class="image-card"
|
||||
>
|
||||
<div class="relative">
|
||||
<Image
|
||||
:src="image.url"
|
||||
:alt="image.filename"
|
||||
class="w-full h-32 object-cover rounded"
|
||||
:preview="true"
|
||||
/>
|
||||
<div class="absolute top-2 right-2">
|
||||
<Tag :color="getTagColor(image.type)">
|
||||
{{ image.type || '未分类' }}
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<div class="text-sm font-medium truncate" :title="image.filename">
|
||||
{{ image.filename }}
|
||||
</div>
|
||||
<div class="text-xs text-gray-500 mt-1">
|
||||
{{ image.uploadTime }}
|
||||
</div>
|
||||
<div class="flex justify-between items-center mt-2">
|
||||
<Space size="small">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleDownload(image)"
|
||||
>
|
||||
<DownloadIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleEdit(image)"
|
||||
>
|
||||
<EditIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这张图片吗?"
|
||||
@confirm="handleDelete(image.id)"
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
danger
|
||||
>
|
||||
<TrashIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.image-card {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.image-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,525 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Select,
|
||||
Table,
|
||||
Upload,
|
||||
message,
|
||||
Tag,
|
||||
Space,
|
||||
Popconfirm,
|
||||
Tooltip,
|
||||
Image,
|
||||
Row,
|
||||
Col
|
||||
} from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import ImageCard from './components/ImageCard.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const EyeIcon = createIconifyIcon('lucide:eye');
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||
const ListIcon = createIconifyIcon('lucide:list');
|
||||
|
||||
import {
|
||||
uploadImageApi,
|
||||
batchUploadImagesApi,
|
||||
updateImageApi,
|
||||
deleteImageApi,
|
||||
getImagePageApi,
|
||||
type MediaImageVO,
|
||||
type MediaImageDTO
|
||||
} from '#/api/media';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
defineOptions({ name: 'ImageRepository' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const imageList = ref<MediaImageVO.MediaImageInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const modalVisible = ref(false);
|
||||
const modalTitle = ref('');
|
||||
const isEdit = ref(false);
|
||||
const currentImageId = ref<number | null>(null);
|
||||
const formRef = ref();
|
||||
const uploadLoading = ref(false);
|
||||
const viewMode = ref<'grid' | 'list'>('grid'); // 视图模式:网格或列表
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
filename: '',
|
||||
type: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<MediaImageDTO.UpdateImageDTO>({
|
||||
id: 0,
|
||||
type: '',
|
||||
tags: '',
|
||||
remark: '',
|
||||
});
|
||||
|
||||
// 图片分类选项
|
||||
const imageTypeOptions = [
|
||||
{ label: '设计图', value: '设计图' },
|
||||
{ label: '实物图', value: '实物图' },
|
||||
{ label: '细节图', value: '细节图' },
|
||||
{ label: '工艺图', value: '工艺图' },
|
||||
{ label: '其他', value: '其他' },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '预览',
|
||||
dataIndex: 'url',
|
||||
key: 'preview',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
return h(Image, {
|
||||
src: record.url,
|
||||
alt: record.filename,
|
||||
width: 60,
|
||||
height: 60,
|
||||
style: { objectFit: 'cover', borderRadius: '4px' },
|
||||
preview: true,
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '文件名',
|
||||
dataIndex: 'filename',
|
||||
key: 'filename',
|
||||
width: 250,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; align-items: center; gap: 8px;' }, [
|
||||
h('span', { style: 'font-weight: 500;' }, record.filename),
|
||||
h(Tag, { color: 'purple', size: 'small' }, () => record.type || '未分类'),
|
||||
]);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '分类',
|
||||
dataIndex: 'type',
|
||||
key: 'type',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
return h(Tag, { color: 'purple' }, () => record.type || '未分类');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
dataIndex: 'tags',
|
||||
key: 'tags',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
if (!record.tags) return h('span', { style: 'color: #999;' }, '无标签');
|
||||
const tags = record.tags.split(',').filter(tag => tag.trim());
|
||||
return h('div', { style: 'display: flex; flex-wrap: wrap; gap: 4px;' },
|
||||
tags.map(tag => h(Tag, { color: 'green', size: 'small' }, () => tag.trim()))
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '说明',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
if (!record.remark) return h('span', { style: 'color: #999;' }, '无说明');
|
||||
return h(Tooltip, { title: record.remark }, {
|
||||
default: () => h('span', {
|
||||
style: 'display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'
|
||||
}, record.remark)
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '上传时间',
|
||||
dataIndex: 'uploadTime',
|
||||
key: 'uploadTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Tooltip, { title: '预览' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handlePreview(record),
|
||||
}, {
|
||||
default: () => h(EyeIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '下载' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handleDownload(record),
|
||||
}, {
|
||||
default: () => h(DownloadIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '编辑' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, {
|
||||
default: () => h(EditIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '删除' }, {
|
||||
default: () => h(Popconfirm, {
|
||||
title: '确定要删除这张图片吗?',
|
||||
onConfirm: () => handleDelete(record.id),
|
||||
}, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
danger: true,
|
||||
}, {
|
||||
default: () => h(TrashIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
})
|
||||
}),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 计算属性 - 由于使用后端分页,不再需要前端过滤
|
||||
const filteredImageList = computed(() => imageList.value);
|
||||
|
||||
// 方法
|
||||
const loadImageList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<MediaImageDTO.MediaImageFilterDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
filename: searchForm.value.filename || undefined,
|
||||
type: searchForm.value.type || undefined,
|
||||
}
|
||||
};
|
||||
|
||||
const response = await getImagePageApi(params);
|
||||
imageList.value = response.records;
|
||||
total.value = response.total;
|
||||
} catch (error) {
|
||||
message.error('加载图片列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSearch = () => {
|
||||
current.value = 1;
|
||||
loadImageList();
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
searchForm.value = {
|
||||
filename: '',
|
||||
type: undefined,
|
||||
};
|
||||
handleSearch();
|
||||
};
|
||||
|
||||
const handleUpload = async (file: File) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await uploadImageApi(file);
|
||||
message.success('图片上传成功');
|
||||
loadImageList();
|
||||
} catch (error) {
|
||||
message.error('图片上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleBatchUpload = async (files: File[]) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await batchUploadImagesApi(files);
|
||||
message.success(`成功上传 ${files.length} 张图片`);
|
||||
loadImageList();
|
||||
} catch (error) {
|
||||
message.error('批量上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = (record: MediaImageVO.MediaImageInfoVO) => {
|
||||
isEdit.value = true;
|
||||
modalTitle.value = '编辑图片信息';
|
||||
currentImageId.value = record.id;
|
||||
formData.value = {
|
||||
id: record.id,
|
||||
type: record.type,
|
||||
tags: record.tags,
|
||||
remark: record.remark,
|
||||
};
|
||||
modalVisible.value = true;
|
||||
};
|
||||
|
||||
const handlePreview = (record: MediaImageVO.MediaImageInfoVO) => {
|
||||
window.open(record.url, '_blank');
|
||||
};
|
||||
|
||||
const handleDownload = (record: MediaImageVO.MediaImageInfoVO) => {
|
||||
const link = document.createElement('a');
|
||||
link.href = record.url;
|
||||
link.download = record.filename;
|
||||
link.click();
|
||||
};
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
await deleteImageApi(id);
|
||||
message.success('删除成功');
|
||||
loadImageList();
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
await updateImageApi(formData.value);
|
||||
message.success('更新成功');
|
||||
modalVisible.value = false;
|
||||
loadImageList();
|
||||
} catch (error) {
|
||||
message.error('更新失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false;
|
||||
formData.value = {
|
||||
id: 0,
|
||||
type: '',
|
||||
tags: '',
|
||||
remark: '',
|
||||
};
|
||||
};
|
||||
|
||||
const toggleViewMode = () => {
|
||||
viewMode.value = viewMode.value === 'grid' ? 'list' : 'grid';
|
||||
};
|
||||
|
||||
// 上传配置
|
||||
const uploadProps = {
|
||||
multiple: true,
|
||||
showUploadList: false,
|
||||
accept: 'image/*',
|
||||
beforeUpload: (file: any) => {
|
||||
const isImage = file.type.startsWith('image/');
|
||||
if (!isImage) {
|
||||
message.error('只能上传图片文件');
|
||||
return false;
|
||||
}
|
||||
const isValidSize = file.size / 1024 / 1024 < 10; // 10MB
|
||||
if (!isValidSize) {
|
||||
message.error('图片大小不能超过 10MB');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
customRequest: (options: any) => {
|
||||
const { file } = options;
|
||||
if (Array.isArray(file)) {
|
||||
handleBatchUpload(file);
|
||||
} else {
|
||||
handleUpload(file);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// 初始化
|
||||
loadImageList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<template #title>图片仓库</template>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<div class="mb-4 p-4 bg-white rounded-lg shadow-sm">
|
||||
<Form :model="searchForm" layout="inline">
|
||||
<Form.Item label="文件名">
|
||||
<Input
|
||||
v-model:value="searchForm.filename"
|
||||
placeholder="请输入文件名"
|
||||
style="width: 200px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="图片分类">
|
||||
<Select
|
||||
v-model:value="searchForm.type"
|
||||
placeholder="请选择图片分类"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in imageTypeOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 操作区域 -->
|
||||
<div class="mb-4 flex justify-between items-center">
|
||||
<div class="flex items-center gap-4">
|
||||
<Upload v-bind="uploadProps">
|
||||
<Button type="primary" :loading="uploadLoading">
|
||||
<UploadIcon class="w-4 h-4 mr-2" />
|
||||
上传图片
|
||||
</Button>
|
||||
</Upload>
|
||||
<span class="text-gray-500">支持批量上传,单个图片最大10MB</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<Button
|
||||
:type="viewMode === 'grid' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<GridIcon class="w-4 h-4 mr-2" />
|
||||
网格视图
|
||||
</Button>
|
||||
<Button
|
||||
:type="viewMode === 'list' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<ListIcon class="w-4 h-4 mr-2" />
|
||||
列表视图
|
||||
</Button>
|
||||
<span class="text-gray-500">
|
||||
共 {{ total }} 张图片
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 网格视图 -->
|
||||
<div v-if="viewMode === 'grid'" class="bg-white rounded-lg shadow-sm p-4">
|
||||
<Row :gutter="[16, 16]">
|
||||
<Col
|
||||
v-for="image in filteredImageList"
|
||||
:key="image.id"
|
||||
:xs="12"
|
||||
:sm="8"
|
||||
:md="6"
|
||||
:lg="4"
|
||||
:xl="3"
|
||||
>
|
||||
<ImageCard
|
||||
:image="image"
|
||||
@download="handleDownload"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
|
||||
<!-- 列表视图 -->
|
||||
<div v-else class="bg-white rounded-lg shadow-sm">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="filteredImageList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
:scroll="{ x: 1200 }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<Modal
|
||||
v-model:open="modalVisible"
|
||||
:title="modalTitle"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="图片分类" name="type">
|
||||
<Select v-model:value="formData.type" placeholder="请选择图片分类">
|
||||
<Select.Option
|
||||
v-for="option in imageTypeOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="标签" name="tags">
|
||||
<Input
|
||||
v-model:value="formData.tags"
|
||||
placeholder="请输入标签,多个标签用逗号分隔"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="说明" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入图片说明"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ant-upload-list {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@@ -2,17 +2,26 @@ import { defineConfig } from '@vben/vite-config';
|
||||
|
||||
export default defineConfig(async () => {
|
||||
return {
|
||||
application: {},
|
||||
application: {
|
||||
// 设置API URL
|
||||
apiURL: '/api',
|
||||
},
|
||||
vite: {
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||
// mock代理目标地址
|
||||
// 后端服务地址
|
||||
target: 'http://localhost:8080',
|
||||
ws: true,
|
||||
},
|
||||
// 静态资源代理 - 用于访问上传的图片和文件
|
||||
'/uploads': {
|
||||
changeOrigin: true,
|
||||
target: 'http://localhost:8080',
|
||||
ws: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user