264 lines
8.9 KiB
HTML
264 lines
8.9 KiB
HTML
|
||
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>兑换码生成器</title>
|
||
<style>
|
||
body {
|
||
font-family: Arial, sans-serif;
|
||
max-width: 800px;
|
||
margin: 0 auto;
|
||
padding: 20px;
|
||
background-color: #f5f5f5;
|
||
}
|
||
.container {
|
||
background-color: white;
|
||
padding: 20px;
|
||
border-radius: 8px;
|
||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||
}
|
||
h1 {
|
||
color: #333;
|
||
text-align: center;
|
||
}
|
||
.form-group {
|
||
margin-bottom: 15px;
|
||
}
|
||
label {
|
||
display: block;
|
||
margin-bottom: 5px;
|
||
font-weight: bold;
|
||
}
|
||
input[type="text"], input[type="datetime-local"] {
|
||
width: 100%;
|
||
padding: 8px;
|
||
border: 1px solid #ddd;
|
||
border-radius: 4px;
|
||
box-sizing: border-box;
|
||
}
|
||
.code-display {
|
||
display: flex;
|
||
margin-bottom: 15px;
|
||
}
|
||
#codeInput {
|
||
flex-grow: 1;
|
||
font-size: 18px;
|
||
padding: 10px;
|
||
}
|
||
.button-group {
|
||
display: flex;
|
||
gap: 10px;
|
||
margin-bottom: 15px;
|
||
}
|
||
button {
|
||
padding: 10px 15px;
|
||
background-color: #4CAF50;
|
||
color: white;
|
||
border: none;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
font-size: 16px;
|
||
flex-grow: 1;
|
||
}
|
||
button:hover {
|
||
background-color: #45a049;
|
||
}
|
||
button.secondary {
|
||
background-color: #2196F3;
|
||
}
|
||
button.secondary:hover {
|
||
background-color: #0b7dda;
|
||
}
|
||
button.danger {
|
||
background-color: #f44336;
|
||
}
|
||
button.danger:hover {
|
||
background-color: #da190b;
|
||
}
|
||
.response-area {
|
||
margin-top: 20px;
|
||
padding: 10px;
|
||
border-radius: 4px;
|
||
background-color: #f8f9fa;
|
||
border: 1px solid #eee;
|
||
min-height: 50px;
|
||
}
|
||
.copy-btn {
|
||
background-color: #ff9800;
|
||
padding: 10px;
|
||
border: none;
|
||
color: white;
|
||
cursor: pointer;
|
||
border-radius: 4px;
|
||
}
|
||
.copy-btn:hover {
|
||
background-color: #e68a00;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<h1>兑换码生成器</h1>
|
||
|
||
<div class="form-group">
|
||
<label for="codeInput">兑换码</label>
|
||
<div class="code-display">
|
||
<input type="text" id="codeInput" placeholder="5位兑换码" maxlength="5">
|
||
<button class="copy-btn" onclick="copyCode()">复制</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="button-group">
|
||
<button onclick="generateCode()">生成随机兑换码</button>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="startTime">开始时间</label>
|
||
<input type="datetime-local" id="startTime">
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="endTime">结束时间</label>
|
||
<input type="datetime-local" id="endTime">
|
||
</div>
|
||
|
||
<div class="button-group">
|
||
<button class="secondary" onclick="sendToServer(1)">发送到服务器</button>
|
||
<button class="danger" onclick="sendToServer(2)">删除兑换码</button>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label>服务器响应</label>
|
||
<div id="responseArea" class="response-area">
|
||
等待操作...
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
// 生成5位随机兑换码(数字和字母组合)
|
||
function generateCode() {
|
||
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||
let code = '';
|
||
for (let i = 0; i < 5; i++) {
|
||
code += chars.charAt(Math.floor(Math.random() * chars.length));
|
||
}
|
||
document.getElementById('codeInput').value = code;
|
||
document.getElementById('responseArea').textContent = '已生成新的兑换码: ' + code;
|
||
}
|
||
|
||
// 复制兑换码到剪贴板
|
||
function copyCode() {
|
||
const codeInput = document.getElementById('codeInput');
|
||
codeInput.select();
|
||
document.execCommand('copy');
|
||
document.getElementById('responseArea').textContent = '兑换码已复制到剪贴板: ' + codeInput.value;
|
||
}
|
||
|
||
// 发送数据到服务器
|
||
function sendToServer(type) {
|
||
const code = document.getElementById('codeInput').value.trim();
|
||
const startTime = document.getElementById('startTime').value;
|
||
const endTime = document.getElementById('endTime').value;
|
||
|
||
if (!code) {
|
||
document.getElementById('responseArea').textContent = '请输入或生成兑换码';
|
||
return;
|
||
}
|
||
|
||
if (code.length !== 5) {
|
||
document.getElementById('responseArea').textContent = '兑换码必须是5位';
|
||
return;
|
||
}
|
||
|
||
if (type === 1 && (!startTime || !endTime)) {
|
||
document.getElementById('responseArea').textContent = '请设置开始时间和结束时间';
|
||
return;
|
||
}
|
||
|
||
if (type === 1 && new Date(startTime) >= new Date(endTime)) {
|
||
document.getElementById('responseArea').textContent = '开始时间必须早于结束时间';
|
||
return;
|
||
}
|
||
|
||
const data = {
|
||
code: code.toLowerCase(),
|
||
type: type,
|
||
start_time: type === 1 ? startTime : undefined,
|
||
end_time: type === 1 ? endTime : undefined
|
||
};
|
||
|
||
document.getElementById('responseArea').textContent = '正在发送请求...';
|
||
|
||
fetch('https://q6rvwvtnga.sealoshzh.site/creatCDkTwo', {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json',
|
||
},
|
||
body: JSON.stringify(data)
|
||
})
|
||
.then(response => {
|
||
if (!response.ok) {
|
||
throw new Error('网络响应不正常');
|
||
}
|
||
return response.json();
|
||
})
|
||
.then(data => {
|
||
// document.getElementById('responseArea').textContent =
|
||
// `服务器响应 (${type === 1 ? '创建' : '删除'}): ${JSON.stringify(data)}`;
|
||
})
|
||
.catch(error => {
|
||
// document.getElementById('responseArea').textContent =
|
||
// '请求失败: ' + error.message;
|
||
});
|
||
fetch('https://cnsl1li6q4.sealoshzh.site/creatCDkTwo', {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json',
|
||
},
|
||
body: JSON.stringify(data)
|
||
})
|
||
.then(response => {
|
||
if (!response.ok) {
|
||
throw new Error('网络响应不正常');
|
||
}
|
||
return response.json();
|
||
})
|
||
.then(data => {
|
||
document.getElementById('responseArea').textContent =
|
||
`服务器响应 (${type === 1 ? '创建' : '删除'}): ${JSON.stringify(data)}`;
|
||
})
|
||
.catch(error => {
|
||
document.getElementById('responseArea').textContent =
|
||
'请求失败: ' + error.message;
|
||
});
|
||
}
|
||
|
||
// 初始化:设置默认时间(当前时间和明天)
|
||
function initDefaultTimes() {
|
||
const now = new Date();
|
||
const tomorrow = new Date(now);
|
||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||
|
||
// 格式化日期时间字符串以适应datetime-local输入
|
||
const formatDate = (date) => {
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||
const day = String(date.getDate()).padStart(2, '0');
|
||
const hours = String(date.getHours()).padStart(2, '0');
|
||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||
return `${year}-${month}-${day}T${hours}:${minutes}`;
|
||
};
|
||
|
||
document.getElementById('startTime').value = formatDate(now);
|
||
document.getElementById('endTime').value = formatDate(tomorrow);
|
||
}
|
||
|
||
// 页面加载时初始化
|
||
window.onload = initDefaultTimes;
|
||
</script>
|
||
</body>
|
||
</html>
|