Commit 2bbf0109 authored by mhqpx's avatar mhqpx Committed by klboke

文件预览:移除needE参数

parent eb3d36e5
...@@ -27,10 +27,11 @@ public class DownloadUtils { ...@@ -27,10 +27,11 @@ public class DownloadUtils {
* @param type * @param type
* @return * @return
*/ */
public ReturnResponse<String> downLoad(String urlAddress, String type, String fileName, String needEncode){ public ReturnResponse<String> downLoad(String urlAddress, String type, String fileName){
ReturnResponse<String> response = new ReturnResponse<>(0, "下载成功!!!", ""); ReturnResponse<String> response = new ReturnResponse<>(0, "下载成功!!!", "");
URL url = null; URL url = null;
try { try {
urlAddress = replacePlusMark(urlAddress);
urlAddress = encodeUrlParam(urlAddress); urlAddress = encodeUrlParam(urlAddress);
// 因为tomcat不能处理'+'号,所以讲'+'号替换成'%20%' // 因为tomcat不能处理'+'号,所以讲'+'号替换成'%20%'
urlAddress = urlAddress.replaceAll("\\+", "%20"); urlAddress = urlAddress.replaceAll("\\+", "%20");
...@@ -92,9 +93,12 @@ public class DownloadUtils { ...@@ -92,9 +93,12 @@ public class DownloadUtils {
* @return * @return
*/ */
private String replacePlusMark(String urlAddress) { private String replacePlusMark(String urlAddress) {
String nonParamStr = urlAddress.substring(0,urlAddress.indexOf("?") + 1); if (urlAddress.contains("?")) {
String paramStr = urlAddress.substring(nonParamStr.length()); String nonParamStr = urlAddress.substring(0,urlAddress.indexOf("?") + 1);
return nonParamStr + paramStr.replace(" ", "+"); String paramStr = urlAddress.substring(nonParamStr.length());
return nonParamStr + paramStr.replace(" ", "+");
}
return urlAddress;
} }
/** /**
......
...@@ -17,8 +17,8 @@ public class SimTextUtil { ...@@ -17,8 +17,8 @@ public class SimTextUtil {
@Autowired @Autowired
DownloadUtils downloadUtils; DownloadUtils downloadUtils;
public ReturnResponse<String> readSimText(String url, String fileName, String needEncode){ public ReturnResponse<String> readSimText(String url, String fileName){
ReturnResponse<String> response = downloadUtils.downLoad(url, "txt", fileName, needEncode); ReturnResponse<String> response = downloadUtils.downLoad(url, "txt", fileName);
return response; return response;
} }
} }
...@@ -50,7 +50,7 @@ public class OnlinePreviewController { ...@@ -50,7 +50,7 @@ public class OnlinePreviewController {
* @return * @return
*/ */
@RequestMapping(value = "onlinePreview",method = RequestMethod.GET) @RequestMapping(value = "onlinePreview",method = RequestMethod.GET)
public String onlinePreview(String url, String needEncode, Model model, HttpServletRequest req) throws UnsupportedEncodingException { public String onlinePreview(String url, Model model, HttpServletRequest req) throws UnsupportedEncodingException {
// 路径转码 // 路径转码
String decodedUrl = URLDecoder.decode(url, "utf-8"); String decodedUrl = URLDecoder.decode(url, "utf-8");
String type = typeFromUrl(url); String type = typeFromUrl(url);
...@@ -62,7 +62,7 @@ public class OnlinePreviewController { ...@@ -62,7 +62,7 @@ public class OnlinePreviewController {
model.addAttribute("imgurl", url); model.addAttribute("imgurl", url);
return "picture"; return "picture";
} else if (type.equalsIgnoreCase("simText")){ } else if (type.equalsIgnoreCase("simText")){
ReturnResponse<String> response = simTextUtil.readSimText(decodedUrl, fileName, needEncode); ReturnResponse<String> response = simTextUtil.readSimText(decodedUrl, fileName);
if (0 != response.getCode()) { if (0 != response.getCode()) {
model.addAttribute("msg", response.getMsg()); model.addAttribute("msg", response.getMsg());
return "fileNotSupported"; return "fileNotSupported";
...@@ -76,7 +76,7 @@ public class OnlinePreviewController { ...@@ -76,7 +76,7 @@ public class OnlinePreviewController {
String fileTree = null; String fileTree = null;
// 判断文件名是否存在(redis缓存读取) // 判断文件名是否存在(redis缓存读取)
if (!StringUtils.hasText(fileUtils.getConvertedFile(fileName))) { if (!StringUtils.hasText(fileUtils.getConvertedFile(fileName))) {
ReturnResponse<String> response = downloadUtils.downLoad(decodedUrl, suffix, fileName, needEncode); ReturnResponse<String> response = downloadUtils.downLoad(decodedUrl, suffix, fileName);
if (0 != response.getCode()) { if (0 != response.getCode()) {
model.addAttribute("msg", response.getMsg()); model.addAttribute("msg", response.getMsg());
return "fileNotSupported"; return "fileNotSupported";
...@@ -109,7 +109,7 @@ public class OnlinePreviewController { ...@@ -109,7 +109,7 @@ public class OnlinePreviewController {
if (!fileUtils.listConvertedFiles().containsKey(pdfName)) { if (!fileUtils.listConvertedFiles().containsKey(pdfName)) {
String filePath = fileDir + fileName; String filePath = fileDir + fileName;
if (!new File(filePath).exists()) { if (!new File(filePath).exists()) {
ReturnResponse<String> response = downloadUtils.downLoad(decodedUrl, suffix, null, needEncode); ReturnResponse<String> response = downloadUtils.downLoad(decodedUrl, suffix, null);
if (0 != response.getCode()) { if (0 != response.getCode()) {
model.addAttribute("msg", response.getMsg()); model.addAttribute("msg", response.getMsg());
return "fileNotSupported"; return "fileNotSupported";
......
...@@ -69,8 +69,7 @@ ...@@ -69,8 +69,7 @@
fulls += ",resizable"; // 对于不支持screen属性的浏览器,可以手工进行最大化。 manually fulls += ",resizable"; // 对于不支持screen属性的浏览器,可以手工进行最大化。 manually
} }
window.open("onlinePreview?url=" window.open("onlinePreview?url="
+ encodeURIComponent("${baseUrl}" + treeNode.fileName) + encodeURIComponent("${baseUrl}" + treeNode.fileName), "_blank",fulls);
+ "&needEncode=1", "_blank",fulls);
} }
} }
} }
......
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
// 每个data添加一列用来操作 // 每个data添加一列用来操作
$(data).each(function (index, item) { $(data).each(function (index, item) {
item.action = "<a class='btn btn-default' target='_blank' href='${baseUrl}onlinePreview?url=" item.action = "<a class='btn btn-default' target='_blank' href='${baseUrl}onlinePreview?url="
+ encodeURIComponent('${baseUrl}' + item.fileName ) +"&needEncode=1'>预览</a>" + + encodeURIComponent('${baseUrl}' + item.fileName ) +"'>预览</a>" +
"<a class='btn btn-default' target='_blank' href='javascript:void(0);' onclick='deleteFile(\""+item.fileName+"\")'>删除</a>"; "<a class='btn btn-default' target='_blank' href='javascript:void(0);' onclick='deleteFile(\""+item.fileName+"\")'>删除</a>";
}); });
return data; return data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment