更新CHANGELOG记录移
This commit is contained in:
696
ht/index.php
696
ht/index.php
@@ -1,372 +1,372 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 投票系统首页
|
||||
* 显示投票列表,支持分页和筛选
|
||||
*/
|
||||
|
||||
// 引入必要文件
|
||||
require_once 'inc/pubs.php';
|
||||
require_once 'inc/sqls.php';
|
||||
|
||||
// 实例化数据库操作类
|
||||
$db = new DB();
|
||||
|
||||
// 获取当前用户
|
||||
$user = checkLogin();
|
||||
|
||||
// 获取分页参数
|
||||
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
|
||||
$pageSize = 10;
|
||||
|
||||
// 获取筛选参数
|
||||
$status = isset($_GET['status']) ? intval($_GET['status']) : -1;
|
||||
$type = isset($_GET['type']) ? intval($_GET['type']) : -1;
|
||||
|
||||
// 构建查询条件
|
||||
$whereConditions = [];
|
||||
if ($status >= 0) {
|
||||
$whereConditions[] = "status = $status";
|
||||
}
|
||||
if ($type >= 0) {
|
||||
$whereConditions[] = "itype = $type";
|
||||
}
|
||||
|
||||
// 当前时间,用于判断投票是否进行中
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$whereStr = !empty($whereConditions) ? implode(' AND ', $whereConditions) : '';
|
||||
|
||||
// 获取总记录数
|
||||
$total = $db->count('vote', $whereStr);
|
||||
|
||||
// 计算分页信息
|
||||
$pagination = getPagination($total, $page, $pageSize);
|
||||
|
||||
// 获取投票列表
|
||||
$orderBy = "addtime DESC";
|
||||
$limit = "{$pagination['offset']}, {$pagination['pageSize']}";
|
||||
$voteList = $db->getAll('vote', $whereStr, '*', $orderBy, $limit);
|
||||
|
||||
// 页面标题
|
||||
$pageTitle = "投票系统首页";
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo $pageTitle; ?> - <?php echo getSiteTitle(); ?></title>
|
||||
<link rel="stylesheet" href="inc/css.css">
|
||||
<style>
|
||||
.vote-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 20px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.vote-card {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.vote-card-body {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.vote-status {
|
||||
display: inline-block;
|
||||
padding: 3px 8px;
|
||||
border-radius: 3px;
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.vote-status-active {
|
||||
background-color: #2ecc71;
|
||||
}
|
||||
|
||||
.vote-status-pending {
|
||||
background-color: #f39c12;
|
||||
}
|
||||
|
||||
.vote-status-ended {
|
||||
background-color: #95a5a6;
|
||||
}
|
||||
|
||||
.vote-status-disabled {
|
||||
background-color: #e74c3c;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
</style>
|
||||
<title>诗词收录 - 古诗词鉴赏平台</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 顶部导航 -->
|
||||
<header class="header">
|
||||
<div class="header-container">
|
||||
<div class="logo"><?php echo getSiteTitle(); ?></div>
|
||||
<nav class="nav">
|
||||
<a href="index.php" class="nav-item active">首页</a>
|
||||
<?php if ($user): ?>
|
||||
<a href="vote.php?act=my" class="nav-item">我的投票</a>
|
||||
<?php if ($user['irole'] == 1): ?>
|
||||
<a href="admin.php" class="nav-item">管理中心</a>
|
||||
<?php endif; ?>
|
||||
<a href="javascript:void(0);" class="nav-item" id="showSettings">个人设置</a>
|
||||
<a href="api/user.php?act=logout" class="nav-item">退出登录</a>
|
||||
<?php else: ?>
|
||||
<a href="login.php" class="nav-item">登录</a>
|
||||
<a href="reger.php" class="nav-item">注册</a>
|
||||
<?php endif; ?>
|
||||
</nav>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>📜 诗词收录</h1>
|
||||
<p>收录经典诗词,传承中华文化</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 主体内容 -->
|
||||
<div class="main">
|
||||
<h1>投票列表</h1>
|
||||
|
||||
<!-- 筛选表单 -->
|
||||
<div class="filter-form">
|
||||
<form action="index.php" method="get">
|
||||
<div style="display: flex; gap: 15px; flex-wrap: wrap;">
|
||||
<div>
|
||||
<label for="status">状态:</label>
|
||||
<select name="status" id="status" class="form-control" style="width: auto;">
|
||||
<option value="-1">全部</option>
|
||||
<option value="1" <?php echo $status == 1 ? 'selected' : ''; ?>>正常</option>
|
||||
<option value="0" <?php echo $status === 0 ? 'selected' : ''; ?>>禁用</option>
|
||||
</select>
|
||||
|
||||
<div class="card">
|
||||
<div id="alert" class="alert"></div>
|
||||
|
||||
<form id="submitForm">
|
||||
<div class="form-group">
|
||||
<label for="name">参考语句 <span class="required">*</span></label>
|
||||
<div class="input-wrapper">
|
||||
<input type="text" id="name" name="name" class="form-control" placeholder="请输入参考语句(如:纤云弄巧,飞星传恨)" required>
|
||||
<span class="icon" id="nameIcon"></span>
|
||||
</div>
|
||||
<div>
|
||||
<label for="type">类型:</label>
|
||||
<select name="type" id="type" class="form-control" style="width: auto;">
|
||||
<option value="-1">全部</option>
|
||||
<option value="0" <?php echo $type === 0 ? 'selected' : ''; ?>>单选</option>
|
||||
<option value="1" <?php echo $type == 1 ? 'selected' : ''; ?>>多选</option>
|
||||
</select>
|
||||
<div class="threshold-wrapper">
|
||||
<label for="threshold">相似度阈值 (%)</label>
|
||||
<input type="number" id="threshold" name="threshold" class="form-control threshold-input" value="80" min="0" max="100" step="1">
|
||||
<button type="button" class="btn btn-secondary" onclick="checkName()">🔍 检测是否存在</button>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-blue">筛选</button>
|
||||
<a href="index.php" class="btn btn-gray">重置</a>
|
||||
<div id="similarityInfo" class="similarity-info"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="catename">分类 <span class="required">*</span></label>
|
||||
<select id="catename" name="catename" class="form-control" required>
|
||||
<option value="">请选择分类</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url">诗人和标题 <span class="required">*</span></label>
|
||||
<input type="text" id="url" name="url" class="form-control" placeholder="请输入诗人和标题(如:李白 静夜思)" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="keywords">关键词 <span class="required">*</span></label>
|
||||
<input type="text" id="keywords" name="keywords" class="form-control" placeholder="请输入关键词,用逗号分隔(如:思乡,月亮,唐诗)" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="img">平台(可选)</label>
|
||||
<input type="text" id="img" name="img" class="form-control" placeholder="请输入平台名称(如:安卓 Flutter)">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="introduce">诗词介绍 <span class="required">*</span></label>
|
||||
<textarea id="introduce" name="introduce" class="form-control" placeholder="请输入诗词详细介绍..." required></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="captcha">人机验证 <span class="required">*</span></label>
|
||||
<div class="captcha-wrapper">
|
||||
<div class="captcha-question" id="captchaQuestion"></div>
|
||||
<input type="text" id="captcha" name="captcha" class="form-control captcha-input" placeholder="请输入答案" required>
|
||||
<button type="button" class="btn btn-secondary refresh-btn" onclick="generateCaptcha()">🔄 刷新</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" id="submitBtn" class="btn btn-primary btn-block">
|
||||
<span class="loading" id="loading"></span>
|
||||
<span id="btnText">📝 提交收录</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php if ($user && $user['irole'] == 1): ?>
|
||||
<div style="margin-bottom: 20px;">
|
||||
<a href="admin/topic.php?act=add" class="btn btn-green">发起新投票</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- 投票列表 -->
|
||||
<?php if (!empty($voteList)): ?>
|
||||
<div class="vote-list">
|
||||
<?php foreach ($voteList as $vote): ?>
|
||||
<?php
|
||||
// 确定投票状态
|
||||
$voteStatus = '';
|
||||
$statusClass = '';
|
||||
|
||||
if ($vote['status'] == 0) {
|
||||
$voteStatus = '已禁用';
|
||||
$statusClass = 'vote-status-disabled';
|
||||
} else {
|
||||
if ($vote['statime'] > $now) {
|
||||
$voteStatus = '未开始';
|
||||
$statusClass = 'vote-status-pending';
|
||||
} elseif ($vote['endtime'] < $now) {
|
||||
$voteStatus = '已结束';
|
||||
$statusClass = 'vote-status-ended';
|
||||
} else {
|
||||
$voteStatus = '进行中';
|
||||
$statusClass = 'vote-status-active';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="card vote-card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">
|
||||
<?php echo htmlspecialchars($vote['title']); ?>
|
||||
<span class="vote-status <?php echo $statusClass; ?>"><?php echo $voteStatus; ?></span>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="card-body vote-card-body">
|
||||
<p>
|
||||
<?php echo mb_substr(strip_tags($vote['idesc']), 0, 100, 'UTF-8'); ?>
|
||||
<?php if (mb_strlen($vote['idesc'], 'UTF-8') > 100): ?>...<?php endif; ?>
|
||||
</p>
|
||||
<p><small>类型:<?php echo $vote['itype'] == 0 ? '单选' : '多选'; ?></small></p>
|
||||
<p><small>时间:<?php echo date('Y-m-d', strtotime($vote['statime'])); ?> 至 <?php echo date('Y-m-d', strtotime($vote['endtime'])); ?></small></p>
|
||||
<p><small>浏览:<?php echo $vote['iview']; ?>次</small></p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<a href="vote.php?id=<?php echo $vote['id']; ?>" class="btn btn-blue">查看详情</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<div class="debug-section">
|
||||
<h3>🔧 开发者调试工具</h3>
|
||||
<button class="debug-btn" onclick="fillTestData()">填充测试数据</button>
|
||||
<button class="debug-btn" onclick="clearForm()">清空表单</button>
|
||||
<button class="debug-btn" onclick="toggleDebugLog()">显示/隐藏日志</button>
|
||||
<div id="debugLog" class="debug-log"></div>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination" id="pagination"></div>
|
||||
<?php else: ?>
|
||||
<div class="card">
|
||||
<div class="card-body" style="text-align: center; padding: 30px;">
|
||||
<p>暂无投票数据</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="inc/js.js"></script>
|
||||
|
||||
<div id="resultModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<span id="modalIcon"></span>
|
||||
<h2 id="modalTitle"></h2>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p id="modalMessage"></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-primary" onclick="closeModal()">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 初始化分页
|
||||
pagination('pagination', <?php echo $pagination['page']; ?>, <?php echo $pagination['totalPage']; ?>, function(page) {
|
||||
// 构建URL参数
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
params.set('page', page);
|
||||
|
||||
// 跳转到新页面
|
||||
window.location.href = 'index.php?' + params.toString();
|
||||
});
|
||||
|
||||
<?php if ($user): ?>
|
||||
// 显示个人设置
|
||||
document.getElementById('showSettings').addEventListener('click', function() {
|
||||
showSettingsModal();
|
||||
});
|
||||
|
||||
// 显示设置模态框
|
||||
function showSettingsModal() {
|
||||
var modal = document.createElement('div');
|
||||
modal.className = 'modal-overlay';
|
||||
modal.innerHTML = `
|
||||
<div class="modal">
|
||||
<div class="modal-header">
|
||||
<h3>个人设置</h3>
|
||||
<button class="modal-close" onclick="closeSettingsModal()">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label for="user_identifier" class="form-label">用户标识</label>
|
||||
<input type="text" id="user_identifier" class="form-control" placeholder="请输入用户标识" value="<?php echo htmlspecialchars($user['user_identifier'] ?? ''); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-gray" onclick="closeSettingsModal()">取消</button>
|
||||
<button class="btn btn-blue" onclick="updateUserIdentifier()">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(modal);
|
||||
}
|
||||
|
||||
// 关闭设置模态框
|
||||
function closeSettingsModal() {
|
||||
var modal = document.querySelector('.modal-overlay');
|
||||
if (modal) {
|
||||
modal.remove();
|
||||
let nameChecked = false;
|
||||
let nameExists = false;
|
||||
|
||||
async function generateCaptcha() {
|
||||
try {
|
||||
const response = await fetch('api.php?api=captcha');
|
||||
const data = await response.json();
|
||||
if (data.ok) {
|
||||
document.getElementById('captchaQuestion').textContent = `${data.num1} + ${data.num2} = ?`;
|
||||
document.getElementById('captcha').value = '';
|
||||
}
|
||||
} catch (error) {
|
||||
addLog('获取验证码失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新用户标识
|
||||
function updateUserIdentifier() {
|
||||
var userIdentifier = document.getElementById('user_identifier').value.trim();
|
||||
|
||||
function showModal(type, title, message) {
|
||||
const modal = document.getElementById('resultModal');
|
||||
const icon = document.getElementById('modalIcon');
|
||||
const modalTitle = document.getElementById('modalTitle');
|
||||
const modalMessage = document.getElementById('modalMessage');
|
||||
|
||||
ajaxRequest('api/user.php', {
|
||||
act: 'updateUserIdentifier',
|
||||
user_identifier: userIdentifier
|
||||
}, function(response) {
|
||||
if (response.code === 0) {
|
||||
showMask('成功', '用户标识更新成功', [
|
||||
{
|
||||
text: '确定',
|
||||
class: 'btn-primary',
|
||||
callback: function() {
|
||||
closeSettingsModal();
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
showMask('错误', response.msg || '更新失败,请稍后重试');
|
||||
icon.textContent = type === 'success' ? '✅' : '❌';
|
||||
modalTitle.textContent = title;
|
||||
modalMessage.textContent = message;
|
||||
|
||||
modal.classList.add('show');
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
const modal = document.getElementById('resultModal');
|
||||
modal.classList.remove('show');
|
||||
}
|
||||
|
||||
function showAlert(message, type = 'info') {
|
||||
const alert = document.getElementById('alert');
|
||||
alert.className = `alert alert-${type} show`;
|
||||
alert.innerHTML = `<span>${type === 'success' ? '✅' : type === 'error' ? '❌' : 'ℹ️'}</span> ${message}`;
|
||||
if (type !== 'error') {
|
||||
setTimeout(() => alert.classList.remove('show'), 5000);
|
||||
}
|
||||
}
|
||||
|
||||
function addLog(message) {
|
||||
const log = document.getElementById('debugLog');
|
||||
const time = new Date().toLocaleTimeString();
|
||||
const item = document.createElement('div');
|
||||
item.className = 'log-item';
|
||||
item.innerHTML = `<span class="log-time">[${time}]</span>${message}`;
|
||||
log.appendChild(item);
|
||||
log.scrollTop = log.scrollHeight;
|
||||
}
|
||||
|
||||
function toggleDebugLog() {
|
||||
document.getElementById('debugLog').classList.toggle('show');
|
||||
}
|
||||
|
||||
async function loadCategories() {
|
||||
try {
|
||||
addLog('正在加载分类数据...');
|
||||
const response = await fetch('api.php?api=categories');
|
||||
addLog('API响应状态: ' + response.status);
|
||||
|
||||
const data = await response.json();
|
||||
addLog('API返回数据: ' + JSON.stringify(data));
|
||||
|
||||
if (data.debug) {
|
||||
addLog('🔍 调试信息:');
|
||||
Object.entries(data.debug).forEach(([key, value]) => {
|
||||
addLog(` ${key}: ${typeof value === 'object' ? JSON.stringify(value) : value}`);
|
||||
});
|
||||
}
|
||||
}, function(error) {
|
||||
showMask('错误', '请求失败,请稍后重试');
|
||||
});
|
||||
|
||||
if (data.ok && data.categories && data.categories.length > 0) {
|
||||
const select = document.getElementById('catename');
|
||||
select.innerHTML = '<option value="">请选择分类</option>';
|
||||
data.categories.forEach(cat => {
|
||||
const option = document.createElement('option');
|
||||
option.value = cat.catename;
|
||||
option.textContent = cat.catename;
|
||||
select.appendChild(option);
|
||||
});
|
||||
addLog(`✅ 分类加载成功,共 ${data.categories.length} 个分类`);
|
||||
} else {
|
||||
addLog('⚠️ 分类加载失败或无数据');
|
||||
}
|
||||
} catch (error) {
|
||||
addLog('❌ 分类加载异常: ' + error.message);
|
||||
}
|
||||
}
|
||||
<?php endif; ?>
|
||||
|
||||
async function checkName() {
|
||||
const name = document.getElementById('name').value.trim();
|
||||
const icon = document.getElementById('nameIcon');
|
||||
const input = document.getElementById('name');
|
||||
const similarityInfo = document.getElementById('similarityInfo');
|
||||
const threshold = parseInt(document.getElementById('threshold').value) || 80;
|
||||
|
||||
if (!name) {
|
||||
icon.className = 'icon';
|
||||
input.className = 'form-control';
|
||||
similarityInfo.innerHTML = '';
|
||||
nameChecked = false;
|
||||
nameExists = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
addLog(`检查名称: ${name}, 阈值: ${threshold}%`);
|
||||
const formData = new FormData();
|
||||
formData.append('name', name);
|
||||
formData.append('threshold', threshold);
|
||||
|
||||
const response = await fetch('api.php?api=check-name', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.ok) {
|
||||
nameChecked = true;
|
||||
nameExists = data.exists;
|
||||
|
||||
if (data.exists) {
|
||||
icon.className = 'icon error';
|
||||
icon.textContent = '❌';
|
||||
input.className = 'form-control invalid';
|
||||
|
||||
let infoHtml = `<div class="similarity-item error">`;
|
||||
infoHtml += `<span class="similarity-label">⚠️ 发现相似内容</span>`;
|
||||
if (data.similar_count > 0) {
|
||||
infoHtml += `<span class="similarity-count">相似 ${data.similar_count} 条</span>`;
|
||||
}
|
||||
if (data.max_similarity > 0) {
|
||||
infoHtml += `<span class="similarity-percent">最高相似度 ${data.max_similarity}%</span>`;
|
||||
}
|
||||
infoHtml += `</div>`;
|
||||
similarityInfo.innerHTML = infoHtml;
|
||||
|
||||
addLog(`名称已存在,相似度 ${data.max_similarity}%,相似 ${data.similar_count} 条`);
|
||||
} else {
|
||||
icon.className = 'icon success';
|
||||
icon.textContent = '✅';
|
||||
input.className = 'form-control valid';
|
||||
|
||||
let infoHtml = `<div class="similarity-item success">`;
|
||||
infoHtml += `<span class="similarity-label">✅ 未发现相似内容</span>`;
|
||||
if (data.max_similarity > 0) {
|
||||
infoHtml += `<span class="similarity-percent">最高相似度 ${data.max_similarity}%</span>`;
|
||||
}
|
||||
infoHtml += `</div>`;
|
||||
similarityInfo.innerHTML = infoHtml;
|
||||
|
||||
addLog('名称可用');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
addLog('检查名称异常: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
function fillTestData() {
|
||||
document.getElementById('name').value = '将进酒';
|
||||
document.getElementById('url').value = '李白 将进酒';
|
||||
document.getElementById('keywords').value = '豪放,饮酒,唐诗';
|
||||
document.getElementById('img').value = 'iOS Swift';
|
||||
document.getElementById('introduce').value = '《将进酒》是唐代大诗人李白沿用乐府古题创作的七言歌行。此诗思想内容非常深沉,艺术表现非常成熟,在同题作品中影响最大。诗人豪饮高歌,借酒消愁,抒发了忧愤深广的人生感慨。';
|
||||
addLog('测试数据已填充');
|
||||
checkName();
|
||||
}
|
||||
|
||||
function clearForm() {
|
||||
document.getElementById('submitForm').reset();
|
||||
document.getElementById('nameIcon').className = 'icon';
|
||||
document.getElementById('name').className = 'form-control';
|
||||
document.getElementById('alert').classList.remove('show');
|
||||
nameChecked = false;
|
||||
nameExists = false;
|
||||
addLog('表单已清空');
|
||||
}
|
||||
|
||||
function setLoading(loading) {
|
||||
const btn = document.getElementById('submitBtn');
|
||||
const loadingEl = document.getElementById('loading');
|
||||
const btnText = document.getElementById('btnText');
|
||||
|
||||
btn.disabled = loading;
|
||||
loadingEl.classList.toggle('show', loading);
|
||||
btnText.textContent = loading ? '提交中...' : '📝 提交收录';
|
||||
}
|
||||
|
||||
document.getElementById('name').addEventListener('blur', checkName);
|
||||
document.getElementById('name').addEventListener('input', () => {
|
||||
nameChecked = false;
|
||||
document.getElementById('nameIcon').className = 'icon';
|
||||
document.getElementById('name').className = 'form-control';
|
||||
});
|
||||
|
||||
document.getElementById('submitForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const name = document.getElementById('name').value.trim();
|
||||
const catename = document.getElementById('catename').value;
|
||||
const url = document.getElementById('url').value;
|
||||
const keywords = document.getElementById('keywords').value;
|
||||
const introduce = document.getElementById('introduce').value;
|
||||
|
||||
if (!nameChecked) {
|
||||
await checkName();
|
||||
}
|
||||
|
||||
if (nameExists) {
|
||||
showAlert('该诗词名称已存在,请更换一个', 'error');
|
||||
addLog('提交被阻止:名称已存在');
|
||||
return;
|
||||
}
|
||||
|
||||
const confirmMessage = `确认提交以下信息?\n\n诗词名称:${name}\n分类:${catename}\n诗人和标题:${url}\n关键词:${keywords}\n诗词介绍:${introduce.substring(0, 50)}${introduce.length > 50 ? '...' : ''}`;
|
||||
|
||||
if (!confirm(confirmMessage)) {
|
||||
addLog('用户取消提交');
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
showAlert('正在提交...', 'info');
|
||||
addLog('开始提交表单...');
|
||||
|
||||
try {
|
||||
const formData = new FormData(e.target);
|
||||
const response = await fetch('api.php?api=submit', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
addLog('API返回数据: ' + JSON.stringify(data));
|
||||
|
||||
if (data.debug) {
|
||||
addLog('🔍 提交调试信息:');
|
||||
Object.entries(data.debug).forEach(([key, value]) => {
|
||||
addLog(` ${key}: ${typeof value === 'object' ? JSON.stringify(value) : value}`);
|
||||
});
|
||||
}
|
||||
|
||||
if (data.ok) {
|
||||
showModal('success', '提交成功', data.message);
|
||||
clearForm();
|
||||
generateCaptcha();
|
||||
addLog('提交成功');
|
||||
} else {
|
||||
showModal('error', '提交失败', data.error);
|
||||
addLog('提交失败: ' + data.error);
|
||||
}
|
||||
} catch (error) {
|
||||
showAlert('提交失败,请稍后重试', 'error');
|
||||
addLog('提交异常: ' + error.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadCategories();
|
||||
generateCaptcha();
|
||||
addLog('页面加载完成');
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal {
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
padding: 15px 20px;
|
||||
border-bottom: 1px solid #eee;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.modal-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
padding: 15px 20px;
|
||||
border-top: 1px solid #eee;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user