<!DOCTYPE html>
|
<html lang="zh-CN">
|
<head>
|
<meta charset="UTF-8">
|
<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 {
|
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; }
|
|
.page {
|
height: 100vh;
|
padding: 4px;
|
display: flex;
|
flex-direction: column;
|
background: #fff;
|
}
|
|
/* 顶部搜索 */
|
.search {
|
flex-shrink: 0;
|
display: flex;
|
align-items: center;
|
padding: 9px 11px;
|
border-bottom: 1px solid #f3f4f6;
|
}
|
.search-box {
|
flex: 1;
|
display: flex;
|
align-items: center;
|
height: 31px;
|
padding: 0 11px;
|
background: #f7f8fa;
|
border-radius: 2px;
|
min-width: 0;
|
}
|
.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;
|
}
|
#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;
|
}
|
.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;
|
}
|
|
/* 状态 */
|
.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; }
|
|
/* 右下角重置气泡 */
|
.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;
|
}
|
.bubble.show { display: flex; }
|
.bubble svg { width: 20px; height: 20px; display: block; }
|
</style>
|
</head>
|
<body>
|
|
<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="list" id="list">
|
<div class="loading"><span class="spinner"></span></div>
|
</div>
|
</div>
|
|
<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>
|
|
<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]));
|
}
|
|
// 与对标页一致:数值 + 空格 + 单位
|
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';
|
}
|
|
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: 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 || [];
|
shownCount = 0;
|
listEl.innerHTML = '';
|
if (!allGames.length) showEmpty('暂无数据');
|
else appendPage();
|
} catch (e) {
|
showEmpty(e.message || '加载失败');
|
} finally {
|
loading = false;
|
}
|
}
|
|
// 回车 / 点击放大镜触发搜索;清空与右下气泡可重置
|
function doSearch() {
|
keyword = kwEl.value.trim();
|
bubble.classList.toggle('show', !!keyword);
|
loadGames(keyword);
|
}
|
|
function resetSearch() {
|
kwEl.value = '';
|
keyword = '';
|
clearBtn.classList.remove('show');
|
bubble.classList.remove('show');
|
loadGames('');
|
}
|
|
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();
|
});
|
|
loadGames('');
|
</script>
|
</body>
|
</html>
|