From c44c3355d534a1e25d927db633fa6cd4160b3623 Mon Sep 17 00:00:00 2001 From: "youhong.ai" Date: Sat, 15 Jul 2023 10:02:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=90=E4=BA=A4=E5=A4=96?= =?UTF-8?q?=E5=87=BA=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- javascript/common/脚本.js | 74 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/javascript/common/脚本.js b/javascript/common/脚本.js index 435b629..8dc0a88 100644 --- a/javascript/common/脚本.js +++ b/javascript/common/脚本.js @@ -1,4 +1,33 @@ (function runJs() { + function findReact(dom, traverseUp = 0) { + const key = Object.keys(dom).find(key => { + return key.startsWith("__reactFiber$") + || key.startsWith("__reactInternalInstance$") + || key.startsWith("__reactEventHandlers$"); + }); + const domFiber = dom[key]; + if (domFiber == null) return null; + if (domFiber._currentElement) { + let compFiber = domFiber._currentElement._owner; + for (let i = 0; i < traverseUp; i++) { + compFiber = compFiber._currentElement._owner; + } + return compFiber._instance; + } + const GetCompFiber = fiber => { + let parentFiber = fiber.return; + while (typeof parentFiber.type == "string") { + parentFiber = parentFiber.return; + } + return parentFiber; + }; + let compFiber = GetCompFiber(domFiber); + for (let i = 0; i < traverseUp; i++) { + compFiber = GetCompFiber(compFiber); + } + return compFiber.stateNode; + } + let currentYear = new Date().getFullYear(); let currentMonth = new Date().getMonth() + 1; let currentDate = new Date().getDate(); @@ -23,9 +52,13 @@ wf.changeFieldValue("100003720000000611", {value: "外出技术支持"}); wf.changeFieldValue("100003720000008715", {value: '2'}); wf.changeFieldValue("877132351682273302", {value: '1'}); - let workflowTitleObj = document.querySelector('input[weid="3rdcst_oxa9w7_i8bbvp_vc1wev_kc1m3l_r1vh81_snhw9p_3r9w93_g28s4n_abfe5k_a9abii"]'); + let workflowTitleObj = document.querySelector('.weapp-form-flowpage-content-FlowPageSysFieldReqName input'); let workflowTitle = workflowTitleObj.value; - workflowTitleObj.value = workflowTitle.substring(0, workflowTitle.length - 5) + formattedMonth + "-" + formattedDay; + let newValue = workflowTitle.substring(0, workflowTitle.length - 5) + formattedMonth + "-" + formattedDay; + workflowTitleObj.setAttribute("value", newValue); + workflowTitleObj.value = newValue; + let input = findReact(workflowTitleObj); + input.props.onChange(newValue); const container = document.getElementById("widget_100003720000000664"); const svgIcon = container.querySelector(".associative-search-icon svg"); if (svgIcon) { @@ -43,6 +76,35 @@ })() (function runJs() { + function findReact(dom, traverseUp = 0) { + const key = Object.keys(dom).find(key => { + return key.startsWith("__reactFiber$") + || key.startsWith("__reactInternalInstance$") + || key.startsWith("__reactEventHandlers$"); + }); + const domFiber = dom[key]; + if (domFiber == null) return null; + if (domFiber._currentElement) { + let compFiber = domFiber._currentElement._owner; + for (let i = 0; i < traverseUp; i++) { + compFiber = compFiber._currentElement._owner; + } + return compFiber._instance; + } + const GetCompFiber = fiber => { + let parentFiber = fiber.return; + while (typeof parentFiber.type == "string") { + parentFiber = parentFiber.return; + } + return parentFiber; + }; + let compFiber = GetCompFiber(domFiber); + for (let i = 0; i < traverseUp; i++) { + compFiber = GetCompFiber(compFiber); + } + return compFiber.stateNode; + } + let currentYear = new Date().getFullYear(); let currentMonth = new Date().getMonth() + 1; let currentDate = new Date().getDate(); @@ -62,9 +124,13 @@ wf.changeFieldValue("100003720000000611", {value: "外出技术支持"}); wf.changeFieldValue("100003720000008715", {value: '4'}); wf.changeFieldValue("877132351682273302", {value: '1'}); - let workflowTitleObj = document.querySelector('input[weid="3rdcst_oxa9w7_i8bbvp_vc1wev_kc1m3l_r1vh81_snhw9p_3r9w93_g28s4n_abfe5k_a9abii"]'); + let workflowTitleObj = document.querySelector('.weapp-form-flowpage-content-FlowPageSysFieldReqName input'); let workflowTitle = workflowTitleObj.value; - workflowTitleObj.value = workflowTitle.substring(0, workflowTitle.length - 5) + formattedMonth + "-" + formattedDay; + let newValue = workflowTitle.substring(0, workflowTitle.length - 5) + formattedMonth + "-" + formattedDay; + workflowTitleObj.setAttribute("value", newValue); + workflowTitleObj.value = newValue; + let input = findReact(workflowTitleObj); + input.props.onChange(newValue); window.open("/sp/workflow/flowpage/fullCreate/100003460000000746?workflowId=100003460000000746&isCreate=1", "_blank"); document.querySelector("button[weid='3rdcst_oxa9w7_i8bbvp_vc1wev_kc1m3l_r1vh81_t03ihg@0_xomsa1@0']").click(); })() \ No newline at end of file