SCRUM3
昨天的成就:
昨天我完成了考核健康模块,包含绩效考核与健康管理功能。并对主页面home.html文件进行了优化缩减,将多余的script文件放入js文件里,对代码进行修正时更直观。
绩效考核(PerformanceManagement.js):
// 动态加载绩效考核内容
function loadPerformanceManagement(container) {
container.innerHTML = `
<div class="performance-management">
<h3 style="font-size: 1.5rem;"></h3>
<div id="performanceContent"></div>
</div>
`;
// 获取用户绩效分数
fetch('/api/user/performance-score')
.then(response => {
if (!response.ok) {
throw new Error('网络响应失败');
}
return response.json();
})
.then(data => {
const performanceContent = document.getElementById('performanceContent');
if (data.performanceScore === null) {
// 用户没有分数,显示提示和生成分数按钮
performanceContent.innerHTML = `
<p style="font-size: 1.2rem;">您当前没有绩效分数。</p>
<button onclick="generatePerformanceScore()" style="font-size: 1.1rem; padding: 10px 20px;">生成分数</button>
`;
} else {
// 用户已有分数,显示分数和重新生成按钮
performanceContent.innerHTML = `
<p style="font-size: 1.2rem;">您的当前绩效分数:${data.performanceScore}</p>
<button onclick="regeneratePerformanceScore()" style="font-size: 1.1rem; padding: 10px 20px;">重新生成分数</button>
`;
}
})
.catch(error => {
console.error('获取绩效分数出错:', error);
document.getElementById('performanceContent').innerHTML = '<p style="color: red; font-size: 1.2rem;">获取绩效分数失败,请刷新重试</p>';
});
}
// 生成随机绩效分数并保存到数据库
function generatePerformanceScore() {
fetch('/api/user/generate-performance-score', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应失败');
}
return response.json();
})
.then(data => {
alert('绩效分数生成成功!');
// 刷新页面以显示新分数
location.reload();
})
.catch(error => {
console.error('生成绩效分数出错:', error);
alert('生成绩效分数失败,请重试');
});
}
// 重新生成随机绩效分数并更新数据库
function regeneratePerformanceScore() {
fetch('/api/user/regenerate-performance-score', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应失败');
}
return response.json();
})
.then(data => {
alert('绩效分数更新成功!');
// 刷新页面以显示新分数
location.reload();
})
.catch(error => {
console.error('更新绩效分数出错:', error);
alert('更新绩效分数失败,请重试');
});
}
健康管理(HealthManagement.js):
// 动态加载体检管理内容
function loadHealthManagement(container) {
container.innerHTML = `
<div class="health-management">
<h3 style="font-size: 1.5rem;"></h3>
<div id="healthContent"></div>
</div>
`;
// 获取用户体检数据
fetch('/api/user/health-data')
.then(response => {
if (!response.ok) {
throw new Error('网络响应失败');
}
return response.json();
})
.then(data => {
const healthContent = document.getElementById('healthContent');
if (data.height === null || data.weight === null || data.vision === null) {
// 用户没有完整的体检数据,显示输入框和保存按钮
healthContent.innerHTML = `
<p style="font-size: 1.2rem;">您尚未录入体检数据,请填写以下信息:</p>
<div style="margin-bottom: 15px;">
<label for="heightInput" style="display: block; margin-bottom: 5px; font-size: 1.1rem;">身高(cm):</label>
<input type="number" id="heightInput" step="0.01" placeholder="例如:175.50" style="width: 100%; padding: 8px; font-size: 1rem;">
</div>
<div style="margin-bottom: 15px;">
<label for="weightInput" style="display: block; margin-bottom: 5px; font-size: 1.1rem;">体重(kg):</label>
<input type="number" id="weightInput" step="0.01" placeholder="例如:68.50" style="width: 100%; padding: 8px; font-size: 1rem;">
</div>
<div style="margin-bottom: 15px;">
<label for="visionInput" style="display: block; margin-bottom: 5px; font-size: 1.1rem;">视力:</label>
<input type="number" id="visionInput" step="0.1" placeholder="例如:5.0" style="width: 100%; padding: 8px; font-size: 1rem;">
</div>
<button onclick="saveHealthData()" style="font-size: 1.1rem; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">保存数据</button>
`;
} else {
// 用户已有体检数据,显示数据和更新按钮
healthContent.innerHTML = `
<p style="font-size: 1.2rem;">您的体检数据:</p>
<p style="margin: 10px 0; font-size: 1.1rem;">身高:${data.height} cm</p>
<p style="margin: 10px 0; font-size: 1.1rem;">体重:${data.weight} kg</p>
<p style="margin: 10px 0; font-size: 1.1rem;">视力:${data.vision}</p>
<button onclick="showUpdateHealthForm()" style="font-size: 1.1rem; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">更新数据</button>
`;
}
})
.catch(error => {
console.error('获取体检数据出错:', error);
document.getElementById('healthContent').innerHTML = '<p style="color: red; font-size: 1.2rem;">获取体检数据失败,请刷新重试</p>';
});
}
// 保存体检数据到数据库
function saveHealthData() {
const height = parseFloat(document.getElementById('heightInput').value);
const weight = parseFloat(document.getElementById('weightInput').value);
const vision = parseFloat(document.getElementById('visionInput').value);
if (isNaN(height) || isNaN(weight) || isNaN(vision)) {
alert('请输入有效的体检数据');
return;
}
// 确保发送的数据格式正确
fetch('/api/user/save-health-data', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
height: height,
weight: weight,
vision: vision
})
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应失败');
}
return response.json();
})
.then(data => {
alert('体检数据保存成功!');
// 刷新页面以显示新数据
location.reload();
})
.catch(error => {
console.error('保存体检数据出错:', error);
alert('保存体检数据失败,请重试');
});
}
// 显示更新体检数据的表单
function showUpdateHealthForm() {
const healthContent = document.getElementById('healthContent');
healthContent.innerHTML = `
<p style="font-size: 1.2rem;">请更新您的体检数据:</p>
<div style="margin-bottom: 15px;">
<label for="heightInput" style="display: block; margin-bottom: 5px; font-size: 1.1rem;">身高(cm):</label>
<input type="number" id="heightInput" step="0.01" placeholder="例如:175.50" style="width: 100%; padding: 8px; font-size: 1rem;">
</div>
<div style="margin-bottom: 15px;">
<label for="weightInput" style="display: block; margin-bottom: 5px; font-size: 1.1rem;">体重(kg):</label>
<input type="number" id="weightInput" step="0.01" placeholder="例如:68.50" style="width: 100%; padding: 8px; font-size: 1rem;">
</div>
<div style="margin-bottom: 15px;">
<label for="visionInput" style="display: block; margin-bottom: 5px; font-size: 1.1rem;">视力:</label>
<input type="number" id="visionInput" step="0.1" placeholder="例如:5.0" style="width: 100%; padding: 8px; font-size: 1rem;">
</div>
<button onclick="updateHealthData()" style="font-size: 1.1rem; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">更新数据</button>
`;
}
// 更新体检数据到数据库
function updateHealthData() {
const height = parseFloat(document.getElementById('heightInput').value);
const weight = parseFloat(document.getElementById('weightInput').value);
const vision = parseFloat(document.getElementById('visionInput').value);
if (isNaN(height) || isNaN(weight) || isNaN(vision)) {
alert('请输入有效的体检数据');
return;
}
// 确保发送的数据格式正确
fetch('/api/user/update-health-data', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
height: height,
weight: weight,
vision: vision
})
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应失败');
}
return response.json();
})
.then(data => {
alert('体检数据更新成功!');
// 刷新页面以显示新数据
location.reload();
})
.catch(error => {
console.error('更新体检数据出错:', error);
alert('更新体检数据失败,请重试');
});
}
遇到的困难:
本来是打算完成入职发展和调动管理功能的,但是在编码的过程中,我在不完全清楚的情况下对项目有些重要文件进行了删改,导致原先的大部分功能无法使用,并且我实现未有备份,所以恢复原先的功能花费了我的大量时间。也导致我剩余的时间不足够完成这两个功能,所以我选择两个相对较为简单的功能进行编码。这件事也让我意识到在编码需要一步步进行,也需要备份重要文件留有后手。
今天的任务:
争取将员工管理模块彻底完成,至少也要完成大半部分。