lowerCodeHelper

低代码平台助手

当前为 2023-12-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name lowerCodeHelper
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 低代码平台助手
  6. // @author Ziker
  7. // @match https://ops.iyunquna.com/63008/*
  8. // @require https://code.jquery.com/jquery-3.4.1.min.js
  9. // @icon https://favicon.qqsuu.cn/work.yqn.com
  10. // @grant unsafeWindow
  11. // @grant window.close
  12. // @grant window.focus
  13. // @run-at document-body
  14. // @noframes
  15. // @license AGPL License
  16. // ==/UserScript==
  17.  
  18. window.jq = $.noConflict(true);
  19.  
  20. (function (window) {
  21. window.pageHelper = {
  22. // 等待元素可见
  23. async waitElementVisible(visibleTag, index, fun) {
  24. let node = jq(visibleTag)
  25. if (node === null || node[index] === null || node[index] === undefined) {
  26. setTimeout(() => {
  27. pageHelper.waitElementVisible(visibleTag, index, fun)
  28. }, 500)
  29. } else {
  30. fun()
  31. }
  32. },
  33. getCurrentAppIndex() {
  34. const nodes = document.getElementsByClassName("bar-tab");
  35. for (let i = 0; i < nodes.length; i++) {
  36. if (nodes[i].className.indexOf("bar-tab-selected") > 0) {
  37. return i;
  38. }
  39. }
  40. return -1;
  41. },
  42. getCurrentAppId() {
  43. const nodes = document.getElementsByClassName("tab-content-presentation-components");
  44. let className = nodes[this.getCurrentAppIndex()].className;
  45. return className.substring(className.indexOf("theia-tab-") + "theia-tab-".length);
  46. },
  47. sleep(duration) {
  48. return new Promise(resolve => {
  49. setTimeout(resolve, duration)
  50. })
  51. },
  52. showToast(msg, duration) {
  53. // 显示提示
  54. duration = isNaN(duration) ? 3000 : duration;
  55. const m = document.createElement('div');
  56. m.innerHTML = msg;
  57. m.style.cssText = "display: flex;justify-content: center;align-items: center;width:60%; min-width:180px; " +
  58. "background:#000000; opacity:0.98; height:auto;min-height: 50px;font-size:25px; color:#fff; " +
  59. "line-height:30px; text-align:center; border-radius:4px; position:fixed; top:85%; left:20%; z-index:999999;";
  60. document.body.appendChild(m);
  61. setTimeout(function () {
  62. const d = 0.5;
  63. m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
  64. m.style.opacity = '0';
  65. setTimeout(function () {
  66. document.body.removeChild(m)
  67. }, d * 1000);
  68. }, duration);
  69. },
  70. copyToClipboard(text) {
  71. // 创建一个临时的 textarea 元素
  72. let textarea = document.createElement('textarea');
  73. // 设置 textarea 的值为要拷贝的文本内容
  74. textarea.value = text;
  75. // 将 textarea 添加到文档中
  76. document.body.appendChild(textarea);
  77. // 选中 textarea 的内容
  78. textarea.select();
  79. // 执行复制操作
  80. document.execCommand('copy');
  81. // 移除临时的 textarea 元素
  82. document.body.removeChild(textarea);
  83. this.showToast("已拷贝 " + text)
  84. }
  85. }
  86. })(window);
  87.  
  88.  
  89. (function () {
  90. let historyTrace = ''
  91. 'use strict';
  92. jq(document).ready(function () {
  93. // 监听api tab变动
  94. waitObserve(".tabs-bar", () => {
  95. // 应用接口面板
  96. const appPanelTag = ".tab-content-presentation-components.theia-tab-" + window.pageHelper.getCurrentAppId();
  97. // 监听属性面板变动
  98. waitObserve(appPanelTag + " .p-8", () => {
  99. const p8 = document.querySelector(appPanelTag + " .p-8");
  100. const panel = p8.querySelector(".ant-form.ant-form-vertical.yqn-form");
  101. if (nonNull(panel) && isNull(panel.querySelector(".customScriptInfo"))) {
  102. const div = document.createElement("div");
  103. div.className = "customScriptInfo";
  104. panel.appendChild(div)
  105. // 获取当前NodeName
  106. const childProcessNode = panel.querySelector("#code");
  107. let nodeName = nonNull(childProcessNode) ? childProcessNode.value : p8.querySelector(".dashboard-code span").textContent
  108. // 获取当前节点信息
  109. getNodeInfo(nodeName, node => {
  110. // 处理信息
  111. const divNode = document.querySelector(appPanelTag + " .customScriptInfo");
  112. // 清空显示
  113. divNode.innerHTML = ""
  114. // 脚本
  115. if (nonNull(node.scriptId)) {
  116. divNode.appendChild(createButton("脚本:" + node.scriptId, () => window.pageHelper.copyToClipboard(node.scriptId)))
  117. }
  118. // 入参
  119. let id = node.inputScriptId;
  120. const inputScriptIds = node.inputScriptIds;
  121. if (nonNull(inputScriptIds)) {
  122. id = nonNull(id) ? id : inputScriptIds.example;
  123. id = nonNull(id) ? id : inputScriptIds.record;
  124. id = nonNull(id) ? id : inputScriptIds.recordList;
  125. id = nonNull(id) ? id : inputScriptIds.condition;
  126. id = nonNull(id) ? id : inputScriptIds.id;
  127. }
  128. if (isNull(id) && nonNull(node.dslBulidData)) {
  129. id = node.dslBulidData.dslScriptId;
  130. }
  131. if (nonNull(id)) {
  132. divNode.appendChild(createButton("入参:" + id, () => window.pageHelper.copyToClipboard(id)))
  133. }
  134. // 条件
  135. const executeScriptId = node.executeScriptId;
  136. if (nonNull(executeScriptId)) {
  137. divNode.appendChild(createButton("条件:" + executeScriptId, () => window.pageHelper.copyToClipboard(executeScriptId)))
  138. }
  139. // 校验
  140. const assertScriptId = node.assertScriptId;
  141. if (nonNull(assertScriptId)) {
  142. divNode.appendChild(createButton("校验:" + assertScriptId, () => window.pageHelper.copyToClipboard(assertScriptId)))
  143. }
  144. })
  145. }
  146. })
  147.  
  148. // 监听执行历史面板变动
  149. const executeHistoryBodyTag = appPanelTag + " .test-split-item.test-split-item-right .ant-table-body tbody";
  150. waitObserve(executeHistoryBodyTag, () => {
  151. const lines = document.querySelectorAll(executeHistoryBodyTag + " .ant-table-row.ant-table-row-level-0");
  152. if (nonNull(lines) && isNull(lines[0].querySelector(".customer-button-div"))) {
  153. const div = document.createElement("div");
  154. lines[0].appendChild(div)
  155. div.className = "customer-button-div";
  156. div.style.display = "none"
  157. getExecuteHistory(content => {
  158. for (let i = 0; i < content.length; i++) {
  159. const tds = lines[i].querySelectorAll("td");
  160. const actionCol = tds[tds.length - 1];
  161. const detailButton = actionCol.querySelectorAll("button")[0];
  162.  
  163. detailButton.style.display = "none"
  164. actionCol.insertBefore(createButton("RT:" + content[i].rt, () => {
  165. detailButton.click()
  166. historyTrace = tds[3].innerText
  167. }), detailButton)
  168. }
  169. })
  170. }
  171. })
  172. })
  173.  
  174. // 监听body变动
  175. waitObserve("body", () => {
  176. // 监听执行日志流程图变动
  177. const processPanelTag = ".node-bpmn #canvas .bjs-container .djs-container .viewport .layer-base";
  178. waitObserve(processPanelTag, () => {
  179. const processPanel = document.querySelector(processPanelTag);
  180. const rtDiv = processPanel.querySelector(".customer-rt");
  181. if (isNull(rtDiv)) {
  182. const div = document.createElement("div");
  183. processPanel.appendChild(div)
  184. div.className = "customer-rt";
  185. div.style.display = "none"
  186. getByTraceId(apiNodeLogList => {
  187. for (let i = 0; i < apiNodeLogList.length; i++) {
  188. const log = apiNodeLogList[i];
  189. const textNode = processPanel.querySelector("[data-element-id='" + log.nodeId + "'] text");
  190. if (isNull(textNode)) {
  191. continue
  192. }
  193. const tspan = textNode.querySelector("tspan");
  194. if (nonNull(tspan)) {
  195. const rtNode = tspan.cloneNode(true);
  196. textNode.appendChild(rtNode)
  197. rtNode.setAttribute("x", "101")
  198. rtNode.setAttribute("y", "45")
  199. rtNode.textContent = "RT:" + log.rt
  200. }
  201. }
  202. })
  203. }
  204. }, false)
  205. })
  206. })
  207.  
  208. function nonNull(o) {
  209. return o !== null && o !== undefined;
  210. }
  211.  
  212. function isNull(o) {
  213. return o === null || o === undefined;
  214. }
  215.  
  216. // 等待出现并监听变化
  217. function waitObserve(visibleTag, fun, attributes = true) {
  218. window.pageHelper.waitElementVisible(visibleTag, 0, () => {
  219. new MutationObserver(function (mutationsList) {
  220. fun()
  221. }).observe(document.querySelector(visibleTag), {
  222. attributes: attributes,
  223. childList: true,
  224. subtree: true,
  225. characterData: true
  226. })
  227. }).then(r => {
  228. })
  229. }
  230.  
  231. // 创建按钮
  232. function createButton(name, listener) {
  233. const button = document.createElement("button")
  234. button.type = "button"
  235. button.id = name
  236. button.className = "ant-btn ant-btn-link perf-tracked yqn-button yqn-link-no-padding customer-button"
  237. button.onclick = listener
  238. const span = document.createElement("span")
  239. span.textContent = name
  240. button.appendChild(span)
  241. return button;
  242. }
  243.  
  244. // 拿流程信息
  245. function getNodeInfo(nodeName, fuc) {
  246. getNodeInfoByApiMode(0, nodeName, fuc)
  247. }
  248.  
  249. const addressArr = ['', '/process', '/mq', '/job'];
  250.  
  251. // 拿流程信息
  252. function getNodeInfoByApiMode(apiMode, nodeName, fuc) {
  253. jq.ajax({
  254. url: 'https://gw-ops.iyunquna.com/api/42080/api' + addressArr[apiMode] + '/details_composer?guid=6f87e073-1da1-4017-b2de-c109abcd6d123',
  255. method: 'POST',
  256. xhrFields: {
  257. withCredentials: true
  258. },
  259. crossDomain: true,
  260. contentType: 'application/json',
  261. data: JSON.stringify({
  262. "header": {
  263. "xSourceAppId": "63008",
  264. "guid": "6f87e073-1da1-4017-b2de-c109abcd6d123",
  265. "lang": "zh",
  266. "timezone": "Asia/Shanghai"
  267. },
  268. "model": {
  269. "id": window.pageHelper.getCurrentAppId(),
  270. "appId": new URLSearchParams(window.location.href.split('?')[1]).get('appId')
  271. }
  272. }),
  273. success: function (response) {
  274. if (response.code === 200) {
  275. if (response.data === null && apiMode === 0) {
  276. getNodeInfoByApiMode(apiMode + 1, nodeName, fuc)
  277. getNodeInfoByApiMode(apiMode + 2, nodeName, fuc)
  278. getNodeInfoByApiMode(apiMode + 3, nodeName, fuc)
  279. return
  280. }
  281. let processDefine = JSON.parse(response.data.processDefine);
  282. for (let i = 0; i < processDefine.nodes.length; i++) {
  283. if (processDefine.nodes[i].code === nodeName) {
  284. fuc(processDefine.nodes[i])
  285. break
  286. }
  287. }
  288. }
  289. },
  290. error: function (xhr, status, error) {
  291. console.log('Request failed:', error);
  292. }
  293. });
  294. }
  295.  
  296. // 拿历史执行数据
  297. function getExecuteHistory(fuc) {
  298. jq.ajax({
  299. url: 'https://gw-ops.iyunquna.com/api/42086/apiLog/list?guid=c74610c3-b840-446f-a452-f678b32a39e8',
  300. method: 'POST',
  301. xhrFields: {
  302. withCredentials: true
  303. },
  304. crossDomain: true,
  305. contentType: 'application/json',
  306. data: JSON.stringify({
  307. "header": {
  308. "xSourceAppId": "63008",
  309. "guid": "6f87e073-1da1-4017-b2de-c109abcd6d123",
  310. "lang": "zh",
  311. "timezone": "Asia/Shanghai"
  312. },
  313. "model": {
  314. "apiId": window.pageHelper.getCurrentAppId(),
  315. "appId": new URLSearchParams(window.location.href.split('?')[1]).get('appId')
  316. }
  317. }),
  318. success: function (response) {
  319. if (response.code === 200 && nonNull(response.data) && nonNull(response.data.content)) {
  320. fuc(response.data.content)
  321. }
  322. },
  323. error: function (xhr, status, error) {
  324. console.log('Request failed:', error);
  325. }
  326. });
  327. }
  328.  
  329. const apiType = ['api', 'process', 'mq', 'job'];
  330.  
  331. // 拿 trace 执行数据
  332. function getByTraceId(fuc) {
  333. return getByTraceIdByApiMode(0, fuc)
  334. }
  335.  
  336. // 拿 trace 执行数据
  337. function getByTraceIdByApiMode(apiMode, fuc) {
  338. jq.ajax({
  339. url: 'https://gw-ops.iyunquna.com/api/42086/apiLog/getByTraceId?guid=3862879a-b379-4171-9644-289ee637dae0',
  340. method: 'POST',
  341. xhrFields: {
  342. withCredentials: true
  343. },
  344. crossDomain: true,
  345. contentType: 'application/json',
  346. data: JSON.stringify({
  347. "header": {
  348. "xSourceAppId": "63008",
  349. "guid": "6f87e073-1da1-4017-b2de-c109abcd6d123",
  350. "lang": "zh",
  351. "timezone": "Asia/Shanghai"
  352. },
  353. "model": {
  354. "appId": new URLSearchParams(window.location.href.split('?')[1]).get('appId'),
  355. "env": "qa4",
  356. "traceIdLike": historyTrace,
  357. "apiId": window.pageHelper.getCurrentAppId(),
  358. "testCaseId": null,
  359. "apiTypeCode": apiMode === 0 ? "api" : apiType[apiMode]
  360. }
  361. }),
  362. success: function (response) {
  363. if (response.code === 200 && nonNull(response.data) && nonNull(response.data.apiNodeLogList) && response.data.apiNodeLogList.length !== 0) {
  364. fuc(response.data.apiNodeLogList)
  365. } else if (apiMode === 0) {
  366. getByTraceIdByApiMode(1, fuc)
  367. getByTraceIdByApiMode(2, fuc)
  368. getByTraceIdByApiMode(3, fuc)
  369. }
  370. },
  371. error: function (xhr, status, error) {
  372. console.log('Request failed:', error);
  373. }
  374. });
  375. }
  376. })();
  377.