优化:文件预览页面对不存在的文件和不能预览的文件进行提示

master
guoxin 1 year ago
parent 5051913119
commit eef9d53218
  1. 2
      shandan-control/src/main/resources/application-dev.yml
  2. 32
      shandan-system/src/main/java/com/keyware/shandan/system/controller/SysFileController.java
  3. 16
      shandan-system/src/main/resources/static/js/sys/file/view.js

@ -47,4 +47,4 @@ project:
logging:
level:
com.keyware: debug
com.keyware: info

@ -2,11 +2,11 @@ package com.keyware.shandan.system.controller;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson.JSONObject;
import com.keyware.shandan.bianmu.service.DataLabelsService;
import com.keyware.shandan.common.controller.BaseController;
import com.keyware.shandan.common.entity.Result;
import com.keyware.shandan.common.util.FileDownload;
import com.keyware.shandan.common.util.PoiFileReadUtil;
import com.keyware.shandan.frame.properties.CustomProperties;
import com.keyware.shandan.system.constants.FormTypeEnum;
import com.keyware.shandan.system.entity.SysFile;
@ -16,23 +16,18 @@ import com.keyware.shandan.system.service.SysFileService;
import com.keyware.shandan.system.service.SysFormConfigService;
import com.keyware.shandan.system.service.SysSettingService;
import com.keyware.shandan.system.utils.FileChunkUploadUtil;
import org.apache.tomcat.util.http.ResponseUtil;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
@ -62,7 +57,6 @@ public class SysFileController extends BaseController<SysFileService, SysFile, S
@Autowired
private SysFormConfigService formConfigService;
@GetMapping("/layer")
public ModelAndView fileUploadLayer(ModelAndView mav) {
mav.setViewName("sys/file/fileUploadLayer");
@ -114,10 +108,6 @@ public class SysFileController extends BaseController<SysFileService, SysFile, S
}
String downloadUrl = bianmuSetting.getSysAddress() + "/sys/file/download/" + fileId;
// TODO 临时调试用
//fileViewUrl = "http://192.168.102.192:8080/bianmu" + file.getWebUri();
//downloadUrl = "http://192.168.102.192:8080/bianmu/sys/file/download/" + fileId;
mav.addObject("fileViewUrl", fileViewUrl.replace("\\", "/"));
mav.addObject("downloadUrl", downloadUrl);
mav.addObject("fileData", file);
@ -128,6 +118,22 @@ public class SysFileController extends BaseController<SysFileService, SysFile, S
}
mav.addObject("readableFileSize", fileSize);
mav.addObject("LabelConfigSet", labelsService.formConfigList());
File ff = new File(customProperties.getFileStorage().getPath() + File.separator + file.getPath());
if (!ff.exists()) {
mav.addObject("fileNotExists", true);
} else {
if (PoiFileReadUtil.isReadilyFile(ff)) {
try {
String text = PoiFileReadUtil.parseTextByFile(ff);
if (text == null) {
mav.addObject("fileReadError", true);
}
} catch (Exception e) {
mav.addObject("fileReadError", true);
}
}
}
return mav;
}

@ -23,7 +23,7 @@ layui.use(['layer', 'laytpl', 'dropdown', 'carousel', 'form', 'datalabel'], func
break;
case 'markRecords':
let markRecords = file[col]
if(markRecords){
if (markRecords) {
for (let mark of markRecords) {
$(`#marktag-${mark.markType}`).html(MarkTag.getStaticTagHtml(mark.markValue))
}
@ -39,17 +39,23 @@ layui.use(['layer', 'laytpl', 'dropdown', 'carousel', 'form', 'datalabel'], func
$(`label[name="${col}"]`).text(file[col] || '');
}
}
if(file.labels){
if (file.labels) {
layui.datalabel.setData(file.labels);
}
if(file.fileSize === 0){
if (file.fileSize === 0) {
showWarningMsg('该文件中没有任何内容');
return;
}
if (fileNotExists) {
showErrorMsg('文件不存在');
return;
}
if (fileReadError) {
showErrorMsg('文件内容不可读,请下载查看');
return;
}
let office_server = DICT.getOfficeServer();
// TODO 临时调试用
//office_server = 'http://127.0.0.1:8888/onlinePreview';
let if_src = office_server + '?url=' + encodeURIComponent(Base64.encode(fileViewUrl))
let if_elem = document.getElementById('office-online');