This commit is contained in:
shenquanyi
2025-08-27 15:36:36 +08:00
parent ec72c6a8b5
commit 2bd1d8c032
100 changed files with 25780 additions and 20 deletions

View File

@@ -0,0 +1,373 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>经纬度输入调试</title>
<style>
body {
padding: 20px;
font-family: Arial, sans-serif;
background: #f5f5f5;
}
.debug-container {
max-width: 900px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.debug-section {
margin-bottom: 30px;
padding: 20px;
border: 1px solid #e8e8e8;
border-radius: 6px;
background: #fafafa;
}
.debug-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 15px;
color: #1890ff;
}
.debug-info {
background: #f0f0f0;
padding: 15px;
border-radius: 4px;
margin-top: 10px;
font-family: 'Courier New', monospace;
white-space: pre-wrap;
border-left: 4px solid #52c41a;
font-size: 13px;
}
.input-group {
display: flex;
gap: 20px;
margin-bottom: 20px;
}
.input-item {
flex: 1;
}
.input-item label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #333;
}
.input-item input {
width: 100%;
padding: 8px 12px;
border: 1px solid #d9d9d9;
border-radius: 4px;
font-size: 14px;
box-sizing: border-box;
}
.input-item input:focus {
border-color: #1890ff;
outline: none;
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}
.test-case {
margin-bottom: 10px;
padding: 12px;
background: white;
border: 1px solid #e8e8e8;
border-radius: 4px;
display: flex;
justify-content: space-between;
align-items: center;
}
.test-case-info {
flex: 1;
}
.test-case-name {
font-weight: bold;
color: #333;
}
.test-case-values {
color: #666;
font-size: 12px;
margin-top: 2px;
}
button {
padding: 6px 12px;
background: #1890ff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
}
button:hover {
background: #40a9ff;
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
.log-area {
height: 200px;
overflow-y: auto;
background: #1e1e1e;
color: #d4d4d4;
padding: 10px;
border-radius: 4px;
font-family: 'Courier New', monospace;
font-size: 12px;
line-height: 1.4;
}
.clear-btn {
background: #ff4d4f;
margin-top: 10px;
}
.clear-btn:hover {
background: #ff7875;
}
</style>
</head>
<body>
<div class="debug-container">
<h1>经纬度输入调试工具</h1>
<!-- 实时输入测试 -->
<div class="debug-section">
<div class="debug-title">实时输入测试</div>
<div class="input-group">
<div class="input-item">
<label>经度 (Longitude):</label>
<input
type="text"
id="longitude"
placeholder="请输入经度 (-180 到 180)"
oninput="handleCoordinateInput('longitude', this.value)"
/>
</div>
<div class="input-item">
<label>纬度 (Latitude):</label>
<input
type="text"
id="latitude"
placeholder="请输入纬度 (-90 到 90)"
oninput="handleCoordinateInput('latitude', this.value)"
/>
</div>
</div>
<div class="debug-info" id="currentValues">
当前值:
经度: undefined (类型: undefined)
纬度: undefined (类型: undefined)
提交数据:
{}
</div>
<div style="margin-top: 15px;">
<button onclick="simulateSubmit()">模拟提交到后端</button>
<button onclick="clearCoordinates()" style="margin-left: 10px;">清空坐标</button>
</div>
</div>
<!-- 预设测试用例 -->
<div class="debug-section">
<div class="debug-title">预设测试用例</div>
<div id="testCases"></div>
</div>
<!-- 操作日志 -->
<div class="debug-section">
<div class="debug-title">操作日志</div>
<div class="log-area" id="logArea"></div>
<button class="clear-btn" onclick="clearLogs()">清空日志</button>
</div>
</div>
<script>
// 全局状态
let formData = {
longitude: undefined,
latitude: undefined
};
let logs = [];
const testCases = [
{ name: '正常小数', longitude: '106.2400', latitude: '38.4900' },
{ name: '整数', longitude: '106', latitude: '38' },
{ name: '高精度小数', longitude: '106.234567', latitude: '38.487654' },
{ name: '负数', longitude: '-106.2400', latitude: '-38.4900' },
{ name: '包含字母', longitude: '106.24abc', latitude: '38.49xyz' },
{ name: '多个小数点', longitude: '106.24.56', latitude: '38.49.78' },
{ name: '空字符串', longitude: '', latitude: '' },
{ name: '只有小数点', longitude: '.', latitude: '.' },
{ name: '边界值', longitude: '180.0', latitude: '90.0' },
{ name: '超出范围', longitude: '200.0', latitude: '100.0' }
];
// 坐标解析器
function parseCoordinate(value) {
if (!value) return value;
// 移除非数字字符,保留小数点和负号
const cleaned = value.toString().replace(/[^\d.-]/g, '');
// 确保只有一个小数点
const parts = cleaned.split('.');
let result;
if (parts.length > 2) {
result = parts[0] + '.' + parts.slice(1).join('');
} else {
result = cleaned;
}
return result;
}
// 处理坐标输入
function handleCoordinateInput(type, value) {
log(`${type === 'longitude' ? '经度' : '纬度'}输入: "${value}"`);
const parsed = parseCoordinate(value);
log(`${type === 'longitude' ? '经度' : '纬度'}解析后: "${parsed}"`);
// 转换为数字
const numValue = parsed === '' ? undefined : parseFloat(parsed);
formData[type] = isNaN(numValue) ? undefined : numValue;
log(`${type === 'longitude' ? '经度' : '纬度'}最终值: ${formData[type]} (类型: ${typeof formData[type]})`);
// 更新输入框显示
document.getElementById(type).value = parsed;
// 更新显示
updateDisplay();
}
// 更新显示
function updateDisplay() {
const currentValuesDiv = document.getElementById('currentValues');
const submitData = getSubmitData();
currentValuesDiv.textContent = `当前值:
经度: ${formData.longitude} (类型: ${typeof formData.longitude})
纬度: ${formData.latitude} (类型: ${typeof formData.latitude})
提交数据:
${JSON.stringify(submitData, null, 2)}`;
}
// 获取提交数据
function getSubmitData() {
const submitData = {
name: '测试农场',
type: 'farm',
owner: '测试负责人',
phone: '13800138000',
address: '测试地址',
status: 'active'
};
// 只有当经纬度有效时才添加
if (formData.longitude !== undefined && formData.longitude !== null) {
submitData.longitude = formData.longitude;
}
if (formData.latitude !== undefined && formData.latitude !== null) {
submitData.latitude = formData.latitude;
}
return submitData;
}
// 应用测试用例
function applyTestCase(testCase) {
log(`\n=== 应用测试用例: ${testCase.name} ===`);
log(`设置经度: "${testCase.longitude}"`);
log(`设置纬度: "${testCase.latitude}"`);
// 设置输入框值并触发处理
document.getElementById('longitude').value = testCase.longitude;
document.getElementById('latitude').value = testCase.latitude;
handleCoordinateInput('longitude', testCase.longitude);
handleCoordinateInput('latitude', testCase.latitude);
}
// 模拟提交
async function simulateSubmit() {
log(`\n=== 模拟API提交 ===`);
const submitData = getSubmitData();
log(`提交数据: ${JSON.stringify(submitData, null, 2)}`);
try {
// 模拟API调用
const response = await fetch('http://localhost:5350/api/farms', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(submitData)
});
const result = await response.json();
log(`API响应成功: ${JSON.stringify(result)}`);
alert('提交成功');
} catch (error) {
log(`API调用失败: ${error.message}`);
alert('API调用失败: ' + error.message);
}
}
// 清空坐标
function clearCoordinates() {
formData.longitude = undefined;
formData.latitude = undefined;
document.getElementById('longitude').value = '';
document.getElementById('latitude').value = '';
updateDisplay();
log('已清空坐标');
}
// 日志功能
function log(message) {
const timestamp = new Date().toLocaleTimeString();
logs.push(`[${timestamp}] ${message}`);
updateLogDisplay();
}
function updateLogDisplay() {
const logArea = document.getElementById('logArea');
logArea.textContent = logs.join('\n');
logArea.scrollTop = logArea.scrollHeight;
}
function clearLogs() {
logs = [];
updateLogDisplay();
}
// 初始化
document.addEventListener('DOMContentLoaded', function() {
// 渲染测试用例
const testCasesDiv = document.getElementById('testCases');
testCases.forEach(testCase => {
const div = document.createElement('div');
div.className = 'test-case';
div.innerHTML = `
<div class="test-case-info">
<div class="test-case-name">${testCase.name}</div>
<div class="test-case-values">经度: ${testCase.longitude}, 纬度: ${testCase.latitude}</div>
</div>
<button onclick="applyTestCase({name: '${testCase.name}', longitude: '${testCase.longitude}', latitude: '${testCase.latitude}'})">应用</button>
`;
testCasesDiv.appendChild(div);
});
log('调试工具已加载');
log('请使用测试用例或手动输入来测试经纬度输入框');
updateDisplay();
});
</script>
</body>
</html>