// ==UserScript== // @name 易迅数据服务管理 // @namespace http://tampermonkey.net/ // @version 63.2 // @description 修复保存失败误报问题;增加点击前禁用状态检测;config显示全功能 // @author 刘运运 // @match *://*/govern/* // @grant none // @run-at document-start // ==/UserScript== (function() { 'use strict'; // --- 1. 定义目标页面特征 --- const TARGET_PATH = '/govern/#/layout/data-assets/dataServices/serviceManagement'; // --- 2. 按钮ID --- const ID_NEW = 'btn_smart_save'; const ID_OLD = 'btn_old_save'; const ID_PREVIEW = 'btn_preview_data'; const ID_TOGGLE = 'btn_toggle_all'; const ID_RESET = 'btn_reset'; const ID_HOT = 'btn_hot_edit'; const ID_BACK = 'btn_manual_back'; // --- 3. 核心判断 (双重验证) --- function isTargetPage() { const currentUrl = window.location.href; return currentUrl.includes(TARGET_PATH) && currentUrl.includes('?type='); } // --- 4. 功能函数 --- // 智能勾选保存 (精准针对“入参”列) function actionSmartSave() { console.log('🟢 [智能保存] 开始精准检查“入参”列...'); const headerCell = $('.el-table__header .cell:contains("入参")').closest('th'); if (headerCell.length === 0) { alert('⚠️ 未找到“入参”列,请确认页面表格已加载!'); return; } const columnIndex = headerCell.index() + 1; const checkboxes = $(`.el-table__body tr td:nth-child(${columnIndex}) .el-checkbox__input`); checkboxes.each(function() { if (!$(this).parent().hasClass('is-checked')) { $(this).click(); } }); // 延迟300ms是为了让勾选动作在界面上生效,避免被校验拦截 setTimeout(() => { executeSaveAndReturn(); }, 300); } // 仅保存 (极简逻辑) function actionOldSave() { console.log('🔵 [仅保存] 准备执行保存操作...'); // 直接调用核心逻辑,不需要额外的 setTimeout executeSaveAndReturn(); } // 公共的保存逻辑:包含 前置禁用检测 + 后置结果校验 function executeSaveAndReturn() { // 1. 获取页面上的保存按钮 const saveBtn = Array.from(document.querySelectorAll('button')) .find(b => b.innerText.trim() === '保存'); // 2. 【新增】前置检测:如果按钮本身就是禁用的,直接报错并返回 if (!saveBtn || saveBtn.disabled || saveBtn.classList.contains('is-disabled')) { console.warn('⛔ [前置拦截] 保存按钮不可用,阻止点击。'); alert('⚠️ 保存失败!当前表单未填写完整或按钮处于禁用状态。'); return; } // 3. 如果按钮可用,执行点击 console.log('🚀 保存按钮可用,正在点击...'); saveBtn.click(); // 4. 【优化】后置检测:监听结果 setTimeout(() => { // 判断依据:如果 URL 包含了目标列表页的路径,说明跳转成功 if (window.location.href.includes(TARGET_PATH)) { // 注意:因为编辑页通常也包含 TARGET_PATH,所以这里主要看是否发生了变化 // 更准确的判断是:如果保存按钮依然存在且可用,说明没跳走也没变灰 const currentBtn = Array.from(document.querySelectorAll('button')) .find(b => b.innerText.trim() === '保存'); if (currentBtn && !currentBtn.disabled) { console.warn('⚠️ 页面未跳转且按钮仍可用,判定为保存失败。'); alert('⚠️ 保存失败!请检查是否有必填项未填写。'); } else { // 按钮变灰了或者消失了,通常意味着正在提交或成功 console.log('✅ 按钮状态改变,视为操作已提交。'); // 如果此时还没跳走,可能是网络慢,我们可以选择再等一会或者强制跳 // 这里为了稳妥,如果2秒后还在当前页,强制跳回列表 if (window.location.href.includes('?type=')) { console.log('ℹ️ 提交后长时间未跳转,执行强制返回...'); window.location.href = TARGET_PATH; } } } }, 1500); } // 数据预览 function actionPreviewData() { const previewBtn = Array.from(document.querySelectorAll('button')) .find(b => b.innerText.includes('预览数据') && !b.disabled); if (previewBtn) { previewBtn.click(); } else { alert('⚠️ 未找到可用的预览按钮'); } } // 反选功能 function actionToggleAll() { const headerCell = $('.el-table__header .cell:contains("入参")').closest('th'); if (headerCell.length === 0) { alert('⚠️ 未找到“入参”列,请确认表格结构是否正确。'); return; } const columnIndex = headerCell.index() + 1; const checkboxes = $(`.el-table__body tr td:nth-child(${columnIndex}) .el-checkbox__input`); checkboxes.click(); } // 重置脚本 function actionReset() { console.log('%c[重置] 正在重新加载脚本按钮...', 'color: orange; font-weight: bold;'); destroyButtons(); setTimeout(createButtons, 100); } // 热修改接口 function actionHotEdit() { const href = window.location.href; if (href.includes('edit=false')) { window.location.href = href.replace('edit=false', 'edit=true'); } else if (href.includes('edit=true')) { window.location.href = href.replace('edit=true', 'edit=false'); } } // 手动返回 function actionManualBack() { window.location.href = TARGET_PATH; } // --- 5. 界面管理 --- function createButtons() { // 只要检测到“仅保存”按钮存在,就绝对不重复创建 if (document.getElementById(ID_OLD)) { return; } // 强制等待 body 加载完成 if (!document.body) { setTimeout(createButtons, 100); return; } const container = document.createElement('div'); container.style.cssText = 'position:fixed; top:100px; right:20px; z-index:9999; display:flex; flex-direction:column; gap:8px;'; const makeBtn = (id, emoji, text, color, fn) => { const btn = document.createElement('button'); btn.id = id; btn.innerText = `${emoji} ${text}`; btn.style.cssText = ` padding:8px 12px; border:none; border-radius:4px; background:${color}; color:#fff; cursor:pointer; font-size:12px; font-weight:bold; box-shadow:0 2px 5px rgba(0,0,0,0.2); transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 6px; `; btn.onmouseover = () => { btn.style.transform = 'scale(1.05)'; }; btn.onmouseout = () => { btn.style.transform = 'scale(1)'; }; btn.onclick = fn; return btn; }; const url = window.location.href; // 核心逻辑:只有当 URL 包含 type=config 时,才显示“智能保存”和“反选” if (url.includes('type=config')) { container.appendChild(makeBtn(ID_NEW, '✅', '智能保存', '#67C23A', actionSmartSave)); container.appendChild(makeBtn(ID_TOGGLE, '🔄', '反选(入参)', '#E65100', actionToggleAll)); } // 基础按钮(所有页面都显示) container.appendChild(makeBtn(ID_OLD, '💾', '仅保存', '#409EFF', actionOldSave)); container.appendChild(makeBtn(ID_PREVIEW, '👀', '数据预览', '#9C27B0', actionPreviewData)); // 热修改(只有URL带edit=时才显示) if (url.includes('edit=')) { container.appendChild(makeBtn(ID_HOT, '🔥', '热修改', '#7B1FA2', actionHotEdit)); } container.appendChild(makeBtn(ID_RESET, '♻️', '重置脚本', '#E6A23C', actionReset)); container.appendChild(makeBtn(ID_BACK, '🔙', '手动返回', '#607D8B', actionManualBack)); document.body.appendChild(container); } function destroyButtons() { [ID_NEW, ID_OLD, ID_PREVIEW, ID_TOGGLE, ID_RESET, ID_HOT, ID_BACK].forEach(id => { const el = document.getElementById(id); if (el) el.remove(); }); } // --- 6. 主循环 --- function mainLoop() { if (isTargetPage()) { createButtons(); } else { destroyButtons(); } } // --- 启动 --- setTimeout(() => { mainLoop(); setInterval(mainLoop, 800); }, 500); })();