feat(file): 完善文件管理功能,增加图片管理和权限控制
- 添加管理员权限验证,删除按钮仅对管理员显示 - 实现文件编辑权限控制,仅创建者或管理员可编辑 - 新增多图上传功能,支持文件和图片两种上传模式 - 实现图片预览轮播功能,支持缩略图导航和计数显示 - 添加文件替换功能,支持编辑模式下替换主文件 - 优化图片管理界面,支持添加、删除和替换操作 - 重构上传组件,使用OSS直传替代原有拖拽上传 - 新增图片关联API接口,支持文件与多张图片关联 - 实现批量图片上传处理,按顺序串行上传避免冲突 - 优化表单重置逻辑,清空临时文件和图片数据 - 添加文件类型自动识别和分类展示功能 - 修复可见用户加载异常导致的重复ID问题 - 优化错误处理机制,提升用户体验和系统稳定性
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package com.klp.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.klp.common.annotation.RepeatSubmit;
|
||||
import com.klp.common.annotation.Log;
|
||||
import com.klp.common.core.controller.BaseController;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
import com.klp.common.core.domain.R;
|
||||
import com.klp.common.core.validate.AddGroup;
|
||||
import com.klp.common.core.validate.EditGroup;
|
||||
import com.klp.common.enums.BusinessType;
|
||||
import com.klp.common.utils.poi.ExcelUtil;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import com.klp.system.domain.bo.SysFileImageBo;
|
||||
import com.klp.system.service.ISysFileImageService;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 文件图片关联
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/fileImage")
|
||||
public class SysFileImageController extends BaseController {
|
||||
|
||||
private final ISysFileImageService iSysFileImageService;
|
||||
|
||||
/**
|
||||
* 查询文件图片关联列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<SysFileImageVo> list(SysFileImageBo bo, PageQuery pageQuery) {
|
||||
return iSysFileImageService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出文件图片关联列表
|
||||
*/
|
||||
@Log(title = "文件图片关联", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(SysFileImageBo bo, HttpServletResponse response) {
|
||||
List<SysFileImageVo> list = iSysFileImageService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "文件图片关联", SysFileImageVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件图片关联详细信息
|
||||
*/
|
||||
@GetMapping("/{imageId}")
|
||||
public R<SysFileImageVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long imageId) {
|
||||
return R.ok(iSysFileImageService.queryById(imageId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增文件图片关联
|
||||
*/
|
||||
@Log(title = "文件图片关联", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody SysFileImageBo bo) {
|
||||
return toAjax(iSysFileImageService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件图片关联
|
||||
*/
|
||||
@Log(title = "文件图片关联", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysFileImageBo bo) {
|
||||
return toAjax(iSysFileImageService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件图片关联
|
||||
*/
|
||||
@Log(title = "文件图片关联", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{imageIds}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] imageIds) {
|
||||
return toAjax(iSysFileImageService.deleteWithValidByIds(Arrays.asList(imageIds), true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.klp.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 文件图片关联对象 sys_file_image
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_file_image")
|
||||
public class SysFileImage {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 图片ID
|
||||
*/
|
||||
@TableId(value = "image_id")
|
||||
private Long imageId;
|
||||
/**
|
||||
* 主记录ID 关联sys_file.file_id
|
||||
*/
|
||||
private Long fileId;
|
||||
/**
|
||||
* 图片原始名称
|
||||
*/
|
||||
private String imageName;
|
||||
/**
|
||||
* 图片存储路径/对象存储地址
|
||||
*/
|
||||
private String imagePath;
|
||||
/**
|
||||
* 图片大小(字节)
|
||||
*/
|
||||
private Long imageSize;
|
||||
/**
|
||||
* 后缀 jpg/png
|
||||
*/
|
||||
private String suffix;
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.klp.system.domain.bo;
|
||||
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import com.klp.system.domain.bo.SysFileImageBo;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 文件主信息业务对象 sys_file
|
||||
@@ -72,4 +75,9 @@ public class SysFileBo extends BaseEntity {
|
||||
*/
|
||||
private Long viewCount;
|
||||
|
||||
/**
|
||||
* 图片列表(多图模式)
|
||||
*/
|
||||
private List<SysFileImageBo> imageList;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.klp.system.domain.bo;
|
||||
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
|
||||
/**
|
||||
* 文件图片关联业务对象 sys_file_image
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysFileImageBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 图片ID
|
||||
*/
|
||||
private Long imageId;
|
||||
|
||||
/**
|
||||
* 主记录ID 关联sys_file.file_id
|
||||
*/
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
* 图片原始名称
|
||||
*/
|
||||
private String imageName;
|
||||
|
||||
/**
|
||||
* 图片存储路径/对象存储地址
|
||||
*/
|
||||
private String imagePath;
|
||||
|
||||
/**
|
||||
* 图片大小(字节)
|
||||
*/
|
||||
private Long imageSize;
|
||||
|
||||
/**
|
||||
* 后缀 jpg/png
|
||||
*/
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.klp.system.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 文件图片关联视图对象 sys_file_image
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class SysFileImageVo {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 图片ID
|
||||
*/
|
||||
@ExcelProperty(value = "图片ID")
|
||||
private Long imageId;
|
||||
|
||||
/**
|
||||
* 主记录ID 关联sys_file.file_id
|
||||
*/
|
||||
@ExcelProperty(value = "主记录ID")
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
* 图片原始名称
|
||||
*/
|
||||
@ExcelProperty(value = "图片原始名称")
|
||||
private String imageName;
|
||||
|
||||
/**
|
||||
* 图片存储路径/对象存储地址
|
||||
*/
|
||||
@ExcelProperty(value = "图片存储路径")
|
||||
private String imagePath;
|
||||
|
||||
/**
|
||||
* 图片大小(字节)
|
||||
*/
|
||||
@ExcelProperty(value = "图片大小")
|
||||
private Long imageSize;
|
||||
|
||||
/**
|
||||
* 后缀 jpg/png
|
||||
*/
|
||||
@ExcelProperty(value = "后缀")
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
@ExcelProperty(value = "排序号")
|
||||
private Integer sortOrder;
|
||||
|
||||
}
|
||||
@@ -5,8 +5,11 @@ import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.klp.common.annotation.ExcelDictFormat;
|
||||
import com.klp.common.convert.ExcelDictConvert;
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 文件主信息视图对象 sys_file
|
||||
@@ -92,4 +95,9 @@ public class SysFileVo extends BaseEntity {
|
||||
@ExcelProperty(value = "创建者昵称")
|
||||
private String createByName;
|
||||
|
||||
/**
|
||||
* 图片列表(多图模式)
|
||||
*/
|
||||
private List<SysFileImageVo> imageList;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.klp.system.mapper;
|
||||
|
||||
import com.klp.system.domain.SysFileImage;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import com.klp.common.core.mapper.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* 文件图片关联Mapper接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
public interface SysFileImageMapper extends BaseMapperPlus<SysFileImageMapper, SysFileImage, SysFileImageVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.klp.system.service;
|
||||
|
||||
import com.klp.system.domain.SysFileImage;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import com.klp.system.domain.bo.SysFileImageBo;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件图片关联Service接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
public interface ISysFileImageService {
|
||||
|
||||
/**
|
||||
* 查询文件图片关联
|
||||
*/
|
||||
SysFileImageVo queryById(Long imageId);
|
||||
|
||||
/**
|
||||
* 查询文件图片关联列表
|
||||
*/
|
||||
TableDataInfo<SysFileImageVo> queryPageList(SysFileImageBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询文件图片关联列表
|
||||
*/
|
||||
List<SysFileImageVo> queryList(SysFileImageBo bo);
|
||||
|
||||
/**
|
||||
* 新增文件图片关联
|
||||
*/
|
||||
Boolean insertByBo(SysFileImageBo bo);
|
||||
|
||||
/**
|
||||
* 修改文件图片关联
|
||||
*/
|
||||
Boolean updateByBo(SysFileImageBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除文件图片关联信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 根据文件ID查询图片列表
|
||||
*/
|
||||
List<SysFileImageVo> queryListByFileId(Long fileId);
|
||||
|
||||
/**
|
||||
* 批量保存图片
|
||||
*/
|
||||
void saveImageList(Long fileId, List<SysFileImageBo> imageList);
|
||||
|
||||
/**
|
||||
* 根据文件ID删除所有图片
|
||||
*/
|
||||
void deleteByFileId(Long fileId);
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.klp.system.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.klp.system.domain.bo.SysFileImageBo;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import com.klp.system.domain.SysFileImage;
|
||||
import com.klp.system.mapper.SysFileImageMapper;
|
||||
import com.klp.system.service.ISysFileImageService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 文件图片关联Service业务层处理
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-07-13
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysFileImageServiceImpl implements ISysFileImageService {
|
||||
|
||||
private final SysFileImageMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询文件图片关联
|
||||
*/
|
||||
@Override
|
||||
public SysFileImageVo queryById(Long imageId){
|
||||
return baseMapper.selectVoById(imageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文件图片关联列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<SysFileImageVo> queryPageList(SysFileImageBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<SysFileImage> lqw = buildQueryWrapper(bo);
|
||||
Page<SysFileImageVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文件图片关联列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysFileImageVo> queryList(SysFileImageBo bo) {
|
||||
LambdaQueryWrapper<SysFileImage> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<SysFileImage> buildQueryWrapper(SysFileImageBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<SysFileImage> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getFileId() != null, SysFileImage::getFileId, bo.getFileId());
|
||||
lqw.orderByAsc(SysFileImage::getSortOrder);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysFileImageVo> queryListByFileId(Long fileId) {
|
||||
LambdaQueryWrapper<SysFileImage> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(SysFileImage::getFileId, fileId);
|
||||
lqw.orderByAsc(SysFileImage::getSortOrder);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量保存图片(先删后插)
|
||||
*/
|
||||
@Override
|
||||
public void saveImageList(Long fileId, List<SysFileImageBo> imageList) {
|
||||
if (fileId == null) return;
|
||||
// 先删除原有图片
|
||||
deleteByFileId(fileId);
|
||||
// 批量插入
|
||||
if (imageList != null && !imageList.isEmpty()) {
|
||||
for (int i = 0; i < imageList.size(); i++) {
|
||||
SysFileImageBo bo = imageList.get(i);
|
||||
SysFileImage entity = BeanUtil.toBean(bo, SysFileImage.class);
|
||||
entity.setFileId(fileId);
|
||||
entity.setSortOrder(i);
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByFileId(Long fileId) {
|
||||
baseMapper.delete(Wrappers.<SysFileImage>lambdaQuery()
|
||||
.eq(SysFileImage::getFileId, fileId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增文件图片关联
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(SysFileImageBo bo) {
|
||||
SysFileImage add = BeanUtil.toBean(bo, SysFileImage.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setImageId(add.getImageId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件图片关联
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(SysFileImageBo bo) {
|
||||
SysFileImage update = BeanUtil.toBean(bo, SysFileImage.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(SysFileImage entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除文件图片关联
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,11 @@ import org.springframework.stereotype.Service;
|
||||
import com.klp.system.domain.bo.SysFileBo;
|
||||
import com.klp.system.domain.vo.SysFileVo;
|
||||
import com.klp.system.domain.SysFile;
|
||||
import com.klp.system.domain.SysFileImage;
|
||||
import com.klp.system.domain.SysFileVisibleUser;
|
||||
import com.klp.system.domain.bo.SysFileImageBo;
|
||||
import com.klp.system.domain.vo.SysFileImageVo;
|
||||
import com.klp.system.mapper.SysFileImageMapper;
|
||||
import com.klp.system.mapper.SysFileMapper;
|
||||
import com.klp.system.mapper.SysFileVisibleUserMapper;
|
||||
import com.klp.system.mapper.SysUserMapper;
|
||||
@@ -39,6 +43,7 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
|
||||
private final SysFileMapper baseMapper;
|
||||
private final SysFileVisibleUserMapper visibleUserMapper;
|
||||
private final SysFileImageMapper fileImageMapper;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
/**
|
||||
@@ -46,7 +51,16 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
*/
|
||||
@Override
|
||||
public SysFileVo queryById(Long fileId){
|
||||
return baseMapper.selectVoById(fileId);
|
||||
SysFileVo vo = baseMapper.selectVoById(fileId);
|
||||
if (vo != null) {
|
||||
// 加载图片列表
|
||||
List<SysFileImageVo> imageList = fileImageMapper.selectVoList(
|
||||
Wrappers.<SysFileImage>lambdaQuery()
|
||||
.eq(SysFileImage::getFileId, fileId)
|
||||
.orderByAsc(SysFileImage::getSortOrder));
|
||||
vo.setImageList(imageList);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,10 +110,25 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setFileId(add.getFileId());
|
||||
// 保存图片列表
|
||||
saveImageList(add.getFileId(), bo.getImageList());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
private void saveImageList(Long fileId, List<SysFileImageBo> imageList) {
|
||||
if (fileId == null || imageList == null || imageList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < imageList.size(); i++) {
|
||||
SysFileImageBo imageBo = imageList.get(i);
|
||||
SysFileImage entity = BeanUtil.toBean(imageBo, SysFileImage.class);
|
||||
entity.setFileId(fileId);
|
||||
entity.setSortOrder(i);
|
||||
fileImageMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件主信息
|
||||
*/
|
||||
@@ -107,7 +136,14 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
public Boolean updateByBo(SysFileBo bo) {
|
||||
SysFile update = BeanUtil.toBean(bo, SysFile.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
boolean flag = baseMapper.updateById(update) > 0;
|
||||
if (flag && bo.getImageList() != null) {
|
||||
// 先删后插图片列表
|
||||
fileImageMapper.delete(Wrappers.<SysFileImage>lambdaQuery()
|
||||
.eq(SysFileImage::getFileId, bo.getFileId()));
|
||||
saveImageList(bo.getFileId(), bo.getImageList());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,6 +223,11 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
if (ids != null && !ids.isEmpty()) {
|
||||
// 删除关联的图片
|
||||
fileImageMapper.delete(Wrappers.<SysFileImage>lambdaQuery()
|
||||
.in(SysFileImage::getFileId, ids));
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.klp.system.mapper.SysFileImageMapper">
|
||||
|
||||
<resultMap type="com.klp.system.domain.SysFileImage" id="SysFileImageResult">
|
||||
<result property="imageId" column="image_id"/>
|
||||
<result property="fileId" column="file_id"/>
|
||||
<result property="imageName" column="image_name"/>
|
||||
<result property="imagePath" column="image_path"/>
|
||||
<result property="imageSize" column="image_size"/>
|
||||
<result property="suffix" column="suffix"/>
|
||||
<result property="sortOrder" column="sort_order"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
@@ -105,3 +105,45 @@ export function listVisibleUserByFileId(fileId) {
|
||||
params: { fileId: fileId }
|
||||
})
|
||||
}
|
||||
|
||||
// ============ OSS 上传 ============
|
||||
|
||||
// 上传文件到OSS
|
||||
export function uploadFile(file) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
return request({
|
||||
url: '/system/oss/upload',
|
||||
method: 'post',
|
||||
data: formData,
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
}
|
||||
|
||||
// ============ 文件图片关联 ============
|
||||
|
||||
// 新增图片关联
|
||||
export function addFileImage(data) {
|
||||
return request({
|
||||
url: '/system/fileImage',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改图片关联(替换图片)
|
||||
export function updateFileImage(data) {
|
||||
return request({
|
||||
url: '/system/fileImage',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除图片关联
|
||||
export function delFileImage(imageIds) {
|
||||
return request({
|
||||
url: '/system/fileImage/' + imageIds,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,7 +49,11 @@ export function parseTime(time, pattern) {
|
||||
// 表单重置
|
||||
export function resetForm(refName) {
|
||||
if (this.$refs[refName]) {
|
||||
this.$refs[refName].resetFields();
|
||||
try {
|
||||
this.$refs[refName].resetFields();
|
||||
} catch (e) {
|
||||
console.warn('resetFields error:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
@clear="handleQuery"
|
||||
/>
|
||||
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">上传文件</el-button>
|
||||
<el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
|
||||
<el-button v-if="isAdmin" type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
|
||||
<span v-if="selectedCardIds.length > 0" class="selected-count">已选 {{ selectedCardIds.length }} 项</span>
|
||||
</div>
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
</div>
|
||||
<div class="card-actions">
|
||||
<el-button type="text" size="mini" icon="el-icon-view" @click.stop="handleShowInfo(file)">详情</el-button>
|
||||
<el-button v-if="isAdmin || file.createBy === $store.getters.name" type="text" size="mini" icon="el-icon-edit" @click.stop="handleUpdate(file)">编辑</el-button>
|
||||
<el-button type="text" size="mini" icon="el-icon-download" @click.stop="downloadFile(file)">下载</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -139,25 +140,75 @@
|
||||
<el-dialog :title="dialogTitle" :visible.sync="open" width="650px" append-to-body @close="handleDialogClose">
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="文件名称" prop="fileName">
|
||||
<el-input v-model="form.fileName" placeholder="请输入文件名称" :disabled="isEdit" />
|
||||
<el-input v-model="form.fileName" placeholder="请输入文件名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上传文件" v-if="!isEdit">
|
||||
<el-upload
|
||||
ref="upload"
|
||||
:action="uploadUrl"
|
||||
:headers="uploadHeaders"
|
||||
:file-list="uploadFileList"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:on-success="handleUploadSuccess"
|
||||
:on-error="handleUploadError"
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
class="upload-demo"
|
||||
drag
|
||||
>
|
||||
<i class="el-icon-upload"></i>
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击选取</em></div>
|
||||
</el-upload>
|
||||
<!-- 上传模式 - 选择方式 -->
|
||||
<el-form-item label="上传方式" v-if="!isEdit">
|
||||
<el-radio-group v-model="uploadMode">
|
||||
<el-radio label="file">上传文件</el-radio>
|
||||
<el-radio label="image">上传图片</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<!-- 上传文件 -->
|
||||
<el-form-item v-if="!isEdit && uploadMode === 'file'" label="选择文件" required>
|
||||
<div class="file-upload-area">
|
||||
<input type="file" ref="mainFileInput" style="display:none" @change="handleMainFileSelect" />
|
||||
<el-button type="primary" @click="$refs.mainFileInput.click()">选择文件</el-button>
|
||||
<span class="upload-hint">支持 pdf / xlsx / docx / 图片 等格式</span>
|
||||
<div v-if="mainFile" class="main-file-info">
|
||||
<i class="el-icon-document"></i>
|
||||
<span class="main-file-name">{{ mainFile.name }}</span>
|
||||
<span class="main-file-size">({{ formatFileSize(mainFile.size) }})</span>
|
||||
<el-button type="text" size="mini" icon="el-icon-delete" @click="removeMainFile" style="color:#f56c6c;"></el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 上传图片(多张) -->
|
||||
<el-form-item v-if="!isEdit && uploadMode === 'image'" label="选择图片" required>
|
||||
<div class="image-upload-area">
|
||||
<input type="file" multiple accept="image/*" ref="fileInput" style="display:none" @change="handleFileSelect" />
|
||||
<el-button @click="$refs.fileInput.click()">选择图片</el-button>
|
||||
<span class="upload-hint">支持多选 jpg/png/webp/bmp</span>
|
||||
<div v-if="stagedImages.length > 0" class="image-grid">
|
||||
<div v-for="(img, idx) in stagedImages" :key="idx" class="image-item">
|
||||
<img :src="img.url" />
|
||||
<div class="image-item-mask">
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle @click="removeStagedImage(idx)"></el-button>
|
||||
</div>
|
||||
<div class="image-item-name">{{ img.name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 编辑模式 - 主文件信息 -->
|
||||
<el-form-item label="当前文件" v-if="isEdit && form.filePath">
|
||||
<div class="main-file-info">
|
||||
<i class="el-icon-document"></i>
|
||||
<span class="main-file-name">{{ form.fileName }}</span>
|
||||
<span class="main-file-size" v-if="form.fileSize">({{ formatFileSize(form.fileSize) }})</span>
|
||||
<el-button type="text" size="mini" icon="el-icon-refresh" @click="handleReplaceMainFile" style="margin-left:8px;">替换</el-button>
|
||||
<el-button type="text" size="mini" icon="el-icon-download" @click="downloadFile(form)" v-if="form.filePath">下载</el-button>
|
||||
<input type="file" ref="replaceMainFileInput" style="display:none" @change="handleReplaceMainFileSelect" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 编辑模式 - 图片管理 -->
|
||||
<el-form-item label="文件图片" v-if="isEdit">
|
||||
<div v-if="form.imageList && form.imageList.length > 0" class="image-grid">
|
||||
<div v-for="(img, idx) in form.imageList" :key="img.imageId || idx" class="image-item">
|
||||
<img :src="img.imagePath" />
|
||||
<div class="image-item-mask">
|
||||
<el-button type="warning" size="mini" icon="el-icon-refresh" circle @click="handleReplaceImage(idx)" title="替换"></el-button>
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle @click="handleRemoveImage(idx)" title="删除"></el-button>
|
||||
</div>
|
||||
<div class="image-item-name">{{ img.imageName }}</div>
|
||||
</div>
|
||||
<div class="image-item image-add-btn" @click="handleAddImage">
|
||||
<i class="el-icon-plus"></i>
|
||||
<span>添加图片</span>
|
||||
</div>
|
||||
<input type="file" multiple accept="image/*" ref="editFileInput" style="display:none" @change="handleEditFileSelect" />
|
||||
</div>
|
||||
<div v-else class="no-images-hint">暂无图片,<el-button type="text" @click="handleAddImage">添加图片</el-button></div>
|
||||
</el-form-item>
|
||||
<el-form-item label="订单编号" prop="orderNo">
|
||||
<el-input v-model="form.orderNo" placeholder="请输入订单编号" />
|
||||
@@ -194,14 +245,33 @@
|
||||
<div v-if="infoFile" class="info-dialog-body">
|
||||
<div class="info-main-row">
|
||||
<div class="info-preview">
|
||||
<ImagePreview v-if="infoFileCategory === 'image'" :src="infoFile.filePath" />
|
||||
<PdfPreview v-else-if="infoFileCategory === 'pdf'" :src="infoFile.filePath" />
|
||||
<DocxPreview v-else-if="infoFileCategory === 'docx'" :src="infoFile.filePath" />
|
||||
<XlsxPreview v-else-if="infoFileCategory === 'xlsx'" :src="infoFile.filePath" />
|
||||
<XlsPreview v-else-if="infoFileCategory === 'xls'" :src="infoFile.filePath" />
|
||||
<div v-else class="info-preview-empty">
|
||||
<el-empty description="暂不支持预览此文件类型" />
|
||||
</div>
|
||||
<!-- 多图模式 -->
|
||||
<template v-if="infoFile.imageList && infoFile.imageList.length > 0">
|
||||
<div class="image-carousel-wrap">
|
||||
<el-carousel height="400px" indicator-position="none" arrow="always" ref="previewCarousel" @change="handlePreviewChange">
|
||||
<el-carousel-item v-for="(img, idx) in infoFile.imageList" :key="idx">
|
||||
<el-image :src="img.imagePath" fit="contain" :preview-src-list="previewSrcList" :initial-index="idx" class="carousel-image" />
|
||||
</el-carousel-item>
|
||||
</el-carousel>
|
||||
<div class="thumbnail-strip">
|
||||
<div v-for="(img, idx) in infoFile.imageList" :key="idx" class="thumbnail-item" :class="{ active: activeImageIndex === idx }" @click="handleThumbnailClick(idx)">
|
||||
<img :src="img.imagePath" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="image-counter">{{ activeImageIndex + 1 }} / {{ infoFile.imageList.length }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 单文件模式 -->
|
||||
<template v-else>
|
||||
<ImagePreview v-if="infoFileCategory === 'image'" :src="infoFile.filePath" />
|
||||
<PdfPreview v-else-if="infoFileCategory === 'pdf'" :src="infoFile.filePath" />
|
||||
<DocxPreview v-else-if="infoFileCategory === 'docx'" :src="infoFile.filePath" />
|
||||
<XlsxPreview v-else-if="infoFileCategory === 'xlsx'" :src="infoFile.filePath" />
|
||||
<XlsPreview v-else-if="infoFileCategory === 'xls'" :src="infoFile.filePath" />
|
||||
<div v-else class="info-preview-empty">
|
||||
<el-empty description="暂不支持预览此文件类型" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="info-meta">
|
||||
<el-descriptions :column="1" border size="small">
|
||||
@@ -260,9 +330,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listFile, getFile, addFile, updateFile, delFile, exportFile, listVisibleUser, addVisibleUser, delVisibleUser, listVisibleUserByFileId, listRelatedToMe, incrementView } from '@/api/system/file'
|
||||
import { listFile, getFile, addFile, updateFile, delFile, exportFile, listVisibleUser, addVisibleUser, delVisibleUser, listVisibleUserByFileId, listRelatedToMe, incrementView, uploadFile, delFileImage } from '@/api/system/file'
|
||||
import { listFileComment, addFileComment } from '@/api/system/fileComment'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import UserSelect from '@/components/KLPService/UserSelect/index'
|
||||
import ImagePreview from '@/components/FilePreview/preview/image/index.vue'
|
||||
import PdfPreview from '@/components/FilePreview/preview/pdf/index.vue'
|
||||
@@ -326,7 +395,8 @@ export default {
|
||||
fileType: undefined,
|
||||
scopeType: 1,
|
||||
visibleUsers: [],
|
||||
remark: undefined
|
||||
remark: undefined,
|
||||
imageList: []
|
||||
},
|
||||
// 可见用户原始数据(编辑时回显)
|
||||
originalVisibleUsers: [],
|
||||
@@ -346,12 +416,12 @@ export default {
|
||||
privateFiles: 0,
|
||||
myFiles: 0
|
||||
},
|
||||
// 上传相关
|
||||
uploadUrl: process.env.VUE_APP_BASE_API + '/system/oss/upload',
|
||||
uploadHeaders: {
|
||||
Authorization: 'Bearer ' + getToken()
|
||||
},
|
||||
uploadFileList: [],
|
||||
// 上传方式 file | image
|
||||
uploadMode: 'file',
|
||||
// 多图上传
|
||||
mainFile: null,
|
||||
stagedImages: [],
|
||||
uploading: false,
|
||||
// 文件详情弹窗
|
||||
infoVisible: false,
|
||||
infoTitle: '',
|
||||
@@ -360,7 +430,9 @@ export default {
|
||||
comments: [],
|
||||
commentExpanded: false,
|
||||
commentInput: '',
|
||||
commentLoading: false
|
||||
commentLoading: false,
|
||||
// 详情弹窗多图预览
|
||||
activeImageIndex: 0
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -380,6 +452,22 @@ export default {
|
||||
if (ext === 'xlsx') return 'xlsx'
|
||||
if (ext === 'xls') return 'xls'
|
||||
return 'other'
|
||||
},
|
||||
/** 多图预览源列表(用于全屏查看) */
|
||||
previewSrcList() {
|
||||
if (this.infoFile && this.infoFile.imageList && this.infoFile.imageList.length > 0) {
|
||||
return this.infoFile.imageList.map(img => img.imagePath)
|
||||
}
|
||||
return []
|
||||
},
|
||||
/** 是否管理员 */
|
||||
isAdmin() {
|
||||
try {
|
||||
const roles = this.$store.getters.roles
|
||||
return roles && roles.some && roles.some(r => r === 'admin')
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -446,10 +534,6 @@ export default {
|
||||
if (size < 1024 * 1024) return (size / 1024).toFixed(1) + ' KB'
|
||||
return (size / 1024 / 1024).toFixed(1) + ' MB'
|
||||
},
|
||||
/** 是否可编辑 */
|
||||
canEdit(row) {
|
||||
return row.createBy === this.$store.getters.name
|
||||
},
|
||||
/** 卡片选中判断 */
|
||||
isSelected(fileId) {
|
||||
return this.selectedCardIds.includes(fileId)
|
||||
@@ -492,11 +576,14 @@ export default {
|
||||
fileType: undefined,
|
||||
scopeType: 1,
|
||||
visibleUsers: [],
|
||||
remark: undefined
|
||||
remark: undefined,
|
||||
imageList: []
|
||||
}
|
||||
this.uploadFileList = []
|
||||
this.stagedImages = []
|
||||
this.mainFile = null
|
||||
this.originalVisibleUsers = []
|
||||
this.isEdit = false
|
||||
this.uploadMode = 'file'
|
||||
this.resetForm('form')
|
||||
},
|
||||
/** 可见范围切换 */
|
||||
@@ -547,6 +634,9 @@ export default {
|
||||
handleUpdate(row) {
|
||||
this.reset()
|
||||
this.isEdit = true
|
||||
this.dialogTitle = '编辑文件'
|
||||
// 先打开对话框,让用户感知操作已触发
|
||||
this.open = true
|
||||
const fileId = row.fileId || this.ids[0]
|
||||
getFile(fileId).then(response => {
|
||||
const data = response.data
|
||||
@@ -561,55 +651,225 @@ export default {
|
||||
fileType: data.fileType,
|
||||
scopeType: data.scopeType,
|
||||
visibleUsers: [],
|
||||
remark: data.remark
|
||||
remark: data.remark,
|
||||
imageList: data.imageList || []
|
||||
}
|
||||
if (data.scopeType === 2) {
|
||||
listVisibleUserByFileId(fileId).then(res => {
|
||||
const rows = res.rows || []
|
||||
this.form.visibleUsers = rows.map(r => r.userId)
|
||||
this.originalVisibleUsers = [...this.form.visibleUsers]
|
||||
// 去重,防止重复 userId 导致 el-select 渲染异常
|
||||
const userIds = [...new Set(rows.map(r => r.userId).filter(id => id != null))]
|
||||
this.form.visibleUsers = userIds
|
||||
this.originalVisibleUsers = [...userIds]
|
||||
}).catch(() => {
|
||||
// 可见用户加载失败不影响对话框使用
|
||||
})
|
||||
}
|
||||
this.open = true
|
||||
this.dialogTitle = '编辑文件'
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('获取文件信息失败')
|
||||
this.open = false
|
||||
})
|
||||
},
|
||||
/** 上传前校验 */
|
||||
handleBeforeUpload(file) {
|
||||
/** 上传模式:选择图片 */
|
||||
handleFileSelect(event) {
|
||||
const files = Array.from(event.target.files || [])
|
||||
files.forEach(file => {
|
||||
if (!file.type.startsWith('image/')) return
|
||||
this.stagedImages.push({
|
||||
file: file,
|
||||
url: URL.createObjectURL(file),
|
||||
name: file.name
|
||||
})
|
||||
})
|
||||
event.target.value = ''
|
||||
},
|
||||
|
||||
/** 上传模式:移除已选图片 */
|
||||
removeStagedImage(idx) {
|
||||
const img = this.stagedImages[idx]
|
||||
if (img && img.url) {
|
||||
URL.revokeObjectURL(img.url)
|
||||
}
|
||||
this.stagedImages.splice(idx, 1)
|
||||
},
|
||||
|
||||
/** 编辑模式:替换图片 */
|
||||
handleReplaceImage(idx) {
|
||||
this._replaceIndex = idx
|
||||
this.$refs.editFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:删除图片 */
|
||||
handleRemoveImage(idx) {
|
||||
this.$modal.confirm('是否确认删除此图片?').then(() => {
|
||||
this.form.imageList.splice(idx, 1)
|
||||
}).catch(() => {})
|
||||
},
|
||||
|
||||
/** 编辑模式:添加新图片 */
|
||||
handleAddImage() {
|
||||
this._replaceIndex = null
|
||||
this.$refs.editFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:文件选择后上传到 OSS */
|
||||
handleEditFileSelect(event) {
|
||||
const files = Array.from(event.target.files || [])
|
||||
if (files.length === 0) return
|
||||
event.target.value = ''
|
||||
|
||||
this.uploading = true
|
||||
const promises = files
|
||||
.filter(file => file.type.startsWith('image/'))
|
||||
.map(file => {
|
||||
return uploadFile(file).then(res => {
|
||||
if (res.code === 200) {
|
||||
return {
|
||||
imageName: file.name,
|
||||
imagePath: res.data.url,
|
||||
imageSize: file.size,
|
||||
suffix: file.name.split('.').pop().toLowerCase()
|
||||
}
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || file.name + ' 上传失败')
|
||||
return null
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Promise.all(promises).then(results => {
|
||||
const validResults = results.filter(r => r != null)
|
||||
if (validResults.length === 0) return
|
||||
if (this._replaceIndex !== null && this._replaceIndex !== undefined) {
|
||||
validResults.forEach((img, i) => {
|
||||
const idx = this._replaceIndex + i
|
||||
if (idx < this.form.imageList.length) {
|
||||
this.$set(this.form.imageList, idx, img)
|
||||
} else {
|
||||
this.form.imageList.push(img)
|
||||
}
|
||||
})
|
||||
this._replaceIndex = null
|
||||
} else {
|
||||
validResults.forEach(img => this.form.imageList.push(img))
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('图片上传失败,请重试')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
},
|
||||
|
||||
/** 上传模式:选择主文件 */
|
||||
handleMainFileSelect(event) {
|
||||
const file = event.target.files && event.target.files[0]
|
||||
if (!file) return
|
||||
event.target.value = ''
|
||||
this.mainFile = file
|
||||
if (!this.form.fileName) {
|
||||
this.form.fileName = file.name
|
||||
}
|
||||
const ext = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
|
||||
this.form.suffix = ext
|
||||
this.form.fileSize = file.size
|
||||
},
|
||||
/** 上传成功 */
|
||||
handleUploadSuccess(response, file, fileList) {
|
||||
if (response.code === 200) {
|
||||
this.form.filePath = response.data.url
|
||||
this.form.fileName = this.form.fileName || response.data.fileName
|
||||
this.$modal.msgSuccess('文件上传成功')
|
||||
this.doSubmit()
|
||||
} else {
|
||||
this.$modal.msgError(response.msg || '上传失败')
|
||||
const name = file.name.lastIndexOf('.') > 0
|
||||
? file.name.substring(0, file.name.lastIndexOf('.'))
|
||||
: file.name
|
||||
this.form.fileName = name
|
||||
}
|
||||
},
|
||||
/** 上传失败 */
|
||||
handleUploadError(err, file, fileList) {
|
||||
this.$modal.msgError('文件上传失败')
|
||||
|
||||
/** 上传模式:移除已选主文件 */
|
||||
removeMainFile() {
|
||||
this.mainFile = null
|
||||
},
|
||||
|
||||
/** 编辑模式:触发替换主文件 */
|
||||
handleReplaceMainFile() {
|
||||
this.$refs.replaceMainFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:选择替换的主文件后直接上传 OSS 并更新表单 */
|
||||
handleReplaceMainFileSelect(event) {
|
||||
const file = event.target.files && event.target.files[0]
|
||||
if (!file) return
|
||||
event.target.value = ''
|
||||
this.uploading = true
|
||||
uploadFile(file).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.form.filePath = res.data.url
|
||||
this.form.fileSize = file.size
|
||||
const ext = file.name.split('.').pop().toLowerCase()
|
||||
this.form.suffix = ext
|
||||
if (!this.form.fileName) {
|
||||
this.form.fileName = file.name.lastIndexOf('.') > 0
|
||||
? file.name.substring(0, file.name.lastIndexOf('.'))
|
||||
: file.name
|
||||
}
|
||||
this.$modal.msgSuccess('文件替换成功')
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || '文件上传失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('文件上传失败')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
},
|
||||
|
||||
/** 提交表单 */
|
||||
submitForm() {
|
||||
this.$refs['form'].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.isEdit) {
|
||||
this.doSubmit()
|
||||
} else {
|
||||
if (this.$refs.upload && this.$refs.upload.uploadFiles.length > 0) {
|
||||
this.$refs.upload.submit()
|
||||
} else {
|
||||
} else if (this.uploadMode === 'file') {
|
||||
// 上传文件模式
|
||||
if (!this.mainFile) {
|
||||
this.$modal.msgWarning('请选择要上传的文件')
|
||||
return
|
||||
}
|
||||
this.uploading = true
|
||||
uploadFile(this.mainFile).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.form.filePath = res.data.url
|
||||
this.form.fileSize = this.mainFile.size
|
||||
this.form.suffix = this.mainFile.name.split('.').pop().toLowerCase()
|
||||
this.doSubmit()
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || '文件上传失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('文件上传失败,请重试')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
} else if (this.uploadMode === 'image') {
|
||||
// 上传图片模式(串行避免前端防重复提交拦截)
|
||||
if (!this.stagedImages || this.stagedImages.length === 0) {
|
||||
this.$modal.msgWarning('请选择要上传的图片')
|
||||
return
|
||||
}
|
||||
this.uploading = true
|
||||
const imageList = []
|
||||
const uploadNext = (idx) => {
|
||||
if (idx >= this.stagedImages.length) {
|
||||
this.form.imageList = imageList
|
||||
this.doSubmit()
|
||||
return
|
||||
}
|
||||
const img = this.stagedImages[idx]
|
||||
uploadFile(img.file).then(res => {
|
||||
if (res.code === 200) {
|
||||
imageList.push({
|
||||
imageName: img.name,
|
||||
imagePath: res.data.url,
|
||||
imageSize: img.file.size,
|
||||
suffix: img.name.split('.').pop().toLowerCase()
|
||||
})
|
||||
}
|
||||
uploadNext(idx + 1)
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('图片上传失败:' + img.name)
|
||||
this.uploading = false
|
||||
})
|
||||
}
|
||||
uploadNext(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -679,10 +939,30 @@ export default {
|
||||
},
|
||||
/** 打开详情弹窗 */
|
||||
handleShowInfo(row) {
|
||||
this.infoFile = row
|
||||
this.activeImageIndex = 0
|
||||
this.infoTitle = '文件详情 - ' + row.fileName
|
||||
this.infoVisible = true
|
||||
incrementView(row.fileId)
|
||||
// 加载完整详情(含 imageList)
|
||||
getFile(row.fileId).then(response => {
|
||||
this.infoFile = response.data
|
||||
}).catch(() => {
|
||||
// 详情加载失败时用行数据兜底
|
||||
this.infoFile = row
|
||||
})
|
||||
},
|
||||
|
||||
/** 多图预览切换 */
|
||||
handlePreviewChange(idx) {
|
||||
this.activeImageIndex = idx
|
||||
},
|
||||
|
||||
/** 缩略图点击跳转 */
|
||||
handleThumbnailClick(idx) {
|
||||
this.activeImageIndex = idx
|
||||
if (this.$refs.previewCarousel) {
|
||||
this.$refs.previewCarousel.setActiveItem(idx)
|
||||
}
|
||||
},
|
||||
/** 点击行选中 */
|
||||
handleRowClick(row) {
|
||||
@@ -1168,4 +1448,206 @@ export default {
|
||||
padding: 8px 12px;
|
||||
border-top: 1px solid #f2f2f2;
|
||||
}
|
||||
|
||||
/* 图片上传/编辑区域 */
|
||||
.image-upload-area {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.image-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.image-item {
|
||||
position: relative;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
cursor: default;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.image-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.image-item-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.image-item:hover .image-item-mask {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.image-item-name {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 2px 4px;
|
||||
font-size: 11px;
|
||||
color: #fff;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.image-add-btn {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
border: 1px dashed #dcdfe6;
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.image-add-btn:hover {
|
||||
border-color: #409eff;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.image-add-btn i {
|
||||
font-size: 28px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.image-count {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
/* 主文件上传区域 */
|
||||
.file-upload-area {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.main-file-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
padding: 8px 12px;
|
||||
background: #f5f7fa;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.main-file-info .el-icon-document {
|
||||
font-size: 18px;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.main-file-name {
|
||||
color: #303133;
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.main-file-size {
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.no-images-hint {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
/* 详情弹窗多图轮播 */
|
||||
.image-carousel-wrap {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.image-carousel-wrap .el-carousel {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.carousel-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.carousel-image /deep/ .el-image__inner {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.thumbnail-strip {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
padding: 8px 0;
|
||||
overflow-x: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.thumbnail-item {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.thumbnail-item:hover {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.thumbnail-item.active {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.thumbnail-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.image-counter {
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -150,25 +150,75 @@
|
||||
<el-dialog :title="dialogTitle" :visible.sync="open" width="650px" append-to-body @close="handleDialogClose">
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="文件名称" prop="fileName">
|
||||
<el-input v-model="form.fileName" placeholder="请输入文件名称" :disabled="isEdit" />
|
||||
<el-input v-model="form.fileName" placeholder="请输入文件名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上传文件" v-if="!isEdit">
|
||||
<el-upload
|
||||
ref="upload"
|
||||
:action="uploadUrl"
|
||||
:headers="uploadHeaders"
|
||||
:file-list="uploadFileList"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:on-success="handleUploadSuccess"
|
||||
:on-error="handleUploadError"
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
class="upload-demo"
|
||||
drag
|
||||
>
|
||||
<i class="el-icon-upload"></i>
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击选取</em></div>
|
||||
</el-upload>
|
||||
<!-- 上传模式 - 选择方式 -->
|
||||
<el-form-item label="上传方式" v-if="!isEdit">
|
||||
<el-radio-group v-model="uploadMode">
|
||||
<el-radio label="file">上传文件</el-radio>
|
||||
<el-radio label="image">上传图片</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<!-- 上传文件 -->
|
||||
<el-form-item v-if="!isEdit && uploadMode === 'file'" label="选择文件" required>
|
||||
<div class="file-upload-area">
|
||||
<input type="file" ref="mainFileInput" style="display:none" @change="handleMainFileSelect" />
|
||||
<el-button type="primary" @click="$refs.mainFileInput.click()">选择文件</el-button>
|
||||
<span class="upload-hint">支持 pdf / xlsx / docx / 图片 等格式</span>
|
||||
<div v-if="mainFile" class="main-file-info">
|
||||
<i class="el-icon-document"></i>
|
||||
<span class="main-file-name">{{ mainFile.name }}</span>
|
||||
<span class="main-file-size">({{ formatFileSize(mainFile.size) }})</span>
|
||||
<el-button type="text" size="mini" icon="el-icon-delete" @click="removeMainFile" style="color:#f56c6c;"></el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 上传图片(多张) -->
|
||||
<el-form-item v-if="!isEdit && uploadMode === 'image'" label="选择图片" required>
|
||||
<div class="image-upload-area">
|
||||
<input type="file" multiple accept="image/*" ref="fileInput" style="display:none" @change="handleFileSelect" />
|
||||
<el-button @click="$refs.fileInput.click()">选择图片</el-button>
|
||||
<span class="upload-hint">支持多选 jpg/png/webp/bmp</span>
|
||||
<div v-if="stagedImages.length > 0" class="image-grid">
|
||||
<div v-for="(img, idx) in stagedImages" :key="idx" class="image-item">
|
||||
<img :src="img.url" />
|
||||
<div class="image-item-mask">
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle @click="removeStagedImage(idx)"></el-button>
|
||||
</div>
|
||||
<div class="image-item-name">{{ img.name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 编辑模式 - 主文件信息 -->
|
||||
<el-form-item label="当前文件" v-if="isEdit && form.filePath">
|
||||
<div class="main-file-info">
|
||||
<i class="el-icon-document"></i>
|
||||
<span class="main-file-name">{{ form.fileName }}</span>
|
||||
<span class="main-file-size" v-if="form.fileSize">({{ formatFileSize(form.fileSize) }})</span>
|
||||
<el-button type="text" size="mini" icon="el-icon-refresh" @click="handleReplaceMainFile" style="margin-left:8px;">替换</el-button>
|
||||
<el-button type="text" size="mini" icon="el-icon-download" @click="downloadFile(form)" v-if="form.filePath">下载</el-button>
|
||||
<input type="file" ref="replaceMainFileInput" style="display:none" @change="handleReplaceMainFileSelect" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 编辑模式 - 图片管理 -->
|
||||
<el-form-item label="文件图片" v-if="isEdit">
|
||||
<div v-if="form.imageList && form.imageList.length > 0" class="image-grid">
|
||||
<div v-for="(img, idx) in form.imageList" :key="img.imageId || idx" class="image-item">
|
||||
<img :src="img.imagePath" />
|
||||
<div class="image-item-mask">
|
||||
<el-button type="warning" size="mini" icon="el-icon-refresh" circle @click="handleReplaceImage(idx)" title="替换"></el-button>
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle @click="handleRemoveImage(idx)" title="删除"></el-button>
|
||||
</div>
|
||||
<div class="image-item-name">{{ img.imageName }}</div>
|
||||
</div>
|
||||
<div class="image-item image-add-btn" @click="handleAddImage">
|
||||
<i class="el-icon-plus"></i>
|
||||
<span>添加图片</span>
|
||||
</div>
|
||||
<input type="file" multiple accept="image/*" ref="editFileInput" style="display:none" @change="handleEditFileSelect" />
|
||||
</div>
|
||||
<div v-else class="no-images-hint">暂无图片,<el-button type="text" @click="handleAddImage">添加图片</el-button></div>
|
||||
</el-form-item>
|
||||
<el-form-item label="订单编号" prop="orderNo">
|
||||
<el-input v-model="form.orderNo" placeholder="请输入订单编号" />
|
||||
@@ -204,14 +254,33 @@
|
||||
<el-dialog :title="infoTitle" :visible.sync="infoVisible" width="1100px" append-to-body top="5vh" @close="handleInfoClose">
|
||||
<div v-if="infoFile" class="info-dialog-body">
|
||||
<div class="info-preview">
|
||||
<ImagePreview v-if="infoFileCategory === 'image'" :src="infoFile.filePath" />
|
||||
<PdfPreview v-else-if="infoFileCategory === 'pdf'" :src="infoFile.filePath" />
|
||||
<DocxPreview v-else-if="infoFileCategory === 'docx'" :src="infoFile.filePath" />
|
||||
<XlsxPreview v-else-if="infoFileCategory === 'xlsx'" :src="infoFile.filePath" />
|
||||
<XlsPreview v-else-if="infoFileCategory === 'xls'" :src="infoFile.filePath" />
|
||||
<div v-else class="info-preview-empty">
|
||||
<el-empty description="暂不支持预览此文件类型" />
|
||||
</div>
|
||||
<!-- 多图模式 -->
|
||||
<template v-if="infoFile.imageList && infoFile.imageList.length > 0">
|
||||
<div class="image-carousel-wrap">
|
||||
<el-carousel height="400px" indicator-position="none" arrow="always" ref="previewCarousel" @change="handlePreviewChange">
|
||||
<el-carousel-item v-for="(img, idx) in infoFile.imageList" :key="idx">
|
||||
<el-image :src="img.imagePath" fit="contain" :preview-src-list="previewSrcList" :initial-index="idx" class="carousel-image" />
|
||||
</el-carousel-item>
|
||||
</el-carousel>
|
||||
<div class="thumbnail-strip">
|
||||
<div v-for="(img, idx) in infoFile.imageList" :key="idx" class="thumbnail-item" :class="{ active: activeImageIndex === idx }" @click="handleThumbnailClick(idx)">
|
||||
<img :src="img.imagePath" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="image-counter">{{ activeImageIndex + 1 }} / {{ infoFile.imageList.length }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 单文件模式 -->
|
||||
<template v-else>
|
||||
<ImagePreview v-if="infoFileCategory === 'image'" :src="infoFile.filePath" />
|
||||
<PdfPreview v-else-if="infoFileCategory === 'pdf'" :src="infoFile.filePath" />
|
||||
<DocxPreview v-else-if="infoFileCategory === 'docx'" :src="infoFile.filePath" />
|
||||
<XlsxPreview v-else-if="infoFileCategory === 'xlsx'" :src="infoFile.filePath" />
|
||||
<XlsPreview v-else-if="infoFileCategory === 'xls'" :src="infoFile.filePath" />
|
||||
<div v-else class="info-preview-empty">
|
||||
<el-empty description="暂不支持预览此文件类型" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="info-meta">
|
||||
<el-descriptions :column="1" border size="small">
|
||||
@@ -269,9 +338,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listFile, getFile, addFile, updateFile, delFile, exportFile, listVisibleUser, addVisibleUser, delVisibleUser, listVisibleUserByFileId, listRelatedToMe, incrementView } from '@/api/system/file'
|
||||
import { listFile, getFile, addFile, updateFile, delFile, exportFile, listVisibleUser, addVisibleUser, delVisibleUser, listVisibleUserByFileId, listRelatedToMe, incrementView, uploadFile, delFileImage } from '@/api/system/file'
|
||||
import { listFileComment, addFileComment } from '@/api/system/fileComment'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import UserSelect from '@/components/KLPService/UserSelect/index'
|
||||
import ImagePreview from '@/components/FilePreview/preview/image/index.vue'
|
||||
import PdfPreview from '@/components/FilePreview/preview/pdf/index.vue'
|
||||
@@ -338,7 +406,8 @@ export default {
|
||||
fileType: undefined,
|
||||
scopeType: 1,
|
||||
visibleUsers: [],
|
||||
remark: undefined
|
||||
remark: undefined,
|
||||
imageList: []
|
||||
},
|
||||
// 可见用户原始数据(编辑时回显)
|
||||
originalVisibleUsers: [],
|
||||
@@ -351,12 +420,12 @@ export default {
|
||||
{ required: true, message: '请选择文件类型', trigger: 'change' }
|
||||
]
|
||||
},
|
||||
// 上传相关
|
||||
uploadUrl: process.env.VUE_APP_BASE_API + '/system/oss/upload',
|
||||
uploadHeaders: {
|
||||
Authorization: 'Bearer ' + getToken()
|
||||
},
|
||||
uploadFileList: [],
|
||||
// 上传方式 file | image
|
||||
uploadMode: 'file',
|
||||
// 多图上传
|
||||
mainFile: null,
|
||||
stagedImages: [],
|
||||
uploading: false,
|
||||
// 文件详情弹窗
|
||||
infoVisible: false,
|
||||
infoTitle: '',
|
||||
@@ -365,7 +434,9 @@ export default {
|
||||
comments: [],
|
||||
commentExpanded: false,
|
||||
commentInput: '',
|
||||
commentLoading: false
|
||||
commentLoading: false,
|
||||
// 详情弹窗多图预览
|
||||
activeImageIndex: 0
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -385,6 +456,13 @@ export default {
|
||||
if (ext === 'xlsx') return 'xlsx'
|
||||
if (ext === 'xls') return 'xls'
|
||||
return 'other'
|
||||
},
|
||||
/** 多图预览源列表(用于全屏查看) */
|
||||
previewSrcList() {
|
||||
if (this.infoFile && this.infoFile.imageList && this.infoFile.imageList.length > 0) {
|
||||
return this.infoFile.imageList.map(img => img.imagePath)
|
||||
}
|
||||
return []
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -458,20 +536,23 @@ export default {
|
||||
reset() {
|
||||
this.form = {
|
||||
fileId: undefined,
|
||||
fileName: undefined,
|
||||
filePath: undefined,
|
||||
fileSize: undefined,
|
||||
suffix: undefined,
|
||||
orderNo: undefined,
|
||||
dept: undefined,
|
||||
fileType: undefined,
|
||||
fileName: '',
|
||||
filePath: '',
|
||||
fileSize: '',
|
||||
suffix: '',
|
||||
orderNo: '',
|
||||
dept: '',
|
||||
fileType: '',
|
||||
scopeType: 1,
|
||||
visibleUsers: [],
|
||||
remark: undefined
|
||||
remark: '',
|
||||
imageList: []
|
||||
}
|
||||
this.uploadFileList = []
|
||||
this.stagedImages = []
|
||||
this.mainFile = null
|
||||
this.originalVisibleUsers = []
|
||||
this.isEdit = false
|
||||
this.uploadMode = 'file'
|
||||
this.resetForm('form')
|
||||
},
|
||||
/** 可见范围切换 */
|
||||
@@ -527,6 +608,9 @@ export default {
|
||||
handleUpdate(row) {
|
||||
this.reset()
|
||||
this.isEdit = true
|
||||
this.dialogTitle = '编辑文件'
|
||||
// 先打开对话框,让用户感知操作已触发
|
||||
this.open = true
|
||||
const fileId = row.fileId || this.ids[0]
|
||||
getFile(fileId).then(response => {
|
||||
const data = response.data
|
||||
@@ -541,55 +625,228 @@ export default {
|
||||
fileType: data.fileType,
|
||||
scopeType: data.scopeType,
|
||||
visibleUsers: [],
|
||||
remark: data.remark
|
||||
remark: data.remark,
|
||||
imageList: data.imageList || []
|
||||
}
|
||||
if (data.scopeType === 2) {
|
||||
listVisibleUserByFileId(fileId).then(res => {
|
||||
const rows = res.rows || []
|
||||
this.form.visibleUsers = rows.map(r => r.userId)
|
||||
this.originalVisibleUsers = [...this.form.visibleUsers]
|
||||
// 去重,防止重复 userId 导致 el-select 渲染异常
|
||||
const userIds = [...new Set(rows.map(r => r.userId).filter(id => id != null))]
|
||||
this.form.visibleUsers = userIds
|
||||
this.originalVisibleUsers = [...userIds]
|
||||
}).catch(() => {
|
||||
// 可见用户加载失败不影响对话框使用
|
||||
})
|
||||
}
|
||||
this.open = true
|
||||
this.dialogTitle = '编辑文件'
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('获取文件信息失败')
|
||||
this.open = false
|
||||
})
|
||||
},
|
||||
/** 上传前校验 */
|
||||
handleBeforeUpload(file) {
|
||||
/** 上传模式:选择图片 */
|
||||
handleFileSelect(event) {
|
||||
const files = Array.from(event.target.files || [])
|
||||
files.forEach(file => {
|
||||
if (!file.type.startsWith('image/')) return
|
||||
this.stagedImages.push({
|
||||
file: file,
|
||||
url: URL.createObjectURL(file),
|
||||
name: file.name
|
||||
})
|
||||
})
|
||||
event.target.value = ''
|
||||
},
|
||||
|
||||
/** 上传模式:移除已选图片 */
|
||||
removeStagedImage(idx) {
|
||||
const img = this.stagedImages[idx]
|
||||
if (img && img.url) {
|
||||
URL.revokeObjectURL(img.url)
|
||||
}
|
||||
this.stagedImages.splice(idx, 1)
|
||||
},
|
||||
|
||||
/** 编辑模式:替换图片 */
|
||||
handleReplaceImage(idx) {
|
||||
this._replaceIndex = idx
|
||||
this.$refs.editFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:删除图片 */
|
||||
handleRemoveImage(idx) {
|
||||
this.$modal.confirm('是否确认删除此图片?').then(() => {
|
||||
this.form.imageList.splice(idx, 1)
|
||||
}).catch(() => {})
|
||||
},
|
||||
|
||||
/** 编辑模式:添加新图片 */
|
||||
handleAddImage() {
|
||||
this._replaceIndex = null
|
||||
this.$refs.editFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:文件选择后上传到 OSS */
|
||||
handleEditFileSelect(event) {
|
||||
const files = Array.from(event.target.files || [])
|
||||
if (files.length === 0) return
|
||||
event.target.value = ''
|
||||
|
||||
this.uploading = true
|
||||
const promises = files
|
||||
.filter(file => file.type.startsWith('image/'))
|
||||
.map(file => {
|
||||
return uploadFile(file).then(res => {
|
||||
if (res.code === 200) {
|
||||
return {
|
||||
imageName: file.name,
|
||||
imagePath: res.data.url,
|
||||
imageSize: file.size,
|
||||
suffix: file.name.split('.').pop().toLowerCase()
|
||||
}
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || file.name + ' 上传失败')
|
||||
return null
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Promise.all(promises).then(results => {
|
||||
const validResults = results.filter(r => r != null)
|
||||
if (validResults.length === 0) return
|
||||
if (this._replaceIndex !== null && this._replaceIndex !== undefined) {
|
||||
// 替换已有图片
|
||||
validResults.forEach((img, i) => {
|
||||
const idx = this._replaceIndex + i
|
||||
if (idx < this.form.imageList.length) {
|
||||
this.$set(this.form.imageList, idx, img)
|
||||
} else {
|
||||
this.form.imageList.push(img)
|
||||
}
|
||||
})
|
||||
this._replaceIndex = null
|
||||
} else {
|
||||
// 新增图片
|
||||
validResults.forEach(img => this.form.imageList.push(img))
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('图片上传失败,请重试')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
},
|
||||
|
||||
/** 上传模式:选择主文件 */
|
||||
handleMainFileSelect(event) {
|
||||
const file = event.target.files && event.target.files[0]
|
||||
if (!file) return
|
||||
event.target.value = ''
|
||||
this.mainFile = file
|
||||
// 自动填充文件名(不含扩展名)
|
||||
if (!this.form.fileName) {
|
||||
this.form.fileName = file.name
|
||||
}
|
||||
const ext = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
|
||||
this.form.suffix = ext
|
||||
this.form.fileSize = file.size
|
||||
},
|
||||
/** 上传成功 */
|
||||
handleUploadSuccess(response, file, fileList) {
|
||||
if (response.code === 200) {
|
||||
this.form.filePath = response.data.url
|
||||
this.form.fileName = this.form.fileName || response.data.fileName
|
||||
this.$modal.msgSuccess('文件上传成功')
|
||||
this.doSubmit()
|
||||
} else {
|
||||
this.$modal.msgError(response.msg || '上传失败')
|
||||
const name = file.name.lastIndexOf('.') > 0
|
||||
? file.name.substring(0, file.name.lastIndexOf('.'))
|
||||
: file.name
|
||||
this.form.fileName = name
|
||||
}
|
||||
},
|
||||
/** 上传失败 */
|
||||
handleUploadError(err, file, fileList) {
|
||||
this.$modal.msgError('文件上传失败')
|
||||
|
||||
/** 上传模式:移除已选主文件 */
|
||||
removeMainFile() {
|
||||
this.mainFile = null
|
||||
},
|
||||
|
||||
/** 编辑模式:触发替换主文件 */
|
||||
handleReplaceMainFile() {
|
||||
this.$refs.replaceMainFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:选择替换的主文件后直接上传 OSS 并更新表单 */
|
||||
handleReplaceMainFileSelect(event) {
|
||||
const file = event.target.files && event.target.files[0]
|
||||
if (!file) return
|
||||
event.target.value = ''
|
||||
this.uploading = true
|
||||
uploadFile(file).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.form.filePath = res.data.url
|
||||
this.form.fileSize = file.size
|
||||
const ext = file.name.split('.').pop().toLowerCase()
|
||||
this.form.suffix = ext
|
||||
if (!this.form.fileName) {
|
||||
this.form.fileName = file.name.lastIndexOf('.') > 0
|
||||
? file.name.substring(0, file.name.lastIndexOf('.'))
|
||||
: file.name
|
||||
}
|
||||
this.$modal.msgSuccess('文件替换成功')
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || '文件上传失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('文件上传失败')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
},
|
||||
|
||||
/** 提交表单 */
|
||||
submitForm() {
|
||||
this.$refs['form'].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.isEdit) {
|
||||
this.doSubmit()
|
||||
} else {
|
||||
if (this.$refs.upload && this.$refs.upload.uploadFiles.length > 0) {
|
||||
this.$refs.upload.submit()
|
||||
} else {
|
||||
} else if (this.uploadMode === 'file') {
|
||||
// 上传文件模式
|
||||
if (!this.mainFile) {
|
||||
this.$modal.msgWarning('请选择要上传的文件')
|
||||
return
|
||||
}
|
||||
this.uploading = true
|
||||
uploadFile(this.mainFile).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.form.filePath = res.data.url
|
||||
this.form.fileSize = this.mainFile.size
|
||||
this.form.suffix = this.mainFile.name.split('.').pop().toLowerCase()
|
||||
this.doSubmit()
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || '文件上传失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('文件上传失败,请重试')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
} else if (this.uploadMode === 'image') {
|
||||
// 上传图片模式(串行避免前端防重复提交拦截)
|
||||
if (!this.stagedImages || this.stagedImages.length === 0) {
|
||||
this.$modal.msgWarning('请选择要上传的图片')
|
||||
return
|
||||
}
|
||||
this.uploading = true
|
||||
const imageList = []
|
||||
const uploadNext = (idx) => {
|
||||
if (idx >= this.stagedImages.length) {
|
||||
this.form.imageList = imageList
|
||||
this.doSubmit()
|
||||
return
|
||||
}
|
||||
const img = this.stagedImages[idx]
|
||||
uploadFile(img.file).then(res => {
|
||||
if (res.code === 200) {
|
||||
imageList.push({
|
||||
imageName: img.name,
|
||||
imagePath: res.data.url,
|
||||
imageSize: img.file.size,
|
||||
suffix: img.name.split('.').pop().toLowerCase()
|
||||
})
|
||||
}
|
||||
uploadNext(idx + 1)
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('图片上传失败:' + img.name)
|
||||
this.uploading = false
|
||||
})
|
||||
}
|
||||
uploadNext(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -665,10 +922,30 @@ export default {
|
||||
},
|
||||
/** 打开详情弹窗 */
|
||||
handleShowInfo(row) {
|
||||
this.infoFile = row
|
||||
this.activeImageIndex = 0
|
||||
this.infoTitle = '文件详情 - ' + row.fileName
|
||||
this.infoVisible = true
|
||||
incrementView(row.fileId)
|
||||
// 加载完整详情(含 imageList)
|
||||
getFile(row.fileId).then(response => {
|
||||
this.infoFile = response.data
|
||||
}).catch(() => {
|
||||
// 详情加载失败时用行数据兜底
|
||||
this.infoFile = row
|
||||
})
|
||||
},
|
||||
|
||||
/** 多图预览切换 */
|
||||
handlePreviewChange(idx) {
|
||||
this.activeImageIndex = idx
|
||||
},
|
||||
|
||||
/** 缩略图点击跳转 */
|
||||
handleThumbnailClick(idx) {
|
||||
this.activeImageIndex = idx
|
||||
if (this.$refs.previewCarousel) {
|
||||
this.$refs.previewCarousel.setActiveItem(idx)
|
||||
}
|
||||
},
|
||||
/** 点击行选中 */
|
||||
handleRowClick(row) {
|
||||
@@ -829,11 +1106,6 @@ export default {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* 上传区域 */
|
||||
.upload-demo {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* 操作列按钮对齐 */
|
||||
.action-cell {
|
||||
display: flex;
|
||||
@@ -962,6 +1234,208 @@ export default {
|
||||
padding: 8px 12px;
|
||||
border-top: 1px solid #f2f2f2;
|
||||
}
|
||||
|
||||
/* 图片上传/编辑区域 */
|
||||
.image-upload-area {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.image-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.image-item {
|
||||
position: relative;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
cursor: default;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.image-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.image-item-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.image-item:hover .image-item-mask {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.image-item-name {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 2px 4px;
|
||||
font-size: 11px;
|
||||
color: #fff;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.image-add-btn {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
border: 1px dashed #dcdfe6;
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.image-add-btn:hover {
|
||||
border-color: #409eff;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.image-add-btn i {
|
||||
font-size: 28px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.image-count {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
/* 主文件上传区域 */
|
||||
.file-upload-area {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.main-file-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
padding: 8px 12px;
|
||||
background: #f5f7fa;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.main-file-info .el-icon-document {
|
||||
font-size: 18px;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.main-file-name {
|
||||
color: #303133;
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.main-file-size {
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.no-images-hint {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
/* 详情弹窗多图轮播 */
|
||||
.image-carousel-wrap {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.image-carousel-wrap .el-carousel {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.carousel-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.carousel-image /deep/ .el-image__inner {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.thumbnail-strip {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
padding: 8px 0;
|
||||
overflow-x: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.thumbnail-item {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.thumbnail-item:hover {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.thumbnail-item.active {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.thumbnail-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.image-counter {
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- 表格选中行高亮 -->
|
||||
|
||||
Reference in New Issue
Block a user