Skip to content
Snippets Groups Projects
Commit 753655b9 authored by Mingyuan Chen's avatar Mingyuan Chen
Browse files

Merge branch 'master' into 'main'

Single page application

See merge request !35
parents ebfe72ed b4fbec74
No related branches found
No related tags found
1 merge request!35Single page application
package com.cardiff.client_project.controller.hospital;
import com.cardiff.client_project.service.HospitalService;
import com.cardiff.client_project.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
//TODO
@RequestMapping("/hospital")
public class HospitalController {
@Autowired
private HospitalService hospitalService;
/**
* select all
* @return
*/
public Result SelectAll() {
// Result result=hospitalService.selectAll();
return null;
//return result;
}
}
package com.cardiff.client_project.service;
public interface HospitalService {
}
package com.cardiff.client_project.service.imp;
public class HospitalService {
}
package com.cardiff.client_project.service.imp;
import com.cardiff.client_project.service.HospitalService;
import org.springframework.stereotype.Service;
@Service
public class HospitalServiceImp implements HospitalService {
}
...@@ -3,4 +3,4 @@ healthcare: ...@@ -3,4 +3,4 @@ healthcare:
url: jdbc:mysql://localhost:3306/health_care url: jdbc:mysql://localhost:3306/health_care
port: 3306 port: 3306
username: root username: root
password: root password: 472500
\ No newline at end of file \ No newline at end of file
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
.sidebar {
position: fixed;
top: 0;
left: 0;
width: 250px;
height: 100vh;
background-color: #1f2937;
color: white;
padding: 1rem;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.sidebar .text-lg {
font-size: 1.25rem;
font-weight: bold;
margin-bottom: 1rem;
}
.sidebar a {
padding: 0.75rem 1rem;
margin-bottom: 0.5rem;
color: white;
text-decoration: none;
border-radius: 0.5rem;
transition: background-color 0.3s ease;
}
.sidebar a:hover {
background-color: #4b5563;
}
.content {
margin-left: 250px;
padding: 2rem;
}
.table-container {
margin-top: 2rem;
padding: 1rem;
background: white;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 1rem;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f9fafb;
color: #333;
}
td {
background-color: #ffffff;
}
button {
padding: 0.5rem 1rem;
margin: 0.5rem;
border-radius: 0.375rem;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
}
button:hover {
background-color: #4b5563;
color: white;
}
#modal {
display: none;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
}
.modal-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
width: 80%;
max-width: 600px;
}
.modal-content input,
.modal-content textarea {
width: 100%;
padding: 0.75rem;
margin-bottom: 1rem;
border-radius: 0.375rem;
border: 1px solid #ccc;
}
.modal-footer {
display: flex;
justify-content: flex-end;
}
.modal-footer button {
padding: 0.75rem 1.5rem;
margin-left: 1rem;
border-radius: 0.375rem;
}
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Administrator Management</title>
<link rel="stylesheet" type="text/css" href="../css/admin.css">
</head> </head>
<body> <body>
超级管理员 <!-- Left Sidebar Navigation -->
<nav class="sidebar">
<div class="text-lg font-semibold">System</div>
<a href="#" data-content="admin">Hospital</a>
<a href="#" data-content="patient">Patient</a>
<a href="#" data-content="logout">Log Out</a>
</nav>
<!-- Main Content Area -->
<div class="content">
<div id="dynamic-content">
<h1>Welcome to the Management System</h1>
<p>Select an option from the sidebar to get started.</p>
</div>
</div>
<!-- Modal for Adding Admin -->
<div id="modal">
<div class="modal-content">
<h2>Add New Admin</h2>
<div>
<label for="modal-name">Name</label>
<input type="text" id="modal-name" />
</div>
<div>
<label for="modal-email">Email</label>
<input type="email" id="modal-email" />
</div>
<div>
<label for="modal-phone">Phone</label>
<input type="text" id="modal-phone" />
</div>
<div>
<label for="modal-status">Status</label>
<select id="modal-status">
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
</div>
<div class="modal-footer">
<button id="modal-save">Save</button>
<button id="modal-close">Close</button>
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function () {
const dynamicContent = document.getElementById("dynamic-content");
const modal = document.getElementById("modal");
const modalClose = document.getElementById("modal-close");
const modalSave = document.getElementById("modal-save");
// Fetch admin data based on search criteria
function loadAdmins(filters = {}) {
const query = new URLSearchParams(filters).toString();
fetch(`/admin/select?${query}`)
.then(response => response.json())
.then(data => {
const tableBody = document.getElementById("table-body");
tableBody.innerHTML = "";
data.forEach(admin => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${admin.id}</td>
<td>${admin.email}</td>
<td>${admin.phone}</td>
<td>${admin.name}</td>
<td>${admin.status}</td>
`;
tableBody.appendChild(row);
});
})
.catch(error => console.error('Error loading admins:', error));
}
// Open add admin modal
function openModal() {
modal.style.display = "block";
}
// Close modal
modalClose.addEventListener("click", () => {
modal.style.display = "none";
});
// Save new admin
modalSave.addEventListener("click", () => {
const name = document.getElementById("modal-name").value;
const email = document.getElementById("modal-email").value;
const phone = document.getElementById("modal-phone").value;
const status = document.getElementById("modal-status").value;
const newAdmin = { name, email, phone, status };
fetch('/admin/sign', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(newAdmin)
})
.then(response => response.json())
.then(() => {
loadAdmins(); // Reload admin list
modal.style.display = "none"; // Close modal
})
.catch(error => console.error('Error saving admin:', error));
});
// Load admin interface with search toolbar
function loadAdminInterface() {
dynamicContent.innerHTML = `
<div id="toolbar">
<label for="searchName">Name</label>
<input type="text" class="searchBox" id="searchName" placeholder="type name..." />
<label for="searchEmail">Email</label>
<input type="text" class="searchBox" id="searchEmail" placeholder="type email..." />
<label for="searchPhone">Phone</label>
<input type="text" class="searchBox" id="searchPhone" placeholder="type phone..." />
<label for="searchStatus">Status</label>
<select class="searchBox" id="searchStatus">
<option value="">All</option>
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
<button id="searchButton">Search</button>
</div>
<div class="table-container">
<button id="add-btn" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Add Admin</button>
<table>
<thead>
<tr>
<th>ID</th>
<th>Email</th>
<th>Phone</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody id="table-body">
<!-- Table content will be dynamically inserted -->
</tbody>
</table>
</div>
`;
// Add admin button event
document.getElementById("add-btn").addEventListener("click", openModal);
// Search button event
document.getElementById("searchButton").addEventListener("click", () => {
const filters = {
name: document.getElementById("searchName").value,
email: document.getElementById("searchEmail").value,
phone: document.getElementById("searchPhone").value,
status: document.getElementById("searchStatus").value
};
loadAdmins(filters);
});
// Load admin data initially
loadAdmins();
}
// Sidebar navigation
document.querySelectorAll(".sidebar a").forEach(link => {
link.addEventListener("click", function (event) {
event.preventDefault();
const contentKey = this.getAttribute("data-content");
if (contentKey === "admin") {
loadAdminInterface();
}
});
});
});
</script>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
window.location.href = "superAdminView.html"; window.location.href = "superAdminView.html";
} }
if (type == "[" + "ADMIN" + "]") { if (type == "[" + "ADMIN" + "]") {
window.location.href = "commonUser.html"; window.location.href = "admin.html";
} }
if (type == "[" + "PATIENT" + "]") { if (type == "[" + "PATIENT" + "]") {
window.location.href = ""; window.location.href = "";
......
...@@ -59,5 +59,61 @@ ...@@ -59,5 +59,61 @@
} }
}) })
var bool;
// 页面加载后生成验证码
window.onload = function () {
createCode(4);
}
function createCode(length) {
var code = "";
var checkCode = document.getElementById("checkCode");
var codeChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
for (var i = 0; i < length; i++) {
var charNum = Math.floor(Math.random() * codeChars.length);
code += codeChars[charNum];
}
if (checkCode) {
checkCode.innerHTML = code;
}
}
function validateCode() {
var inputCode = document.getElementById("inputCode").value;
var checkCode = document.getElementById("checkCode").innerHTML;
if (!inputCode) {
alert("Please enter the verification code!");
return false;
}
if (inputCode.toUpperCase() !== checkCode.toUpperCase()) {
alert("Verification code error!");
createCode(4);
return false;
}
return true;
}
const form = document.getElementById('loginForm');
form.addEventListener('submit', function (event) {
event.preventDefault();
// 验证验证码
if (!validateCode()) {
return;
}
// 验证用户名和密码
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
if (username === '2649783657@qq.com' && password === 'admin') {
alert("Login successful! Redirecting...");
window.location.href = "superAdminView.html"; // 成功后跳转
} else {
alert("Invalid email or password. Please try again.");
}
});
</script> </script>
</html> </html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment