首次提交:初始化项目代码
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
// admin-menus.js - 菜单管理页面功能
|
||||
|
||||
function openAddMenuModal() {
|
||||
document.getElementById('menuId').value = '';
|
||||
document.getElementById('menuName').value = '';
|
||||
document.getElementById('menuIcon').value = '';
|
||||
document.getElementById('menuPath').value = '';
|
||||
document.getElementById('menuSortOrder').value = '0';
|
||||
document.getElementById('menuParentID').value = '';
|
||||
document.getElementById('menuIsEnabled').checked = true;
|
||||
document.getElementById('menuIsFixed').checked = false;
|
||||
document.getElementById('menuModalTitle').textContent = '添加菜单';
|
||||
document.getElementById('menuModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeMenuModal() {
|
||||
document.getElementById('menuModal').style.display = 'none';
|
||||
}
|
||||
|
||||
function editMenu(id) {
|
||||
fetch(`/api/admin/menus/${id}`)
|
||||
.then(response => response.json())
|
||||
.then(menu => {
|
||||
document.getElementById('menuId').value = menu.id;
|
||||
document.getElementById('menuName').value = menu.name;
|
||||
document.getElementById('menuIcon').value = menu.icon || '';
|
||||
document.getElementById('menuPath').value = menu.path;
|
||||
document.getElementById('menuSortOrder').value = menu.sort_order || '0';
|
||||
document.getElementById('menuParentID').value = menu.parent_id || '';
|
||||
document.getElementById('menuIsEnabled').checked = menu.is_enabled;
|
||||
document.getElementById('menuIsFixed').checked = menu.is_fixed;
|
||||
document.getElementById('menuModalTitle').textContent = '编辑菜单';
|
||||
document.getElementById('menuModal').style.display = 'flex';
|
||||
})
|
||||
.catch(error => {
|
||||
showCustomAlert('error', '获取失败', '获取菜单信息失败');
|
||||
});
|
||||
}
|
||||
|
||||
function saveMenu(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const menuId = document.getElementById('menuId').value;
|
||||
const data = {
|
||||
name: document.getElementById('menuName').value,
|
||||
icon: document.getElementById('menuIcon').value,
|
||||
path: document.getElementById('menuPath').value,
|
||||
sort_order: parseInt(document.getElementById('menuSortOrder').value) || 0,
|
||||
parent_id: document.getElementById('menuParentID').value || null,
|
||||
is_enabled: document.getElementById('menuIsEnabled').checked,
|
||||
is_fixed: document.getElementById('menuIsFixed').checked
|
||||
};
|
||||
|
||||
const url = menuId ? `/api/admin/menus/${menuId}` : '/api/admin/menus';
|
||||
const method = menuId ? 'PUT' : 'POST';
|
||||
|
||||
fetch(url, {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.success) {
|
||||
showCustomAlert('success', '保存成功', menuId ? '菜单更新成功' : '菜单添加成功');
|
||||
closeMenuModal();
|
||||
window.location.reload();
|
||||
} else {
|
||||
showCustomAlert('error', '保存失败', result.message || '操作失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
showCustomAlert('error', '保存失败', '网络请求失败');
|
||||
});
|
||||
}
|
||||
|
||||
function deleteMenu(id) {
|
||||
if (!confirm('确定要删除该菜单吗?')) return;
|
||||
|
||||
fetch(`/api/admin/menus/${id}`, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.success) {
|
||||
showCustomAlert('success', '删除成功', '菜单删除成功');
|
||||
window.location.reload();
|
||||
} else {
|
||||
showCustomAlert('error', '删除失败', result.message || '操作失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
showCustomAlert('error', '删除失败', '网络请求失败');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user