javaweb课程运动会报名项目前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

761 lines
38 KiB

document.addEventListener('DOMContentLoaded', function () {
1 month ago
var currentUserName = document.getElementById('currentUserName');
var logoutBtn = document.getElementById('logoutBtn');
var sidebarNav = document.getElementById('sidebarNav');
1 month ago
var sectionTitle = document.getElementById('sectionTitle');
var sectionDesc = document.getElementById('sectionDesc');
var subTabs = document.getElementById('subTabs');
var mainView = document.getElementById('mainView');
1 month ago
var state = {
user: null,
currentView: '',
currentTab: 'all',
1 month ago
events: [],
myEvents: [],
adminUsers: [],
adminRegistrations: [],
adminEvents: [],
editingEventId: null
1 month ago
};
var studentMenus = [
{ key: 'profile', label: '涓汉淇℃伅', desc: '鏌ョ湅骞剁淮鎶ゅ綋鍓嶇櫥褰曚汉鍛樼殑鍩虹璧勬枡銆? },
{ key: 'events', label: '杩愬姩浼氭姤鍚?, desc: '娴忚鏈夐苟瀹屾垚鎶ュ悕锛屼篃鍙互鏌ョ湅鑷繁鐨勬姤鍚嶄俊鎭? }
];
var adminMenus = [
{ key: 'admin-home', label: '杩愬姩浼氱鐞?, desc: '鏌ョ湅鍚庡彴棣栭鍜岀郴缁熸瑙堛? },
{ key: 'team-info', label: '鍥綋淇℃伅绠$悊', desc: '缁存姢鍙傝禌鍥綋涓庣粍缁囦俊鎭? },
{ key: 'user-manage', label: '鐢ㄦ埛淇℃伅绠$悊', desc: '鏌ョ湅銆佺淮鎶ょ敤鎴疯祫鏂欏苟鎵ц彿绠悊鎿嶄綔銆? },
{ key: 'event-manage', label: '椤圭洰绠$悊', desc: '缁存姢璧涗簨椤圭洰銆佸垎绫汇佺粍鍒拰鎶ュ悕鍙傛暟銆? },
{ key: 'athlete-manage', label: '鍙傝禌杩愬姩鍛樼鐞?, desc: '鏌ョ湅鎵鏈夊凡鎶ュ悕杩愬姩鍛樺拰鍙傝禌鍚嶅崟銆? },
{ key: 'score-manage', label: '鍙傝禌鎴愮哗绠$悊', desc: '褰曞叆銆佹煡鐪嬪拰缁存姢姣旇禌鎴愮哗銆? },
{ key: 'record-manage', label: '椤圭洰璁板綍绠$悊', desc: '悊椤圭洰璁板綍銆佺З搴忓唽鍜岃禌浜嬭褰曘? },
{ key: 'system-manage', label: '绯荤粺绠$悊', desc: '缁存姢绯荤粺鍩虹閰嶇疆鍜屽悗鍙拌繍琛屼俊鎭? }
];
1 month ago
function escapeHtml(value) {
return String(value == null ? '' : value)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}
function getMenus() {
return state.user && state.user.role === 'ADMIN' ? adminMenus : studentMenus;
1 month ago
}
function renderSidebar() {
var menus = getMenus();
sidebarNav.innerHTML = menus.map(function (item, index) {
return '<button class="nav-item ' + (item.key === state.currentView ? 'active' : '') + '" data-view="' + item.key + '">' + item.label + '</button>';
1 month ago
}).join('');
Array.prototype.slice.call(sidebarNav.querySelectorAll('.nav-item')).forEach(function (button) {
button.addEventListener('click', function () {
switchView(button.getAttribute('data-view'));
});
});
1 month ago
}
function renderTabs() {
var html = '';
if (state.currentView === 'events') {
html = ''
+ '<button class="tab-item ' + (state.currentTab === 'all' ? 'active' : '') + '" data-tab="all">鎶ュ悕</button>'
+ '<button class="tab-item ' + (state.currentTab === 'mine' ? 'active' : '') + '" data-tab="mine">鎶ュ悕淇℃伅</button>';
1 month ago
}
subTabs.innerHTML = html;
subTabs.classList.toggle('hidden', !html);
Array.prototype.slice.call(subTabs.querySelectorAll('.tab-item')).forEach(function (button) {
button.addEventListener('click', function () {
state.currentTab = button.getAttribute('data-tab');
1 month ago
renderTabs();
renderCurrentView();
});
});
}
function renderProfile() {
mainView.innerHTML = ''
1 month ago
+ '<div class="section-block">'
+ ' <div class="section-head"><div><h3>鍩虹璧勬枡</h3><p class="info-meta">褰撳墠璐﹀彿鐨勪釜浜轰俊鎭涓嬨€?/p></div></div>'
1 month ago
+ ' <div class="profile-grid">'
+ ' <div class="info-card"><strong>韬唤璇佸彿</strong><p>' + escapeHtml(state.user.idCard) + '</p></div>'
+ ' <div class="info-card"><strong>鐧诲綍璐﹀彿</strong><p>' + escapeHtml(state.user.username) + '</p></div>'
+ ' <div class="info-card"><strong>濮撳悕</strong><p>' + escapeHtml(state.user.name) + '</p></div>'
+ ' <div class="info-card"><strong>鑱旂郴鐢佃瘽</strong><p>' + escapeHtml(state.user.phone) + '</p></div>'
+ ' <div class="info-card"><strong>鎬у埆</strong><p>' + escapeHtml(state.user.gender) + '</p></div>'
+ ' <div class="info-card"><strong>瀛﹂櫌</strong><p>' + escapeHtml(state.user.college) + '</p></div>'
+ ' <div class="info-card"><strong>鐝骇</strong><p>' + escapeHtml(state.user.className) + '</p></div>'
+ ' <div class="info-card"><strong>瀛﹀彿</strong><p>' + escapeHtml(state.user.studentNo) + '</p></div>'
+ ' <div class="info-card"><strong>绫诲埆</strong><p>' + escapeHtml(state.user.category) + '</p></div>'
+ ' <div class="info-card"><strong>瑙掕壊</strong><p>' + escapeHtml(state.user.role) + '</p></div>'
+ ' </div>'
+ '</div>';
}
function renderProfile() {
mainView.innerHTML = ''
+ '<div class="section-block">'
+ ' <div class="section-head"><div><h3>鍩虹璧勬枡</h3><p class="info-meta">褰撳墠璐﹀彿鐨勪釜浜轰俊鎭涓嬨€?/p></div></div>'
+ ' <div class="profile-grid">'
+ ' <div class="info-card"><strong>韬唤璇佸彿</strong><p>' + escapeHtml(state.user.idCard) + '</p></div>'
+ ' <div class="info-card"><strong>鐧诲綍璐﹀彿</strong><p>' + escapeHtml(state.user.username) + '</p></div>'
+ ' <div class="info-card"><strong>濮撳悕</strong><p>' + escapeHtml(state.user.name) + '</p></div>'
+ ' <div class="info-card"><strong>鑱旂郴鐢佃瘽</strong><p>' + escapeHtml(state.user.phone) + '</p></div>'
+ ' <div class="info-card"><strong>鎬у埆</strong><p>' + escapeHtml(state.user.gender) + '</p></div>'
+ ' <div class="info-card"><strong>瀛﹂櫌</strong><p>' + escapeHtml(state.user.college) + '</p></div>'
+ ' <div class="info-card"><strong>鐝骇</strong><p>' + escapeHtml(state.user.className) + '</p></div>'
+ ' <div class="info-card"><strong>瀛﹀彿</strong><p>' + escapeHtml(state.user.studentNo) + '</p></div>'
+ ' <div class="info-card"><strong>绫诲埆</strong><p>' + escapeHtml(state.user.category) + '</p></div>'
+ ' <div class="info-card"><strong>瑙掕壊</strong><p>' + escapeHtml(state.user.role) + '</p></div>'
1 month ago
+ ' </div>'
+ '</div>'
+ '<div class="section-block">'
+ ' <div class="section-head"><div><h3>淇敼涓汉淇℃伅</h3><p class="info-meta">鍙互鍦ㄨ繖閲屾洿鏂板鍚嶃€佺數璇濄€佸闄€佺彮绾у拰瀛﹀彿绛変俊鎭€?/p></div></div>'
1 month ago
+ ' <form id="profileForm" class="form-grid two-columns">'
+ ' <label class="field"><span>濮撳悕</span><input name="name" value="' + escapeHtml(state.user.name) + '" placeholder="璇疯緭鍏ュ鍚?></label>'
+ ' <label class="field"><span>鑱旂郴鐢佃瘽</span><input name="phone" value="' + escapeHtml(state.user.phone) + '" placeholder="璇疯緭鍏ョ數璇?></label>'
+ ' <label class="field"><span>Gender</span><input name="gender" value="' + escapeHtml(state.user.gender) + '" placeholder="gender"></label>'
+ ' <label class="field"><span>???</span><input name="college" value="' + escapeHtml(state.user.college) + '" placeholder="????????></label>'
+ ' <label class="field"><span>???</span><input name="className" value="' + escapeHtml(state.user.className) + '" placeholder="????????></label>'
+ ' <label class="field"><span>???</span><input name="studentNo" value="' + escapeHtml(state.user.studentNo) + '" placeholder="????????></label>'
+ ' <label class="field full-row"><span>???</span><input name="category" value="' + escapeHtml(state.user.category) + '" placeholder="?????????????></label>'
+ ' </label>'
+ ' <label class="field"><span>瀛﹂櫌</span><input name="college" value="' + escapeHtml(state.user.college) + '" placeholder="璇疯緭鍏ュ闄?></label>'
+ ' <label class="field"><span>鐝骇</span><input name="className" value="' + escapeHtml(state.user.className) + '" placeholder="璇疯緭鍏ョ彮绾?></label>'
+ ' <label class="field"><span>瀛﹀彿</span><input name="studentNo" value="' + escapeHtml(state.user.studentNo) + '" placeholder="璇疯緭鍏ュ鍙?></label>'
+ ' <label class="field full-row"><span>绫诲埆</span><input name="category" value="' + escapeHtml(state.user.category) + '" placeholder="渚嬪锛氬鐢熴€佹暀甯?></label>'
+ ' <div class="form-actions full-row">'
+ ' <button type="submit" class="primary-btn">淇濆瓨淇敼</button>'
+ ' </div>'
1 month ago
+ ' <p id="profileMessage" class="form-message full-row"></p>'
+ ' </form>'
+ '</div>';
bindProfileForm();
}
function bindProfileForm() {
var form = document.getElementById('profileForm');
var messageEl = document.getElementById('profileMessage');
if (!form) {
return;
}
form.addEventListener('submit', function (event) {
1 month ago
event.preventDefault();
var formData = new FormData(form);
var payload = {
name: String(formData.get('name') || '').trim(),
phone: String(formData.get('phone') || '').trim(),
gender: String(formData.get('gender') || '').trim(),
college: String(formData.get('college') || '').trim(),
className: String(formData.get('className') || '').trim(),
studentNo: String(formData.get('studentNo') || '').trim(),
category: String(formData.get('category') || '').trim()
};
1 month ago
appUtils.ajax({
method: 'PUT',
url: '/api/users/me',
data: payload,
1 month ago
success: function (response) {
if (!response.success || !response.data) {
appUtils.showMessage(messageEl, response.message || '淇敼澶辫触', false);
1 month ago
return;
}
1 month ago
state.user = response.data;
currentUserName.textContent = state.user.name + (state.user.role === 'ADMIN' ? ' 绠$悊鍛? : ' 鐢ㄦ埛');
1 month ago
renderProfile();
appUtils.showMessage(document.getElementById('profileMessage'), 'Saved successfully', true);
1 month ago
},
error: function (xhr, response) {
appUtils.showMessage(messageEl, (response && response.message) || '淇敼澶辫触', false);
1 month ago
}
});
});
}
function renderEventTable(list, isMine) {
if (!list.length) {
mainView.innerHTML = '<div class="empty-state"><h3>鏆傛棤鏁版嵁</h3><p>' + (isMine ? '褰撳墠杩樻病鏈夋姤鍚嶈褰曘€? : '褰撳墠娌湁鍙睍绀洪?) + '</p></div>';
return;
1 month ago
}
mainView.innerHTML = ''
1 month ago
+ '<table class="event-table">'
+ ' <thead><tr><th>椤圭洰鍚嶇О</th><th>椤圭洰绫诲埆</th><th>姣旇禌鏃堕棿</th><th>姣旇禌鍦扮偣</th><th>鎶ュ悕鎯呭喌</th><th>椤圭洰璇存槑</th><th>鎿嶄綔</th></tr></thead>'
1 month ago
+ ' <tbody>'
+ list.map(function (item) {
1 month ago
var actionHtml = isMine
? '<button class="action-btn cancel-btn" data-id="' + item.id + '">鍙栨秷鎶ュ悕</button>'
: '<button class="action-btn register-btn" data-id="' + item.id + '" ' + (item.registered ? 'disabled' : '') + '>' + (item.registered ? '宸叉姤鍚? : '鎶ュ悕') + '</button>';
1 month ago
return ''
+ '<tr>'
+ '<td>' + escapeHtml(item.eventName) + '</td>'
+ '<td>' + escapeHtml(item.eventCategory) + '</td>'
+ '<td>' + escapeHtml(item.eventTime) + '</td>'
+ '<td>' + escapeHtml(item.location) + '</td>'
+ '<td>' + escapeHtml(item.registeredCount + '/' + item.quota) + '</td>'
+ '<td>' + escapeHtml(item.description) + '</td>'
+ '<td>' + actionHtml + '</td>'
+ '</tr>';
}).join('')
+ ' </tbody>'
+ '</table>';
bindEventButtons();
1 month ago
}
function renderUserManage() {
1 month ago
if (!state.adminUsers.length) {
mainView.innerHTML = '<div class="empty-state"><h3>鏆傛棤鐢ㄦ埛</h3><p>褰撳墠绯荤粺杩樻病鏈夌敤鎴锋暟鎹€?/p></div>';
return;
1 month ago
}
mainView.innerHTML = ''
+ '<div class="section-block">'
+ ' <div class="section-head"><div><h3>鏁版嵁姒傝</h3><p class="info-meta">鏌ョ湅褰撳墠绯荤粺鍐呯敤鎴锋€讳綋鎯呭喌銆?/p></div></div>'
+ ' <div class="summary-grid">'
+ ' <div class="summary-card"><strong>鐢ㄦ埛鎬绘暟</strong><p>' + state.adminUsers.length + '</p></div>'
+ ' <div class="summary-card"><strong>绠$悊鍛樻暟閲?/strong><p>' + state.adminUsers.filter(function (item) { return item.role === "ADMIN"; }).length + '</p></div>'
+ ' <div class="summary-card"><strong>绂佺敤璐﹀彿鏁伴噺</strong><p>' + state.adminUsers.filter(function (item) { return item.status === "DISABLED"; }).length + '</p></div>'
+ ' </div>'
+ '</div>'
+ '<div class="section-block">'
+ ' <div class="section-head"><div><h3>鐢ㄦ埛鍒楄〃</h3><p class="info-meta">鏌ョ湅绯荤粺鍐呮墍鏈夌敤鎴蜂俊鎭€?/p></div></div>'
+ ' <table class="event-table">'
+ ' <thead><tr><th>濮撳悕</th><th>璐﹀彿</th><th>韬唤璇佸彿</th><th>鐢佃瘽</th><th>鎬у埆</th><th>瀛﹂櫌</th><th>绫诲埆</th><th>瑙掕壊</th><th>鐘舵€?/th><th>鎿嶄綔</th></tr></thead>'
+ ' <tbody>'
1 month ago
+ state.adminUsers.map(function (item) {
var isAdmin = item.role === 'ADMIN';
var statusText = item.status === 'DISABLED' ? '宸茬鐢? : '姝e父';
var statusAction = isAdmin
? ''
: (item.status === 'DISABLED'
? '<button class="action-btn enable-user-btn" data-id="' + item.id + '">瑙i櫎绂佺敤</button>'
: '<button class="action-btn disable-user-btn" data-id="' + item.id + '">绂佺敤璐︽埛</button>');
var deleteAction = isAdmin ? '' : '<button class="action-btn delete-user-btn" data-id="' + item.id + '">鍒犻櫎</button>';
return ''
+ '<tr>'
+ '<td>' + escapeHtml(item.name) + '</td>'
+ '<td>' + escapeHtml(item.username) + '</td>'
+ '<td>' + escapeHtml(item.idCard) + '</td>'
+ '<td>' + escapeHtml(item.phone) + '</td>'
+ '<td>' + escapeHtml(item.gender) + '</td>'
+ '<td>' + escapeHtml(item.college) + '</td>'
+ '<td>' + escapeHtml(item.category) + '</td>'
+ '<td>' + escapeHtml(isAdmin ? '绠$悊鍛? : '氱敤鎴?) + '</td>'
+ '<td>' + escapeHtml(statusText) + '</td>'
+ '<td><button class="action-btn reset-password-btn" data-id="' + item.id + '">閲嶇疆瀵嗙爜</button> ' + statusAction + ' ' + deleteAction + '</td>'
+ '</tr>';
}).join('')
+ ' </tbody>'
+ ' </table>'
+ '</div>';
bindUserManageActions();
1 month ago
}
function renderAthleteManage() {
if (!state.adminRegistrations.length) {
mainView.innerHTML = '<div class="empty-state"><h3>鏆傛棤鎶ュ悕璁板綍</h3><p>褰撳墠杩樻病鏈夊弬璧涜繍鍔ㄥ憳鏁版嵁銆?/p></div>';
return;
}
1 month ago
mainView.innerHTML = ''
+ '<div class="section-block">'
+ ' <div class="section-head"><div><h3>鏁版嵁姒傝</h3><p class="info-meta">鏌ョ湅褰撳墠鍙傝禌杩愬姩鍛樼殑鎬讳綋缁熻銆?/p></div></div>'
+ ' <div class="summary-grid">'
+ ' <div class="summary-card"><strong>鎶ュ悕璁板綍鎬绘暟</strong><p>' + state.adminRegistrations.length + '</p></div>'
+ ' <div class="summary-card"><strong>宸叉姤鍚嶇姸鎬?/strong><p>' + state.adminRegistrations.filter(function (item) { return item.status === "宸叉姤鍚?; }).length + '</p></div>'
+ ' <div class="summary-card"><strong>瑕嗙洊椤圭洰鏁?/strong><p>' + uniqueEventCount() + '</p></div>'
+ ' </div>'
+ '</div>'
+ '<div class="section-block">'
+ ' <div class="section-head"><div><h3>鍙傝禌鍚嶅崟</h3><p class="info-meta">鏌ョ湅鎵€鏈夊凡鎶ュ悕杩愬姩鍛樺拰椤圭洰鏄庣粏銆?/p></div></div>'
+ ' <table class="event-table">'
+ ' <thead><tr><th>濮撳悕</th><th>璐﹀彿</th><th>鐢佃瘽</th><th>瀛﹂櫌</th><th>绫诲埆</th><th>椤圭洰鍚嶇О</th><th>椤圭洰绫诲埆</th><th>鏃堕棿鍦扮偣</th><th>鐘舵€?/th><th>鎶ュ悕鏃堕棿</th></tr></thead>'
+ ' <tbody>'
+ state.adminRegistrations.map(function (item) {
return ''
+ '<tr>'
+ '<td>' + escapeHtml(item.studentName) + '</td>'
+ '<td>' + escapeHtml(item.username) + '</td>'
+ '<td>' + escapeHtml(item.phone) + '</td>'
+ '<td>' + escapeHtml(item.college) + '</td>'
+ '<td>' + escapeHtml(item.category) + '</td>'
+ '<td>' + escapeHtml(item.eventName) + '</td>'
+ '<td>' + escapeHtml(item.eventCategory) + '</td>'
+ '<td>' + escapeHtml(item.eventTime + ' / ' + item.location) + '</td>'
+ '<td>' + escapeHtml(item.status) + '</td>'
+ '<td>' + escapeHtml(item.createdAt) + '</td>'
+ '</tr>';
}).join('')
+ ' </tbody>'
+ ' </table>'
+ '</div>';
}
function renderEventManage() {
var formTitle = state.editingEventId ? '缂栬緫椤圭洰' : '鏂板椤圭洰';
var editingItem = state.adminEvents.find(function (item) {
return item.id === state.editingEventId;
}) || {
eventName: '',
eventCategory: '',
location: '',
quota: '',
description: '',
eventTime: ''
};
mainView.innerHTML = ''
+ '<div class="section-block">'
+ ' <div class="section-head"><div><h3>' + formTitle + '</h3><p class="info-meta">鍙湪杩欓噷缁存姢姣旇禌椤圭洰鐨勫熀纭€淇℃伅銆?/p></div></div>'
+ ' <form id="eventForm" class="form-grid two-columns">'
+ ' <label class="field"><span>椤圭洰鍚嶇О</span><input name="eventName" value="' + escapeHtml(editingItem.eventName) + '" placeholder="渚嬪锛氱敺瀛?00绫?></label>'
+ ' <label class="field"><span>椤圭洰鍒嗙被</span><input name="eventCategory" value="' + escapeHtml(editingItem.eventCategory) + '" placeholder="渚嬪锛氱敯寰勭煭璺?></label>'
+ ' <label class="field"><span>姣旇禌鍦扮偣</span><input name="location" value="' + escapeHtml(editingItem.location) + '" placeholder="渚嬪锛氫笢鎿嶅満A鍖?></label>'
+ ' <label class="field"><span>浜烘暟涓婇檺</span><input name="quota" type="number" min="1" value="' + escapeHtml(editingItem.quota) + '" placeholder="璇疯緭鍏ヤ汉鏁颁笂闄?></label>'
+ ' <label class="field full-row"><span>姣旇禌鏃堕棿</span><input name="eventTime" value="' + escapeHtml(editingItem.eventTime) + '" placeholder="渚嬪锛?026-05-20 08:30"></label>'
+ ' <label class="field full-row"><span>椤圭洰璇存槑</span><input name="description" value="' + escapeHtml(editingItem.description) + '" placeholder="璇疯緭鍏ラ」鐩鏄?></label>'
+ ' <div class="form-actions full-row">'
+ ' <button type="submit" class="primary-btn">' + (state.editingEventId ? '淇濆瓨淇敼' : '鏂板椤圭洰') + '</button>'
+ ' <button type="button" class="ghost-btn" id="resetEventForm">娓呯┖琛ㄥ崟</button>'
+ ' </div>'
+ ' <p id="eventFormMessage" class="form-message full-row"></p>'
+ ' </form>'
+ '</div>'
+ '<div class="section-block">'
+ ' <div class="section-head"><div><h3>椤圭洰鍒楄〃</h3><p class="info-meta">褰撳墠绯荤粺鍐呯殑鍏ㄩ儴姣旇禌椤圭洰銆?/p></div></div>'
+ (state.adminEvents.length ? ''
+ '<table class="event-table">'
+ ' <thead><tr><th>椤圭洰鍚嶇О</th><th>椤圭洰鍒嗙被</th><th>姣旇禌鏃堕棿</th><th>姣旇禌鍦扮偣</th><th>浜烘暟涓婇檺</th><th>宸叉姤鍚?/th><th>椤圭洰璇存槑</th><th>鎿嶄綔</th></tr></thead>'
+ ' <tbody>'
+ state.adminEvents.map(function (item) {
return ''
+ '<tr>'
+ '<td>' + escapeHtml(item.eventName) + '</td>'
+ '<td>' + escapeHtml(item.eventCategory) + '</td>'
+ '<td>' + escapeHtml(item.eventTime) + '</td>'
+ '<td>' + escapeHtml(item.location) + '</td>'
+ '<td>' + escapeHtml(item.quota) + '</td>'
+ '<td>' + escapeHtml(item.registeredCount || 0) + '</td>'
+ '<td>' + escapeHtml(item.description) + '</td>'
+ '<td><button class="action-btn edit-event-btn" data-id="' + item.id + '">缂栬緫</button> <button class="action-btn delete-event-btn" data-id="' + item.id + '">鍒犻櫎</button></td>'
+ '</tr>';
}).join('')
+ ' </tbody>'
+ '</table>'
: '<div class="empty-state"><h3>鏆傛棤椤圭洰</h3><p>褰撳墠杩樻病鏈夋瘮璧涢」鐩紝璇峰厛鏂板椤圭洰銆?/p></div>')
+ '</div>';
bindEventManageActions();
}
function renderPlaceholder(title, text) {
mainView.innerHTML = ''
+ '<div class="empty-state">'
+ ' <h3>' + title + '</h3>'
+ ' <p>' + text + '</p>'
+ '</div>';
1 month ago
}
function uniqueEventCount() {
var map = {};
state.adminRegistrations.forEach(function (item) {
map[item.eventName] = true;
});
return Object.keys(map).length;
}
function bindEventButtons() {
1 month ago
Array.prototype.slice.call(document.querySelectorAll('.register-btn')).forEach(function (button) {
button.addEventListener('click', function () {
appUtils.ajax({
method: 'POST',
url: '/api/events/' + button.getAttribute('data-id') + '/register',
success: function (response) {
if (!response.success) {
window.alert(response.message || '鎶ュ悕澶辫触');
1 month ago
return;
}
window.alert('鎶ュ悕鎴愬姛');
1 month ago
loadEventData();
},
error: function (xhr, response) {
window.alert((response && response.message) || '鎶ュ悕澶辫触');
1 month ago
}
});
});
});
Array.prototype.slice.call(document.querySelectorAll('.cancel-btn')).forEach(function (button) {
button.addEventListener('click', function () {
appUtils.ajax({
method: 'DELETE',
url: '/api/events/' + button.getAttribute('data-id') + '/register',
success: function (response) {
if (!response.success) {
window.alert(response.message || '鍙栨秷鎶ュ悕澶辫触');
return;
1 month ago
}
window.alert('鍙栨秷鎶ュ悕鎴愬姛');
loadEventData();
},
error: function (xhr, response) {
window.alert((response && response.message) || '鍙栨秷鎶ュ悕澶辫触');
}
});
1 month ago
});
});
}
function bindUserManageActions() {
Array.prototype.slice.call(document.querySelectorAll('.reset-password-btn')).forEach(function (button) {
1 month ago
button.addEventListener('click', function () {
var id = button.getAttribute('data-id');
appUtils.ajax({
method: 'POST',
url: '/api/admin/users/' + id + '/reset-password',
success: function (response) {
if (!response.success) {
window.alert(response.message || '閲嶇疆瀵嗙爜澶辫触');
return;
}
window.alert('瀵嗙爜宸查噸缃负 123456');
},
error: function (xhr, response) {
window.alert((response && response.message) || '閲嶇疆瀵嗙爜澶辫触');
}
});
});
});
Array.prototype.slice.call(document.querySelectorAll('.disable-user-btn')).forEach(function (button) {
button.addEventListener('click', function () {
var id = button.getAttribute('data-id');
appUtils.ajax({
method: 'POST',
url: '/api/admin/users/' + id + '/disable',
success: function (response) {
if (!response.success) {
window.alert(response.message || '绂佺敤璐︽埛澶辫触');
return;
}
loadAdminData();
},
error: function (xhr, response) {
window.alert((response && response.message) || '绂佺敤璐︽埛澶辫触');
}
});
});
});
Array.prototype.slice.call(document.querySelectorAll('.enable-user-btn')).forEach(function (button) {
button.addEventListener('click', function () {
var id = button.getAttribute('data-id');
appUtils.ajax({
method: 'POST',
url: '/api/admin/users/' + id + '/enable',
success: function (response) {
if (!response.success) {
window.alert(response.message || '瑙i櫎绂佺敤澶辫触');
return;
}
loadAdminData();
},
error: function (xhr, response) {
window.alert((response && response.message) || '瑙i櫎绂佺敤澶辫触');
1 month ago
}
});
});
});
Array.prototype.slice.call(document.querySelectorAll('.delete-user-btn')).forEach(function (button) {
button.addEventListener('click', function () {
var id = button.getAttribute('data-id');
if (!window.confirm('畾瑕佸垹闄よ繖涓处鍙峰悧锛?)) {
return;
1 month ago
}
appUtils.ajax({
method: 'DELETE',
url: '/api/admin/users/' + id,
success: function (response) {
if (!response.success) {
window.alert(response.message || '鍒犻櫎鐢ㄦ埛澶辫触');
return;
}
loadAdminData();
},
error: function (xhr, response) {
window.alert((response && response.message) || '鍒犻櫎鐢ㄦ埛澶辫触');
}
});
1 month ago
});
});
}
function renderCurrentView() {
var currentMenu = getMenus().find(function (item) {
return item.key === state.currentView;
});
if (currentMenu) {
sectionTitle.textContent = currentMenu.label;
sectionDesc.textContent = currentMenu.desc;
}
renderTabs();
1 month ago
if (state.currentView === 'profile') {
renderProfile();
return;
}
if (state.currentView === 'events') {
renderEventTable(state.currentTab === 'mine' ? state.myEvents : state.events, state.currentTab === 'mine');
return;
}
if (state.currentView === 'user-manage') {
renderUserManage();
return;
}
if (state.currentView === 'athlete-manage') {
renderAthleteManage();
1 month ago
return;
}
if (state.currentView === 'admin-home') {
renderPlaceholder('杩愬姩浼氱鐞?, '杩欓噷灏嗕綔涓虹鐞嗗憳鍚庡彴棣栭锛屽彲灞曠ず鎶ュ悕鎬昏銆佺郴缁熷叕鍛娿佽繍鍔ㄤ細绠悊鍏ュ彛绛夊唴瀹广?);
1 month ago
return;
}
if (state.currentView === 'team-info') {
renderPlaceholder('鍥綋淇℃伅绠$悊', '杩欓噷灏嗙户缁ˉ鍏呭侀儴闂ㄣ佷唬琛ㄩ槦绛夊洟浣撲俊鎭鐞嗗姛鑳姐?);
1 month ago
return;
}
if (state.currentView === 'event-manage') {
renderEventManage();
return;
}
if (state.currentView === 'score-manage') {
renderPlaceholder('鍙傝禌鎴愮哗绠$悊', '杩欓噷灏嗙户缁ˉ鍏呮垚缁綍鍏ャ佹垚缁淮鎶ゃ佹垚缁煡璇瓑鍔熻兘銆?);
return;
}
if (state.currentView === 'record-manage') {
renderPlaceholder('椤圭洰璁板綍绠$悊', '杩欓噷灏嗙户缁ˉ鍏呴褰曘佽禌浜嬬З搴忓唽鍜岄妗堢鐞嗗姛鑳姐?);
return;
}
if (state.currentView === 'system-manage') {
renderPlaceholder('绯荤粺绠$悊', '杩欓噷灏嗙户缁ˉ鍏呯郴缁熼厤缃佽处鍙锋潈闄愬拰杩愯缁存姢鍔熻兘銆?);
}
}
function switchView(view) {
state.currentView = view;
if (view === 'events' && state.currentTab !== 'mine') {
state.currentTab = 'all';
}
renderSidebar();
renderCurrentView();
1 month ago
}
function loadEventData() {
appUtils.ajax({
method: 'GET',
url: '/api/events',
success: function (response) {
if (response.success) {
state.events = response.data || [];
renderCurrentView();
}
}
});
1 month ago
appUtils.ajax({
method: 'GET',
url: '/api/events/my',
success: function (response) {
if (response.success) {
state.myEvents = response.data || [];
renderCurrentView();
}
}
});
}
function loadAdminData() {
if (!state.user || state.user.role !== 'ADMIN') {
return;
}
1 month ago
appUtils.ajax({
method: 'GET',
url: '/api/admin/users',
success: function (response) {
if (response.success) {
state.adminUsers = response.data || [];
renderCurrentView();
}
}
});
1 month ago
appUtils.ajax({
method: 'GET',
url: '/api/admin/registrations',
success: function (response) {
if (response.success) {
state.adminRegistrations = response.data || [];
renderCurrentView();
}
}
});
appUtils.ajax({
method: 'GET',
url: '/api/admin/events',
success: function (response) {
if (response.success) {
state.adminEvents = response.data || [];
renderCurrentView();
}
}
});
1 month ago
}
function bindEventManageActions() {
var form = document.getElementById('eventForm');
var resetButton = document.getElementById('resetEventForm');
var messageEl = document.getElementById('eventFormMessage');
if (form) {
form.addEventListener('submit', function (event) {
event.preventDefault();
var formData = new FormData(form);
var payload = {
eventName: String(formData.get('eventName') || '').trim(),
eventCategory: String(formData.get('eventCategory') || '').trim(),
location: String(formData.get('location') || '').trim(),
quota: Number(formData.get('quota') || 0),
description: String(formData.get('description') || '').trim(),
eventTime: String(formData.get('eventTime') || '').trim()
};
var successText = state.editingEventId ? '椤圭洰淇敼鎴愬姛' : '椤圭洰鏂板鎴愬姛';
appUtils.ajax({
method: state.editingEventId ? 'PUT' : 'POST',
url: state.editingEventId ? '/api/admin/events/' + state.editingEventId : '/api/admin/events',
data: payload,
success: function (response) {
if (!response.success) {
appUtils.showMessage(messageEl, response.message || '淇濆瓨澶辫触', false);
return;
}
state.editingEventId = null;
window.alert(successText);
loadAdminData();
},
error: function (xhr, response) {
appUtils.showMessage(messageEl, (response && response.message) || '淇濆瓨澶辫触', false);
}
});
});
1 month ago
}
if (resetButton) {
resetButton.addEventListener('click', function () {
state.editingEventId = null;
renderCurrentView();
});
}
Array.prototype.slice.call(document.querySelectorAll('.edit-event-btn')).forEach(function (button) {
button.addEventListener('click', function () {
state.editingEventId = Number(button.getAttribute('data-id'));
renderCurrentView();
});
});
Array.prototype.slice.call(document.querySelectorAll('.delete-event-btn')).forEach(function (button) {
button.addEventListener('click', function () {
var eventId = button.getAttribute('data-id');
if (!window.confirm('畾瑕佸垹闄よ繖涓悧锛熷垹闄ゅ悗璇ラ殑鎶ュ悕璁板綍涔熶細涓骞舵竻闄ゃ?)) {
return;
}
appUtils.ajax({
method: 'DELETE',
url: '/api/admin/events/' + eventId,
success: function (response) {
if (!response.success) {
window.alert(response.message || '鍒犻櫎澶辫触');
return;
}
if (state.editingEventId === Number(eventId)) {
state.editingEventId = null;
}
loadAdminData();
},
error: function (xhr, response) {
window.alert((response && response.message) || '鍒犻櫎澶辫触');
}
});
});
1 month ago
});
}
function loadCurrentUser() {
appUtils.ajax({
method: 'GET',
url: '/api/users/me',
success: function (response) {
if (!response.success || !response.data) {
window.location.href = './login.html';
return;
}
1 month ago
state.user = response.data;
currentUserName.textContent = state.user.name + (state.user.role === 'ADMIN' ? ' 绠$悊鍛? : ' 鐢ㄦ埛');
state.currentView = state.user.role === 'ADMIN' ? 'admin-home' : 'profile';
renderSidebar();
renderCurrentView();
1 month ago
loadEventData();
loadAdminData();
},
error: function () {
window.location.href = './login.html';
}
});
}
logoutBtn.addEventListener('click', function () {
appUtils.ajax({
method: 'POST',
url: '/api/auth/logout',
success: function () {
window.location.href = './login.html';
},
error: function () {
window.location.href = './login.html';
}
});
});
loadCurrentUser();
});