完成大作业服务端代码,新建管理端,管理端不可用

This commit is contained in:
2024-06-14 14:53:50 +08:00
parent ad767a806b
commit cfbaf585a7
80 changed files with 3563 additions and 128 deletions

View File

@@ -0,0 +1,15 @@
var checkInfo = {};
checkInfo.checkMobileNo = function() {
let mobileNo = document.getElementById('mobileNo').value;
let regexMobileNo = /^1[3-9]\d{9}$/;
return regexMobileNo.test(mobileNo);
}
checkInfo.checkPassword = function() {
let password = document.getElementById('password').value;
let regexPassword = /^[A-Za-z0-9\W_]{6,20}$/;
let isValidPassword = regexPassword.test(password);
let confirmPassword = document.getElementById('confirmPassword').value;
return isValidPassword && (password === confirmPassword);
}

View File

@@ -0,0 +1,29 @@
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
function increment() {
var passengers = document.getElementById("passengers");
var value = parseInt(passengers.value, 10);
if (value < 50) {
passengers.value = value + 1;
}
}
function decrement() {
var passengers = document.getElementById("passengers");
var value = parseInt(passengers.value, 10);
if (value > 1) {
passengers.value = value - 1;
}
}

View File

@@ -0,0 +1,81 @@
window.onload = function() {
autoLogin();
};
var checkInfo = {};
checkInfo.checkMobileNo = function() {
let mobileNo = document.getElementById('mobileNo').value;
let regexMobileNo = /^1[3-9]\d{9}$/;
if (!regexMobileNo.test(mobileNo)) {
document.getElementById('mobileNoError').textContent = '手机号格式有误';
return false;
}
document.getElementById('mobileNoError').textContent = '';
return true;
}
checkInfo.checkPassword = function() {
let password = document.getElementById('password').value;
let regexPassword = /^[A-Za-z0-9\W_]{6,20}$/;
if (!regexPassword.test(password)) {
document.getElementById('loginError').textContent = "密码须为长度为6-20位字母、数字或符号";
return false;
}
document.getElementById('loginError').textContent = '';
return true;
}
function submitForm() {
if (checkInfo.checkMobileNo() && checkInfo.checkPassword()) {
document.getElementById('encryptedPassword').value = md5(
document.getElementById('password').value
);
login();
return true;
}
return false;
}
// 登录函数
async function login() {
const mobileNo = document.getElementById('mobileNo').value;
const encryptedPassword = document.getElementById('encryptedPassword').value;
try {
const response = await fetch('/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username: mobileNo, password: encryptedPassword }),
credentials: 'include' // 确保请求包含凭据cookies
});
const data = await response.json();
if (response.ok) {
alert('登录成功');
// 自动跳转到主页
window.location.href = data.redirect;
} else {
document.getElementById('loginError').textContent = data.message;
}
} catch (error) {
alert('数据库错误,请稍后再试');
}
}
// 自动登录函数
async function autoLogin() {
const token = localStorage.getItem('token');
if (token) {
const response = await fetch('http://localhost:5000/index', {
headers: {
'Authorization': 'Bearer ' + token
}
});
if (response.ok) {
document.getElementById('content').innerText = '已自动登录';
} else {
document.getElementById('content').innerText = '自动登录失败';
}
}
}

View File

@@ -0,0 +1,31 @@
var modify = {};
modify.showModifyPassword = function() {
let modifyType = document.querySelector('.tablinks.active').textContent;
let info = {
modifyPasswordLis: document.getElementsByClassName('modifyPassword'),
modifymobileNoLis: document.getElementsByClassName('modifymobileNo'),
modifyUsernameLis: document.getElementsByClassName('modifyUsername'),
}
for (let key in info) {
let elements = info[key];
for (let item of elements) {
item.style.display = 'none';
}
}
if (modifyType === "修改密码") {
for (let item of info.modifyPasswordLis) {
item.style.display = 'block';
}
} else if (modifyType === "修改手机号") {
for (let item of info.modifymobileNoLis) {
item.style.display = 'block';
}
} else if (modifyType === "修改用户名") {
for (let item of info.modifyUsernameLis) {
item.style.display = 'block';
}
}
}

View File

@@ -0,0 +1,42 @@
function validateForm() {
var departure = document.getElementById('departure').value;
var destination = document.getElementById('destination').value;
var warning = document.getElementById('destination-warning');
if (departure === destination) {
warning.textContent = '出发地和目的地不能相同';
return false;
} else {
warning.textContent = '';
}
return true;
}
function increment() {
var passengers = document.getElementById("passengers");
var value = parseInt(passengers.value, 10);
if (value < 50) {
passengers.value = value + 1;
}
}
function decrement() {
var passengers = document.getElementById("passengers");
var value = parseInt(passengers.value, 10);
if (value > 1) {
passengers.value = value - 1;
}
}
document.addEventListener('DOMContentLoaded', function() {
// Set default date to tomorrow
var departureDate = document.getElementById('departure-date');
if (!departureDate.value) {
var today = new Date();
var tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
var month = ('0' + (tomorrow.getMonth() + 1)).slice(-2);
var day = ('0' + tomorrow.getDate()).slice(-2);
var year = tomorrow.getFullYear();
departureDate.value = `${year}-${month}-${day}`;
}
});

View File

@@ -0,0 +1,32 @@
function submitForm() {
let isValid = true;
clearErrors();
if (!checkInfo.checkMobileNo()) {
document.getElementById('mobileNoError').innerText = '手机号格式有误';
isValid = false;
}
if (!checkInfo.checkPassword()) {
document.getElementById('passwordError').innerText = '密码须为长度为6-20位字母、数字或符号';
document.getElementById('confirmPasswordError').innerText = '两次输入的密码不一致';
isValid = false;
}
if (isValid) {
document.getElementById('encryptedPassword').value = md5(
document.getElementById('password').value
);
document.getElementById('encryptedConfirmPassword').value = md5(
document.getElementById('confirmPassword').value
);
return true;
}
return false;
}
function clearErrors() {
document.getElementById('mobileNoError').innerText = '';
document.getElementById('passwordError').innerText = '';
document.getElementById('confirmPasswordError').innerText = '';
}

View File

@@ -0,0 +1,14 @@
let slideIndex = 0;
const slides = document.getElementById('slide-container');
const totalSlides = slides.children.length;
function showSlides() {
slideIndex++;
if (slideIndex >= totalSlides) {
slideIndex = 0;
}
slides.style.transform = 'translateX(' + (-slideIndex * 100) + '%)';
setTimeout(showSlides, 5000); // Change image every 5 seconds
}
showSlides();