invokeService.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <script src="jquery-3.4.1.min.js"></script>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <script src="vue.js"></script>
  9. <link rel="stylesheet" href="bootstrap/css/bootstrap.css"></link>
  10. <title>Service Invoke</title>
  11. <style>
  12. table {
  13. table-layout: auto;
  14. }
  15. table,
  16. td,
  17. th,
  18. tr {
  19. border-color: black!important;
  20. text-overflow: ellipsis;
  21. overflow: hidden;
  22. white-space: nowrap;
  23. max-width: 400px;
  24. min-width: 150px;
  25. }
  26. .ID {
  27. width: 10%;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32. <div class="row" style="margin-top: 40px;">
  33. <div class="col-md-6" style="margin:0 auto" id="serviceList" v-if="show">
  34. <h4 style="text-align: center;">Service Information</h4>
  35. <p>Service Name: {{service["name"]}}</p>
  36. <p style="word-wrap: break-word;word-break: break-all;overflow: hidden;max-height: 100px;">Service Description: {{service["desc"]}}</p>
  37. <p style="word-wrap: break-word;word-break: break-all;overflow: hidden;max-height: 100px;">URL: {{backEndAddressServiceWrapper}}/backEnd/invokeService?id={{service["id"]}}</p>
  38. <p>Please Input Parameters: </p>
  39. <form id="form">
  40. <table class="table table-bordered">
  41. <tbody>
  42. <tr>
  43. <th style="min-width: 50px;">ID</th>
  44. <th>Parameter Name</th>
  45. <th>Invoke Name</th>
  46. <th>Parameter Type</th>
  47. <th>Parameter Value</th>
  48. </tr>
  49. <tr v-if="service.inputParameters.length>0" v-for="i in service.inputParameters.length">
  50. <td style="min-width: 50px;">{{i}}</td>
  51. <td>{{service.inputParameters[i-1]["nodeName"]}}</td>
  52. <td>{{service.inputParameters[i-1]["name"]}}</td>
  53. <td>{{service.inputParameters[i-1]["type"]}}</td>
  54. <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>
  55. </tr>
  56. </tbody>
  57. </table>
  58. </form>
  59. <button style="margin-left: 5px;" v-on:click="localExcuteInstant" class="btn btn-primary">Directly Run locally</button>
  60. <button style="margin-left: 5px;" v-on:click="remoteExcuteInstant" class="btn btn-primary">Directly Run Remotely</button>
  61. <div style="margin-bottom: 10px;">
  62. <label style="margin-top: 10px;">Task ID:</label>
  63. <input class="form-control" v-model="ID"></input>
  64. <p></p>
  65. <p>提示:点击下方按钮获得任务ID,然后根据此ID进行服务执行;也可自己POST调用接口得到ID,具体参照POST调用文档。</p>
  66. <a href="javascript:void(0)" v-on:click="invokeService" class="btn btn-primary">Get Task ID</a>
  67. <button v-on:click="localExcute" style="margin-left: 8px;" class="btn btn-primary">Run locally</button>
  68. <button v-on:click="remoteExcute" style="margin-left: 8px;" class="btn btn-primary">Run remotely</button></div>
  69. </div>
  70. </div>
  71. </div>
  72. </body>
  73. </html>
  74. <script>
  75. function getUrlParam(name) {
  76. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  77. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  78. if (r != null) return unescape(r[2]);
  79. return ""; //返回参数值,默认后台地址
  80. }
  81. var sId = getUrlParam('id');
  82. var app = new Vue({
  83. el: '#serviceList',
  84. data: {
  85. service: {},
  86. show: false, //是否渲染
  87. ID: "暂无",
  88. backEndAddressServiceWrapper: getUrlParam("backEndAddressServiceWrapper"),
  89. },
  90. methods: {
  91. invokeService: function() {
  92. if (confirm("确定要获得任务ID吗?")) {
  93. var para = {};
  94. var t = $('#form').serializeArray();
  95. t.forEach(function(item, index) {
  96. para[item.name] = item.value;
  97. });
  98. $.post(app.$data.backEndAddressServiceWrapper + "/backEnd/invokeService?id=" + sId, {
  99. id: this.service.id,
  100. paras: JSON.stringify(para)
  101. }, function(result) {
  102. app.$data.ID = result; //得到返回的ID
  103. });
  104. }
  105. },
  106. localExcute: function() {
  107. if (this.ID == "暂无") {
  108. alert("请先获得任务ID!");
  109. return;
  110. }
  111. if (confirm("确定要本地执行任务吗?")) {
  112. let message = { //显示flowchart
  113. type: 5, //消息类型,调用执行程序
  114. message: {
  115. "id": app.$data.ID,
  116. }
  117. };
  118. ws.send(JSON.stringify(message));
  119. }
  120. },
  121. remoteExcute: function() {
  122. if (this.ID == "暂无") {
  123. alert("请先获得任务ID!");
  124. return;
  125. }
  126. if (confirm("确定要远程执行任务吗?")) {
  127. let message = { //显示flowchart
  128. type: 5, //消息类型,调用执行程序
  129. message: {
  130. "id": app.$data.ID,
  131. }
  132. };
  133. ws.send(JSON.stringify(message));
  134. }
  135. },
  136. localExcuteInstant: function() {
  137. if (confirm("确定要直接本地执行任务吗?")) {
  138. var para = {};
  139. var t = $('#form').serializeArray();
  140. t.forEach(function(item, index) {
  141. para[item.name] = item.value;
  142. });
  143. $.post(app.$data.backEndAddressServiceWrapper + "/backEnd/invokeService?id=" + sId, {
  144. id: this.service.id,
  145. paras: JSON.stringify(para)
  146. }, function(result) {
  147. let message = { //显示flowchart
  148. type: 5, //消息类型,调用执行程序
  149. message: {
  150. "id": result,
  151. }
  152. };
  153. ws.send(JSON.stringify(message));
  154. });
  155. }
  156. },
  157. remoteExcuteInstant: function() {
  158. if (confirm("确定要直接远程执行任务吗?")) {
  159. var para = {};
  160. var t = $('#form').serializeArray();
  161. t.forEach(function(item, index) {
  162. para[item.name] = item.value;
  163. });
  164. $.post(app.$data.backEndAddressServiceWrapper + "/backEnd/invokeService?id=" + sId, {
  165. id: this.service.id,
  166. paras: JSON.stringify(para)
  167. }, function(result) {
  168. //待实现
  169. });
  170. }
  171. },
  172. }
  173. });
  174. $.get(app.$data.backEndAddressServiceWrapper + "/backEnd/queryService?id=" + sId, function(result) {
  175. app.$data.service = result;
  176. app.$data.show = true;
  177. });
  178. ws = new WebSocket("ws://localhost:8084");
  179. ws.onopen = function() {
  180. // Web Socket 已连接上,使用 send() 方法发送数据
  181. console.log("已连接");
  182. message = {
  183. type: 0, //消息类型,0代表链接操作
  184. message: {
  185. id: 1, //socket id
  186. }
  187. };
  188. this.send(JSON.stringify(message));
  189. };
  190. ws.onclose = function() {
  191. // 关闭 websocket
  192. console.log("连接已关闭...");
  193. };
  194. </script>