114 lines
5.5 KiB
HTML
114 lines
5.5 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>游戏管理 · GameParlor</title>
|
|
<link rel="stylesheet" href="/app.css">
|
|
<script src="/js/vendor/tailwind.min.js"></script>
|
|
<script defer src="/js/vendor/alpine.min.js"></script>
|
|
</head>
|
|
<body x-data="gamesApp()" x-init="init()">
|
|
<div class="flex items-center justify-between mb-6">
|
|
<h2 class="text-xl font-bold">游戏管理</h2>
|
|
<button class="btn btn-primary" @click="openCreate()">+ 新增游戏</button>
|
|
</div>
|
|
|
|
<div class="card overflow-x-auto">
|
|
<table class="table">
|
|
<thead>
|
|
<tr><th>ID</th><th>名称</th><th>通用</th><th>设备</th><th>会员单价</th><th>备注</th><th>操作</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<template x-for="g in list" :key="g.id">
|
|
<tr>
|
|
<td x-text="g.id"></td>
|
|
<td x-text="g.name"></td>
|
|
<td><span class="badge" :class="g.isUniversal ? 'badge-accent' : 'badge-success'" x-text="g.isUniversal ? '通用' : '绑定'"></span></td>
|
|
<td x-text="g.device ? g.device.name : '-'"></td>
|
|
<td x-text="'¥'+fmtMoney(g.memberPrice)"></td>
|
|
<td class="remark" x-text="g.remark"></td>
|
|
<td>
|
|
<button class="btn btn-ghost !py-1 !px-2 text-xs" @click="openEdit(g)">编辑</button>
|
|
<button class="btn btn-danger !py-1 !px-2 text-xs" @click="remove(g.id)">删除</button>
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
<tr x-show="list.length === 0"><td colspan="7" class="text-center text-[#6b6b78] py-8">暂无数据</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="flex justify-center gap-2 mt-4">
|
|
<button class="btn btn-ghost !py-1 text-xs" :disabled="page===0" @click="page--;load()">上一页</button>
|
|
<span class="text-sm text-[#9a9aa5] self-center" x-text="`${page+1} / ${totalPages}`"></span>
|
|
<button class="btn btn-ghost !py-1 text-xs" :disabled="page>=totalPages-1" @click="page++;load()">下一页</button>
|
|
</div>
|
|
|
|
<div x-show="modal" x-cloak class="modal-mask" @click.self="modal=false">
|
|
<div class="modal">
|
|
<h3 class="text-lg font-bold mb-4" x-text="editing ? '编辑游戏' : '新增游戏'"></h3>
|
|
<div class="space-y-3">
|
|
<div><label class="label">名称</label><input x-model="form.name" class="input"></div>
|
|
<div><label class="label">描述</label><input x-model="form.description" class="input"></div>
|
|
<div><label class="label">备注(小字灰色显示)</label><input x-model="form.remark" class="input"></div>
|
|
<div class="flex items-center gap-2">
|
|
<input type="checkbox" x-model="form.isUniversal" id="univ">
|
|
<label for="univ" class="text-sm">通用游戏(不绑定设备)</label>
|
|
</div>
|
|
<div x-show="!form.isUniversal">
|
|
<label class="label">绑定设备</label>
|
|
<select x-model="form.deviceId" class="select">
|
|
<option value="">请选择</option>
|
|
<template x-for="d in devices" :key="d.id">
|
|
<option :value="d.id" x-text="d.name"></option>
|
|
</template>
|
|
</select>
|
|
</div>
|
|
<div><label class="label">会员单价(用于拼套餐)</label><input type="number" step="0.01" x-model="form.memberPrice" class="input"></div>
|
|
</div>
|
|
<div class="flex justify-end gap-2 mt-5">
|
|
<button class="btn btn-ghost" @click="modal=false">取消</button>
|
|
<button class="btn btn-primary" @click="save()">保存</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="/app.js"></script>
|
|
<script>
|
|
function gamesApp() {
|
|
return {
|
|
list: [], devices: [], page: 0, totalPages: 1, modal: false, editing: null,
|
|
form: { name: '', description: '', remark: '', isUniversal: false, deviceId: '', memberPrice: 0 },
|
|
async init() { await initLayout('games'); this.devices = await api('/api/devices').catch(() => []); this.load(); },
|
|
async load() {
|
|
const data = await api(`/api/admin/games?page=${this.page}&size=10`).catch(() => ({ content: [], totalPages: 1 }));
|
|
this.list = data.content || []; this.totalPages = data.totalPages || 1;
|
|
},
|
|
openCreate() { this.editing = null; this.form = { name: '', description: '', remark: '', isUniversal: false, deviceId: '', memberPrice: 0 }; this.modal = true; },
|
|
openEdit(g) {
|
|
this.editing = g;
|
|
this.form = { name: g.name, description: g.description || '', remark: g.remark || '', isUniversal: !!g.isUniversal, deviceId: g.device ? g.device.id : '', memberPrice: g.memberPrice || 0 };
|
|
this.modal = true;
|
|
},
|
|
async save() {
|
|
if (!this.form.name) { toast('请输入名称', 'error'); return; }
|
|
const payload = { ...this.form, memberPrice: Number(this.form.memberPrice) || 0 };
|
|
if (!payload.isUniversal) payload.deviceId = Number(payload.deviceId) || null;
|
|
const method = this.editing ? 'PUT' : 'POST';
|
|
const url = this.editing ? `/api/admin/games/${this.editing.id}` : '/api/admin/games';
|
|
await api(url, { method, body: JSON.stringify(payload) });
|
|
toast(this.editing ? '已更新' : '已创建', 'success');
|
|
this.modal = false; this.load();
|
|
},
|
|
async remove(id) {
|
|
if (!confirm('确认删除?')) return;
|
|
await api(`/api/admin/games/${id}`, { method: 'DELETE' });
|
|
toast('已删除', 'success'); this.load();
|
|
}
|
|
};
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|