185 lines
7.3 KiB
HTML
185 lines
7.3 KiB
HTML
|
|
<!DOCTYPE html>
|
|||
|
|
<html>
|
|||
|
|
<head>
|
|||
|
|
<title>新增项目功能测试</title>
|
|||
|
|
<style>
|
|||
|
|
body { font-family: Arial, sans-serif; margin: 20px; }
|
|||
|
|
.form-group { margin-bottom: 15px; }
|
|||
|
|
label { display: block; margin-bottom: 5px; font-weight: bold; }
|
|||
|
|
input, select, textarea { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; }
|
|||
|
|
button { background: #1890ff; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; }
|
|||
|
|
button:hover { background: #40a9ff; }
|
|||
|
|
.result { margin-top: 20px; padding: 15px; background: #f5f5f5; border-radius: 4px; }
|
|||
|
|
.success { background: #f6ffed; border: 1px solid #b7eb8f; }
|
|||
|
|
.error { background: #fff2f0; border: 1px solid #ffccc7; }
|
|||
|
|
</style>
|
|||
|
|
</head>
|
|||
|
|
<body>
|
|||
|
|
<h1>新增项目功能测试</h1>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>项目名称:</label>
|
|||
|
|
<input type="text" id="name" value="测试项目_20241220" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>养殖场名称:</label>
|
|||
|
|
<input type="text" id="farmName" value="测试养殖场" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>监管对象:</label>
|
|||
|
|
<input type="text" id="supervisionObject" value="牛" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>监管周期:</label>
|
|||
|
|
<input type="text" id="supervisionPeriod" value="12个月" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>监管数量:</label>
|
|||
|
|
<input type="number" id="supervisionQuantity" value="100" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>监管金额:</label>
|
|||
|
|
<input type="number" id="supervisionAmount" value="500000" step="0.01" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>起始时间:</label>
|
|||
|
|
<input type="date" id="startTime" value="2024-01-01" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>结束时间:</label>
|
|||
|
|
<input type="date" id="endTime" value="2024-12-31" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>耳标数量:</label>
|
|||
|
|
<input type="number" id="earTag" value="50" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>项圈数量:</label>
|
|||
|
|
<input type="number" id="collar" value="30" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>主机数量:</label>
|
|||
|
|
<input type="number" id="host" value="20" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>贷款专员:</label>
|
|||
|
|
<input type="text" id="loanOfficer" value="张专员" />
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>项目描述:</label>
|
|||
|
|
<textarea id="description" rows="3">这是一个测试项目</textarea>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<button onclick="testCreateProject()">测试创建项目</button>
|
|||
|
|
|
|||
|
|
<div id="result" class="result" style="display: none;"></div>
|
|||
|
|
|
|||
|
|
<script>
|
|||
|
|
let token = '';
|
|||
|
|
|
|||
|
|
async function testCreateProject() {
|
|||
|
|
try {
|
|||
|
|
// 1. 先登录
|
|||
|
|
console.log('1. 登录获取token...');
|
|||
|
|
const loginResponse = await fetch('http://localhost:5351/api/auth/login', {
|
|||
|
|
method: 'POST',
|
|||
|
|
headers: {
|
|||
|
|
'Content-Type': 'application/json'
|
|||
|
|
},
|
|||
|
|
body: JSON.stringify({
|
|||
|
|
username: 'admin',
|
|||
|
|
password: 'Admin123456'
|
|||
|
|
})
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
const loginData = await loginResponse.json();
|
|||
|
|
if (!loginData.success) {
|
|||
|
|
throw new Error('登录失败: ' + loginData.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
token = loginData.data.token;
|
|||
|
|
console.log('登录成功,token:', token.substring(0, 20) + '...');
|
|||
|
|
|
|||
|
|
// 2. 创建项目
|
|||
|
|
console.log('2. 创建项目...');
|
|||
|
|
const projectData = {
|
|||
|
|
name: document.getElementById('name').value,
|
|||
|
|
status: 'supervision',
|
|||
|
|
farmName: document.getElementById('farmName').value,
|
|||
|
|
supervisionObject: document.getElementById('supervisionObject').value,
|
|||
|
|
supervisionQuantity: parseInt(document.getElementById('supervisionQuantity').value),
|
|||
|
|
supervisionPeriod: document.getElementById('supervisionPeriod').value,
|
|||
|
|
supervisionAmount: parseFloat(document.getElementById('supervisionAmount').value),
|
|||
|
|
startTime: document.getElementById('startTime').value,
|
|||
|
|
endTime: document.getElementById('endTime').value,
|
|||
|
|
earTag: parseInt(document.getElementById('earTag').value),
|
|||
|
|
collar: parseInt(document.getElementById('collar').value),
|
|||
|
|
host: parseInt(document.getElementById('host').value),
|
|||
|
|
loanOfficer: document.getElementById('loanOfficer').value,
|
|||
|
|
description: document.getElementById('description').value
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
console.log('项目数据:', projectData);
|
|||
|
|
|
|||
|
|
const createResponse = await fetch('http://localhost:5351/api/projects', {
|
|||
|
|
method: 'POST',
|
|||
|
|
headers: {
|
|||
|
|
'Authorization': 'Bearer ' + token,
|
|||
|
|
'Content-Type': 'application/json'
|
|||
|
|
},
|
|||
|
|
body: JSON.stringify(projectData)
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
const createData = await createResponse.json();
|
|||
|
|
console.log('创建响应:', createData);
|
|||
|
|
|
|||
|
|
const resultDiv = document.getElementById('result');
|
|||
|
|
resultDiv.style.display = 'block';
|
|||
|
|
|
|||
|
|
if (createData.success) {
|
|||
|
|
resultDiv.className = 'result success';
|
|||
|
|
resultDiv.innerHTML = `
|
|||
|
|
<h3>✅ 项目创建成功!</h3>
|
|||
|
|
<p><strong>项目ID:</strong> ${createData.data.id}</p>
|
|||
|
|
<p><strong>项目名称:</strong> ${createData.data.name}</p>
|
|||
|
|
<p><strong>养殖场:</strong> ${createData.data.farmName}</p>
|
|||
|
|
<p><strong>监管对象:</strong> ${createData.data.supervisionObject}</p>
|
|||
|
|
<p><strong>监管数量:</strong> ${createData.data.supervisionQuantity}</p>
|
|||
|
|
<p><strong>监管金额:</strong> ${createData.data.supervisionAmount}元</p>
|
|||
|
|
<p><strong>创建时间:</strong> ${new Date(createData.data.createdAt).toLocaleString()}</p>
|
|||
|
|
`;
|
|||
|
|
} else {
|
|||
|
|
resultDiv.className = 'result error';
|
|||
|
|
resultDiv.innerHTML = `
|
|||
|
|
<h3>❌ 项目创建失败</h3>
|
|||
|
|
<p><strong>错误信息:</strong> ${createData.message}</p>
|
|||
|
|
`;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('测试失败:', error);
|
|||
|
|
const resultDiv = document.getElementById('result');
|
|||
|
|
resultDiv.style.display = 'block';
|
|||
|
|
resultDiv.className = 'result error';
|
|||
|
|
resultDiv.innerHTML = `
|
|||
|
|
<h3>❌ 测试失败</h3>
|
|||
|
|
<p><strong>错误信息:</strong> ${error.message}</p>
|
|||
|
|
`;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
</script>
|
|||
|
|
</body>
|
|||
|
|
</html>
|