ttvtlb's picture
Xây dựng một hệ thống đầy đủ, hoàn chỉnh việc quản lý KPI của đơn vị, người dùng đăng nhập và cập nhật KPI thực hiện hành ngày, tổ trưỡng có thể cập nhật KPI của nhân viên, quản lý KPI trong tổ, Admin quản lý tất cả, cập nhật danh sách KPI, thống kê, xuất dữ liệu ra excel
63fb39f verified
// Shared utility functions
const formatDate = (dateString) => {
const options = { year: 'numeric', month: 'short', day: 'numeric' };
return new Date(dateString).toLocaleDateString(undefined, options);
};
const calculateProgress = (current, target) => {
return Math.min(Math.round((current / target) * 100), 100);
};
// Auth state management
let currentUser = null;
const setCurrentUser = (user) => {
currentUser = user;
localStorage.setItem('currentUser', JSON.stringify(user));
updateUIForUserRole();
};
const getCurrentUser = () => {
if (!currentUser && localStorage.getItem('currentUser')) {
currentUser = JSON.parse(localStorage.getItem('currentUser'));
}
return currentUser;
};
const logout = () => {
currentUser = null;
localStorage.removeItem('currentUser');
window.location.href = '/';
};
const updateUIForUserRole = () => {
const user = getCurrentUser();
if (!user) return;
// Show/hide elements based on role
document.querySelectorAll('[data-role="admin"]').forEach(el => {
el.style.display = user.role === 'admin' ? 'block' : 'none';
});
document.querySelectorAll('[data-role="manager"]').forEach(el => {
el.style.display = user.role === 'manager' ? 'block' : 'none';
});
document.querySelectorAll('[data-role="employee"]').forEach(el => {
el.style.display = user.role === 'employee' ? 'block' : 'none';
});
};
// Initialize app when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
updateUIForUserRole();
});