客户BUG代码提交检查单填充

表单填充

// ==UserScript==
// @name         客户BUG代码提交检查单填充
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  表单填充
// @license MIT
// @author       none
// @match        http*://*/seeyon/app/collaboration/index.html*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    setTimeout(function () {
        awaitInit();
    }, 3000);

    var zwDoc = window.document;
    function awaitInit(){
        if ($(".mask").length > 0) {
            setTimeout(function () {
                awaitInit();
            }, 1000);
            return;
        }
        setTimeout(function () {
            init();
        }, 200);
    }
    function init() {
        var zwWin = window;
        // for (let i = 0; i < 10; i++) {
        //     zwWin = zwWin.top;
        // }
        if ($(zwWin.document).find("#zwIframe").contents().length == 1) {
            zwWin = $(zwWin.document).find("#zwIframe")[0].contentWindow
            zwDoc = zwWin.document;
        }
        if ("-7586290624698760574" == window.templateId && $(zwDoc).find("#auxiliaryformmain_0line0col2_id").text().indexOf("客户bug代码提交检查单") != -1) {
            var select1StrArr = ["是", "否"];
            var select2StrArr = ["高版本无问题", "高版本提交过", "操作错误、无需提交", "低版本无此功能"];
            // 创建第一个选择框
            var select1 = $('<select style="text-align: center;min-width: 30px;" id="option1" name="option1"></select>');
            for (let i = 0; i < 2; i++) {
                var selected = i == 1 ? "selected" : "";
                select1.append('<option ' + selected + ' value="' + i + '">' + select1StrArr[i] + '</option>');
            }
            // 创建第二个选择框
            var select2 = $('<select  style="text-align: center;min-width: 30px;" id="option2" name="option2"></select>');
            for (let i = 0; i < 4; i++) {
                select2.append('<option value="' + i + '">' + select2StrArr[i] + '</option>');
            }
            zwWin.__AutoFillValue__V_123 = {};
            zwWin.__AutoFillValue__V_123.runAutoFillValue = runAutoFillValue;
            zwWin.__AutoFillValue__V_123.select1 = select1;
            zwWin.__AutoFillValue__V_123.select2 = select2;
            // 创建一个按钮
            var button = $('<button id="actionButton" onclick="__AutoFillValue__V_123.runAutoFillValue(__AutoFillValue__V_123.select1.val(),__AutoFillValue__V_123.select2.val())">点击填充</button>');
            // 将创建的元素添加到容器中
            $(zwDoc).find('#auxiliaryformmain_0line0col2_id').append(select1, select2, button);
        }
    }
    function sleep(delay) {
        return new Promise((resolve) => setTimeout(resolve, delay));
    }
    async function runAutoFillValue(options1Index, options2Index) {
        var trArr = [];
        for (let i = 5; i <= 12; i++) {
            let find = $(zwDoc).find("#tableName-front_formmain_" + i).find("tr");
            for (let j = 0; j < find.length; j++) {
                trArr.push(find.get(j));
            }
        }
        var options2Arr = [];
        var clearArr = [];
        console.log("获取的tr:");
        console.log(trArr)
        for (let i = 0; i < trArr.length; i++) {
            let tr = trArr[i];
            let select = $(tr).find(".ui-select");
            console.log("选项:");
            console.log(select);
            if (select.length >= 2) {
                $(select[0]).trigger("click");
                await sleep(50)
                let options = $(zwDoc).find(".ui-popper").find(".cap4-select__option__left");
                if (options.length == 2) {
                    $(options[options1Index]).trigger("click");
                }
                if (options1Index == 0) {

                    clearArr.push($(tr).find(".ui-input__suffix--clear")[1]);
                }else{
                    //等于否选第二个
                    options2Arr.push($(select[1]));
                }
            }
        }
        await sleep(1000)
        for (let i = 0; i < options2Arr.length; i++) {
            options2Arr[i].trigger("click");
            await sleep(50)
            var options = $(zwDoc).find(".ui-popper").find(".cap4-select__option__left");
            console.log(options)
            if (options.length > 0) {
                $(options[options2Index]).trigger("click");
            }
        }
        for (let i = 0; i < clearArr.length; i++) {
            $(clearArr[i]).trigger("click");
        }
    }




})();