2025-12-04 14:41:20 +08:00

441 lines
14 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>智慧监督AI文书写作 - 解析接口测试</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 12px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 28px;
margin-bottom: 10px;
}
.header p {
opacity: 0.9;
font-size: 14px;
}
.content {
padding: 30px;
}
.section {
margin-bottom: 30px;
}
.section-title {
font-size: 18px;
font-weight: 600;
color: #333;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 2px solid #667eea;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
color: #555;
font-weight: 500;
}
.form-group input,
.form-group select,
.form-group textarea {
width: 100%;
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 6px;
font-size: 14px;
transition: border-color 0.3s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
outline: none;
border-color: #667eea;
}
.form-group textarea {
min-height: 100px;
resize: vertical;
font-family: inherit;
}
.input-fields {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 15px;
margin-bottom: 15px;
}
.input-fields input {
margin-bottom: 0;
}
.btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 12px 30px;
border-radius: 6px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}
.btn:active {
transform: translateY(0);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.result-box {
background: #f8f9fa;
border: 2px solid #e0e0e0;
border-radius: 6px;
padding: 20px;
margin-top: 20px;
max-height: 500px;
overflow-y: auto;
}
.result-box pre {
margin: 0;
font-family: 'Courier New', monospace;
font-size: 13px;
line-height: 1.6;
white-space: pre-wrap;
word-wrap: break-word;
}
.result-item {
background: white;
padding: 15px;
margin-bottom: 10px;
border-radius: 6px;
border-left: 4px solid #667eea;
}
.result-item strong {
color: #667eea;
display: inline-block;
min-width: 150px;
}
.loading {
display: none;
text-align: center;
padding: 20px;
}
.loading.active {
display: block;
}
.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #667eea;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.error {
background: #fee;
border-left-color: #f44336;
color: #c62828;
}
.success {
background: #e8f5e9;
border-left-color: #4caf50;
}
.add-field-btn {
background: #4caf50;
padding: 8px 15px;
font-size: 14px;
margin-top: 10px;
}
.remove-field-btn {
background: #f44336;
padding: 6px 12px;
font-size: 12px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>智慧监督AI文书写作</h1>
<p>解析接口测试工具 - 初步核实审批表</p>
</div>
<div class="content">
<!-- 输入区域 -->
<div class="section">
<div class="section-title">输入数据</div>
<div class="form-group">
<label>业务类型</label>
<select id="businessType">
<option value="INVESTIGATION">INVESTIGATION (调查核实)</option>
<option value="COMPLAINT">COMPLAINT (投诉举报)</option>
</select>
</div>
<div class="form-group">
<label>输入字段数据</label>
<div id="inputFieldsContainer">
<!-- 动态生成的输入字段 -->
</div>
<button class="btn add-field-btn" onclick="addInputField()">+ 添加输入字段</button>
</div>
</div>
<!-- 操作按钮 -->
<div class="section">
<button class="btn" onclick="extractData()" id="extractBtn">开始解析</button>
</div>
<!-- 加载提示 -->
<div class="loading" id="loading">
<div class="spinner"></div>
<p>AI正在解析中请稍候...</p>
</div>
<!-- 结果展示 -->
<div class="section" id="resultSection" style="display: none;">
<div class="section-title">解析结果</div>
<div class="result-box" id="resultBox"></div>
</div>
</div>
</div>
<script>
let inputFields = [];
let outputFields = [];
// 页面加载时初始化
window.onload = function() {
loadFields();
initDefaultInputFields();
};
// 加载字段配置
async function loadFields() {
try {
const response = await fetch('/api/fields?businessType=INVESTIGATION');
const result = await response.json();
if (result.isSuccess && result.data) {
outputFields = result.data.output_fields || [];
// 可以在这里使用outputFields来显示字段信息
}
} catch (error) {
console.error('加载字段配置失败:', error);
}
}
// 初始化默认输入字段
function initDefaultInputFields() {
addInputField('clue_info', '线索信息', '被举报用户名称是张三年龄30岁某公司总经理');
addInputField('target_basic_info_clue', '被核查人员工作基本情况线索', '张三汉族1980年5月出生山西太原人本科学历2000年参加工作2005年加入中国共产党。');
}
// 添加输入字段
function addInputField(fieldCode = '', fieldName = '', fieldValue = '') {
const container = document.getElementById('inputFieldsContainer');
const fieldDiv = document.createElement('div');
fieldDiv.className = 'input-fields';
fieldDiv.innerHTML = `
<input type="text" placeholder="字段编码 (如: clue_info)" value="${fieldCode}" class="field-code">
<div style="display: flex; gap: 10px;">
<input type="text" placeholder="字段值" value="${fieldValue}" class="field-value" style="flex: 1;">
<button class="btn remove-field-btn" onclick="removeInputField(this)">删除</button>
</div>
`;
container.appendChild(fieldDiv);
}
// 删除输入字段
function removeInputField(btn) {
btn.closest('.input-fields').remove();
}
// 提取数据
async function extractData() {
const extractBtn = document.getElementById('extractBtn');
const loading = document.getElementById('loading');
const resultSection = document.getElementById('resultSection');
const resultBox = document.getElementById('resultBox');
// 收集输入数据
const inputFields = [];
const fieldContainers = document.querySelectorAll('#inputFieldsContainer .input-fields');
fieldContainers.forEach(container => {
const fieldCode = container.querySelector('.field-code').value.trim();
const fieldValue = container.querySelector('.field-value').value.trim();
if (fieldCode && fieldValue) {
inputFields.push({
fieldCode: fieldCode,
fieldValue: fieldValue
});
}
});
if (inputFields.length === 0) {
alert('请至少添加一个输入字段');
return;
}
const businessType = document.getElementById('businessType').value;
// 构建请求数据
const requestData = {
businessType: businessType,
inputData: inputFields
};
// 显示加载状态
extractBtn.disabled = true;
loading.classList.add('active');
resultSection.style.display = 'none';
try {
const response = await fetch('/api/ai/extract', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
});
const result = await response.json();
// 显示结果
displayResult(result, requestData);
} catch (error) {
displayError(error.message);
} finally {
extractBtn.disabled = false;
loading.classList.remove('active');
}
}
// 显示结果
function displayResult(result, requestData) {
const resultSection = document.getElementById('resultSection');
const resultBox = document.getElementById('resultBox');
resultSection.style.display = 'block';
let html = '';
// 显示请求数据
html += '<div class="result-item"><strong>请求数据:</strong></div>';
html += '<div class="result-item"><pre>' + JSON.stringify(requestData, null, 2) + '</pre></div>';
// 显示响应结果
if (result.isSuccess) {
html += '<div class="result-item success"><strong>解析成功!</strong></div>';
if (result.data && result.data.outData) {
html += '<div class="result-item"><strong>提取的字段:</strong></div>';
result.data.outData.forEach(item => {
html += `<div class="result-item">
<strong>${item.fieldCode}:</strong> ${item.fieldValue || '(空)'}
</div>`;
});
}
} else {
html += `<div class="result-item error">
<strong>解析失败!</strong><br>
错误码: ${result.code}<br>
错误信息: ${result.errorMsg}
</div>`;
}
// 显示完整响应
html += '<div class="result-item"><strong>完整响应:</strong></div>';
html += '<div class="result-item"><pre>' + JSON.stringify(result, null, 2) + '</pre></div>';
resultBox.innerHTML = html;
// 滚动到结果区域
resultSection.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
// 显示错误
function displayError(errorMsg) {
const resultSection = document.getElementById('resultSection');
const resultBox = document.getElementById('resultBox');
resultSection.style.display = 'block';
resultBox.innerHTML = `<div class="result-item error">
<strong>请求失败!</strong><br>
${errorMsg}
</div>`;
}
</script>
</body>
</html>