Compare commits
14 Commits
test-workf
...
feature/qu
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e4765b2ac | |||
| b03303b90c | |||
| aa0cbfadeb | |||
| ac67602ce3 | |||
| 7721223a74 | |||
| c45070300f | |||
| 0a55dea92f | |||
| 4eeef1d1b3 | |||
| 0d333d6492 | |||
| 0aadca89a7 | |||
| 0caf063e09 | |||
| 54651daee1 | |||
| 5941191ed6 | |||
| de9fd8a73e |
17
.gitea/workflows/build.yml
Normal file
17
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
name: Code Review
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created, edited]
|
||||
|
||||
jobs:
|
||||
code-review:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: OpenAI Code Review
|
||||
uses: bhavik/gitea-code-review-action@v0.1
|
||||
with:
|
||||
PROGRAMMING_LANGUAGE: 'JavaScript'
|
||||
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
FULL_REVIEW_COMMENT: 'openai'
|
||||
REVIEW_COMMENT_PREFIX: 'openai:'
|
||||
203
css/styles.css
Normal file
203
css/styles.css
Normal file
@@ -0,0 +1,203 @@
|
||||
/* 基本样式重置 */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Microsoft YaHei', Arial, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
background-color: #f4f4f4;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 90%;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
/* 头部样式 */
|
||||
header {
|
||||
background-color: #3498db;
|
||||
color: #fff;
|
||||
padding: 1rem 0;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
header h1 {
|
||||
margin: 0;
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
nav {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
nav ul {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
nav ul li {
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
nav ul li a {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
padding: 5px 10px;
|
||||
border-radius: 3px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
nav ul li a:hover,
|
||||
nav ul li a.active {
|
||||
background-color: rgba(255,255,255,0.2);
|
||||
}
|
||||
|
||||
/* 页脚样式 */
|
||||
footer {
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
padding: 1rem 0;
|
||||
margin-top: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 主内容区域 */
|
||||
main {
|
||||
padding: 2rem 0;
|
||||
}
|
||||
|
||||
.welcome-section {
|
||||
background-color: #fff;
|
||||
padding: 2rem;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
/* 登录页面样式 */
|
||||
.login-page {
|
||||
background-color: #f9f9f9;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.login-box {
|
||||
background-color: #fff;
|
||||
padding: 2rem;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 15px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.login-box h1 {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
color: #3498db;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 0.8rem;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 1rem;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
input[type="text"]:focus,
|
||||
input[type="password"]:focus {
|
||||
border-color: #3498db;
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
|
||||
}
|
||||
|
||||
.btn-login {
|
||||
background-color: #3498db;
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 0.8rem;
|
||||
width: 100%;
|
||||
font-size: 1rem;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.btn-login:hover {
|
||||
background-color: #2980b9;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #e74c3c;
|
||||
font-size: 0.85rem;
|
||||
margin-top: 5px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form-message {
|
||||
text-align: center;
|
||||
margin-top: 1rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.form-message.error {
|
||||
color: #e74c3c;
|
||||
}
|
||||
|
||||
.form-message.success {
|
||||
color: #2ecc71;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media screen and (max-width: 768px) {
|
||||
header h1 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
nav ul {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
nav ul li {
|
||||
margin-right: 0;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 480px) {
|
||||
.login-container {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.login-box {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.login-box h1 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
}
|
||||
58
index.html
Normal file
58
index.html
Normal file
@@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>首页 - 演示项目</title>
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="container">
|
||||
<h1>欢迎来到演示项目</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="index.html" class="active">首页</a></li>
|
||||
<li><a href="#" id="logout">退出登录</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="container">
|
||||
<section class="welcome-section">
|
||||
<h2>欢迎,<span id="username">用户</span>!</h2>
|
||||
<p>您已成功登录系统。</p>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="container">
|
||||
<p>© 2025 演示项目</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="js/main.js"></script>
|
||||
<script>
|
||||
// 检查用户是否已登录
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const isLoggedIn = localStorage.getItem('isLoggedIn');
|
||||
const storedUsername = localStorage.getItem('username');
|
||||
|
||||
if (!isLoggedIn) {
|
||||
window.location.href = 'login.html';
|
||||
} else if (storedUsername) {
|
||||
document.getElementById('username').textContent = storedUsername;
|
||||
}
|
||||
|
||||
// 退出登录功能
|
||||
document.getElementById('logout').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
localStorage.removeItem('isLoggedIn');
|
||||
localStorage.removeItem('username');
|
||||
window.location.href = 'login.html';
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
121
js/login.js
Normal file
121
js/login.js
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* 登录功能实现
|
||||
* 原生JavaScript,不依赖框架
|
||||
*/
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const loginForm = document.getElementById('loginForm');
|
||||
const usernameInput = document.getElementById('username');
|
||||
const passwordInput = document.getElementById('password');
|
||||
const usernameError = document.getElementById('username-error');
|
||||
const passwordError = document.getElementById('password-error');
|
||||
const formMessage = document.getElementById('form-message');
|
||||
|
||||
// 用于演示的模拟用户数据
|
||||
const mockUsers = [
|
||||
{ username: 'admin', password: 'admin123' },
|
||||
{ username: 'user', password: 'user123' }
|
||||
];
|
||||
|
||||
/**
|
||||
* 表单提交处理
|
||||
*/
|
||||
loginForm.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// 重置错误信息
|
||||
resetErrors();
|
||||
|
||||
// 获取输入值
|
||||
const username = usernameInput.value.trim();
|
||||
const password = passwordInput.value.trim();
|
||||
|
||||
// 验证表单
|
||||
let isValid = validateForm(username, password);
|
||||
|
||||
if (isValid) {
|
||||
// 模拟登录请求
|
||||
mockLogin(username, password);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 表单验证
|
||||
*/
|
||||
function validateForm(username, password) {
|
||||
let isValid = true;
|
||||
|
||||
// 验证用户名
|
||||
if (username === '') {
|
||||
displayError(usernameError, '请输入用户名');
|
||||
isValid = false;
|
||||
} else if (username.length < 3) {
|
||||
displayError(usernameError, '用户名长度必须至少为3个字符');
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
if (password === '') {
|
||||
displayError(passwordError, '请输入密码');
|
||||
isValid = false;
|
||||
} else if (password.length < 6) {
|
||||
displayError(passwordError, '密码长度必须至少为6个字符');
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示错误信息
|
||||
*/
|
||||
function displayError(element, message) {
|
||||
element.textContent = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置错误信息
|
||||
*/
|
||||
function resetErrors() {
|
||||
usernameError.textContent = '';
|
||||
passwordError.textContent = '';
|
||||
formMessage.textContent = '';
|
||||
formMessage.className = 'form-message';
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟登录
|
||||
*/
|
||||
function mockLogin(username, password) {
|
||||
// 显示加载状态
|
||||
formMessage.textContent = '登录中...';
|
||||
formMessage.className = 'form-message';
|
||||
|
||||
// 模拟网络延迟
|
||||
setTimeout(function() {
|
||||
// 检查用户是否存在
|
||||
const user = mockUsers.find(user =>
|
||||
user.username === username && user.password === password
|
||||
);
|
||||
|
||||
if (user) {
|
||||
// 登录成功
|
||||
formMessage.textContent = '登录成功,即将跳转...';
|
||||
formMessage.className = 'form-message success';
|
||||
|
||||
// 保存登录状态到本地存储
|
||||
localStorage.setItem('isLoggedIn', 'true');
|
||||
localStorage.setItem('username', username);
|
||||
|
||||
// 重定向到首页
|
||||
setTimeout(function() {
|
||||
window.location.href = 'index.html';
|
||||
}, 1000);
|
||||
} else {
|
||||
// 登录失败
|
||||
formMessage.textContent = '用户名或密码错误';
|
||||
formMessage.className = 'form-message error';
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
56
js/main.js
Normal file
56
js/main.js
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* 主页JavaScript
|
||||
*/
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 检查用户是否已登录
|
||||
checkLoginStatus();
|
||||
|
||||
// 初始化页面事件
|
||||
initEvents();
|
||||
});
|
||||
|
||||
/**
|
||||
* 检查用户登录状态
|
||||
*/
|
||||
function checkLoginStatus() {
|
||||
const isLoggedIn = localStorage.getItem('isLoggedIn');
|
||||
|
||||
if (!isLoggedIn) {
|
||||
// 如果未登录,重定向到登录页面
|
||||
window.location.href = 'login.html';
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取并显示用户名
|
||||
const username = localStorage.getItem('username');
|
||||
if (username) {
|
||||
document.getElementById('username').textContent = username;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化页面事件
|
||||
*/
|
||||
function initEvents() {
|
||||
// 退出登录
|
||||
const logoutBtn = document.getElementById('logout');
|
||||
if (logoutBtn) {
|
||||
logoutBtn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
logout();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
function logout() {
|
||||
// 清除本地存储中的登录信息
|
||||
localStorage.removeItem('isLoggedIn');
|
||||
localStorage.removeItem('username');
|
||||
|
||||
// 重定向到登录页面
|
||||
window.location.href = 'login.html';
|
||||
}
|
||||
176
js/quicksort.js
Normal file
176
js/quicksort.js
Normal file
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* 快速排序算法实现
|
||||
* 时间复杂度: 平均 O(n log n), 最坏 O(n²)
|
||||
* 空间复杂度: O(log n)
|
||||
*/
|
||||
|
||||
/**
|
||||
* 快速排序主函数
|
||||
* @param {Array} arr - 要排序的数组
|
||||
* @returns {Array} - 排序后的数组
|
||||
*/
|
||||
function quickSort(arr) {
|
||||
// 如果数组长度小于等于1,直接返回
|
||||
if (arr.length <= 1) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
// 选择基准值(这里选择最后一个元素)
|
||||
const pivot = arr[arr.length - 1];
|
||||
const left = [];
|
||||
const right = [];
|
||||
|
||||
// 将数组分成两部分
|
||||
for (let i = 0; i < arr.length - 1; i++) {
|
||||
if (arr[i] <= pivot) {
|
||||
left.push(arr[i]);
|
||||
} else {
|
||||
right.push(arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 递归排序左右两部分,并合并结果
|
||||
return [...quickSort(left), pivot, ...quickSort(right)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 原地快速排序(优化版本,节省空间)
|
||||
* @param {Array} arr - 要排序的数组
|
||||
* @param {number} low - 起始索引
|
||||
* @param {number} high - 结束索引
|
||||
*/
|
||||
function quickSortInPlace(arr, low = 0, high = arr.length - 1) {
|
||||
if (low < high) {
|
||||
const pivotIndex = partition(arr, low, high);
|
||||
quickSortInPlace(arr, low, pivotIndex - 1);
|
||||
quickSortInPlace(arr, pivotIndex + 1, high);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分区函数
|
||||
* @param {Array} arr - 数组
|
||||
* @param {number} low - 起始索引
|
||||
* @param {number} high - 结束索引
|
||||
* @returns {number} - 基准值的最终位置
|
||||
*/
|
||||
function partition(arr, low, high) {
|
||||
// 选择最后一个元素作为基准值
|
||||
const pivot = arr[high];
|
||||
let i = low - 1; // 小于基准值的元素的最后位置
|
||||
|
||||
for (let j = low; j < high; j++) {
|
||||
// 如果当前元素小于等于基准值
|
||||
if (arr[j] <= pivot) {
|
||||
i++;
|
||||
// 交换元素
|
||||
[arr[i], arr[j]] = [arr[j], arr[i]];
|
||||
}
|
||||
}
|
||||
|
||||
// 将基准值放到正确的位置
|
||||
[arr[i + 1], arr[high]] = [arr[high], arr[i + 1]];
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 三路快速排序(处理重复元素较多的数组)
|
||||
* @param {Array} arr - 要排序的数组
|
||||
* @param {number} low - 起始索引
|
||||
* @param {number} high - 结束索引
|
||||
*/
|
||||
function quickSortThreeWay(arr, low = 0, high = arr.length - 1) {
|
||||
if (low < high) {
|
||||
const [lt, gt] = partitionThreeWay(arr, low, high);
|
||||
quickSortThreeWay(arr, low, lt - 1);
|
||||
quickSortThreeWay(arr, gt + 1, high);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 三路分区函数
|
||||
* @param {Array} arr - 数组
|
||||
* @param {number} low - 起始索引
|
||||
* @param {number} high - 结束索引
|
||||
* @returns {Array} - [lt, gt] 小于和大于基准值的边界
|
||||
*/
|
||||
function partitionThreeWay(arr, low, high) {
|
||||
const pivot = arr[low];
|
||||
let lt = low; // 小于基准值的右边界
|
||||
let gt = high; // 大于基准值的左边界
|
||||
let i = low + 1; // 当前扫描位置
|
||||
|
||||
while (i <= gt) {
|
||||
if (arr[i] < pivot) {
|
||||
[arr[lt], arr[i]] = [arr[i], arr[lt]];
|
||||
lt++;
|
||||
i++;
|
||||
} else if (arr[i] > pivot) {
|
||||
[arr[gt], arr[i]] = [arr[i], arr[gt]];
|
||||
gt--;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return [lt, gt];
|
||||
}
|
||||
|
||||
// 测试函数
|
||||
function testQuickSort() {
|
||||
console.log("=== 快速排序算法测试 ===");
|
||||
|
||||
// 测试数据
|
||||
const testCases = [
|
||||
[64, 34, 25, 12, 22, 11, 90],
|
||||
[5, 2, 4, 6, 1, 3],
|
||||
[1],
|
||||
[],
|
||||
[3, 3, 3, 3, 3],
|
||||
[9, 8, 7, 6, 5, 4, 3, 2, 1],
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
];
|
||||
|
||||
testCases.forEach((testCase, index) => {
|
||||
console.log(`\n测试用例 ${index + 1}:`);
|
||||
console.log(`原始数组: [${testCase}]`);
|
||||
|
||||
// 测试标准快速排序
|
||||
const sorted1 = quickSort([...testCase]);
|
||||
console.log(`标准快排: [${sorted1}]`);
|
||||
|
||||
// 测试原地快速排序
|
||||
const arr2 = [...testCase];
|
||||
quickSortInPlace(arr2);
|
||||
console.log(`原地快排: [${arr2}]`);
|
||||
|
||||
// 测试三路快速排序
|
||||
const arr3 = [...testCase];
|
||||
quickSortThreeWay(arr3);
|
||||
console.log(`三路快排: [${arr3}]`);
|
||||
});
|
||||
}
|
||||
|
||||
// 导出函数供其他模块使用
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = {
|
||||
quickSort,
|
||||
quickSortInPlace,
|
||||
quickSortThreeWay,
|
||||
partition,
|
||||
partitionThreeWay
|
||||
};
|
||||
}
|
||||
|
||||
// 如果直接在浏览器中运行,执行测试
|
||||
if (typeof window !== 'undefined') {
|
||||
// 将函数添加到全局作用域
|
||||
window.quickSort = quickSort;
|
||||
window.quickSortInPlace = quickSortInPlace;
|
||||
window.quickSortThreeWay = quickSortThreeWay;
|
||||
|
||||
// 自动运行测试
|
||||
testQuickSort();
|
||||
}
|
||||
37
login.html
Normal file
37
login.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>用户登录 - 演示项目</title>
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
</head>
|
||||
<body class="login-page">
|
||||
<div class="login-container">
|
||||
<div class="login-box">
|
||||
<h1>用户登录</h1>
|
||||
<form id="loginForm">
|
||||
<div class="form-group">
|
||||
<label for="username">用户名</label>
|
||||
<input type="text" id="username" name="username" placeholder="请输入用户名" required>
|
||||
<span class="error-message" id="username-error"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">密码</label>
|
||||
<input type="password" id="password" name="password" placeholder="请输入密码" required>
|
||||
<span class="error-message" id="password-error"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn-login">登录</button>
|
||||
</div>
|
||||
|
||||
<div class="form-message" id="form-message"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="js/login.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
14
quicksort.py
Normal file
14
quicksort.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def quick_sort(arr):
|
||||
if len(arr) <= 1:
|
||||
return arr
|
||||
pivot = arr[len(arr) // 2] # 选取中间元素作为基准
|
||||
left = [x for x in arr if x < pivot]
|
||||
middle = [x for x in arr if x == pivot]
|
||||
right = [x for x in arr if x > pivot]
|
||||
return quick_sort(left) + middle + quick_sort(right)
|
||||
|
||||
|
||||
# 示例
|
||||
nums = [3, 6, 8, 10, 1, 2, 1]
|
||||
print("排序前:", nums)
|
||||
print("排序后:", quick_sort(nums))
|
||||
Reference in New Issue
Block a user