You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SOP/sop-admin/sop-admin-front/pages/service/serviceList.js

101 lines
3.9 KiB

6 years ago
lib.config({
base: '../../assets/lib/layuiext/module/'
}).extend({
treetable: 'treetable-lay/treetable'
}).use(['element', 'table', 'form', 'treetable'], function () {
var table = layui.table;
6 years ago
var layer = layui.layer;
var form = layui.form;
var treetable = layui.treetable;
// 渲染表格
var renderTable = function (params) {
6 years ago
layer.load(2);
treetable.render({
elem: '#treeTable',
6 years ago
treeColIndex: 1,
treeSpid: 0,
treeIdName: 'id',
treePidName: 'parentId',
treeDefaultClose: false,
6 years ago
treeLinkage: false,
url: ApiUtil.createUrl('service.instance.list', params),
6 years ago
page: false,
cols: [[
{type: 'numbers'},
6 years ago
{field: 'name', title: '服务名称(serviceId)', width: 200},
6 years ago
{field: 'instanceId', title: 'instanceId', width: 220},
{field: 'ipAddr', title: 'IP地址', width: 150},
{field: 'serverPort', title: '端口号', width: 100},
6 years ago
{field: 'status', title: '服务状态', width: 100, templet: function (row) {
if (row.parentId > 0) {
var html = [];
if (row.status === 'UP') {
return '<span class="x-green">已上线</span>'
}
if (row.status === 'OUT_OF_SERVICE') {
return '<span class="x-red">已下线</span>'
}
}
return '';
}},
6 years ago
{field: 'updateTime', title: '最后更新时间', width: 150},
6 years ago
{fixed: 'right', title: '操作', width: 150, templet: function (row) {
if (row.parentId > 0) {
var html = [];
if (row.status === 'UP') {
html.push('<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="offline">下线</a>');
}
if (row.status === 'OUT_OF_SERVICE') {
html.push('<a class="layui-btn layui-btn-xs" lay-event="online">上线</a>');
}
return html.join('');
}
return '';
}}
6 years ago
]],
done: function () {
layer.closeAll('loading');
}
});
//监听单元格事件
table.on('tool(treeTableFilter)', function(obj) {
if (obj.event === 'offline') {
var data = obj.data;
layer.confirm('确定要下线【'+data.name+'】吗?', {icon: 3, title:'提示'}, function(index){
var params = {
serviceId: data.name
, instanceId: data.instanceId
};
ApiUtil.post('service.instance.offline', params, function (resp) {
layer.alert('修改成功');
});
layer.close(index);
});
}
if (obj.event === 'online') {
var data = obj.data;
layer.confirm('确定要上线【'+data.name+'】吗?', {icon: 3, title:'提示'}, function(index){
var params = {
serviceId: data.name
, instanceId: data.instanceId
};
ApiUtil.post('service.instance.online', params, function (resp) {
layer.alert('修改成功');
});
layer.close(index);
});
}
});
6 years ago
};
renderTable();
form.on('submit(searchFilter)', function(data){
var param = data.field;
renderTable(param)
6 years ago
return false;
});
});