instance.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <!-- 配置服务器 -->
  2. <div class="plg-tab-container">
  3. <div class="plg-flex" style="height: 100%">
  4. <div class="flex_item" id="instanseServe">
  5. 配置实例
  6. </div>
  7. </div>
  8. </div>
  9. <style>
  10. .jdk-upload {
  11. position: absolute;
  12. }
  13. .jdk-upload .layui-upload-choose {
  14. position: absolute;
  15. top: 100px
  16. }
  17. .mt_15 {
  18. margin: 0;
  19. margin-top: 15px;
  20. }
  21. .validate_error .dhxform_label {}
  22. </style>
  23. <script>
  24. (function () {
  25. window.global_fun.instance = {};
  26. var comboList = [];
  27. var res_opts = {
  28. fixedLast: true,
  29. renderer: "instanseServe",
  30. url: APIS.settings.server.instanceInfo(),
  31. type: "get",
  32. // pageNum: "pageNo",//设置分页参数页码key值,默认为pageNum
  33. };
  34. var _typeLang = ["其它", "Java", "nodeJs", ".net"]
  35. res_opts.pagebar = {
  36. buttons: [
  37. { text: PLG_BUTTON.value.delBtn(), className: "layui-btn-danger plg-btn-height-auto", name: "delBtn" }
  38. ]
  39. },
  40. res_opts.columns = [
  41. {
  42. name: "id",
  43. id: "id",
  44. hidden: true
  45. },
  46. {
  47. name: "服务名",
  48. id: "servicename",
  49. align: "left",
  50. type: "ro",
  51. render: function (v) {
  52. return `<span style="color:#2F4056">${v}</span>`
  53. }
  54. },
  55. {
  56. name: "实例",
  57. id: "instancename",
  58. align: "left",
  59. type: "ro",
  60. render: function (v) {
  61. return `<span style="color:#2F4056">${v}</span>`
  62. }
  63. },
  64. {
  65. name: "容器名称",
  66. id: "containername",
  67. align: "left",
  68. type: "ro",
  69. render: function (v) {
  70. return `<span style="color:#2F4056">${v}</span>`
  71. }
  72. },
  73. {
  74. name: "服务器地址",
  75. id: "serverhost",
  76. align: "left",
  77. type: "ro",
  78. width: 180,
  79. render: function (v) {
  80. return `<span style="color:#2F4056">${v}</span>`
  81. }
  82. },
  83. {
  84. name: "应用类型",
  85. id: "type",
  86. align: "center",
  87. type: "ro",
  88. width: 100,
  89. render: function (v) {
  90. return _typeLang[v]
  91. }
  92. },
  93. {
  94. name: "端口",
  95. id: "port",
  96. align: "center",
  97. type: "ro",
  98. width: 100,
  99. render: function (v) {
  100. if (!v) {
  101. return `<span style="color:#888">无</span>`
  102. }
  103. }
  104. },
  105. {
  106. name: "容器状态",
  107. id: "status",
  108. align: "center",
  109. type: "ro",
  110. width: 120,
  111. render: function (v) {
  112. return v ? `<i class="layui-badge-dot layui-bg-blue"></i> 启动` : `<i class="layui-badge-dot"></i> 末启动`
  113. }
  114. },
  115. {
  116. name: "版本号",
  117. id: "version",
  118. align: "left",
  119. type: "ro",
  120. width: 120,
  121. render: function (v) {
  122. if (!v) {
  123. return `<span style="color:#888">末定义</span>`
  124. }
  125. }
  126. },
  127. {
  128. id: "op",
  129. name: "操作",
  130. type: 'button',
  131. width: 180,
  132. align: "center",
  133. render: function (v, d) {
  134. return `部署应用^global_fun.instance.arrangeClick,启动^global_fun.instance.toggleClick,删除^global_fun.instance.deleteClick`;
  135. }
  136. }
  137. ];
  138. res_opts.toolbar = [{
  139. type: 'row',
  140. blockOffset: 0,
  141. className: "layui-col-md12",
  142. list: [
  143. {
  144. type: "row",
  145. className: "layui-col-md6",
  146. blockOffset: 0,
  147. list: [
  148. {
  149. type: "combo",
  150. className: "layui-col-md4",
  151. name: "serverhost",
  152. label: "服务器IP:",
  153. placeholder: "选择或输入IP",
  154. options: [
  155. { value: '', text: '' },
  156. ]
  157. },
  158. {
  159. className: "layui-col-md4",
  160. type: "input",
  161. name: "servicename",
  162. label: "服务名:",
  163. placeholder: "跟踞服务名查询"
  164. },
  165. {
  166. type: "button",
  167. className: "left",
  168. name: "selectAllBtn",
  169. value: PLG_BUTTON.value.searchBtn()
  170. },
  171. {
  172. type: "button",
  173. name: "resetBtn",
  174. className: "left",
  175. value: PLG_BUTTON.value.resetBtn()
  176. },
  177. ]
  178. },
  179. {
  180. type: "block",
  181. className: "layui-col-md6 right",
  182. blockOffset: 0,
  183. list: [
  184. {
  185. type: "button",
  186. name: "addBtn",
  187. value: PLG_BUTTON.value.addBtn() + "服务实例"
  188. }
  189. ]
  190. }]
  191. }];
  192. function getAllServersList(combo, value) {
  193. if (!combo) return
  194. Prolog.ajax({
  195. url: APIS.settings.server.getAllServers(),
  196. type: "get",
  197. dataType: "json",
  198. success: function (data) {
  199. if (data.success) {
  200. var data = data.data;
  201. var opt = [];
  202. data.forEach(function (item, index) {
  203. opt.push([item.serverhost, item.serverhost + " - " + item.servername])
  204. });
  205. combo.addOption(opt);
  206. combo.setComboValue(value);
  207. } else {
  208. return console.error("获取服务器列表信息错误");
  209. }
  210. },
  211. error: function (XMLHttpRequest, textStatus, errorThrown) {
  212. console.error("获取服务器列表信息错误:" + XMLHttpRequest.status);
  213. }
  214. });
  215. };
  216. res_opts.formData = [{
  217. type: "row",
  218. list: [{
  219. type: "settings",
  220. labelWidth: 90,
  221. position: "label-left",
  222. labelAlign: "right"
  223. },
  224. {
  225. type: "hidden",
  226. name: "id",
  227. label: "id",
  228. },
  229. {
  230. type: "combo",
  231. name: "serverhost",
  232. className: 'combo',
  233. label: "选择服务器:",
  234. inputWidth: "305",
  235. required: true,
  236. options: [
  237. { value: '', text: '请选择服务器IP' },
  238. ]
  239. },
  240. {
  241. type: "combo",
  242. name: "type",
  243. className: 'combo',
  244. label: "应用类型:",
  245. inputWidth: "305",
  246. required: true,
  247. options: [
  248. { value: '', text: '请选择' },
  249. { value: 1, text: _typeLang[1] },
  250. { value: 2, text: _typeLang[2] },
  251. { value: 3, text: _typeLang[3] },
  252. { value: 0, text: _typeLang[0] }
  253. ]
  254. },
  255. {
  256. type: "input",
  257. name: "containername",
  258. label: "容器名:",
  259. required: true,
  260. validate: 'NotEmpty',
  261. placeholder: _t("请输入容器名")
  262. },
  263. {
  264. type: "input",
  265. name: "servicename",
  266. label: "服务名:",
  267. required: true,
  268. validate: "NotEmpty",
  269. placeholder: _t("不允许包含中文,对应applicationName")
  270. },
  271. {
  272. type: "input",
  273. name: "instancename",
  274. label: "实例名:",
  275. required: true,
  276. validate: "NotEmpty",
  277. placeholder: _t("不允许包含中文,对应instanceId")
  278. },
  279. {
  280. type: "row",
  281. className: "layui-col-md12",
  282. list: [
  283. {
  284. type: "input",
  285. className: "layui-col-md6",
  286. name: "port",
  287. label: "端口:",
  288. required: true,
  289. validate: "NotEmpty,NotNegativeNume",
  290. placeholder: "例:9809"
  291. },
  292. {
  293. type: "input",
  294. className: "layui-col-md6",
  295. name: "version",
  296. label: "版本号:",
  297. placeholder: "例:1.0.0"
  298. }
  299. ]
  300. }
  301. ]
  302. }
  303. ];
  304. var res_inst = new AdminPlant({
  305. instance: new PlgGrid(setConfig(res_opts)).loadData(),
  306. addBtnUrl: APIS.settings.server.instanceInfo(),
  307. // editBtnUrl: APIS.settings.server.update(),
  308. // delBtnUrl: APIS.settings.server.deleteAll(),
  309. // downBtnUrl: APIS.settings.server.download(),
  310. // importBtnUrl: APIS.settings.server.import(),
  311. }).init();
  312. getAllServersList(res_inst.PlgGridInstance.getToolBarForm().getCombo("serverhost"), "");
  313. res_inst.showDialogAfter(function (gridForm, data) {
  314. getAllServersList(gridForm.getCombo("serverhost"), gridForm.getFormData().serverhost);
  315. })
  316. window.global_fun.instance.deleteClick = function (id) {
  317. res_inst.PlgGridInstance.selectRowById(id);
  318. res_inst.delBtnUrl = APIS.settings.server.instanceInfo() + '/' + id;
  319. res_inst.delBtn('DELETE', null);
  320. };
  321. //部署
  322. window.global_fun.instance.arrangeClick = function (id) {
  323. // res_inst.PlgGridInstance.selectRowById(id);
  324. layer.confirm("是否部署应用", {
  325. title: '提示',
  326. btn: ["确定", "取消"] //按钮
  327. }, function (index) {
  328. layer.close(index);
  329. var _form = [{
  330. type: "row",
  331. list: [{
  332. type: "settings",
  333. labelWidth: 90,
  334. position: "label-left",
  335. labelAlign: "right"
  336. },
  337. {
  338. type: "hidden",
  339. name: "instanceId",
  340. value: id
  341. },
  342. {
  343. type: "combo",
  344. name: "applicationfile",
  345. label: "环境配置:",
  346. validate: "NotEmpty",
  347. required: true,
  348. placeholder: "",
  349. value: "prod",
  350. options: [
  351. { value: "pre", text: "pre" },
  352. { value: "prod", text: "prod" },
  353. { value: "test", text: "test" },
  354. { value: "dev", text: "dev" }
  355. ]
  356. },
  357. {
  358. type: "input",
  359. name: "command",
  360. label: "JVM参数:",
  361. required: true,
  362. validate: 'NotEmpty',
  363. rows: 3, labelTop: -20,
  364. value: "-Xms1g -Xmx2g -Xmn512m -Xss256k",
  365. placeholder: "例:-Xms1g -Xmx2g -Xmn512m -Xss256k"
  366. },
  367. {
  368. type: "block",
  369. className: "mt_15 right",
  370. list: [
  371. {
  372. type: "label",
  373. name: "fileName",
  374. label: "",
  375. },
  376. {
  377. type: "newcolumn"
  378. },
  379. {
  380. type: "button",
  381. name: "selectFile",
  382. value: '<i class="iconfont p-icon-daoru" style="color:#467cfd"></i> 选择文件',
  383. },
  384. {
  385. type: "newcolumn"
  386. },
  387. {
  388. type: "button",
  389. className: "btn-normal",
  390. name: "upload",
  391. value: '开始上传',
  392. disabled: true
  393. }
  394. ]
  395. },
  396. {
  397. type: "template",
  398. hidden: true,
  399. className: "jdk-upload left",
  400. format: function (name, value) {
  401. return `
  402. <button type="button" class="layui-btn layui-btn-primary" id="selectFile">
  403. `
  404. }
  405. }
  406. ]
  407. }
  408. ];
  409. var gridForm = new PlgForm({ items: _form });
  410. PlgDialog.open({
  411. title: '部署应用',
  412. content: `<div id="arrange"></div>`,
  413. closeBtn: 1,
  414. type: 1,
  415. area: ["400px", "250px"],
  416. resize: true,
  417. tipsMore: true,
  418. btn: null,
  419. // cancel: function(index, layero){
  420. // gridForm=null
  421. // return false;
  422. // } ,
  423. success: function (ayero, index2) {
  424. gridForm.renderTo("arrange");
  425. var _selectFile = $("#selectFile");
  426. var _file_data = null;
  427. Prolog.upload({
  428. elem: _selectFile,
  429. auto: false,//不自动上传
  430. accept: 'file', //普通文件
  431. exts: '',
  432. multiple: false,
  433. acceptMime: "",
  434. choose: function (obj) {
  435. obj.preview(function (index, file, result) {
  436. gridForm.setItemLabel("fileName", file.name);
  437. gridForm.enableItem("upload");
  438. _file_data = {
  439. file: file,
  440. command: gridForm.getItemValue("command"),
  441. applicationfile: gridForm.getItemValue("applicationfile"),
  442. instanceId: gridForm.getItemValue("instanceId")
  443. };
  444. });
  445. }
  446. }, true);
  447. gridForm.on("onButtonClick", function (name) {
  448. if (name == "selectFile") {
  449. if (!gridForm.validate()) return false;
  450. _selectFile.click();
  451. } else if (name == "upload") {
  452. if (_file_data !== null) {
  453. if (!gridForm.validate()) return false;
  454. const formData = new FormData();
  455. Object.keys(_file_data).forEach(key => {
  456. formData.append(key, _file_data[key]);
  457. });
  458. var closeLoad = Prolog.loading2()
  459. Prolog.ajax({
  460. url: APIS.settings.server.setArrange(),
  461. type: "post",
  462. processData: false,
  463. contentType: false,
  464. data: formData,
  465. success: function (res) {
  466. if (res.success) {
  467. layer.closeAll()
  468. layer.msg(res.message);
  469. } else {
  470. layer.open({
  471. title: 'message'
  472. , content: res.message || "上传错误"
  473. });
  474. }
  475. closeLoad();
  476. },
  477. error: function (XMLHttpRequest, textStatus, errorThrown) {
  478. console.error("获取服务器列表信息错误:" + XMLHttpRequest.status);
  479. layer.open({
  480. title: 'message'
  481. , content: XMLHttpRequest.status
  482. });
  483. closeLoad();
  484. }
  485. });
  486. }
  487. }
  488. })
  489. },
  490. });
  491. }, function () {
  492. close()
  493. });
  494. };
  495. //启动
  496. window.global_fun.instance.toggleClick = function (id, data) {
  497. layer.confirm("是否启动容器", {
  498. title: _t("提示"),
  499. btn: [_t("确定"), _t("取消")] //按钮
  500. }, function (index) {
  501. var close = PlgDialog.loading2();
  502. Prolog.ajax({
  503. url: APIS.settings.server.toggleContainer(),
  504. type: "post",
  505. data: {
  506. host: data.serverhost,
  507. containerName: data.containername,
  508. type: data.type
  509. },
  510. success: function (res) {
  511. if (res.success) {
  512. layer.msg(res.message);
  513. res_inst.PlgGridInstance.reload();
  514. } else {
  515. layer.open({
  516. title: 'message'
  517. , content: res.message || "启动错误"
  518. });
  519. }
  520. close();
  521. layer.close(index);
  522. },
  523. error: function (XMLHttpRequest, textStatus, errorThrown) {
  524. console.error("获取服务器列表信息错误:" + XMLHttpRequest.status);
  525. layer.open({
  526. title: 'message'
  527. , content: XMLHttpRequest.status
  528. });
  529. close();
  530. }
  531. });
  532. })
  533. }
  534. // //开始
  535. // window.global_fun.instance.startClick = function (id) {
  536. // res_inst.PlgGridInstance.selectRowById(id);
  537. // };
  538. // //停止
  539. // window.global_fun.instance.stopClick = function (id) {
  540. // res_inst.PlgGridInstance.selectRowById(id);
  541. // };
  542. res_inst.showDialogComplete(function (XMLHttpRequest, textStatus) {
  543. if (XMLHttpRequest.responseJSON.success) {
  544. global_fun.instance.arrangeClick(XMLHttpRequest.responseJSON.data)
  545. } else {
  546. layer.open({
  547. title: 'message',
  548. content: XMLHttpRequest.responseJSON.message || "上传错误"
  549. });
  550. }
  551. })
  552. })()
  553. </script>