* 扫描页面表单结构(增强版)
()
| 389 | * 扫描页面表单结构(增强版) |
| 390 | */ |
| 391 | function scanForm() { |
| 392 | const inputs = Array.from(document.querySelectorAll('input:not([type="hidden"]):not([type="submit"]):not([type="button"]), select, textarea')); |
| 393 | const formStructure = []; |
| 394 | |
| 395 | inputs.forEach((input, index) => { |
| 396 | if (!isVisible(input) || input.disabled || input.readOnly) return; |
| 397 | |
| 398 | // 获取标签文本(增强版) |
| 399 | const labelInfo = getEnhancedLabel(input); |
| 400 | |
| 401 | // 获取扩展上下文(向上遍历3层) |
| 402 | const context = getExpandedContext(input); |
| 403 | |
| 404 | // 检测所属分组 |
| 405 | const group = detectFieldGroup(input); |
| 406 | |
| 407 | // 检测相邻字段关系 |
| 408 | const siblingInfo = detectSiblingRelation(input, inputs); |
| 409 | |
| 410 | // 获取 ID 或 Name 作为唯一标识 |
| 411 | const id = input.id || input.name || `field_${index}`; |
| 412 | |
| 413 | formStructure.push({ |
| 414 | id: id, |
| 415 | type: input.type || input.tagName.toLowerCase(), |
| 416 | label: labelInfo.text, |
| 417 | labelSource: labelInfo.source, |
| 418 | placeholder: input.placeholder || '', |
| 419 | context: context, |
| 420 | group: group, |
| 421 | siblings: siblingInfo, |
| 422 | name: input.name || '', |
| 423 | className: input.className || '', |
| 424 | required: input.required || input.getAttribute('aria-required') === 'true', |
| 425 | min: input.min || '', |
| 426 | max: input.max || '', |
| 427 | maxLength: input.maxLength > 0 ? input.maxLength : '', |
| 428 | pattern: input.pattern || '', |
| 429 | autocomplete: input.autocomplete || '' |
| 430 | }); |
| 431 | }); |
| 432 | |
| 433 | // 获取页面语义信息(增强版) |
| 434 | const pageContext = analyzePageContext(); |
| 435 | |
| 436 | return { |
| 437 | fields: formStructure, |
| 438 | pageContext: pageContext |
| 439 | }; |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * 获取增强的标签信息 |
no test coverage detected