js 代码优化

This commit is contained in:
jiangzeyin 2019-03-01 16:22:41 +08:00
parent c98a9b3968
commit 4308c09311
17 changed files with 279 additions and 305 deletions

View File

@ -37,6 +37,8 @@
8. 此项目完全不依赖数据库,随装随用
9. 整个服务器top监听
10. 查看项目运行进程占用的端口
11. 安全模式运行,更好的保证服务器稳定、避免误操作
12. 项目路径白名单模式,杜绝用户误操作系统文件
#### 项目截图

View File

@ -10,7 +10,6 @@ import cn.keepbx.jpom.model.ProjectInfoModel;
import cn.keepbx.jpom.service.manage.CommandService;
import cn.keepbx.jpom.service.manage.ManageService;
import cn.keepbx.jpom.service.oss.OssManagerService;
import cn.keepbx.jpom.service.user.UserService;
import com.alibaba.fastjson.JSONArray;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
@ -38,10 +37,8 @@ public class BuildController extends BaseController {
private ManageService manageService;
@Resource
private CommandService commandService;
@Resource
private UserService userService;
@RequestMapping(value = "build", method = RequestMethod.GET)
@RequestMapping(value = "build", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public String build(String id) throws IOException {
ProjectInfoModel projectInfoModel = manageService.getProjectInfo(id);
if (projectInfoModel != null && StrUtil.isNotEmpty(projectInfoModel.getBuildTag())) {
@ -52,24 +49,26 @@ public class BuildController extends BaseController {
return "manage/build";
}
@RequestMapping(value = "build_download", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = "build_download", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public String buildDownload(String id, String key) {
if (!userName.isProject(id)) {
return "redirect:error";
}
try {
ProjectInfoModel projectInfoModel = manageService.getProjectInfo(id);
if (projectInfoModel == null) {
return "error";
return "redirect:error";
}
return "redirect:" + ossManagerService.getUrl(key);
} catch (Exception e) {
DefaultSystemLog.ERROR().error("获取下载地址失败", e);
return "error";
return "redirect:error";
}
}
@RequestMapping(value = "build_install", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public String buildInstall(String id, String key) throws Exception {
// boolean manager = userService.isManager(id, getUserName());
if (!userName.isProject(id)) {
return JsonMessage.getString(400, "你没有对应操作权限操作!");
}

View File

@ -69,6 +69,9 @@ public class FileControl extends BaseController {
@RequestMapping(value = "getFileList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public String getFileList(String id) {
if (!userName.isProject(id)) {
return JsonMessage.getString(400, "你没有该操作权限操作!");
}
try {
// 查询项目路径
ProjectInfoModel pim = manageService.getProjectInfo(id);
@ -140,7 +143,7 @@ public class FileControl extends BaseController {
*
* @return File
*/
@RequestMapping(value = "download")
@RequestMapping(value = "download", method = RequestMethod.GET)
@ResponseBody
public String download() {
String id = getParameter("id");

View File

@ -14,7 +14,7 @@ import java.io.FileNotFoundException;
* json
*
* @author jiangzeyin
* date 2017/5/15
* @date 2017/5/15
*/
public class JsonUtil {

View File

@ -1,5 +1,7 @@
# description: Auto-starts boot
#!/bin/bash
# description: Auto-starts boot
# 变量
Tag="$2"
WebClose="$3"

View File

@ -8,10 +8,18 @@
<link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript">
var $;
layui.use(['layer', 'element', 'form'], function () {
var $, layer, form, element, table;
layui.use(['layer', 'element', 'form', 'table'], function () {
$ = layui.$;
element = layui.element;
layer = layui.layer;
form = layui.form;
table = layui.table;
//
try {
loadSuccess && loadSuccess();
} catch (e) {
}
});
function tabChange(options) {

View File

@ -99,12 +99,7 @@
</div>
</body>
<script type="text/javascript">
layui.use(['layer', 'element', 'form'], function () {
var $ = layui.$;
var element = layui.element;
var layer = layui.layer;
var form = layui.form;
function loadSuccess() {
// 左侧导航条事件
element.on('nav(menu)', function (data) {
var dataJSON = $(data.context).attr("data-options");
@ -193,7 +188,9 @@
// 退出系统
$('#li-exit').click(function () {
layer.confirm('确定退出系统?', {'title': '系统提示'}, function (index) {
layer.confirm('确定退出系统?', {
'title': '系统提示'
}, function (index) {
window.location.href = "/logout";
layer.close(index);
})
@ -213,6 +210,6 @@
// function closeallPage() {
// }
});
}
</script>
</html>

View File

@ -44,42 +44,39 @@
</div>
</body>
<script type="text/javascript">
layui.use(['form', 'carousel', 'layer'], function () {
var $ = layui.$;
var form = layui.form;
var carousel = layui.carousel;
var layer = layui.layer;
carousel.render({
elem: '#div-carousel',
width: '100%',
height: '100%',
anim: 'fade',
arrow: 'none',
indicator: 'none'
});
form.on('submit(from_login)', function (data) {
$.ajax({
url: '/install_submit.json',
type: 'POST',
dataType: 'json',
data: data.field,
success: function (data) {
if (200 == data.code) {
window.location.href = '/index';
} else {
layer.msg(data.msg);
}
},
error: function (err) {
layer.alert(err.msg);
}
function loadSuccess() {
layui.use(['carousel'], function () {
var carousel = layui.carousel;
carousel.render({
elem: '#div-carousel',
width: '100%',
height: '100%',
anim: 'fade',
arrow: 'none',
indicator: 'none'
});
form.on('submit(from_login)', function (data) {
$.ajax({
url: '/install_submit.json',
type: 'POST',
dataType: 'json',
data: data.field,
success: function (data) {
if (200 == data.code) {
window.location.href = '/index';
} else {
layer.msg(data.msg);
}
},
error: function (err) {
layer.alert(err.msg);
}
});
return false;
});
return false;
});
});
}
</script>
</html>

View File

@ -52,46 +52,44 @@
</div>
</body>
<script type="text/javascript">
layui.use(['form', 'carousel', 'layer'], function () {
var $ = layui.$;
var form = layui.form;
var carousel = layui.carousel;
var layer = layui.layer;
function loadSuccess() {
layui.use(['carousel'], function () {
var carousel = layui.carousel;
//判断是否在iframe中, 如果是,刷新父页面
if (self != top) {
parent.window.location.replace(window.location.href);
}
//判断是否在iframe中, 如果是,刷新父页面
if (self != top) {
parent.window.location.replace(window.location.href);
}
carousel.render({
elem: '#div-carousel',
width: '100%',
height: '100%',
anim: 'fade',
arrow: 'none',
indicator: 'none'
});
form.on('submit(from_login)', function (data) {
$.ajax({
url: '/userLogin',
type: 'POST',
dataType: 'json',
data: data.field,
success: function (data) {
if (200 == data.code) {
window.location.href = '/index';
} else {
layer.msg(data.msg);
}
},
error: function (err) {
layer.alert(err.msg);
}
carousel.render({
elem: '#div-carousel',
width: '100%',
height: '100%',
anim: 'fade',
arrow: 'none',
indicator: 'none'
});
form.on('submit(from_login)', function (data) {
$.ajax({
url: '/userLogin',
type: 'POST',
dataType: 'json',
data: data.field,
success: function (data) {
if (200 == data.code) {
window.location.href = '/index';
} else {
layer.msg(data.msg);
}
},
error: function (err) {
layer.alert(err.msg);
}
});
return false;
});
return false;
});
});
}
</script>
</html>

View File

@ -43,10 +43,7 @@
</div>
</body>
<script type="text/javascript">
layui.use(['layer', 'element', 'table', 'form'], function () {
var $ = layui.$;
var layer = layui.layer;
function loadSuccess() {
$("button[name='install']").click(function () {
var that = $(this);
var name = that.attr("data-name");
@ -82,6 +79,6 @@
});
});
});
}
</script>
</html>

View File

@ -9,20 +9,22 @@
<body>
<div class="console">
#if($manager)
<div class="layui-row">
<!-- layui-elem-quote -->
#if($logSize)
<button id="export" class="layui-btn layui-btn-sm">导出日志(<span id="logSize">$logSize</span>)</button>
#end
<div class="layui-row">
<!-- layui-elem-quote -->
#if($logSize)
<button id="export" class="layui-btn layui-btn-sm">导出日志(<span id="logSize">$logSize</span>)</button>
#end
<a href="javascript:;" class="btn-op layui-btn layui-btn-sm" op="start">启动</a>
<a href="javascript:;" class="btn-op layui-btn layui-btn-sm layui-btn-warm" op="restart">重启</a>
<a href="javascript:;" class="btn-op layui-btn layui-btn-sm layui-btn-danger" op="stop">停止</a>
<div class="status">
<div class="status-div"></div>
<span></span>
<a href="javascript:;" class="btn-op layui-btn layui-btn-sm" op="start">启动</a>
<a href="javascript:;" class="btn-op layui-btn layui-btn-sm layui-btn-warm" op="restart">重启</a>
<a href="javascript:;" class="btn-op layui-btn layui-btn-sm layui-btn-danger" op="stop">停止</a>
<div class="status">
<div class="status-div"></div>
<span></span>
</div>
</div>
</div>
#end
<div class="terminal"></div>
</div>
</body>
@ -33,11 +35,7 @@
var loopLog = false;
var loopLogTime;
layui.use(['layer', 'element', 'table', 'form'], function () {
var $ = layui.$;
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
function loadSuccess() {
var showLogDom = $('.console .terminal');
@ -53,10 +51,10 @@
// 如果是
if (data.data.indexOf('{') === 0) {
var json_data = JSON.parse(data.data);
var op = json_data.op;
if (json_data.code !== 200) {
layer.msg(json_data.msg);
}
var op = json_data.op;
switch (op) {
case 'status':
case 'start':
@ -159,7 +157,6 @@
$('#export').on('click', function () {
location.href = "export.html?id=" + projectInfo.id;
});
});
}
</script>
</html>

View File

@ -123,13 +123,7 @@
</div>
</body>
<script type="text/javascript">
layui.use(['layer', 'element', 'table', 'form'], function () {
var $ = layui.$;
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
function loadSuccess() {
// 提交项目表单
form.on('submit(submitProject)', function (data) {
$.ajax({
@ -191,6 +185,6 @@
});
});
});
});
}
</script>
</html>

View File

@ -37,153 +37,151 @@
</script>
<script type="text/javascript">
var id = '$id';
layui.use(['layer', 'element', 'table', 'form', 'upload'], function () {
var $ = layui.$;
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
var upload = layui.upload;
table.render({
id: 'table_file',
elem: '#tab_file',
url: '/file/getFileList',
method: 'post',
height: 'full-52',
even: true,
where: {
id: id
},
cols: [[
{field: 'index', title: '编号', width: '10%'},
{field: 'filename', title: '文件名称', width: '30%'},
{field: 'modifytime', title: '修改时间', width: '15%'},
{field: 'filesize', title: '文件大小', width: '15%'},
{field: 'op', title: '操作', toolbar: '#bar_projects'}
]],
loading: true,
response: {
statusCode: 200
}
});
var uploadInst = upload.render({
elem: '#uploadFile',
accept: 'file',
data: {
id: id
},
multiple: true,
url: '/file/upload',
before: function () {
layer.load(1, {
shade: [0.5, '#fff'] //0.1透明度的白色背景
});
},
allDone: function (obj) {
layer.msg("文件总数:" + obj.total + " 成功上传:" + obj.successful + " 上传失败:" + obj.aborted);
setTimeout(function () {
table.reload('table_file', {
height: 'full-52'
});
layer.closeAll();
}, 2000);
},
done: function (res, index, upload) {
//layer.msg('success');
},
error: function () {
layer.msg('fail');
}
});
// 点击'上传文件'事件
$('#refresh').on('click', function () {
table.reload('table_file', {height: 'full-52'});
});
// 点击'上传文件'事件
$('#clear').on('click', function () {
layer.confirm('确定清空此项目文件吗?',
{title: '系统提示'},
function (index) {
layer.close(index);
$.ajax({
url: '/file/clear',
type: 'POST',
dataType: 'json',
data: {
id: id
},
success: function (data) {
if (200 === data.code) {
layer.msg(data.msg);
// 刷新项目列表
table.reload('table_file', {
height: 'full-52'
});
} else {
layer.msg(data.msg);
}
},
error: function (err) {
layer.msg('删除失败!');
}
});
});
});
// 表格工具条事件
table.on('tool(tab_file)', function (obj) {
var data = obj.data;
var event = obj.event;
if ('delete' === event) {
// 删除文件
deleteFile(data);
}
if ('download' === event) {
// 下载文件
downloadFile(data);
}
});
/**
* 下载文件
* @param data
*/
function downloadFile(data) {
var url = "/file/download?id=" + data.projectid + "&filename=" + data.filename
self.location.href = url;
}
// 删除文件
function deleteFile(data) {
layer.confirm('确定删除文件 ' + data.filename + '', {title: '系统提示'}, function (index) {
layer.close(index);
$.ajax({
url: '/file/deleteFile',
type: 'POST',
dataType: 'json',
data: {
id: data.projectid,
filename: data.filename
},
success: function (data) {
if (200 === data.code) {
layer.msg('删除成功!');
// 刷新项目列表
table.reload('table_file', {height: 'full-52'});
} else {
layer.msg(data.msg);
}
},
error: function (err) {
layer.msg('删除失败!');
}
});
function loadSuccess() {
layui.use(['upload'], function () {
var upload = layui.upload;
table.render({
id: 'table_file',
elem: '#tab_file',
url: '/file/getFileList',
method: 'post',
height: 'full-52',
even: true,
where: {
id: id
},
cols: [[
{field: 'index', title: '编号', width: '10%'},
{field: 'filename', title: '文件名称', width: '30%'},
{field: 'modifytime', title: '修改时间', width: '15%'},
{field: 'filesize', title: '文件大小', width: '15%'},
{field: 'op', title: '操作', toolbar: '#bar_projects'}
]],
loading: true,
response: {
statusCode: 200
}
});
}
});
var uploadInst = upload.render({
elem: '#uploadFile',
accept: 'file',
data: {
id: id
},
multiple: true,
url: '/file/upload',
before: function () {
layer.load(1, {
shade: [0.5, '#fff'] //0.1透明度的白色背景
});
},
allDone: function (obj) {
layer.msg("文件总数:" + obj.total + " 成功上传:" + obj.successful + " 上传失败:" + obj.aborted);
setTimeout(function () {
table.reload('table_file', {
height: 'full-52'
});
layer.closeAll();
}, 2000);
},
done: function (res, index, upload) {
//layer.msg('success');
},
error: function () {
layer.msg('fail');
}
});
// 点击'上传文件'事件
$('#refresh').on('click', function () {
table.reload('table_file', {height: 'full-52'});
});
// 点击'上传文件'事件
$('#clear').on('click', function () {
layer.confirm('确定清空此项目文件吗?',
{title: '系统提示'},
function (index) {
layer.close(index);
$.ajax({
url: '/file/clear',
type: 'POST',
dataType: 'json',
data: {
id: id
},
success: function (data) {
if (200 === data.code) {
layer.msg(data.msg);
// 刷新项目列表
table.reload('table_file', {
height: 'full-52'
});
} else {
layer.msg(data.msg);
}
},
error: function (err) {
layer.msg('删除失败!');
}
});
});
});
// 表格工具条事件
table.on('tool(tab_file)', function (obj) {
var data = obj.data;
var event = obj.event;
if ('delete' === event) {
// 删除文件
deleteFile(data);
}
if ('download' === event) {
// 下载文件
downloadFile(data);
}
});
/**
* 下载文件
* @param data
*/
function downloadFile(data) {
var url = "/file/download?id=" + data.projectid + "&filename=" + data.filename
self.location.href = url;
}
// 删除文件
function deleteFile(data) {
layer.confirm('确定删除文件 ' + data.filename + '', {title: '系统提示'}, function (index) {
layer.close(index);
$.ajax({
url: '/file/deleteFile',
type: 'POST',
dataType: 'json',
data: {
id: data.projectid,
filename: data.filename
},
success: function (data) {
if (200 === data.code) {
layer.msg('删除成功!');
// 刷新项目列表
table.reload('table_file', {height: 'full-52'});
} else {
layer.msg(data.msg);
}
},
error: function (err) {
layer.msg('删除失败!');
}
});
});
}
});
}
</script>
</html>

View File

@ -12,7 +12,8 @@
.info {
margin-top: 30px;
}
.but{
.but {
width: 50px;
padding: 10px;
background: #cccccc;
@ -34,15 +35,8 @@
</body>
<script type="text/javascript">
layui.use(['layer', 'element', 'form'], function () {
var element = layui.element;
var layer = layui.layer;
var form = layui.form;
var $ = layui.$;
})
function loadSuccess() {
}
</script>
</html>

View File

@ -89,14 +89,9 @@
</script>
<script type="text/javascript">
var table;
var groupMap = new Map();
layui.use(['layer', 'element', 'table', 'form'], function () {
var $ = layui.$;
table = layui.table;
var form = layui.form;
var layer = layui.layer;
const groupMap = new Map();
function loadSuccess() {
table.render({
id: 'table_project',
elem: '#tab_project',
@ -198,6 +193,10 @@
content: 'build?id=' + data.id
});
} else if ('ram' === event) {
if (!data.status) {
layer.msg('请先运行程序!');
return;
}
layer.open({
type: 2,
title: '内存',
@ -245,8 +244,7 @@
title: data.id + ' - 管理',
});
}
})
;
}
function reloadTable() {
table.reload('table_project', {

View File

@ -37,12 +37,7 @@
</div>
</body>
<script type="text/javascript">
layui.use(['form', 'layer'], function () {
var $ = layui.$;
var form = layui.form;
var layer = layui.layer;
function loadSuccess() {
form.on('submit(formDemo)', function (data) {
$.ajax({
url: './whitelistDirectory_submit',
@ -63,7 +58,7 @@
});
return false;
});
});
}
</script>
</html>

View File

@ -39,7 +39,7 @@
<div class="layui-inline">
<label class="layui-form-label">登录名</label>
<div class="layui-input-block">
<input type="text" name="id" placeholder="登录名" required lay-verify="required"
<input type="text" name="id" placeholder="登录名,创建后不能修改" required lay-verify="required"
class="layui-input">
</div>
</div>
@ -99,12 +99,7 @@
</script>
<script type="text/javascript">
layui.use(['layer', 'element', 'table', 'form', 'laytpl'], function () {
var $ = layui.$;
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
var laytpl = layui.laytpl;
function loadSuccess() {
table.render({
id: 'tab_user',
@ -261,6 +256,6 @@
});
});
}
});
}
</script>
</html>