| | |
| | | <!DOCTYPE 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> |
| | | <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> |
| | | <title>游戏目录 · 游趣电玩</title> |
| | | <style> |
| | | * { margin: 0; padding: 0; box-sizing: border-box; } |
| | | html, body { height: 100%; } |
| | | body { |
| | | background: #14161f; |
| | | color: #fff; |
| | | font-family: "Microsoft YaHei", "PingFang SC", sans-serif; |
| | | min-height: 100vh; |
| | | font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, "Segoe UI", Arial, "Microsoft YaHei", "PingFang SC", sans-serif; |
| | | background: #fff; |
| | | color: #000; |
| | | overflow: hidden; |
| | | } |
| | | img { display: block; } |
| | | |
| | | /* 顶部栏 */ |
| | | header { |
| | | position: sticky; top: 0; z-index: 100; |
| | | background: rgba(20, 22, 31, .95); |
| | | backdrop-filter: blur(10px); |
| | | border-bottom: 1px solid #252a3a; |
| | | padding: 14px 24px; |
| | | display: flex; align-items: center; gap: 14px; flex-wrap: wrap; |
| | | .page { |
| | | height: 100vh; |
| | | padding: 4px; |
| | | display: flex; |
| | | flex-direction: column; |
| | | background: #fff; |
| | | } |
| | | .logo { |
| | | width: 42px; height: 42px; border-radius: 50%; |
| | | background: linear-gradient(135deg, #ff5c8a, #b44dff); |
| | | display: flex; align-items: center; justify-content: center; |
| | | font-size: 18px; font-weight: bold; flex-shrink: 0; |
| | | box-shadow: 0 0 18px rgba(255, 92, 138, .45); |
| | | |
| | | /* 顶部搜索 */ |
| | | .search { |
| | | flex-shrink: 0; |
| | | display: flex; |
| | | align-items: center; |
| | | padding: 9px 11px; |
| | | border-bottom: 1px solid #f3f4f6; |
| | | } |
| | | .brand { display: flex; flex-direction: column; margin-right: 8px; } |
| | | .brand b { font-size: 17px; letter-spacing: 1px; } |
| | | .brand span { font-size: 11px; color: #7d8598; } |
| | | .search-box { |
| | | flex: 1; min-width: 200px; max-width: 420px; |
| | | position: relative; margin-left: auto; |
| | | flex: 1; |
| | | display: flex; |
| | | align-items: center; |
| | | height: 31px; |
| | | padding: 0 11px; |
| | | background: #f7f8fa; |
| | | border-radius: 2px; |
| | | min-width: 0; |
| | | } |
| | | .search-box input { |
| | | width: 100%; height: 38px; padding: 0 40px 0 16px; |
| | | background: #1c1f2e; border: 1px solid #2c3247; border-radius: 19px; |
| | | color: #fff; font-size: 13px; outline: none; |
| | | .search-icon { width: 16px; height: 16px; flex-shrink: 0; margin-right: 8px; } |
| | | .search-icon svg { width: 100%; height: 100%; display: block; } |
| | | #kw { |
| | | flex: 1; |
| | | min-width: 0; |
| | | height: 100%; |
| | | border: 0; |
| | | outline: 0; |
| | | background: transparent; |
| | | font-size: 13px; |
| | | color: #323233; |
| | | font-family: inherit; |
| | | } |
| | | .search-box input:focus { border-color: #ff5c8a; } |
| | | .search-box .icon { |
| | | position: absolute; right: 14px; top: 50%; transform: translateY(-50%); |
| | | color: #7d8598; font-size: 14px; font-style: normal; |
| | | #kw::placeholder { color: #969799; } |
| | | .clear-btn { |
| | | flex-shrink: 0; |
| | | width: 16px; |
| | | height: 16px; |
| | | margin-left: 6px; |
| | | border: 0; |
| | | padding: 0; |
| | | background: transparent; |
| | | cursor: pointer; |
| | | display: none; |
| | | } |
| | | .client-tip { |
| | | font-size: 12px; color: #7d8598; |
| | | padding: 7px 14px; border: 1px solid #2c3247; border-radius: 16px; |
| | | .clear-btn.show { display: block; } |
| | | .clear-btn svg { width: 100%; height: 100%; display: block; } |
| | | |
| | | /* 游戏列表 */ |
| | | .list { flex: 1; overflow-y: auto; } |
| | | .row { |
| | | display: flex; |
| | | padding: 8px; |
| | | border-bottom: 1px solid #f8f8f8; |
| | | } |
| | | .cover { |
| | | width: 124px; |
| | | height: 73px; |
| | | flex-shrink: 0; |
| | | border-radius: 4px; |
| | | background: #f5f5f5; |
| | | overflow: hidden; |
| | | } |
| | | .cover img { width: 100%; height: 100%; object-fit: cover; } |
| | | .meta { |
| | | flex: 1; |
| | | min-width: 0; |
| | | padding-left: 8px; |
| | | display: flex; |
| | | flex-direction: column; |
| | | justify-content: space-between; |
| | | } |
| | | .name { |
| | | font-size: 16px; |
| | | line-height: 28px; |
| | | font-weight: 400; |
| | | color: #000; |
| | | overflow: hidden; |
| | | display: -webkit-box; |
| | | -webkit-line-clamp: 2; |
| | | -webkit-box-orient: vertical; |
| | | word-break: break-all; |
| | | } |
| | | .line { display: flex; align-items: center; min-width: 0; } |
| | | .tags { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; } |
| | | .tag { |
| | | display: inline-flex; |
| | | align-items: center; |
| | | height: 15px; |
| | | padding: 0 4px; |
| | | margin-right: 4px; |
| | | background: #ff0000; |
| | | color: #fff; |
| | | font-size: 11px; |
| | | line-height: 15px; |
| | | border-radius: 2px; |
| | | vertical-align: middle; |
| | | } |
| | | .size { |
| | | flex-shrink: 0; |
| | | margin-left: 8px; |
| | | font-size: 12px; |
| | | color: #9ca3af; |
| | | white-space: nowrap; |
| | | } |
| | | |
| | | /* 类别栏 */ |
| | | .cats { |
| | | display: flex; gap: 10px; overflow-x: auto; padding: 16px 24px 4px; |
| | | scrollbar-width: none; |
| | | } |
| | | .cats::-webkit-scrollbar { display: none; } |
| | | .cat-chip { |
| | | padding: 8px 18px; border-radius: 16px; white-space: nowrap; |
| | | background: #1c1f2e; color: #aab2c5; font-size: 13px; |
| | | cursor: pointer; border: 1px solid transparent; user-select: none; |
| | | transition: all .2s; |
| | | } |
| | | .cat-chip:hover { color: #fff; } |
| | | .cat-chip.active { |
| | | background: linear-gradient(135deg, #ff5c8a, #ff7e5a); |
| | | color: #fff; font-weight: bold; |
| | | } |
| | | |
| | | /* 游戏网格 */ |
| | | main { |
| | | max-width: 1280px; margin: 0 auto; padding: 20px 24px 60px; |
| | | display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); |
| | | gap: 22px 18px; |
| | | } |
| | | .card { |
| | | border-radius: 10px; overflow: hidden; cursor: pointer; |
| | | background: #1c1f2e; border: 1px solid #262b3d; |
| | | transition: transform .25s, box-shadow .25s, border-color .25s; |
| | | } |
| | | .card:hover { |
| | | transform: translateY(-5px); |
| | | box-shadow: 0 10px 28px rgba(0, 0, 0, .5); |
| | | border-color: #ff5c8a; |
| | | } |
| | | .cover { |
| | | aspect-ratio: 3/4; background: #10121c; position: relative; overflow: hidden; |
| | | } |
| | | .cover img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s; } |
| | | .card:hover .cover img { transform: scale(1.05); } |
| | | .cover .size-tag { |
| | | position: absolute; right: 0; bottom: 0; |
| | | background: rgba(0, 0, 0, .65); color: #e7eaf3; |
| | | font-size: 11px; padding: 3px 8px; border-radius: 6px 0 0 0; |
| | | } |
| | | .card .info { padding: 10px 12px 12px; } |
| | | .card .title { |
| | | font-size: 13px; font-weight: bold; line-height: 1.45; height: 2.9em; |
| | | display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; |
| | | overflow: hidden; margin-bottom: 8px; |
| | | } |
| | | .tags { display: flex; flex-wrap: wrap; gap: 5px; } |
| | | .tag { |
| | | font-size: 11px; color: #9aa3b8; background: #262b3d; |
| | | padding: 2px 8px; border-radius: 4px; |
| | | } |
| | | .tag.cat { color: #4a92ff; } |
| | | |
| | | .empty { |
| | | grid-column: 1 / -1; text-align: center; color: #5c6478; |
| | | padding: 80px 0; font-size: 14px; |
| | | } |
| | | .loading { grid-column: 1 / -1; text-align: center; color: #5c6478; padding: 80px 0; } |
| | | .loading .spin { |
| | | display: inline-block; width: 28px; height: 28px; |
| | | border: 3px solid #2c3247; border-top-color: #ff5c8a; |
| | | border-radius: 50%; animation: spin .8s linear infinite; |
| | | /* 状态 */ |
| | | .footer, .loading, .empty { text-align: center; color: #969799; } |
| | | .footer { font-size: 14px; padding: 14px 0; } |
| | | .loading { padding: 24px 0 14px; } |
| | | .loading .spinner { |
| | | display: inline-block; |
| | | width: 20px; |
| | | height: 20px; |
| | | border: 2px solid #ebedf0; |
| | | border-top-color: #c8c9cc; |
| | | border-radius: 50%; |
| | | animation: spin .8s linear infinite; |
| | | } |
| | | @keyframes spin { to { transform: rotate(360deg); } } |
| | | .empty { padding: 90px 0; font-size: 14px; } |
| | | .empty svg { width: 100px; height: 100px; margin: 0 auto 12px; display: block; } |
| | | .empty .desc { line-height: 20px; } |
| | | |
| | | /* 详情弹窗 */ |
| | | .modal-mask { |
| | | position: fixed; inset: 0; z-index: 200; |
| | | background: rgba(5, 6, 10, .8); backdrop-filter: blur(4px); |
| | | display: none; align-items: flex-start; justify-content: center; |
| | | padding: 4vh 16px; overflow-y: auto; |
| | | /* 右下角重置气泡 */ |
| | | .bubble { |
| | | position: fixed; |
| | | right: 16px; |
| | | bottom: 16px; |
| | | width: 44px; |
| | | height: 44px; |
| | | border: 0; |
| | | padding: 0; |
| | | border-radius: 50%; |
| | | background: #ff0000; |
| | | box-shadow: 0 3px 10px rgba(0, 0, 0, .18); |
| | | display: none; |
| | | align-items: center; |
| | | justify-content: center; |
| | | cursor: pointer; |
| | | z-index: 20; |
| | | } |
| | | .modal-mask.show { display: flex; } |
| | | .modal { |
| | | width: 860px; max-width: 100%; |
| | | background: #1b1e2e; border: 1px solid #2c3247; border-radius: 12px; |
| | | padding: 26px; position: relative; |
| | | animation: pop .25s ease; |
| | | } |
| | | @keyframes pop { from { opacity: 0; transform: translateY(18px); } } |
| | | .close-btn { |
| | | position: absolute; top: 14px; right: 14px; |
| | | width: 32px; height: 32px; border-radius: 50%; |
| | | background: #262b3d; color: #aab2c5; border: none; cursor: pointer; |
| | | font-size: 16px; line-height: 32px; text-align: center; |
| | | } |
| | | .close-btn:hover { background: #ff5c8a; color: #fff; } |
| | | .detail-top { display: flex; gap: 24px; } |
| | | .detail-cover { |
| | | width: 240px; flex-shrink: 0; aspect-ratio: 3/4; |
| | | border-radius: 10px; overflow: hidden; background: #10121c; |
| | | } |
| | | .detail-cover img { width: 100%; height: 100%; object-fit: cover; } |
| | | .detail-meta { flex: 1; min-width: 0; } |
| | | .detail-meta h2 { font-size: 20px; margin-bottom: 12px; line-height: 1.4; padding-right: 36px; } |
| | | .meta-rows { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; } |
| | | .meta-row { display: flex; font-size: 13px; } |
| | | .meta-row .k { color: #7d8598; width: 70px; flex-shrink: 0; } |
| | | .meta-row .v { color: #dfe3ee; word-break: break-all; } |
| | | .desc { |
| | | font-size: 13px; color: #aab2c5; line-height: 1.8; |
| | | max-height: 180px; overflow-y: auto; white-space: pre-wrap; |
| | | } |
| | | .shots { margin-top: 20px; } |
| | | .shots h3 { font-size: 14px; color: #dfe3ee; margin-bottom: 10px; } |
| | | .shot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; } |
| | | .shot-grid img, .shot-grid video { |
| | | width: 100%; border-radius: 8px; background: #10121c; |
| | | } |
| | | .video-box { margin-top: 20px; } |
| | | .video-box video { width: 100%; border-radius: 8px; background: #000; } |
| | | .only-view { |
| | | margin-top: 22px; padding: 12px 16px; border-radius: 8px; |
| | | background: rgba(255, 92, 138, .08); border: 1px solid rgba(255, 92, 138, .3); |
| | | color: #ff8aa8; font-size: 13px; text-align: center; |
| | | } |
| | | |
| | | footer { |
| | | text-align: center; color: #5c6478; font-size: 12px; |
| | | padding: 30px 0 40px; border-top: 1px solid #1e2231; |
| | | } |
| | | |
| | | @media (max-width: 640px) { |
| | | header { padding: 12px 14px; } |
| | | .client-tip { display: none; } |
| | | .cats { padding: 12px 14px 4px; } |
| | | main { padding: 14px 14px 50px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 12px; } |
| | | .modal { padding: 18px; } |
| | | .detail-top { flex-direction: column; } |
| | | .detail-cover { width: 170px; margin: 0 auto; } |
| | | .detail-meta h2 { padding-right: 30px; } |
| | | } |
| | | .bubble.show { display: flex; } |
| | | .bubble svg { width: 20px; height: 20px; display: block; } |
| | | </style> |
| | | </head> |
| | | <body> |
| | | |
| | | <header> |
| | | <div class="logo">99</div> |
| | | <div class="brand"><b>游趣电玩</b><span>游戏目录 · 精选游戏一览</span></div> |
| | | <div class="search-box"> |
| | | <input id="kw" type="text" placeholder="搜索游戏名称..." /> |
| | | <i class="icon">🔍</i> |
| | | <div class="page"> |
| | | <div class="search"> |
| | | <div class="search-box"> |
| | | <span class="search-icon"> |
| | | <svg viewBox="0 0 1024 1024" fill="#969799"><path d="M459.094 786.667c-180.107 0-326.667-146.56-326.667-326.667S278.987 133.333 459.094 133.333 785.761 279.893 785.761 460s-146.56 326.667-326.667 326.667z m0-57.6c148.587 0 269.067-120.48 269.067-269.067S607.681 190.933 459.094 190.933 190.027 311.413 190.027 460s120.48 269.067 269.067 269.067z"></path><path d="M665.579 601.259a28.8 28.8 0 0 1 40.704 40.704l-71.723 71.723a28.8 28.8 0 1 1-40.704-40.704l71.723-71.723z"></path><path d="M662.486 662.486a28.8 28.8 0 0 1 40.704 0l133.76 133.76a28.8 28.8 0 0 1-40.704 40.704L662.486 703.19a28.8 28.8 0 0 1 0-40.704z"></path></svg> |
| | | </span> |
| | | <input id="kw" type="text" placeholder="请输入搜索关键词" autocomplete="off"> |
| | | <button class="clear-btn" id="clearBtn" type="button" aria-label="清空"> |
| | | <svg viewBox="0 0 1024 1024" fill="#c8c9cc"><path d="M512 85.333c235.648 0 426.667 191.019 426.667 426.667S747.648 938.667 512 938.667 85.333 747.648 85.333 512 276.352 85.333 512 85.333z m149.333 240.213a35.925 35.925 0 0 0-50.773 0L512 424.107 413.397 325.504a35.925 35.925 0 0 0-50.773 50.773L461.227 512 362.624 610.603a35.925 35.925 0 0 0 50.773 50.773L512 562.773l98.603 98.603a35.925 35.925 0 0 0 50.773-50.773L562.773 512l98.603-98.603a35.925 35.925 0 0 0 0-50.773z"></path></svg> |
| | | </button> |
| | | </div> |
| | | </div> |
| | | <div class="client-tip">本页面仅用于浏览,下载游戏请使用游趣电玩客户端</div> |
| | | </header> |
| | | |
| | | <nav class="cats" id="cats"></nav> |
| | | |
| | | <main id="grid"> |
| | | <div class="loading"><span class="spin"></span></div> |
| | | </main> |
| | | |
| | | <footer>游趣电玩 · 游戏盒子 © 2026 | 本目录仅供展示,具体游戏以客户端为准</footer> |
| | | |
| | | <!-- 详情弹窗 --> |
| | | <div class="modal-mask" id="mask"> |
| | | <div class="modal"> |
| | | <button class="close-btn" onclick="closeDetail()">✕</button> |
| | | <div id="detailBody"></div> |
| | | <div class="list" id="list"> |
| | | <div class="loading"><span class="spinner"></span></div> |
| | | </div> |
| | | </div> |
| | | |
| | | <script> |
| | | const API = ''; |
| | | let allGames = []; |
| | | let categories = []; |
| | | let curCat = 0; |
| | | let curKw = ''; |
| | | let debounceTimer = null; |
| | | <button class="bubble" id="bubble" type="button" aria-label="重置搜索"> |
| | | <svg viewBox="0 0 1024 1024" fill="#fff"><path d="M512 85.333c235.648 0 426.667 191.019 426.667 426.667S747.648 938.667 512 938.667 85.333 747.648 85.333 512 276.352 85.333 512 85.333z m149.333 240.213a35.925 35.925 0 0 0-50.773 0L512 424.107 413.397 325.504a35.925 35.925 0 0 0-50.773 50.773L461.227 512 362.624 610.603a35.925 35.925 0 0 0 50.773 50.773L512 562.773l98.603 98.603a35.925 35.925 0 0 0 50.773-50.773L562.773 512l98.603-98.603a35.925 35.925 0 0 0 0-50.773z"></path></svg> |
| | | </button> |
| | | |
| | | function gbLabel(s) { |
| | | if (!s) return '未知大小'; |
| | | const t = String(s).trim(); |
| | | return /[a-zA-Z]/.test(t) ? t : t + ' GB'; |
| | | } |
| | | <template id="emptyTpl"> |
| | | <div class="empty"> |
| | | <svg viewBox="0 0 1024 1024"> |
| | | <ellipse cx="512" cy="700" rx="260" ry="34" fill="#f2f3f5"></ellipse> |
| | | <rect x="292" y="238" width="440" height="374" rx="28" fill="#f7f8fa" stroke="#e5e7eb"></rect> |
| | | <circle cx="470" cy="404" r="76" fill="#fff" stroke="#dcdfe6"></circle> |
| | | <path d="M530 464l72 72" stroke="#dcdfe6" stroke-width="18" stroke-linecap="round"></path> |
| | | </svg> |
| | | <div class="desc"></div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | const PAGE_SIZE = 20; |
| | | const listEl = document.getElementById('list'); |
| | | const kwEl = document.getElementById('kw'); |
| | | const clearBtn = document.getElementById('clearBtn'); |
| | | const bubble = document.getElementById('bubble'); |
| | | const emptyTpl = document.getElementById('emptyTpl'); |
| | | |
| | | let allGames = []; |
| | | let shownCount = 0; |
| | | let loading = false; |
| | | let keyword = ''; |
| | | |
| | | function esc(s) { |
| | | return String(s == null ? '' : s).replace(/[&<>"']/g, m => |
| | | ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[m])); |
| | | ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[m])); |
| | | } |
| | | |
| | | async function loadCategories() { |
| | | try { |
| | | const res = await fetch(API + '/api/categories').then(r => r.json()); |
| | | if (res.code === 0) categories = res.data || []; |
| | | } catch (e) {} |
| | | const el = document.getElementById('cats'); |
| | | let html = `<div class="cat-chip active" data-id="0" onclick="pickCat(0)">全部</div>`; |
| | | html += categories.map(c => |
| | | `<div class="cat-chip" data-id="${c.id}" onclick="pickCat(${c.id})">${esc(c.name)}</div>`).join(''); |
| | | el.innerHTML = html; |
| | | // 与对标页一致:数值 + 空格 + 单位 |
| | | function formatSize(v) { |
| | | if (!v) return ''; |
| | | const t = String(v).trim(); |
| | | const m = t.match(/^([0-9]+(?:\.[0-9]+)?)\s*(TB|GB|MB|KB|B)$/i); |
| | | if (m) return m[1] + ' ' + m[2].toUpperCase(); |
| | | return /[a-zA-Z]/.test(t) ? t : t + ' GB'; |
| | | } |
| | | |
| | | async function loadGames() { |
| | | const grid = document.getElementById('grid'); |
| | | grid.innerHTML = '<div class="loading"><span class="spin"></span></div>'; |
| | | function tagList(g) { |
| | | const out = []; |
| | | const push = v => { |
| | | String(v || '').split(/[,,、/\s]+/).map(s => s.trim()).forEach(s => { |
| | | if (s && !out.includes(s)) out.push(s); |
| | | }); |
| | | }; |
| | | push(g.category_name); |
| | | push(g.tags); |
| | | return out; |
| | | } |
| | | |
| | | function rowHtml(g) { |
| | | const tags = tagList(g).map(t => `<span class="tag">${esc(t)}</span>`).join(''); |
| | | return `<div class="row"> |
| | | <div class="cover">${g.cover ? `<img src="${esc(g.cover)}" alt="${esc(g.title)}" loading="lazy" onerror="this.remove()">` : ''}</div> |
| | | <div class="meta"> |
| | | <div class="name">${esc(g.title)}</div> |
| | | <div class="line"> |
| | | <div class="tags">${tags}</div> |
| | | <div class="size">${esc(formatSize(g.size))}</div> |
| | | </div> |
| | | </div> |
| | | </div>`; |
| | | } |
| | | |
| | | function showLoading() { |
| | | listEl.innerHTML = '<div class="loading"><span class="spinner"></span></div>'; |
| | | } |
| | | |
| | | function showEmpty(msg) { |
| | | const node = emptyTpl.content.cloneNode(true); |
| | | node.querySelector('.desc').textContent = msg || '暂无数据'; |
| | | listEl.innerHTML = ''; |
| | | listEl.appendChild(node); |
| | | } |
| | | |
| | | function appendPage() { |
| | | const next = allGames.slice(shownCount, shownCount + PAGE_SIZE); |
| | | if (!next.length) return; |
| | | const frag = document.createDocumentFragment(); |
| | | const wrap = document.createElement('div'); |
| | | wrap.innerHTML = next.map(rowHtml).join(''); |
| | | while (wrap.firstChild) frag.appendChild(wrap.firstChild); |
| | | const oldFooter = listEl.querySelector('.footer'); |
| | | if (oldFooter) oldFooter.remove(); |
| | | listEl.appendChild(frag); |
| | | shownCount += next.length; |
| | | if (shownCount >= allGames.length && allGames.length) { |
| | | const footer = document.createElement('div'); |
| | | footer.className = 'footer'; |
| | | footer.textContent = '没有更多了~'; |
| | | listEl.appendChild(footer); |
| | | } |
| | | } |
| | | |
| | | async function loadGames(kw) { |
| | | if (loading) return; |
| | | loading = true; |
| | | showLoading(); |
| | | try { |
| | | const p = new URLSearchParams({ platform: 'all', category: '0', keyword: curKw, sort: 'updated' }); |
| | | const res = await fetch(API + '/api/games?' + p).then(r => r.json()); |
| | | if (res.code !== 0) throw 0; |
| | | const p = new URLSearchParams({ platform: 'all', category: '0', keyword: kw || '', sort: 'updated' }); |
| | | const res = await fetch('/api/games?' + p.toString()).then(r => r.json()); |
| | | if (res.code !== 0) throw new Error(res.msg || '加载失败'); |
| | | allGames = res.data || []; |
| | | render(); |
| | | shownCount = 0; |
| | | listEl.innerHTML = ''; |
| | | if (!allGames.length) showEmpty('暂无数据'); |
| | | else appendPage(); |
| | | } catch (e) { |
| | | grid.innerHTML = '<div class="empty">加载失败,请刷新重试</div>'; |
| | | showEmpty(e.message || '加载失败'); |
| | | } finally { |
| | | loading = false; |
| | | } |
| | | } |
| | | |
| | | function render() { |
| | | const grid = document.getElementById('grid'); |
| | | if (!allGames.length) { |
| | | grid.innerHTML = '<div class="empty">暂无游戏</div>'; |
| | | return; |
| | | } |
| | | const list = curCat > 0 ? allGames.filter(g => g.category_id === curCat) : allGames; |
| | | if (!list.length) { |
| | | grid.innerHTML = '<div class="empty">该类别下暂无游戏</div>'; |
| | | return; |
| | | } |
| | | grid.innerHTML = list.map(g => ` |
| | | <div class="card" onclick="openDetail(${g.id})"> |
| | | <div class="cover"> |
| | | ${g.cover_url |
| | | ? `<img src="${esc(g.cover_url)}" loading="lazy" alt="${esc(g.title)}" onerror="this.style.display='none'">` |
| | | : ''} |
| | | <span class="size-tag">${esc(gbLabel(g.size))}</span> |
| | | </div> |
| | | <div class="info"> |
| | | <div class="title">${esc(g.title)}</div> |
| | | <div class="tags"> |
| | | ${g.category_name ? `<span class="tag cat">${esc(g.category_name)}</span>` : ''} |
| | | ${(g.tags || '').split(/[,,\s]+/).filter(Boolean).slice(0, 2).map(t => |
| | | `<span class="tag">${esc(t)}</span>`).join('')} |
| | | </div> |
| | | </div> |
| | | </div>`).join(''); |
| | | // 回车 / 点击放大镜触发搜索;清空与右下气泡可重置 |
| | | function doSearch() { |
| | | keyword = kwEl.value.trim(); |
| | | bubble.classList.toggle('show', !!keyword); |
| | | loadGames(keyword); |
| | | } |
| | | |
| | | function pickCat(id) { |
| | | curCat = id; |
| | | document.querySelectorAll('.cat-chip').forEach(c => |
| | | c.classList.toggle('active', +c.dataset.id === id)); |
| | | render(); |
| | | function resetSearch() { |
| | | kwEl.value = ''; |
| | | keyword = ''; |
| | | clearBtn.classList.remove('show'); |
| | | bubble.classList.remove('show'); |
| | | loadGames(''); |
| | | } |
| | | |
| | | document.getElementById('kw').addEventListener('input', e => { |
| | | clearTimeout(debounceTimer); |
| | | debounceTimer = setTimeout(() => { curKw = e.target.value.trim(); loadGames(); }, 350); |
| | | kwEl.addEventListener('input', () => { |
| | | clearBtn.classList.toggle('show', !!kwEl.value); |
| | | }); |
| | | kwEl.addEventListener('keydown', e => { |
| | | if (e.key === 'Enter') doSearch(); |
| | | }); |
| | | document.querySelector('.search-icon').addEventListener('click', doSearch); |
| | | clearBtn.addEventListener('click', resetSearch); |
| | | bubble.addEventListener('click', resetSearch); |
| | | |
| | | listEl.addEventListener('scroll', () => { |
| | | if (loading) return; |
| | | const rest = listEl.scrollHeight - listEl.scrollTop - listEl.clientHeight; |
| | | if (rest < 100 && shownCount < allGames.length) appendPage(); |
| | | }); |
| | | |
| | | async function openDetail(id) { |
| | | const mask = document.getElementById('mask'); |
| | | const body = document.getElementById('detailBody'); |
| | | body.innerHTML = '<div class="loading"><span class="spin"></span></div>'; |
| | | mask.classList.add('show'); |
| | | mask.onclick = e => { if (e.target === mask) closeDetail(); }; |
| | | try { |
| | | const res = await fetch(API + '/api/games/' + id).then(r => r.json()); |
| | | if (res.code !== 0) throw 0; |
| | | const g = res.data; |
| | | let shots = []; |
| | | try { shots = JSON.parse(g.screenshots || '[]'); } catch (e) {} |
| | | const tagList = (g.tags || '').split(/[,,\s]+/).filter(Boolean); |
| | | body.innerHTML = ` |
| | | <div class="detail-top"> |
| | | <div class="detail-cover"> |
| | | ${g.cover_url ? `<img src="${esc(g.cover_url)}" alt="${esc(g.title)}">` : ''} |
| | | </div> |
| | | <div class="detail-meta"> |
| | | <h2>${esc(g.title)}</h2> |
| | | <div class="meta-rows"> |
| | | ${g.category_name ? `<div class="meta-row"><span class="k">类别</span><span class="v">${esc(g.category_name)}</span></div>` : ''} |
| | | ${tagList.length ? `<div class="meta-row"><span class="k">标签</span><span class="v">${tagList.map(esc).join(' / ')}</span></div>` : ''} |
| | | <div class="meta-row"><span class="k">游戏大小</span><span class="v">${esc(gbLabel(g.size))}</span></div> |
| | | ${g.install_size ? `<div class="meta-row"><span class="k">磁盘占用</span><span class="v">${esc(gbLabel(g.install_size))}</span></div>` : ''} |
| | | <div class="meta-row"><span class="k">平台</span><span class="v">${esc(g.platform === 'switch' ? 'Switch 资源' : 'PC 资源')}</span></div> |
| | | </div> |
| | | <div class="desc">${esc(g.description || '暂无简介')}</div> |
| | | </div> |
| | | </div> |
| | | ${g.video_url ? `<div class="video-box"><video src="${esc(g.video_url)}" controls preload="none" poster="${esc(g.cover_url || '')}"></video></div>` : ''} |
| | | ${shots.length ? `<div class="shots"><h3>游戏截图</h3><div class="shot-grid"> |
| | | ${shots.map(s => `<img src="${esc(s)}" loading="lazy" onerror="this.style.display='none'">`).join('')} |
| | | </div></div>` : ''} |
| | | <div class="only-view">本页面仅提供游戏预览,如需下载游戏请在游趣电玩客户端中操作</div> |
| | | `; |
| | | } catch (e) { |
| | | body.innerHTML = '<div class="empty">详情加载失败</div>'; |
| | | } |
| | | } |
| | | |
| | | function closeDetail() { |
| | | document.getElementById('mask').classList.remove('show'); |
| | | const v = document.querySelector('#detailBody video'); |
| | | if (v) v.pause(); |
| | | } |
| | | |
| | | document.addEventListener('keydown', e => { if (e.key === 'Escape') closeDetail(); }); |
| | | |
| | | loadCategories(); |
| | | loadGames(); |
| | | loadGames(''); |
| | | </script> |
| | | </body> |
| | | </html> |