From acd555dc37b60cfa96ca1a0f68e2b0d75d31ac09 Mon Sep 17 00:00:00 2001 From: manchuwork Date: Wed, 6 Aug 2025 06:25:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=88=B1=E4=BC=81=E6=9F=A5?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.json | 23 + new-group.html | 693 ++++++++++++++++++++++++ new-group2.html | 1370 +++++++++++++++++++++++++++++++++++++++++++++++ script2-1.js | 947 ++++++++++++++++++++++++++++++++ script2.js | 105 ---- script3.js | 451 ++++++++++++++++ 6 files changed, 3484 insertions(+), 105 deletions(-) create mode 100644 data.json create mode 100644 new-group.html create mode 100644 new-group2.html create mode 100644 script2-1.js create mode 100644 script3.js diff --git a/data.json b/data.json new file mode 100644 index 0000000..9fa672b --- /dev/null +++ b/data.json @@ -0,0 +1,23 @@ +{ + "企业名称": "杭州奥杰装饰工程有限公司", + "统一社会信用代码": "9133011031131201XU", + "法定代表人": "曾显军", + "经营状态": "开业", + "成立日期": "2014-08-05", + "行政区划": "浙江省杭州市余杭区", + "注册资本": "200万(元)", + "实缴资本": "200万(元)", + "企业类型": "有限责任公司(自然人独资)", + "所属行业": "批发业", + "工商注册号": "330184000311238", + "组织机构代码": "31131201-X", + "纳税人识别号": "9133011031131201XU", + "纳税人资质": "增值税一般纳税人", + "营业期限": "2014-08-05 至 2034-08-04", + "核准日期": "2020-08-24", + "参保人数": "3人", + "登记机关": "杭州市余杭区市场监督管理局", + "曾用名": "杭州茂复建材有限公司", + "注册地址": "浙江省杭州市余杭区五常街道郭家兜路8号1幢4楼408室", + "经营范围": "设计、施工:建筑工程、室内外装饰工程、幕墙工程;销售:建筑材料,装饰材料,石材,五金;服务:铝合金门窗上门安装,建筑工程技术咨询,国内广告设计和制作。(依法须经批准的项目,经相关部门批准后方可开展经营活动)" + } \ No newline at end of file diff --git a/new-group.html b/new-group.html new file mode 100644 index 0000000..5707898 --- /dev/null +++ b/new-group.html @@ -0,0 +1,693 @@ + + + + + 集团客户 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+
+ + + + +
+ + +
+
+
+ +
+
+ +
+ + + + +
+
AI智能建档 +
+
集团客户是指以组织名义与一个公司签署协议,订购并使用该公司通信产品和服务,并在该公司建立起集团客户关系管理的法人单位及所附属的产业活动单位。 集团业务的客户竞争,关键在于运营商是否有一个闭环的管理过程,必须通过内部前后端协同优化,从客户需求发现,到需求确认、方案制定、执行,以及售后服务,提供集团客户优质的服务。
+
+ +
+
提示
+
针对营业执照、统一社会信用代码证等企业致信系统可获取数据的标准证件,通过AI智能识别后,直接建档。
+
+ +
+
+
+
证件上传
+
+
+
证件识别:
+ 上传证件 + + + 上传营业执照证件或统一社会信用代码后自动进行OCR识别,建议附件不超过2M +
+
+ + + +
+
证件类型:
+
+ + * +
+
+
+
+
机构类型:
+
+ + * +
+
+
+
+ +
单位证件编号
+
+
+
单位证件编号:
+
+ + * +
+ + 若编号识别错误,可手工微调 +
+
+
+ +
证照信息
+
+
+
单位名称:
+
+ + * +
+
+
+ +
+
单位证件号码:
+
+ + * +
+
+
+ +
+
法人代表:
+
+ + * +
+
+
+
+
证件地址:
+
+ + * +
+
+
+
+
营业期限:
+
+ + * +
+
+
+ +
+
行业类别1:
+
+ + * +
+
+
+ +
+
行业类别2:
+
+ + * +
+
+
+ +
+
核准日期:
+
+ + * +
+
+
+
+
登记管理部门:
+
+ + * +
+
+
+
+
联系信息
+
+
+
联系电话:
+
+ + * +
+
+
+
+
办公地址:
+
+ + * +
+
+
+ +
+
楼层房号:
+
+ +
+
+
+
+
13级地址:
+
+ + +
+
+
+ +
+ + +
+
+ + +
+
+
经度[118,123]:
+
+ + * +
+
+
+ +
+
纬度[27,35]:
+
+ + * +
+
+
+ +
+
网格
+
+
+
地市:
+
+ + * +
+
+
+ +
+
区县:
+
+ + * +
+
+
+
+
网格:
+
+ + * +
+
+
+ +
+
地市:
+
+ + * +
+
+
+
+
县市:
+
+ + * +
+
+
+ +
+
片区:
+
+ + * +
+
+
+
+
分类信息
+
+
+
是否中小微:
+
+ + * +
+
+
+
+
是否同步CMIOT:
+
+ + * +
+
+
+
+
集团级别:
+
+ + * +
+
+
+
+
管理模式:
+
+ + * +
+
+
+
+
场景类别:
+
+ + * +
+
+
+
+
场所类别:
+
+ + * +
+
+
+
+
建筑物名称:
+
+ + +
+
+
+
+
建筑物编号:
+
+ + * +
+
+
+
+
商客行业一级类型:
+
+ + * +
+
+
+ +
+
商客行业二级类型:
+
+ + * +
+
+
+
+
细分客群类别:
+
+ + * +
+
+
+ +
+
是否分支机构建档:
+
+ + * +
+
+
+ +
+ + +
+
+
+
+ +
+
+ + +
+
+ +
+
+
+
+
+ + + + + + + + +
+
\ No newline at end of file diff --git a/new-group2.html b/new-group2.html new file mode 100644 index 0000000..2196da5 --- /dev/null +++ b/new-group2.html @@ -0,0 +1,1370 @@ + + + + + + + 集团客户 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + +
+
+ +
+
+
+
+ + + + +
+ + +
+
+
+ +
+
+ +
+ + + + +
+
集团客户新增 +
+
集团客户是指以组织名义与一个公司签署协议,订购并使用该公司通信产品和服务,并在该公司建立起集团客户关系管理的法人单位及所附属的产业活动单位。 集团业务的客户竞争,关键在于运营商是否有一个闭环的管理过程,必须通过内部前后端协同优化,从客户需求发现,到需求确认、方案制定、执行,以及售后服务,提供集团客户优质的服务。
+
+ +
+
提示
+ 新建集团客户为先建后审模式,请务必保证集团/证件名称准确无误,错误将导致协议重签。 +
+ +
+
+
+
证件信息
+ + +
+
+
证件识别:
+ 上传证件 + + + 手输证件 + + + 上传营业执照证件后自动进行OCR识别 +
+
+
+ + + +
+
+
证件名称(总部):
+
+ + * +
+
+
+ +
+
证件号码:
+
+ + * +
+
+
+ +
+
法人代表:
+
+ + * +
+
+
+ +
+
证件地址:
+
+ + * +
+
+
+ +
+
证件有效期:
+
+ +
+ * + 若证件有效期为长期有效,请选择十年之后日期 +
+
+ +
+
机构类型:
+
+ + * +
+
+
+ +
+
证件类型:
+
+ + * +
+
+
+ +
+
登记管理部门:
+
+ + * +
+
+
+ +
+
客户类型:
+
+ + * +
+
+
+
+
集团类型:
+
+ + * +
+
+
+
+ +
基础信息
+
+
+
集团名称:
+
+ + + * +
+
+
+ +
+
集团状态:
+
+ + * +
+
+
+
+
集团级别:
+
+ + * +
+
+
+ +
+
客户经理姓名:
+
+ + + +
+ * +
+
+
+ +
联系信息
+
+ +
+
客户地址:
+
+ + * +
+
+
+ +
+
13级地址:
+
+ + + * +
+
+
+ +
+
联系电话:
+
+ + * +
+
+
+ +
+
经度[118,123]:
+
+ + * +
+
+
+ +
+
纬度[27,35]:
+
+ + * +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + + +
+
区域归属信息
+ +
+
+
地市(网格平台):
+
+ + * +
+
+
+ +
+
区县(网格平台):
+
+ + * +
+
+
+ +
+
网格(网格平台):
+
+ + * +
+
+
+ +
+
片区(业务大厅):
+
+ + * +
+
+
+
+
重要管理分类
+
+
+
行业类别1:
+
+ + * +
+
+
+ +
+
行业类别2:
+
+ + * +
+
+
+ +
+
重客行业1备注:
+
+ +
+
+
+ +
+
管理模式:
+
+ + * +
+
+
+ +
+
管理模式备注:
+
+ + +
+
+
+ +
+
+
+
+
+
+
+
实体分类一级:
+
+ +
+
+
+
?
+ + 1、实体集团:指具备统一社会信用代码的重要客户,1个统一社会信用代码对应唯一实际存在的实体集团,可以对应系统内N个建档客户。实体集团作为看管客户数量和资源配置的统计依据,各级重客单元的直管集团应为实体集团。 + 2、附属集团:指客户单位的内设部门(无统一社会信用代码)或者因产品订购和付费需要建立的关联集团。内设部门原则上不单独建档看管,若有独立的社会信用代码、财政权或信息化采购行为可单列。附属集团需关联上级集团统一管理,行业属性与上级集团保持一致,相关指标纳入上级集团统计。 + 3、产品集团:包括离岸产品集团和代理产品集团等。离岸产品集团,指拓展本地业务的域外集团客户;代理产品集团,指以代理政企或移动业务为主的集团客户。 + +
+ +
+ +
+
实体分类二级:
+
+ +
+
+
+ +
+
商客场景分类
+
+
+
+ + + + + + + + + + + + + + + +
其他分类信息
+
+
+
+ + +
渠道信息
+
+
+
+ + +
+
邮寄省份:
+
+ + + * +
+
+
+
+ +
法人信息
+ +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+ 下一步 +
+
+ +
+
+ + +
+
+
+
+
+ +
+ + + + + + + + + + + + + + +
+ +
+
+ + + + + + +
+ + +
\ No newline at end of file diff --git a/script2-1.js b/script2-1.js new file mode 100644 index 0000000..f91df8e --- /dev/null +++ b/script2-1.js @@ -0,0 +1,947 @@ +// ==UserScript== +// @name 页面工具按钮 +// @namespace http://tampermonkey.net/ +// @version 0.2 +// @description 在页面右下角添加工具按钮,支持复制源码和解析公司信息 +// @author You +// @match https://www.qcc.com/firm/* +// @match https://aiqicha.baidu.com/company_detail_* +// @grant none +// ==/UserScript== + +(function () { + "use strict"; + + // 工具类 - 存放通用函数 + class ToolUtils { + static cleanText(text) { + return text + .replace(/\s+/g, " ") + .replace(/[\r\n\t]/g, "") + .trim(); + } + + static extractText(doc, selectors) { + for (const selector of selectors) { + const element = doc.querySelector(selector); + if (element && element.textContent.trim()) { + return element.textContent.trim(); + } + } + return ""; + } + + static copyToClipboard(content, successMessage) { + const textarea = document.createElement("textarea"); + textarea.value = content; + textarea.style.position = "fixed"; + textarea.style.top = "0"; + textarea.style.left = "0"; + textarea.style.width = "1px"; + textarea.style.height = "1px"; + textarea.style.opacity = "0"; + + document.body.appendChild(textarea); + textarea.select(); + document.execCommand("copy"); + document.body.removeChild(textarea); + + if (successMessage) { + alert(successMessage); + } + } + + static showResult(data) { + const modal = document.createElement("div"); + modal.style.position = "fixed"; + modal.style.top = "50%"; + modal.style.left = "50%"; + modal.style.transform = "translate(-50%, -50%)"; + modal.style.width = "600px"; + modal.style.maxHeight = "80vh"; + modal.style.overflowY = "auto"; + modal.style.backgroundColor = "white"; + modal.style.padding = "20px"; + modal.style.boxShadow = "0 0 10px rgba(0,0,0,0.3)"; + modal.style.zIndex = "10000"; + + const pre = document.createElement("pre"); + pre.textContent = JSON.stringify(data, null, 2); + pre.style.whiteSpace = "pre-wrap"; + pre.style.wordWrap = "break-word"; + + const copyBtn = document.createElement("button"); + copyBtn.textContent = "复制JSON"; + copyBtn.style.marginTop = "10px"; + copyBtn.style.padding = "8px 16px"; + copyBtn.style.backgroundColor = "#52c41a"; + copyBtn.style.color = "white"; + copyBtn.style.border = "none"; + copyBtn.style.borderRadius = "4px"; + copyBtn.style.cursor = "pointer"; + + copyBtn.addEventListener("click", () => { + navigator.clipboard + .writeText(JSON.stringify(data, null, 2)) + .then(() => alert("已复制到剪贴板")) + .catch((err) => alert("复制失败: " + err)); + }); + + const closeBtn = document.createElement("button"); + closeBtn.textContent = "关闭"; + closeBtn.style.marginLeft = "10px"; + closeBtn.style.marginTop = "10px"; + closeBtn.style.padding = "8px 16px"; + closeBtn.style.backgroundColor = "#f5222d"; + closeBtn.style.color = "white"; + closeBtn.style.border = "none"; + closeBtn.style.borderRadius = "4px"; + closeBtn.style.cursor = "pointer"; + + closeBtn.addEventListener("click", () => { + document.body.removeChild(modal); + }); + + modal.innerHTML = '

企业信息解析结果

'; + modal.appendChild(pre); + modal.appendChild(document.createElement("br")); + modal.appendChild(copyBtn); + modal.appendChild(closeBtn); + + document.body.appendChild(modal); + } + } + + // 爱企查解析类 + class AiQiChaParser { + constructor() { + this.table = null; + } + + // 初始化表格 + initTable() { + this.table = document.querySelector("table.zx-detail-basic-table"); + if (!this.table) { + alert("未找到企业信息表格"); + return false; + } + return true; + } + + // 获取优化后的值 + getOptimizedValue(title) { + const cells = Array.from(this.table.querySelectorAll("td")); + const titleCell = cells.find( + (cell) => ToolUtils.cleanText(cell.textContent) === title + ); + + if (!titleCell) return null; + + let valueCell = titleCell.nextElementSibling; + if (!valueCell) return null; + + const valueElement = valueCell.querySelector(".enter-bg-ele") || + valueCell.querySelector(".addr-enter-bg-ele") || + valueCell; + + return ToolUtils.cleanText(valueElement.textContent); + } + + // 获取法定代表人 + getLegalRepresentative() { + const legalElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => ToolUtils.cleanText(td.textContent) === "法定代表人" + ); + + if (legalElements.length > 0) { + const valueCell = legalElements[0].nextElementSibling; + if (valueCell && valueCell.classList.contains("image-text-content")) { + const nameElement = valueCell.querySelector(".person-name-warp a"); + if (nameElement) { + return ToolUtils.cleanText(nameElement.textContent); + } + return ToolUtils.cleanText(valueCell.textContent); + } + } + + const titleElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => td.textContent.includes("法定代表人") + ); + + if (titleElements.length > 0 && titleElements[0].nextElementSibling) { + const valueCell = titleElements[0].nextElementSibling; + return ToolUtils.cleanText(valueCell.textContent); + } + + return null; + } + + // 获取统一社会信用代码 + getUnifiedSocialCreditCode() { + const codeElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => { + return ( + td.textContent.includes("统一社会信用代码") && + td.nextElementSibling && + td.nextElementSibling.classList.contains("table-regCapital-lable") + ); + } + ); + + if (codeElements.length > 0) { + const valueCell = codeElements[0].nextElementSibling; + const rawValue = valueCell.querySelector(".enter-bg-ele")?.textContent || valueCell.textContent; + return ToolUtils.cleanText(rawValue); + } + + const taxElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => td.textContent.includes("纳税人识别号") + ); + + if (taxElements.length > 0 && taxElements[0].nextElementSibling) { + const valueCell = taxElements[0].nextElementSibling; + const rawValue = valueCell.querySelector(".enter-bg-ele")?.textContent || valueCell.textContent; + return ToolUtils.cleanText(rawValue); + } + + return null; + } + + // 获取工商注册号 + getBusinessRegistrationNo() { + const regElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => ToolUtils.cleanText(td.textContent).includes("工商注册号") + ); + + if (regElements.length > 0 && regElements[0].nextElementSibling) { + const valueCell = regElements[0].nextElementSibling; + const rawValue = valueCell.querySelector(".enter-bg-ele")?.textContent || valueCell.textContent; + return ToolUtils.cleanText(rawValue); + } + + return null; + } + + // 获取组织机构代码 + getOrganizationCode() { + const orgCodeElements = Array.from( + this.table.querySelectorAll(".poptip-wrap-org-no") + ).filter((el) => el.textContent.includes("组织机构代码")); + + if (orgCodeElements.length > 0) { + const valueCell = orgCodeElements[0].closest("td").nextElementSibling; + if (valueCell && valueCell.classList.contains("enter-bg")) { + const rawValue = valueCell.querySelector(".enter-bg-ele")?.textContent || valueCell.textContent; + return ToolUtils.cleanText(rawValue); + } + } + + const titleElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => ToolUtils.cleanText(td.textContent) === "组织机构代码" + ); + + if (titleElements.length > 0 && titleElements[0].nextElementSibling) { + const valueCell = titleElements[0].nextElementSibling; + const rawValue = valueCell.querySelector(".enter-bg-ele")?.textContent || valueCell.textContent; + return ToolUtils.cleanText(rawValue); + } + + return null; + } + + // 获取纳税人识别号 + getTaxpayerId() { + const taxElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => ToolUtils.cleanText(td.textContent).includes("纳税人识别号") + ); + + if (taxElements.length > 0 && taxElements[0].nextElementSibling) { + const valueCell = taxElements[0].nextElementSibling; + const rawValue = valueCell.querySelector(".enter-bg-ele")?.textContent || valueCell.textContent; + return ToolUtils.cleanText(rawValue); + } + + const creditElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => ToolUtils.cleanText(td.textContent).includes("统一社会信用代码") + ); + + if (creditElements.length > 0 && creditElements[0].nextElementSibling) { + const valueCell = creditElements[0].nextElementSibling; + const rawValue = valueCell.querySelector(".enter-bg-ele")?.textContent || valueCell.textContent; + return ToolUtils.cleanText(rawValue); + } + + return null; + } + + // 获取参保人数 + getInsuranceNumber() { + const insuranceElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => { + return ( + td.textContent.includes("参保人数") && + td.querySelector(".insurance-info") + ); + } + ); + + if (insuranceElements.length > 0) { + const valueCell = insuranceElements[0].nextElementSibling; + if (!valueCell) return null; + + const rawText = valueCell.textContent.replace(/[\r\n\t]/g, "").trim(); + const match = rawText.match(/(\d+人)/); + return match ? match[0] : null; + } + + const registrationElements = Array.from( + this.table.querySelectorAll("td") + ).filter((td) => td.textContent.includes("登记机关")); + + if ( + registrationElements.length > 0 && + registrationElements[0].previousElementSibling + ) { + const valueCell = registrationElements[0].previousElementSibling; + const rawText = valueCell.textContent.replace(/[\r\n\t]/g, "").trim(); + const match = rawText.match(/(\d+人)/); + return match ? match[0] : null; + } + + return null; + } + + // 获取核准日期 + getApprovalDate() { + const approvalElements = Array.from( + this.table.querySelectorAll(".poptip-wrap-annual-date") + ).filter((el) => el.textContent.includes("核准日期")); + + if (approvalElements.length > 0) { + const valueCell = approvalElements[0].closest("td").nextElementSibling; + if (valueCell) { + const rawValue = valueCell.textContent + .replace(/[\r\n\t]/g, "") + .trim(); + if (/^\d{4}-\d{2}-\d{2}$/.test(rawValue)) { + return rawValue; + } + } + } + + const titleElements = Array.from(this.table.querySelectorAll("td")).filter( + (td) => ToolUtils.cleanText(td.textContent) === "核准日期" + ); + + if (titleElements.length > 0 && titleElements[0].nextElementSibling) { + const valueCell = titleElements[0].nextElementSibling; + const rawValue = ToolUtils.cleanText(valueCell.textContent); + if (/^\d{4}-\d{2}-\d{2}$/.test(rawValue)) { + return rawValue; + } + } + + return null; + } + + // 解析公司信息主方法 + parseCompanyInfo() { + if (!this.initTable()) return; + + const companyData = { + 企业名称: this.getOptimizedValue("企业名称"), + 统一社会信用代码: this.getUnifiedSocialCreditCode(), + 法定代表人: this.getLegalRepresentative(), + 经营状态: this.getOptimizedValue("经营状态"), + 成立日期: this.getOptimizedValue("成立日期"), + 行政区划: this.getOptimizedValue("行政区划"), + 注册资本: this.getOptimizedValue("注册资本"), + 实缴资本: this.getOptimizedValue("实缴资本"), + 企业类型: this.getOptimizedValue("企业类型"), + 所属行业: this.getOptimizedValue("所属行业"), + 工商注册号: this.getBusinessRegistrationNo(), + 组织机构代码: this.getOrganizationCode(), + 纳税人识别号: this.getTaxpayerId(), + 纳税人资质: this.getOptimizedValue("纳税人资质"), + 营业期限: this.getOptimizedValue("营业期限"), + 核准日期: this.getApprovalDate(), + 参保人数: this.getInsuranceNumber(), + 登记机关: this.getOptimizedValue("登记机关"), + 曾用名: this.getOptimizedValue("曾用名"), + 注册地址: this.getOptimizedValue("注册地址"), + 经营范围: this.getOptimizedValue("经营范围"), + }; + + ToolUtils.showResult(companyData); + } + } + + // QCC解析类 - 预留扩展 + class QCCParser { + constructor() { + // 预留QCC网站解析逻辑 + } + + parseCompanyInfo() { + alert("QCC解析功能即将上线"); + } + } + + // 创建按钮容器 + function createButtonContainer() {{ + const container = document.createElement("div"); + container.id = "tool-container"; + Object.assign(container.style, { + position: "fixed", + right: "20px", + bottom: "20px", + zIndex: "9999", + display: "flex", + flexDirection: "column", + gap: "10px", + width: "40px", + height: "40px", + backgroundColor: "#4CAF50", + borderRadius: "50%", + transition: "all 0.3s ease", + overflow: "hidden", + cursor: "move", + }); + + // +号指示器 + const plusSign = document.createElement("div"); + plusSign.textContent = "+"; + Object.assign(plusSign.style, { + color: "white", + fontSize: "24px", + textAlign: "center", + lineHeight: "40px", + width: "100%", + }); + container.appendChild(plusSign); + + // 悬停展开效果 + container.addEventListener("mouseenter", () => { + container.style.width = "150px"; + container.style.height = "auto"; + container.style.borderRadius = "8px"; + }); + + container.addEventListener("mouseleave", () => { + container.style.width = "40px"; + container.style.height = "40px"; + container.style.borderRadius = "50%"; + }); + + // 添加拖动功能 + let isDragging = false; + let offsetX, offsetY; + + // 鼠标按下开始拖动 + container.addEventListener("mousedown", (e) => { + // 只有点击+号区域才允许拖动 + if (e.target === plusSign || e.target === container) { + isDragging = true; + const rect = container.getBoundingClientRect(); + offsetX = e.clientX - rect.left; + offsetY = e.clientY - rect.top; + container.style.cursor = "grabbing"; + // 阻止事件冒泡和默认行为 + e.stopPropagation(); + e.preventDefault(); + } + }); + + // 鼠标移动时更新位置 + document.addEventListener("mousemove", (e) => { + if (!isDragging) return; + container.style.left = e.clientX - offsetX + "px"; + container.style.top = e.clientY - offsetY + "px"; + container.style.right = "auto"; + container.style.bottom = "auto"; + }); + + // 鼠标释放结束拖动 + document.addEventListener("mouseup", () => { + if (isDragging) { + isDragging = false; + container.style.cursor = "move"; + } + }); + // 创建功能按钮 + function createButton(text, onClick) { + const button = document.createElement("button"); + button.textContent = text; + Object.assign(button.style, { + padding: "8px 12px", + border: "none", + borderRadius: "4px", + backgroundColor: "white", + color: "#333", + cursor: "pointer", + width: "100%", + transition: "backgroundColor 0.2s", + }); + button.addEventListener( + "mouseenter", + () => (button.style.backgroundColor = "#f0f0f0") + ); + button.addEventListener( + "mouseleave", + () => (button.style.backgroundColor = "white") + ); + button.addEventListener("click", onClick); + return button; + } + + // 复制源码按钮 + const copySourceButton = createButton("复制源码", () => { + const html = document.documentElement.outerHTML; + + copyToClipboard(html, "HTML源码已复制到剪贴板"); + /* + navigator.clipboard + .writeText(html) + .then(() => { + alert("源码已复制到剪贴板"); + }) + .catch((err) => { + console.error("复制失败:", err); + }); + */ + }); + + // 解析公司信息按钮 + const parseInfoButton = createButton("解析公司信息", () => { + // 根据当前URL选择对应的解析器 + let parser; + if (window.location.host.includes('aiqicha.baidu.com')) { + parser = new AiQiChaParser(); + } else if (window.location.host.includes('qcc.com')) { + parser = new QCCParser(); + } else { + alert('不支持的网站'); + return; + } + parser.parseCompanyInfo(); + }); + + // 法定代表人提取方法(优化版) + function getLegalRepresentative(table) { + // 方法1:通过特定class组合定位 + const legalElements = Array.from(table.querySelectorAll("td")).filter( + (td) => cleanText(td.textContent) === "法定代表人" + ); + + if (legalElements.length > 0) { + const valueCell = legalElements[0].nextElementSibling; + if (valueCell && valueCell.classList.contains("image-text-content")) { + // 从包含头像的复杂结构中提取姓名 + const nameElement = valueCell.querySelector(".person-name-warp a"); + if (nameElement) { + return cleanText(nameElement.textContent); + } + // 备用方案:直接提取单元格文本 + return cleanText(valueCell.textContent); + } + } + + // 方法2:通过标题文本定位(备用方案) + const titleElements = Array.from(table.querySelectorAll("td")).filter( + (td) => td.textContent.includes("法定代表人") + ); + + if (titleElements.length > 0 && titleElements[0].nextElementSibling) { + const valueCell = titleElements[0].nextElementSibling; + return cleanText(valueCell.textContent); + } + + return null; + } + + // 核准日期提取方法(优化版) + function getApprovalDate(table) { + // 方法1:通过特定class组合定位 + const approvalElements = Array.from( + table.querySelectorAll(".poptip-wrap-annual-date") + ).filter((el) => el.textContent.includes("核准日期")); + + if (approvalElements.length > 0) { + const valueCell = approvalElements[0].closest("td").nextElementSibling; + if (valueCell) { + const rawValue = valueCell.textContent + .replace(/[\r\n\t]/g, "") + .trim(); + // 验证日期格式 + if (/^\d{4}-\d{2}-\d{2}$/.test(rawValue)) { + return rawValue; + } + } + } + + // 方法2:通过标题文本定位 + const titleElements = Array.from(table.querySelectorAll("td")).filter( + (td) => cleanText(td.textContent) === "核准日期" + ); + + if (titleElements.length > 0 && titleElements[0].nextElementSibling) { + const valueCell = titleElements[0].nextElementSibling; + const rawValue = cleanText(valueCell.textContent); + if (/^\d{4}-\d{2}-\d{2}$/.test(rawValue)) { + return rawValue; + } + } + + return null; + } + + // 组织机构代码提取方法 + function getOrganizationCode(table) { + // 方法1:通过特定class组合定位 + const orgCodeElements = Array.from( + table.querySelectorAll(".poptip-wrap-org-no") + ).filter((el) => el.textContent.includes("组织机构代码")); + + if (orgCodeElements.length > 0) { + const valueCell = orgCodeElements[0].closest("td").nextElementSibling; + if (valueCell && valueCell.classList.contains("enter-bg")) { + const rawValue = + valueCell.querySelector(".enter-bg-ele")?.textContent || + valueCell.textContent; + return cleanText(rawValue); + } + } + + // 方法2:通过标题文本定位 + const titleElements = Array.from(table.querySelectorAll("td")).filter( + (td) => cleanText(td.textContent) === "组织机构代码" + ); + + if (titleElements.length > 0 && titleElements[0].nextElementSibling) { + const valueCell = titleElements[0].nextElementSibling; + const rawValue = + valueCell.querySelector(".enter-bg-ele")?.textContent || + valueCell.textContent; + return cleanText(rawValue); + } + + return null; + } + + // 纳税人识别号提取方法 + function getTaxpayerId(table) { + // 方法1:尝试直接获取纳税人识别号 + const taxElements = Array.from(table.querySelectorAll("td")).filter( + (td) => cleanText(td.textContent).includes("纳税人识别号") + ); + + if (taxElements.length > 0 && taxElements[0].nextElementSibling) { + const valueCell = taxElements[0].nextElementSibling; + const rawValue = + valueCell.querySelector(".enter-bg-ele")?.textContent || + valueCell.textContent; + return cleanText(rawValue); + } + + // 方法2:使用统一社会信用代码(通常与纳税人识别号相同) + const creditElements = Array.from(table.querySelectorAll("td")).filter( + (td) => cleanText(td.textContent).includes("统一社会信用代码") + ); + + if (creditElements.length > 0 && creditElements[0].nextElementSibling) { + const valueCell = creditElements[0].nextElementSibling; + const rawValue = + valueCell.querySelector(".enter-bg-ele")?.textContent || + valueCell.textContent; + return cleanText(rawValue); + } + + return null; + } + + // 工商注册号提取方法 + function getBusinessRegistrationNo(table) { + const regElements = Array.from(table.querySelectorAll("td")).filter( + (td) => cleanText(td.textContent).includes("工商注册号") + ); + + if (regElements.length > 0 && regElements[0].nextElementSibling) { + const valueCell = regElements[0].nextElementSibling; + const rawValue = + valueCell.querySelector(".enter-bg-ele")?.textContent || + valueCell.textContent; + return cleanText(rawValue); + } + + return null; + } + + // 专用参保人数提取方法 + function getInsuranceNumber(table) { + // 方法1:通过标题和特定class组合定位 + const insuranceElements = Array.from(table.querySelectorAll("td")).filter( + (td) => { + return ( + td.textContent.includes("参保人数") && + td.querySelector(".insurance-info") + ); + } + ); + + if (insuranceElements.length > 0) { + const valueCell = insuranceElements[0].nextElementSibling; + if (!valueCell) return null; + + // 提取纯文本内容,过滤掉img标签 + const rawText = valueCell.textContent.replace(/[\r\n\t]/g, "").trim(); + // 匹配"数字+人"格式 + const match = rawText.match(/(\d+人)/); + return match ? match[0] : null; + } + + // 方法2:备用方案,通过相邻单元格内容定位 + const registrationElements = Array.from( + table.querySelectorAll("td") + ).filter((td) => td.textContent.includes("登记机关")); + + if ( + registrationElements.length > 0 && + registrationElements[0].previousElementSibling + ) { + const valueCell = registrationElements[0].previousElementSibling; + const rawText = valueCell.textContent.replace(/[\r\n\t]/g, "").trim(); + const match = rawText.match(/(\d+人)/); + return match ? match[0] : null; + } + + return null; + } + + // 优化后的统一社会信用代码提取方法 + function getUnifiedSocialCreditCode(table) { + // 方法1:直接通过标题定位 + const codeElements = Array.from(table.querySelectorAll("td")).filter( + (td) => { + return ( + td.textContent.includes("统一社会信用代码") && + td.nextElementSibling && + td.nextElementSibling.classList.contains("table-regCapital-lable") + ); + } + ); + + if (codeElements.length > 0) { + const valueCell = codeElements[0].nextElementSibling; + const rawValue = + valueCell.querySelector(".enter-bg-ele")?.textContent || + valueCell.textContent; + return cleanText(rawValue); + } + + // 方法2:备用方案,通过纳税人识别号获取(通常与统一社会信用代码相同) + const taxElements = Array.from(table.querySelectorAll("td")).filter( + (td) => td.textContent.includes("纳税人识别号") + ); + + if (taxElements.length > 0 && taxElements[0].nextElementSibling) { + const valueCell = taxElements[0].nextElementSibling; + const rawValue = + valueCell.querySelector(".enter-bg-ele")?.textContent || + valueCell.textContent; + return cleanText(rawValue); + } + + return null; + } + + // 通用优化字段提取方法 + function getOptimizedValue(table, title) { + const cells = Array.from(table.querySelectorAll("td")); + const titleCell = cells.find( + (cell) => cleanText(cell.textContent) === title + ); + + if (!titleCell) return null; + + // 查找值单元格(考虑多种DOM结构情况) + let valueCell = titleCell.nextElementSibling; + if (!valueCell) return null; + + // 优先提取.enter-bg-ele内的值,若无则直接取单元格文本 + const valueElement = + valueCell.querySelector(".enter-bg-ele") || + valueCell.querySelector(".addr-enter-bg-ele") || + valueCell; + + return cleanText(valueElement.textContent); + } + + // 文本清理函数 + function cleanText(text) { + return text + .replace(/\s+/g, " ") + .replace(/[\r\n\t]/g, "") + .trim(); + } + + // 辅助函数:显示解析结果 + function showResult(data) { + // 创建弹窗 + const modal = document.createElement("div"); + modal.style.position = "fixed"; + modal.style.top = "50%"; + modal.style.left = "50%"; + modal.style.transform = "translate(-50%, -50%)"; + modal.style.width = "600px"; + modal.style.maxHeight = "80vh"; + modal.style.overflowY = "auto"; + modal.style.backgroundColor = "white"; + modal.style.padding = "20px"; + modal.style.boxShadow = "0 0 10px rgba(0,0,0,0.3)"; + modal.style.zIndex = "10000"; + + // 创建JSON显示区域 + const pre = document.createElement("pre"); + pre.textContent = JSON.stringify(data, null, 2); + pre.style.whiteSpace = "pre-wrap"; + pre.style.wordWrap = "break-word"; + + // 创建复制按钮 + const copyBtn = document.createElement("button"); + copyBtn.textContent = "复制JSON"; + copyBtn.style.marginTop = "10px"; + copyBtn.style.padding = "8px 16px"; + copyBtn.style.backgroundColor = "#52c41a"; + copyBtn.style.color = "white"; + copyBtn.style.border = "none"; + copyBtn.style.borderRadius = "4px"; + copyBtn.style.cursor = "pointer"; + + copyBtn.addEventListener("click", function () { + navigator.clipboard + .writeText(JSON.stringify(data, null, 2)) + .then(() => alert("已复制到剪贴板")) + .catch((err) => alert("复制失败: " + err)); + }); + + // 创建关闭按钮 + const closeBtn = document.createElement("button"); + closeBtn.textContent = "关闭"; + closeBtn.style.marginLeft = "10px"; + closeBtn.style.marginTop = "10px"; + closeBtn.style.padding = "8px 16px"; + closeBtn.style.backgroundColor = "#f5222d"; + closeBtn.style.color = "white"; + closeBtn.style.border = "none"; + closeBtn.style.borderRadius = "4px"; + closeBtn.style.cursor = "pointer"; + + closeBtn.addEventListener("click", function () { + document.body.removeChild(modal); + }); + + // 组装弹窗内容 + modal.innerHTML = '

企业信息解析结果

'; + modal.appendChild(pre); + modal.appendChild(document.createElement("br")); + modal.appendChild(copyBtn); + modal.appendChild(closeBtn); + + document.body.appendChild(modal); + } + + // 解析公司信息函数 + function parseCompanyInfo(html) { + // 创建临时DOM解析器 + const parser = new DOMParser(); + const doc = parser.parseFromString(html, "text/html"); + + // 常见公司信息字段解析 + const companyInfo = { + name: extractText(doc, [ + ".company-name", + ".company-title", + "h1", + "title", + ]), + socialCreditCodeText: extractText(doc, [".social-credit-code-text"]), + + legalRepresentative: extractText(doc, [ + ".legal-representative span.a", + ".legal-person", + '[itemprop="founder"]', + ]), + registeredCapital: extractText(doc, [ + ".registered-capital", + ".capital", + '[itemprop="foundingFund"]', + ]), + registrationDate: extractText(doc, [ + ".registration-date", + ".establish-date", + '[itemprop="foundingDate"]', + ]), + businessScope: extractText(doc, [ + ".business-scope", + ".scope", + '[itemprop="knowsAbout"]', + ]), + address: extractText(doc, [ + ".addr-enter-bg-ele", + ".company-address", + ".address", + '[itemprop="address"]', + ]), + phone: extractText(doc, [ + '[data-log-title="detail-head-phone"] span', + ".company-phone", + ".contact-phone", + '[itemprop="telephone"]', + ]), + }; + + return companyInfo; + } + + // 辅助函数:从多个可能的选择器中提取文本 + function extractText(doc, selectors) { + for (const selector of selectors) { + const element = doc.querySelector(selector); + if (element && element.textContent.trim()) { + return element.textContent.trim(); + } + } + return ""; + } + + // 辅助函数:复制到剪贴板 + function copyToClipboard(content, successMessage) { + const textarea = document.createElement("textarea"); + textarea.value = content; + textarea.style.position = "fixed"; + textarea.style.top = "0"; + textarea.style.left = "0"; + textarea.style.width = "1px"; + textarea.style.height = "1px"; + textarea.style.opacity = "0"; + + document.body.appendChild(textarea); + textarea.select(); + document.execCommand("copy"); + document.body.removeChild(textarea); + + if (successMessage) { + alert(successMessage); + } + } + + // 添加按钮到容器 + container.appendChild(copySourceButton); + container.appendChild(parseInfoButton); + + document.body.appendChild(container); + } + + // 页面加载完成后创建按钮 + window.addEventListener("load", createButtonContainer); +})(); \ No newline at end of file diff --git a/script2.js b/script2.js index efa478a..e69de29 100644 --- a/script2.js +++ b/script2.js @@ -1,105 +0,0 @@ -// ==UserScript== -// @name 页面工具按钮 -// @namespace http://tampermonkey.net/ -// @version 0.1 -// @description 在页面右下角添加工具按钮,支持复制源码和解析公司信息 -// @author You -// @match *://*/* -// @grant none -// ==/UserScript== - -(function() { - 'use strict'; - - // 创建按钮容器 - function createButtonContainer() { - const container = document.createElement('div'); - container.id = 'tool-container'; - Object.assign(container.style, { - position: 'fixed', - right: '20px', - bottom: '20px', - zIndex: '9999', - display: 'flex', - flexDirection: 'column', - gap: '10px', - width: '40px', - height: '40px', - backgroundColor: '#4CAF50', - borderRadius: '50%', - transition: 'all 0.3s ease', - overflow: 'hidden', - cursor: 'pointer' - }); - - // +号指示器 - const plusSign = document.createElement('div'); - plusSign.textContent = '+'; - Object.assign(plusSign.style, { - color: 'white', - fontSize: '24px', - textAlign: 'center', - lineHeight: '40px', - width: '100%' - }); - container.appendChild(plusSign); - - // 悬停展开效果 - container.addEventListener('mouseenter', () => { - container.style.width = '150px'; - container.style.height = 'auto'; - container.style.borderRadius = '8px'; - }); - - container.addEventListener('mouseleave', () => { - container.style.width = '40px'; - container.style.height = '40px'; - container.style.borderRadius = '50%'; - }); - - // 创建功能按钮 - function createButton(text, onClick) { - const button = document.createElement('button'); - button.textContent = text; - Object.assign(button.style, { - padding: '8px 12px', - border: 'none', - borderRadius: '4px', - backgroundColor: 'white', - color: '#333', - cursor: 'pointer', - width: '100%', - transition: 'backgroundColor 0.2s' - }); - button.addEventListener('mouseenter', () => button.style.backgroundColor = '#f0f0f0'); - button.addEventListener('mouseleave', () => button.style.backgroundColor = 'white'); - button.addEventListener('click', onClick); - return button; - } - - // 复制源码按钮 - const copySourceButton = createButton('复制源码', () => { - const html = document.documentElement.outerHTML; - navigator.clipboard.writeText(html).then(() => { - alert('源码已复制到剪贴板'); - }).catch(err => { - console.error('复制失败:', err); - }); - }); - - // 解析公司信息按钮 - const parseInfoButton = createButton('解析公司信息', () => { - // 这里添加解析公司信息的逻辑 - alert('解析公司信息功能待实现'); - }); - - // 添加按钮到容器 - container.appendChild(copySourceButton); - container.appendChild(parseInfoButton); - - document.body.appendChild(container); - } - - // 页面加载完成后创建按钮 - window.addEventListener('load', createButtonContainer); -})(); diff --git a/script3.js b/script3.js new file mode 100644 index 0000000..e6ce88d --- /dev/null +++ b/script3.js @@ -0,0 +1,451 @@ +// ==UserScript== +// @name 企业信息自动填写工具 +// @namespace http://tampermonkey.net/ +// @version 0.1 +// @description 从剪贴板读取JSON数据并自动填写表单 +// @author You + +// @grant none +// ==/UserScript== + +(function () { + "use strict"; + + /** + { + "企业名称": "杭州奥杰装饰工程有限公司", + "统一社会信用代码": "9133011031131201XU", + "法定代表人": "曾显军", + "经营状态": "开业", + "成立日期": "2014-08-05", + "行政区划": "浙江省杭州市余杭区", + "注册资本": "200万(元)", + "实缴资本": "200万(元)", + "企业类型": "有限责任公司(自然人独资)", + "所属行业": "批发业", + "工商注册号": "330184000311238", + "组织机构代码": "31131201-X", + "纳税人识别号": "9133011031131201XU", + "纳税人资质": "增值税一般纳税人", + "营业期限": "2014-08-05 至 2034-08-04", + "核准日期": "2020-08-24", + "参保人数": "3人", + "登记机关": "杭州市余杭区市场监督管理局", + "曾用名": "杭州茂复建材有限公司", + "注册地址": "浙江省杭州市余杭区五常街道郭家兜路8号1幢4楼408室", + "经营范围": "设计、施工:建筑工程、室内外装饰工程、幕墙工程;销售:建筑材料,装饰材料,石材,五金;服务:铝合金门窗上门安装,建筑工程技术咨询,国内广告设计和制作。(依法须经批准的项目,经相关部门批准后方可开展经营活动)" + } + */ + // 添加字段映射配置 - 新增代码 + const FIELD_MAPPING = { + 企业名称: { names: ["EC_CUST_NAME", "GROUP_NAME"] }, + 统一社会信用代码: { name: "CUST_CERT_CODE" }, + 法定代表人: { name: "LEGAL_CUST_NAME" }, + 注册地址: { name: "CUST_CERT_ADDRESS" }, + 证件有效期: { name: "CUST_CERT_EXPIRE", type: "date" }, + 集团客户状态: { + name: "GROUP_STATUS", + default: "潜在集团客户", // 添加默认值配置 + }, + "区县(网格平台)": { + name: "GRID_COUNTY_ID", + default: "余杭", + }, + "网格(网格平台)": { + name: "GRID_ID", + default: "余杭未来科技城网格", + }, + "片区(业务大厅)": { + name: "CHNL_REGION_DETAIL", + default: "余杭未来科技城网格", + }, + "营业期限":{ + name: "CUST_CERT_EXPIRE" + } + }; + + // 创建按钮容器 + function createButtonContainer() { + const container = document.createElement("div"); + container.id = "tool-container"; + Object.assign(container.style, { + position: "fixed", + right: "20px", + bottom: "20px", + zIndex: "9999", + display: "flex", + flexDirection: "column", + gap: "10px", + width: "40px", + height: "40px", + backgroundColor: "#4CAF50", + borderRadius: "50%", + transition: "all 0.3s ease", + overflow: "hidden", + cursor: "move", + }); + + // +号指示器 + const plusSign = document.createElement("div"); + plusSign.textContent = "+"; + Object.assign(plusSign.style, { + color: "white", + fontSize: "24px", + textAlign: "center", + lineHeight: "40px", + width: "100%", + }); + container.appendChild(plusSign); + + // 添加JSON输入框 + const jsonInput = document.createElement("textarea"); + jsonInput.placeholder = "粘贴JSON数据..."; + Object.assign(jsonInput.style, { + width: "100%", + height: "100px", + padding: "8px", + borderRadius: "4px", + border: "1px solid #ddd", + resize: "vertical", + marginBottom: "5px", + display: "none", // 默认隐藏 + position: "relative", + zIndex: "10000", // 确保在最上层显示 + }); + + // 悬停展开效果 + container.addEventListener("mouseenter", () => { + container.style.width = "180px"; + container.style.height = "auto"; + container.style.borderRadius = "8px"; + + // 强制显示输入框 + jsonInput.style.display = "block"; + }); + + container.addEventListener("mouseleave", () => { + container.style.width = "40px"; + container.style.height = "40px"; + container.style.borderRadius = "50%"; + jsonInput.style.display = "none"; + }); + container.appendChild(jsonInput); + + // 拖拽功能实现 + let isDragging = false; + let offsetX, offsetY; + + container.addEventListener("mousedown", (e) => { + if (e.target === plusSign || e.target === container) { + isDragging = true; + const rect = container.getBoundingClientRect(); + offsetX = e.clientX - rect.left; + offsetY = e.clientY - rect.top; + container.style.cursor = "grabbing"; + e.stopPropagation(); + e.preventDefault(); + } + }); + + document.addEventListener("mousemove", (e) => { + if (!isDragging) return; + container.style.left = e.clientX - offsetX + "px"; + container.style.top = e.clientY - offsetY + "px"; + container.style.right = "auto"; + container.style.bottom = "auto"; + }); + + document.addEventListener("mouseup", () => { + if (isDragging) { + isDragging = false; + container.style.cursor = "move"; + } + }); + + // 创建功能按钮 + function createButton(text, onClick) { + const button = document.createElement("button"); + button.textContent = text; + Object.assign(button.style, { + padding: "10px", + border: "none", + borderRadius: "4px", + backgroundColor: "white", + color: "#333", + cursor: "pointer", + width: "100%", + transition: "backgroundColor 0.2s", + }); + button.addEventListener( + "mouseenter", + () => (button.style.backgroundColor = "#f0f0f0") + ); + button.addEventListener( + "mouseleave", + () => (button.style.backgroundColor = "white") + ); + button.addEventListener("click", onClick); + return button; + } + + // autoClickToAuditTab + const autoClickToAuditTabButton = createButton( + "自动点击审核建档tab", + async () => { + try { + // 1. 点击审核建档tab + const auditTab = Array.from( + document.querySelectorAll("div, span") + ).find((el) => el.textContent.trim() === "审核建档"); + if (!auditTab) { + throw new Error("未找到审核建档tab"); + } + auditTab.click(); + + // 2. 等待页面加载完成 + await waitForElementToDisappear("table:contains(页面信息加载中...)"); + + // 5. 点击手输证件按钮 + const idButton = Array.from(document.querySelectorAll("button")).find( + (btn) => btn.textContent.includes("手输证件") + ); + if (idButton) { + idButton.click(); + } else { + console.warn("未找到手输证件按钮"); + } + } catch (error) { + alert("点击失败: " + error.message); + console.error("自动点击错误:", error); + } + } + ); + // 添加按钮到容器 + container.appendChild(autoClickToAuditTabButton); + + // 自动填写表单按钮 + const autoFillButton = createButton("自动填写表单", async () => { + try { + // 获取JSON数据(优先使用输入框内容) + let jsonData = jsonInput.value.trim(); + if (!jsonData) { + // 输入框为空时从剪贴板读取 + jsonData = await navigator.clipboard.readText(); + } + const companyInfo = JSON.parse(jsonData); + // 遍历字段映射配置而非JSON数据 - 修改这里 + let filledCount = 0; + for (const [fieldKey, config] of Object.entries(FIELD_MAPPING)) { + // 获取值(JSON数据优先,其次使用默认值) + let value = + companyInfo[fieldKey] !== undefined + ? companyInfo[fieldKey] + : config.default; + + if("营业期限" == fieldKey){ + value = getCustCertExpire(value) + } + if (value !== undefined) { + fillFormField(fieldKey, value); + filledCount++; + } + } + + alert( + "表单填写完成!共填充 " + Object.keys(companyInfo).length + " 个字段" + ); + } catch (error) { + alert("填写失败: " + error.message); + console.error("自动填写错误:", error); + } + }); + + // 添加按钮到容器 + container.appendChild(autoFillButton); + document.body.appendChild(container); + } + + // 等待元素消失 + function waitForElementToDisappear(selector) { + return new Promise((resolve, reject) => { + const checkInterval = setInterval(() => { + const element = document.querySelector(selector); + if (!element || !element.offsetParent) { + clearInterval(checkInterval); + resolve(); + } + }, 300); + + // 设置超时(30秒) + setTimeout(() => { + clearInterval(checkInterval); + reject(new Error("等待超时,页面加载未完成")); + }, 30000); + }); + } + + function getCustCertExpire(value){ + if (value !== undefined) { + const businessTerm = value; + const endDate = parseEndDate(businessTerm); + + // 检查是否需要设置为20年后的日期 + if (!endDate || endDate === "9999-01-01" || endDate === "9999-1-1") { + const currentDate = new Date(); + currentDate.setFullYear(currentDate.getFullYear() + 20); + const formattedDate = `${currentDate.getFullYear()}-${String(currentDate.getMonth() + 1).padStart(2, '0')}-${String(currentDate.getDate()).padStart(2, '0')}`; + return formattedDate + } else { + return endDate + } + } + } + + // 添加营业期限解析函数 + function parseEndDate(businessTerm) { + if (!businessTerm || typeof businessTerm !== "string") return null; + + // 分割"至"前后的日期 + const parts = businessTerm.split('至').map(part => part.trim()); + if (parts.length < 2) return null; + + const endDateStr = parts[1]; + // 验证日期格式并补全位数 + if (/^\d{4}(-\d{1,2}){2}$/.test(endDateStr)) { + const [year, month, day] = endDateStr.split('-').map(Number); + return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`; + } + + return null; + } + + // 表单字段填充函数 + function fillFormField(fieldName, value) { + // 优先使用字段映射 - 新增代码 + const fieldConfig = FIELD_MAPPING[fieldName]; + let opt = false; + if (fieldConfig) { + const doOpt = function (fieldConfigFieldName) { + // 按name属性精确查找 + const input = document.querySelector( + `input[name="${fieldConfigFieldName}"], textarea[name="${fieldConfigFieldName}"], select[name="${fieldConfigFieldName}"]` + ); + if (input) { + // 日期字段特殊处理 + if (fieldConfig.type === "date" && value) { + // 直接设置值并触发WdatePicker所需事件 + input.value = value; + input.dispatchEvent(new Event("focus")); + input.dispatchEvent(new Event("blur")); + } else if (input.tagName === "SELECT") { + Array.from(input.options).forEach((option) => { + if (option.value === value || option.textContent === value) { + option.selected = true; + } + }); + // 触发change事件使选择生效 + input.dispatchEvent(new Event("change")); + } else { + setInputValue(input, value); + } + return true; + } + return false; + }; + if (fieldConfig.names) { + // 遍历names数组填充所有关联字段 + fieldConfig.names.forEach((fieldConfigFieldName) => { + let optTmp = doOpt(fieldConfigFieldName); + if (optTmp) { + opt = true; + } + }); + } + if (fieldConfig.name) { + let optTmp = doOpt(fieldConfig.name); + if (optTmp) { + opt = true; + } + } + } + if (opt) { + return true; + } + // 尝试通过label文本匹配 + const labels = document.querySelectorAll("label"); + for (const label of labels) { + if (label.textContent.trim().includes(fieldName)) { + const input = + label.querySelector("input, textarea, select") || + document.getElementById(label.htmlFor); + if (input) { + setInputValue(input, value); + return true; + } + } + } + + // 尝试通过input的placeholder匹配 + const placeholders = document.querySelectorAll( + "input[placeholder], textarea[placeholder]" + ); + for (const input of placeholders) { + if (input.placeholder.includes(fieldName)) { + setInputValue(input, value); + return true; + } + } + + // 尝试通过input的name属性匹配 + const nameInputs = document.querySelectorAll( + `input[name*=${fieldName}], textarea[name*=${fieldName}]` + ); + if (nameInputs.length > 0) { + setInputValue(nameInputs[0], value); + return true; + } + + console.log(`未找到字段: ${fieldName}`); + return false; + } + + // 设置输入框值 + function setInputValue(input, value) { + if (!input) return; + + // 根据输入框类型设置值 + if (input.type === "checkbox") { + input.checked = value === "true" || value === true || value === "1"; + } else if (input.type === "radio") { + const radio = document.querySelector( + `input[name="${input.name}"][value="${value}"]` + ); + if (radio) radio.checked = true; + } else if (input.tagName === "SELECT") { + Array.from(input.options).forEach((option) => { + if (option.value === value || option.textContent === value) { + option.selected = true; + } + }); + } else if ( + input.tagName === "TEXTAREA" || + input.type === "text" || + input.type === "number" || + input.type === "email" + ) { + input.value = value; + // 触发输入事件以确保表单验证和相关逻辑执行 + input.dispatchEvent(new Event("input", { bubbles: true })); + input.dispatchEvent(new Event("change", { bubbles: true })); + + // 日期字段额外触发focus/blur事件 - 新增代码 + if (input.classList.contains("Wdate")) { + input.dispatchEvent(new Event("focus")); + input.dispatchEvent(new Event("blur")); + } + } + } + + // 初始化工具 + createButtonContainer(); +})(); \ No newline at end of file