| | |
| | | <html lang="zh-CN"> |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <title>99游戏盒子 - 管理后台</title> |
| | | <title>游趣电玩 - 管理后台</title> |
| | | <style> |
| | | * { margin:0; padding:0; box-sizing:border-box; } |
| | | body { font-family:"Microsoft YaHei",sans-serif; background:#14161f; color:#e0e0e0; font-size:14px; } |
| | |
| | | <!-- 登录 --> |
| | | <div id="loginPage"> |
| | | <div class="login-box"> |
| | | <h1>99游戏盒子 · 管理后台</h1> |
| | | <h1>游趣电玩 · 管理后台</h1> |
| | | <div class="sub">GameBox Admin</div> |
| | | <input id="adminUser" placeholder="管理员账号" value="admin"> |
| | | <input id="adminPwd" type="password" placeholder="密码"> |
| | |
| | | <!-- 主面板 --> |
| | | <div id="mainPage"> |
| | | <div class="topbar"> |
| | | <div class="logo">99游戏盒子 · 管理后台</div> |
| | | <div class="logo">游趣电玩 · 管理后台</div> |
| | | <div class="nav-tabs"> |
| | | <button class="active" data-tab="keys" onclick="switchTab('keys')">密钥管理</button> |
| | | <button data-tab="games" onclick="switchTab('games')">游戏管理</button> |
| | | <button data-tab="cats" onclick="switchTab('cats')">类别管理</button> |
| | | <button data-tab="ann" onclick="switchTab('ann')">公告设置</button> |
| | | <button data-tab="tools" onclick="switchTab('tools')">工具管理</button> |
| | | </div> |
| | | <button id="logoutBtn" onclick="logout()">退出登录</button> |
| | | </div> |
| | |
| | | <div id="tab-keys" class="panel"> |
| | | <h2>会员密钥</h2> |
| | | <div class="toolbar"> |
| | | <select id="genType"><option value="day">日卡</option><option value="month">月卡</option><option value="year">年卡</option></select> |
| | | <select id="genType"><option value="day">日卡</option><option value="month">月卡</option><option value="year">年卡</option><option value="forever">永久卡</option></select> |
| | | <input id="genCount" type="number" value="10" min="1" max="100" style="width:80px"> |
| | | <button class="btn" onclick="generateKeys()">生成密钥</button> |
| | | <span style="flex:1"></span> |
| | | <input id="keyKeyword" placeholder="搜索激活码"> |
| | | <input id="keyKeyword" placeholder="搜索激活码/手机号"> |
| | | <select id="keyStatus"> |
| | | <option value="">全部状态</option> |
| | | <option value="0">未使用</option> |
| | |
| | | <tbody id="catTable"></tbody> |
| | | </table> |
| | | </div> |
| | | |
| | | <!-- 公告设置 --> |
| | | <div id="tab-ann" class="panel hidden"> |
| | | <h2>首页公告</h2> |
| | | <p style="color:#888;font-size:12px;margin-bottom:14px">客户端打开首页时自动弹出的系统公告;内容留空则不弹出。</p> |
| | | <div class="form-row"> |
| | | <textarea id="annContent" style="min-height:180px" placeholder="请输入公告内容..."></textarea> |
| | | </div> |
| | | <button class="btn" onclick="saveAnnouncement()">保存公告</button> |
| | | </div> |
| | | |
| | | <!-- 工具管理 --> |
| | | <div id="tab-tools" class="panel hidden"> |
| | | <h2>工具管理</h2> |
| | | <div class="toolbar"> |
| | | <button class="btn" onclick="showToolModal()">+ 添加工具</button> |
| | | </div> |
| | | <table> |
| | | <thead><tr><th>ID</th><th>封面</th><th>名称</th><th>大小</th><th>描述</th><th>下载文件</th><th>操作</th></tr></thead> |
| | | <tbody id="toolTable"></tbody> |
| | | </table> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | |
| | | <div id="g_shots_list"></div> |
| | | </div> |
| | | <div class="upload-box"> |
| | | <div class="hint">游戏安装包(zip/rar/exe/iso 等,可多选)</div> |
| | | <div class="hint">游戏压缩包(游戏安装目录打包成的 zip/rar/7z,可多选。用户下载后自动解压到游戏目录并删除压缩包)</div> |
| | | <input type="file" multiple onchange="uploadPackages(this)"> |
| | | <div id="g_files_list"></div> |
| | | </div> |
| | | <div class="form-row"><label>游戏启动程序(相对路径,如 Binaries\Win64\Game.exe,用户启动游戏时直接打开)</label><input id="g_launch_exe" placeholder="Binaries\Win64\Game.exe"></div> |
| | | <div class="form-row"><label>游戏介绍(说明图片文字)</label><textarea id="g_description"></textarea></div> |
| | | <div style="display:flex;gap:10px;justify-content:flex-end;margin-top:16px"> |
| | | <button class="btn btn-gray" onclick="hideGameModal()">取消</button> |
| | | <button class="btn" onclick="saveGame()">保存</button> |
| | | <button class="btn" id="saveGameBtn" onclick="saveGame()">保存</button> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | <div id="toast" class="toast"></div> |
| | | |
| | | <!-- 工具编辑弹窗 --> |
| | | <div id="toolModal" class="modal-mask hidden"> |
| | | <div class="modal"> |
| | | <h3 id="toolModalTitle">添加工具</h3> |
| | | <input type="hidden" id="t_id"> |
| | | <div class="form-row"><label>工具名称 *</label><input id="t_name" placeholder="如:百度网盘"></div> |
| | | <div class="form-row"><label>大小(如 85.2MB)</label><input id="t_size"></div> |
| | | <div class="form-row"><label>封面图</label> |
| | | <input id="t_cover" placeholder="封面图URL,或点击上传" onchange="renderToolCover()"> |
| | | <input type="file" accept="image/*" onchange="uploadSingle(this, 'image', 't_cover'); setTimeout(renderToolCover, 500)"> |
| | | <div id="t_cover_list"></div> |
| | | </div> |
| | | <div class="form-row"><label>下载文件</label> |
| | | <input id="t_file_url" placeholder="安装包URL,或点击上传"> |
| | | <input type="file" onchange="uploadSingle(this, 'file', 't_file_url')"> |
| | | </div> |
| | | <div class="form-row"><label>描述</label><textarea id="t_description"></textarea></div> |
| | | <div style="display:flex;gap:10px;justify-content:flex-end;margin-top:16px"> |
| | | <button class="btn btn-gray" onclick="hideToolModal()">取消</button> |
| | | <button class="btn" onclick="saveTool()">保存</button> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | <script> |
| | | let token = localStorage.getItem('admin_token') || ''; |
| | | let editingScreenshots = [], editingFiles = []; |
| | |
| | | setTimeout(() => t.className = 'toast', 2500); |
| | | } |
| | | async function api(path, opts = {}) { |
| | | opts.headers = Object.assign({'Content-Type': 'application/json'}, opts.headers || {}); |
| | | opts.headers = Object.assign({}, opts.headers || {}); |
| | | if (token) opts.headers['Authorization'] = 'Bearer ' + token; |
| | | if (opts.body && typeof opts.body !== 'string' && !(opts.body instanceof FormData)) { |
| | | opts.body = JSON.stringify(opts.body); |
| | | // FormData(文件上传)不能手动设置 Content-Type,由浏览器自动生成 multipart 边界 |
| | | if (opts.body instanceof FormData) { |
| | | if (opts.headers['Content-Type']) delete opts.headers['Content-Type']; |
| | | } else { |
| | | opts.headers['Content-Type'] = 'application/json'; |
| | | if (opts.body && typeof opts.body !== 'string') { |
| | | opts.body = JSON.stringify(opts.body); |
| | | } |
| | | } |
| | | const res = await fetch(path, opts); |
| | | if (res.status === 401) { localStorage.removeItem('admin_token'); location.reload(); throw new Error('未登录'); } |
| | |
| | | function enterPanel() { |
| | | document.getElementById('loginPage').style.display = 'none'; |
| | | document.getElementById('mainPage').style.display = 'flex'; |
| | | loadStats(); loadKeys(1); loadGames(); loadCategories(); |
| | | loadStats(); loadKeys(1); loadGames(); loadCategories(); loadAnnouncement(); loadTools(); |
| | | } |
| | | function switchTab(tab) { |
| | | document.querySelectorAll('.nav-tabs button').forEach(b => b.classList.toggle('active', b.dataset.tab === tab)); |
| | | ['keys','games','cats'].forEach(t => document.getElementById('tab-' + t).classList.toggle('hidden', t !== tab)); |
| | | ['keys','games','cats','ann','tools'].forEach(t => document.getElementById('tab-' + t).classList.toggle('hidden', t !== tab)); |
| | | } |
| | | |
| | | async function loadStats() { |
| | |
| | | if (k.status === 0) { st = '未使用'; cls = 'tag-blue'; } |
| | | else if (k.expired) { st = '已过期'; cls = 'tag-red'; } |
| | | else { st = '使用中'; cls = 'tag-green'; } |
| | | if (k.frozen) st += ' · 已冻结'; |
| | | return `<tr> |
| | | <td>${k.id}</td><td style="font-family:Consolas">${k.code}</td> |
| | | <td><span class="tag tag-gray">${k.card_name}</span></td> |
| | | <td><span class="tag ${cls}">${st}</span></td> |
| | | <td><span class="tag ${k.frozen ? 'tag-red' : cls}">${st}</span></td> |
| | | <td>${k.phone || '-'}</td> |
| | | <td style="max-width:160px;overflow:hidden;text-overflow:ellipsis">${k.machine_code || '-'}</td> |
| | | <td>${k.expired_at_str || '-'}</td> |
| | | <td>${k.reset_count}</td> |
| | | <td> |
| | | <button class="btn btn-sm" onclick="freezeKey(${k.id})">${k.frozen ? '解冻' : '冻结'}</button> |
| | | ${k.status === 1 ? `<button class="btn btn-sm" onclick="resetKey(${k.id})">重置(可再用)</button> ` : ''} |
| | | <button class="btn btn-sm btn-danger" onclick="deleteKey(${k.id})">删除</button> |
| | | </td></tr>`; |
| | |
| | | toast(res.msg, res.code !== 0); |
| | | loadKeys(keyPage); |
| | | } |
| | | async function freezeKey(id) { |
| | | if (!confirm('确定冻结/解冻该密钥?冻结后该激活码无法使用。')) return; |
| | | const res = await api(`/admin/api/keys/${id}/freeze`, {method: 'POST'}); |
| | | toast(res.msg, res.code !== 0); |
| | | loadKeys(keyPage); |
| | | } |
| | | async function deleteKey(id) { |
| | | if (!confirm('确定删除该密钥?')) return; |
| | | const res = await api(`/admin/api/keys/${id}`, {method: 'DELETE'}); |
| | |
| | | g_size.value = g.size || ''; g_install_size.value = g.install_size || ''; |
| | | g_os.value = g.os_req || ''; g_cpu.value = g.cpu_req || ''; g_gpu.value = g.gpu_req || ''; g_ram.value = g.ram_req || ''; |
| | | g_version_note.value = g.version_note || ''; g_description.value = g.description || ''; |
| | | g_launch_exe.value = g.launch_exe || ''; |
| | | g_platform.value = g.platform || 'pc'; g_banner.value = g.is_banner ? '1' : '0'; |
| | | g_cover.value = g.cover || ''; g_video.value = g.video || ''; |
| | | try { editingScreenshots = JSON.parse(g.screenshots || '[]'); } catch(e) {} |
| | |
| | | toast('上传成功'); |
| | | } |
| | | async function uploadScreenshots(input) { |
| | | let ok = 0, fail = 0; |
| | | for (const f of input.files) { |
| | | const fd = new FormData(); |
| | | fd.append('file', f); fd.append('type', 'image'); |
| | | const res = await api('/admin/api/upload', {method: 'POST', body: fd}); |
| | | if (res.code === 0) editingScreenshots.push(res.data.url); |
| | | if (res.code === 0) { editingScreenshots.push(res.data.url); ok++; } |
| | | else { fail++; toast(f.name + ':' + (res.msg || '上传失败'), true); } |
| | | } |
| | | renderShots(); toast('截图上传完成'); |
| | | renderShots(); |
| | | if (ok > 0) toast(`截图上传完成(${ok}个${fail > 0 ? ',失败' + fail + '个' : ''})`); |
| | | } |
| | | async function uploadPackages(input) { |
| | | if (!input.files.length) return; |
| | | let ok = 0, fail = 0; |
| | | setSaveEnabled(false); |
| | | for (const f of input.files) { |
| | | const fd = new FormData(); |
| | | fd.append('file', f); fd.append('type', 'file'); |
| | | const res = await api('/admin/api/upload', {method: 'POST', body: fd}); |
| | | if (res.code === 0) editingFiles.push({name: res.data.name, size: res.data.size, url: res.data.url}); |
| | | try { |
| | | // 大文件用 XHR 上传并显示进度 |
| | | const res = await new Promise((resolve, reject) => { |
| | | const xhr = new XMLHttpRequest(); |
| | | xhr.open('POST', '/admin/api/upload'); |
| | | if (token) xhr.setRequestHeader('Authorization', 'Bearer ' + token); |
| | | xhr.upload.onprogress = e => { |
| | | if (e.lengthComputable) renderUploadProgress(f.name, e.loaded, e.total); |
| | | }; |
| | | xhr.onload = () => { try { resolve(JSON.parse(xhr.responseText)); } catch (err) { reject(err); } }; |
| | | xhr.onerror = () => reject(new Error('网络错误')); |
| | | xhr.send(fd); |
| | | }); |
| | | if (res.code === 0) { editingFiles.push({name: res.data.name, size: res.data.size, url: res.data.url}); ok++; } |
| | | else { fail++; toast(f.name + ':' + (res.msg || '上传失败'), true); } |
| | | } catch (e) { |
| | | fail++; toast(f.name + ':上传失败(' + e.message + ')', true); |
| | | } |
| | | } |
| | | renderFiles(); toast('安装包上传完成'); |
| | | setSaveEnabled(true); |
| | | renderFiles(); |
| | | if (ok > 0) toast(`安装包上传完成(${ok}个${fail > 0 ? ',失败' + fail + '个' : ''})`); |
| | | } |
| | | /// 压缩包上传中时禁用保存按钮,防止保存了空的文件列表 |
| | | function setSaveEnabled(enabled) { |
| | | const btn = document.getElementById('saveGameBtn'); |
| | | if (btn) { btn.disabled = !enabled; btn.style.opacity = enabled ? '' : '0.5'; } |
| | | } |
| | | function renderUploadProgress(name, loaded, total) { |
| | | const pct = Math.floor(loaded / total * 100); |
| | | const size = total > 1024*1024*1024 ? (total/1024/1024/1024).toFixed(2)+' GB' |
| | | : total > 1024*1024 ? (total/1024/1024).toFixed(1)+' MB' : (total/1024).toFixed(0)+' KB'; |
| | | document.getElementById('g_files_list').innerHTML = |
| | | `<div class="file-item"><span>${name}(${size})上传中 ${pct}%</span></div>`; |
| | | } |
| | | function renderShots() { |
| | | document.getElementById('g_shots_list').innerHTML = editingScreenshots.map((u, i) => |
| | |
| | | platform: g_platform.value, tags: g_tags.value.trim(), |
| | | size: g_size.value.trim(), install_size: g_install_size.value.trim(), |
| | | os_req: g_os.value.trim(), cpu_req: g_cpu.value.trim(), gpu_req: g_gpu.value.trim(), ram_req: g_ram.value.trim(), |
| | | version_note: g_version_note.value.trim(), cover: g_cover.value, video: g_video.value, |
| | | version_note: g_version_note.value.trim(), launch_exe: g_launch_exe.value.trim(), cover: g_cover.value, video: g_video.value, |
| | | screenshots: JSON.stringify(editingScreenshots), description: g_description.value, |
| | | files: JSON.stringify(editingFiles), is_banner: g_banner.value === '1', |
| | | }; |
| | |
| | | loadCategories(); |
| | | } |
| | | |
| | | /* ---------- 公告 ---------- */ |
| | | async function loadAnnouncement() { |
| | | const res = await api('/admin/api/announcement'); |
| | | if (res.code !== 0) return; |
| | | document.getElementById('annContent').value = (res.data && res.data.content) || ''; |
| | | } |
| | | async function saveAnnouncement() { |
| | | const content = document.getElementById('annContent').value; |
| | | const res = await api('/admin/api/announcement', {method: 'POST', body: {content}}); |
| | | toast(res.msg, res.code !== 0); |
| | | } |
| | | |
| | | /* ---------- 工具管理 ---------- */ |
| | | async function loadTools() { |
| | | const res = await api('/admin/api/tools'); |
| | | if (res.code !== 0) return; |
| | | const rows = res.data.map(t => `<tr> |
| | | <td>${t.id}</td> |
| | | <td><img src="${t.cover}" style="width:56px;height:36px;object-fit:cover;border-radius:4px" onerror="this.style.visibility='hidden'"></td> |
| | | <td>${t.name}</td> |
| | | <td>${t.size || '-'}</td> |
| | | <td style="max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${t.description || ''}">${t.description || '-'}</td> |
| | | <td style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${t.file_url || ''}">${t.file_url || '-'}</td> |
| | | <td> |
| | | <button class="btn btn-sm" onclick='showToolModal(${JSON.stringify(t).replace(/'/g,"'")})'>修改</button> |
| | | <button class="btn btn-sm btn-danger" onclick="deleteTool(${t.id})">删除</button> |
| | | </td></tr>`).join(''); |
| | | document.getElementById('toolTable').innerHTML = rows || '<tr><td colspan="7" style="text-align:center;color:#666">暂无数据</td></tr>'; |
| | | } |
| | | function renderToolCover() { |
| | | const url = document.getElementById('t_cover').value; |
| | | document.getElementById('t_cover_list').innerHTML = url ? `<div class="file-item"><img src="${url}"><span>${url}</span></div>` : ''; |
| | | } |
| | | function showToolModal(t) { |
| | | document.getElementById('toolModalTitle').innerText = t ? '修改工具' : '添加工具'; |
| | | document.getElementById('t_id').value = t ? t.id : ''; |
| | | document.getElementById('t_name').value = t ? t.name : ''; |
| | | document.getElementById('t_size').value = t ? (t.size || '') : ''; |
| | | document.getElementById('t_cover').value = t ? (t.cover || '') : ''; |
| | | document.getElementById('t_file_url').value = t ? (t.file_url || '') : ''; |
| | | document.getElementById('t_description').value = t ? (t.description || '') : ''; |
| | | renderToolCover(); |
| | | document.getElementById('toolModal').classList.remove('hidden'); |
| | | } |
| | | function hideToolModal() { document.getElementById('toolModal').classList.add('hidden'); } |
| | | async function saveTool() { |
| | | const body = { |
| | | id: parseInt(document.getElementById('t_id').value) || 0, |
| | | name: document.getElementById('t_name').value.trim(), |
| | | size: document.getElementById('t_size').value.trim(), |
| | | cover: document.getElementById('t_cover').value.trim(), |
| | | file_url: document.getElementById('t_file_url').value.trim(), |
| | | description: document.getElementById('t_description').value.trim(), |
| | | }; |
| | | if (!body.name) return toast('请填写工具名称', true); |
| | | const res = await api('/admin/api/tools', {method: 'POST', body}); |
| | | toast(res.msg, res.code !== 0); |
| | | if (res.code === 0) { hideToolModal(); loadTools(); } |
| | | } |
| | | async function deleteTool(id) { |
| | | if (!confirm('确定删除该工具?')) return; |
| | | const res = await api(`/admin/api/tools/${id}`, {method: 'DELETE'}); |
| | | toast(res.msg, res.code !== 0); |
| | | loadTools(); |
| | | } |
| | | |
| | | document.getElementById('adminPwd').addEventListener('keydown', e => { if (e.key === 'Enter') adminLogin(); }); |
| | | if (token) enterPanel(); |
| | | </script> |