解决综合浏览预览文件提示文件不存在的问题

master
guoxin 1 year ago
parent bceef32891
commit 3f2007cf9f
  1. 21
      shandan-system/src/main/java/com/keyware/shandan/system/controller/SysFileController.java
  2. 9
      shandan-system/src/main/resources/static/js/sys/file/view.js
  3. 2
      shandan-system/src/main/resources/view/sys/file/fileView.html

@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.ZipUtil;
import cn.hutool.http.HttpUtil;
import com.keyware.shandan.bianmu.service.DataLabelsService;
import com.keyware.shandan.common.controller.BaseController;
import com.keyware.shandan.common.entity.Result;
@ -29,6 +30,10 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.*;
@ -120,22 +125,6 @@ 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;
}

@ -47,14 +47,7 @@ layui.use(['layer', 'laytpl', 'dropdown', 'carousel', 'form', 'datalabel'], func
showWarningMsg('该文件中没有任何内容');
return;
}
if (fileNotExists) {
showErrorMsg('文件不存在');
return;
}
if (fileReadError) {
showErrorMsg('文件内容不可读,请下载查看');
return;
}
let office_server = DICT.getOfficeServer();
let if_src = office_server + '?url=' + encodeURIComponent(Base64.encode(fileViewUrl))

@ -17,8 +17,6 @@
const file = /*[[${fileData}]]*/ {};
const fileViewUrl = /*[[${fileViewUrl}]]*/ '';
const downloadUrl = /*[[${downloadUrl}]]*/ '';
const fileNotExists = /*[[${fileNotExists}]]*/ false;
const fileReadError = /*[[${fileReadError}]]*/ false;
</script>
</head>
<body>