1、增加在线编辑文件格式控制,server端配置文件中fileFormat属性

This commit is contained in:
chenzhao 2020-11-04 14:36:47 +08:00
parent ee19336319
commit 89835e9bab
5 changed files with 57 additions and 7 deletions

View File

@ -30,6 +30,7 @@ public enum MethodFeature {
DEL_LOG("删除日志"),
CONFIG("配置"),
READ_FILE("读取文件"),
GET_FILE_FOMAT("获取在线编辑文件格式"),
UPDATE_CONFIG_FILE("更新文件"),
;

View File

@ -77,6 +77,8 @@ public enum NodeUrl {
Manage_File_ReadFile("/manage/file/readFile"),
Get_File_Format("/manage/file/getFileFormat"),
Manage_File_Download("/manage/file/download"),

View File

@ -1,6 +1,7 @@
package io.jpom.controller.node.manage.file;
import cn.hutool.core.io.FileUtil;
import cn.jiangzeyin.common.JsonMessage;
import com.alibaba.fastjson.JSONObject;
import io.jpom.common.BaseServerController;
import io.jpom.common.forward.NodeForward;
@ -11,6 +12,7 @@ import io.jpom.plugin.ClassFeature;
import io.jpom.plugin.Feature;
import io.jpom.plugin.MethodFeature;
import io.jpom.service.node.manage.ProjectInfoService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@ -31,6 +33,8 @@ public class ProjectFileControl extends BaseServerController {
@Resource
private ProjectInfoService projectInfoService;
@Value("${fileFormat}")
private String fileFormat;
/**
* 文件管理页面
*
@ -123,4 +127,19 @@ public class ProjectFileControl extends BaseServerController {
public String readFile() {
return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_File_ReadFile).toString();
}
/**
* 获取可编辑文件格式
*
* @return json
*/
@RequestMapping(value = "geFileFormat", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
@Feature(method = MethodFeature.GET_FILE_FOMAT)
public String geFileFormat() {
String[] file = fileFormat.split("\\|");
JSONObject jsonObject = new JSONObject();
jsonObject.put("fileFormat",file);
return JsonMessage.getString(200,"获取成功",jsonObject);
}
}

View File

@ -35,4 +35,6 @@ preload:
# 强制去掉空格
request:
trimAll: true
parameterXss: false
parameterXss: false
#在线编辑格式
fileFormat: txt|yml|conf|properties|ini

View File

@ -24,6 +24,7 @@
overflow-x: scroll;
padding: 10px;
}
#yaml {
color: white;
background-color: black;
@ -74,7 +75,9 @@
{{# if(!d.isDirectory){ }}
<a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-normal" lay-event="download">下载</a>
{{# } }}
{{# if(!d.isDirectory&&isAssetTypeAnImage(d.filename)){ }}
<a href="javascript:;" class="layui-btn layui-btn-sm layui-btn" lay-event="edit">编辑</a>
{{# } }}
</script>
<script type="text/javascript">
var zTreeObj;
@ -104,7 +107,26 @@
index: -1,
isDirectory: true
};
var fileType;
//加载可在线编辑文件类型
jQuery.ajax({
url: "./geFileFormat",
dataType: "json",
type: "get",
success: function(result) { //这里就是我出错的地方
fileType=result.data.fileFormat;
},
error: function(data) {
alert("请求出错");
alert(data);
}
});
//判断文件格式是否允许编辑
function isAssetTypeAnImage(ext) {
var index= ext.lastIndexOf(".");
ext = ext.substr(index+1);
return fileType.indexOf(ext.toLowerCase()) !== -1;
}
function loadSuccess() {
//
asyncLoadJs("[[${session.jpomProxyPath}]]/static/ztree/jquery.ztree.core.min.js", function () {
@ -292,20 +314,24 @@
//读取文件
function readFile(data) {
var path=$("#currentPath").text();
if(path!=''&path!=null){
path+='/';
}
loadingAjax({
url: './readFile',
data: {
id: '[[${id}]]',
filename: data.filename,
filename: path + data.filename,
levelName: data.levelName
},
success: function (fileData) {
console.log(fileData.msg);
//console.log(fileData.msg);
$("#yaml").val(fileData.msg);
layerOpen({
type: 1,
title: '编辑配置文件',
btn: ['确认','取消'],
btn: ['确认', '取消'],
content: $('#yaml'),
area: ['60%', '70%'],
shade: 0,
@ -315,7 +341,7 @@
url: './updateConfigFile',
data: {
id: '[[${id}]]',
filename: data.filename,
filename: $("#currentPath").text() + '\\' + data.filename,
levelName: data.levelName,
fileText: $("#yaml").val()
},
@ -326,7 +352,7 @@
}*/
}
});
},btn2: function(){
}, btn2: function () {
layer.close();
},
cancel: function () {