EasySpider/ServiceGrid/frontEnd/invokeService.html
NaiboWang-Alienware 3646513d5b New version
2022-10-17 13:38:26 +08:00

204 lines
8.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<script src="jquery-3.4.1.min.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="vue.js"></script>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css"></link>
<title>Service Invoke</title>
<style>
table {
table-layout: auto;
}
table,
td,
th,
tr {
border-color: black!important;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
max-width: 400px;
min-width: 150px;
}
.ID {
width: 10%;
}
</style>
</head>
<body>
<div class="row" style="margin-top: 40px;">
<div class="col-md-6" style="margin:0 auto" id="serviceList" v-if="show">
<h4 style="text-align: center;">Service Information</h4>
<p>Service Name: {{service["name"]}}</p>
<p style="word-wrap: break-word;word-break: break-all;overflow: hidden;max-height: 100px;">Service Description: {{service["desc"]}}</p>
<p style="word-wrap: break-word;word-break: break-all;overflow: hidden;max-height: 100px;">URL: {{backEndAddressServiceWrapper}}/backEnd/invokeService?id={{service["id"]}}</p>
<p>Please Input Parameters: </p>
<form id="form">
<table class="table table-bordered">
<tbody>
<tr>
<th style="min-width: 50px;">ID</th>
<th>Parameter Name</th>
<th>Invoke Name</th>
<th>Parameter Type</th>
<th>Parameter Value</th>
</tr>
<tr v-if="service.inputParameters.length>0" v-for="i in service.inputParameters.length">
<td style="min-width: 50px;">{{i}}</td>
<td>{{service.inputParameters[i-1]["nodeName"]}}</td>
<td>{{service.inputParameters[i-1]["name"]}}</td>
<td>{{service.inputParameters[i-1]["type"]}}</td>
<td><textarea style="min-height: 100px;min-width: 300px;" v-bind:name="service.inputParameters[i-1]['name']" class="form-control" v-model="service.inputParameters[i-1]['value']"></textarea></td>
</tr>
</tbody>
</table>
</form>
<button style="margin-left: 5px;" v-on:click="localExcuteInstant" class="btn btn-primary">Directly Run locally</button>
<button style="margin-left: 5px;" v-on:click="remoteExcuteInstant" class="btn btn-primary">Directly Run Remotely</button>
<div style="margin-bottom: 10px;">
<label style="margin-top: 10px;">Task ID:</label>
<input class="form-control" v-model="ID"></input>
<p></p>
<p>提示点击下方按钮获得任务ID然后根据此ID进行服务执行也可自己POST调用接口得到ID具体参照POST调用文档。</p>
<a href="javascript:void(0)" v-on:click="invokeService" class="btn btn-primary">Get Task ID</a>
<button v-on:click="localExcute" style="margin-left: 8px;" class="btn btn-primary">Run locally</button>
<button v-on:click="remoteExcute" style="margin-left: 8px;" class="btn btn-primary">Run remotely</button></div>
</div>
</div>
</div>
</body>
</html>
<script>
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]);
return ""; //返回参数值,默认后台地址
}
var sId = getUrlParam('id');
var app = new Vue({
el: '#serviceList',
data: {
service: {},
show: false, //是否渲染
ID: "暂无",
backEndAddressServiceWrapper: getUrlParam("backEndAddressServiceWrapper"),
},
methods: {
invokeService: function() {
if (confirm("确定要获得任务ID吗")) {
var para = {};
var t = $('#form').serializeArray();
t.forEach(function(item, index) {
para[item.name] = item.value;
});
$.post(app.$data.backEndAddressServiceWrapper + "/backEnd/invokeService?id=" + sId, {
id: this.service.id,
paras: JSON.stringify(para)
}, function(result) {
app.$data.ID = result; //得到返回的ID
});
}
},
localExcute: function() {
if (this.ID == "暂无") {
alert("请先获得任务ID");
return;
}
if (confirm("确定要本地执行任务吗?")) {
let message = { //显示flowchart
type: 5, //消息类型,调用执行程序
message: {
"id": app.$data.ID,
}
};
ws.send(JSON.stringify(message));
}
},
remoteExcute: function() {
if (this.ID == "暂无") {
alert("请先获得任务ID");
return;
}
if (confirm("确定要远程执行任务吗?")) {
let message = { //显示flowchart
type: 5, //消息类型,调用执行程序
message: {
"id": app.$data.ID,
}
};
ws.send(JSON.stringify(message));
}
},
localExcuteInstant: function() {
if (confirm("确定要直接本地执行任务吗?")) {
var para = {};
var t = $('#form').serializeArray();
t.forEach(function(item, index) {
para[item.name] = item.value;
});
$.post(app.$data.backEndAddressServiceWrapper + "/backEnd/invokeService?id=" + sId, {
id: this.service.id,
paras: JSON.stringify(para)
}, function(result) {
let message = { //显示flowchart
type: 5, //消息类型,调用执行程序
message: {
"id": result,
}
};
ws.send(JSON.stringify(message));
});
}
},
remoteExcuteInstant: function() {
if (confirm("确定要直接远程执行任务吗?")) {
var para = {};
var t = $('#form').serializeArray();
t.forEach(function(item, index) {
para[item.name] = item.value;
});
$.post(app.$data.backEndAddressServiceWrapper + "/backEnd/invokeService?id=" + sId, {
id: this.service.id,
paras: JSON.stringify(para)
}, function(result) {
//待实现
});
}
},
}
});
$.get(app.$data.backEndAddressServiceWrapper + "/backEnd/queryService?id=" + sId, function(result) {
app.$data.service = result;
app.$data.show = true;
});
ws = new WebSocket("ws://localhost:8084");
ws.onopen = function() {
// Web Socket 已连接上,使用 send() 方法发送数据
console.log("已连接");
message = {
type: 0, //消息类型0代表链接操作
message: {
id: 1, //socket id
}
};
this.send(JSON.stringify(message));
};
ws.onclose = function() {
// 关闭 websocket
console.log("连接已关闭...");
};
</script>