| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <!DOCTYPE html>
- <html>
- <head>
- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
- <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.6.8/css/layui.css">
- <link rel="stylesheet" href="css/styles.css">
- </head>
- <body class="gray-bg">
- <h2 class="layui-font-20 layui-text-center" style="margin: 20px 0;">游戏管理控制台</h2>
- <!-- 固定在头部的输入框 -->
- <div class="fixed-header">
- <form class="layui-form">
- <div class="layui-form-item">
- <label class="layui-form-label">命令:</label>
- <div class="layui-input-inline gm-input">
- <input type="text" id="gmCommand" placeholder="输入命令,如:/gm..." class="layui-input"
- autocomplete="off">
- <!-- 历史记录下拉菜单 -->
- <div class="history-dropdown" id="historyDropdown"></div>
- </div>
- <div class="layui-input-inline handle-gm-btn">
- <button class="layui-btn layui-btn-normal" type="button" onclick="handleGmCommand()">执行</button>
- </div>
- <div class="layui-input-inline">
- <button class="layui-btn layui-btn-normal help-btn" type="button" onclick="showGmHelp()">
- <i class="layui-icon"></i>
- </button>
- <!-- GM命令帮助窗口 -->
- <div class="gm-help-window" id="gmHelpWindow">
- <div class="help-header">
- <h3>GM命令列表</h3>
- <button class="close-btn" onclick="hideGmHelp()">×</button>
- </div>
- <div class="help-content">
- <div class="help-section">
- <h4>玩家管理</h4>
- <ul>
- <li>设置领主等级 等级为10</li>
- <li><code>/gm player level 10</code></li>
- <li>设置领主经验 添加1000经验</li>
- <li><code>/gm player exp 1000</code></li>
- </ul>
- </div>
- <div class="help-section">
- <h4>道具管理</h4>
- <ul>
- <li>添加道具 1道具ID 10数量</li>
- <li><code>/gm asset add 1 10</code></li>
- <li>扣除道具 1道具ID 10数量</li>
- <li><code>/gm asset add 1 -10</code></li>
- </ul>
- </div>
- <div class="help-section">
- <h4>部队管理</h4>
- <ul>
- <li>设置部队体力 1部队ID(0全部) 1位置(0全部) 10当前体力</li>
- <li><code>/gm team energy 1 1 10</code></li>
- <li>设置部队重伤 1部队ID(0全部) 1位置(0全部) 10重伤秒数</li>
- <li><code>/gm team state 1 1 10</code></li>
- </ul>
- </div>
- <div class="help-section">
- <h4>时间管理</h4>
- <ul>
- <li>设置日期和时间</li>
- <li><code>/gm time date 2025-10-10 14:30:00</code></li>
- <li>设置当天时间</li>
- <li><code>/gm time set 14:30:00</code></li>
- <li>时间偏移(秒)可为负值</li>
- <li><code>/gm time offset 3600</code></li>
- <li>重置offset时间</li>
- <li><code>/gm time reset</code></li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- </div>
- </form>
- </div>
- <!-- 固定在左侧的表单(玩家ID和服务器ID) -->
- <div class="fixed-left">
- <form class="layui-form">
- <div class="layui-form-item">
- <label class="layui-form-label">服务器ID:</label>
- <div class="layui-input-block">
- <input type="text" id="gameNodeID" placeholder="服务器节点ID" class="layui-input" value="1">
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">玩家ID:</label>
- <div class="layui-input-block">
- <input type="text" id="toUid" placeholder="玩家ID" class="layui-input">
- </div>
- </div>
- <!-- 战斗验证开关按钮 -->
- <div class="layui-form-item">
- <label class="layui-form-label">战斗校验:</label>
- <div class="layui-input-block">
- <div class="inline-btns">
- <!-- 参数:true = 开启,false = 关闭 -->
- <button class="layui-btn layui-btn-normal layui-btn-sm" type="button"
- onclick="setBattleValidation(true)">开启</button>
- <button class="layui-btn layui-btn-danger layui-btn-sm" type="button"
- onclick="setBattleValidation(false)">关闭</button>
- </div>
- </div>
- </div>
- </form>
- </div>
- <!-- 玩家管理模块 -->
- <div id="player-module" class="layui-row layui-container"></div>
- <!-- 道具管理模块 -->
- <div id="asset-module" class="layui-row layui-container"></div>
- <!-- 部队管理模块 -->
- <div id="team-module" class="layui-row layui-container"></div>
- <!-- 时间管理模块 -->
- <div id="time-module" class="layui-row layui-container"></div>
- <!-- 探险管理模块 -->
- <div id="chapter-module" class="layui-row layui-container"></div>
- <!-- 引入 LayUI JS -->
- <script src="https://www.layuicdn.com/layui-v2.6.8/layui.js"></script>
- <script>
- // 动态加载模块
- $(document).ready(function () {
- // 加载玩家管理模块
- $("#player-module").load("modules/player.html");
- // 加载道具管理模块
- $("#asset-module").load("modules/asset.html");
- // 加载队伍管理模块
- $("#team-module").load("modules/team.html");
- // 时间管理模块
- $("#time-module").load("modules/time.html");
- // 探险管理模块
- $("#chapter-module").load("modules/chapter.html");
- // 绑定输入框事件
- $("#gmCommand").on("focus", showHistory);
- $("#gmCommand").on("blur", function () {
- setTimeout(() => $("#historyDropdown").hide(), 200);
- });
- // 绑定输入事件,实现模糊查询
- $("#gmCommand").on("input", function () {
- const inputText = $(this).val().toLowerCase();
- if (inputText) {
- filterHistory(inputText);
- } else {
- showHistory();
- }
- });
- });
- // 显示历史记录
- function showHistory() {
- const history = JSON.parse(localStorage.getItem("gmCommandHistory") || "[]");
- const dropdown = $("#historyDropdown");
- dropdown.empty();
- if (history.length === 0) {
- dropdown.append("<div>暂无历史记录</div>");
- } else {
- history.forEach(cmd => {
- dropdown.append(`<div onclick="selectHistory('${cmd}')">${cmd}</div>`);
- });
- }
- dropdown.show();
- }
- // 模糊查询历史记录
- function filterHistory(inputText) {
- const history = JSON.parse(localStorage.getItem("gmCommandHistory") || "[]");
- const dropdown = $("#historyDropdown");
- dropdown.empty();
- if (history.length === 0) {
- dropdown.append("<div>暂无历史记录</div>");
- } else {
- const filteredHistory = history.filter(cmd =>
- cmd.toLowerCase().includes(inputText)
- );
- if (filteredHistory.length === 0) {
- dropdown.append("<div>未找到匹配记录</div>");
- } else {
- filteredHistory.forEach(cmd => {
- dropdown.append(`<div onclick="selectHistory('${cmd}')">${cmd}</div>`);
- });
- }
- }
- dropdown.show();
- }
- // 选择历史记录
- function selectHistory(cmd) {
- $("#gmCommand").val(cmd);
- $("#historyDropdown").hide();
- }
- // 保存历史记录
- function saveHistory(cmd) {
- const history = JSON.parse(localStorage.getItem("gmCommandHistory") || "[]");
- if (!history.includes(cmd)) {
- history.unshift(cmd); // 添加到开头
- if (history.length > 10) history.pop(); // 限制最多10条
- localStorage.setItem("gmCommandHistory", JSON.stringify(history));
- }
- }
- // 执行gm命令功能
- function handleGmCommand() {
- var gmCommand = $("#gmCommand").val();
- if (!gmCommand) {
- layer.msg("请输入操作命令", { icon: 3 });
- return;
- }
- if (!gmCommand.startsWith("/gm")) {
- layer.msg("请输入正确的操作命令 如:/gm ....", { icon: 3 });
- return;
- }
- // 保存历史记录
- saveHistory(gmCommand);
- // 提交命令
- submitForm(gmCommand);
- }
- // 显示GM命令帮助窗口
- function showGmHelp() {
- const helpWindow = $("#gmHelpWindow");
- if (helpWindow.is(":visible")) {
- hideGmHelp();
- } else {
- helpWindow.show();
- // 点击窗口外部关闭
- $(document).on("click.gmHelp", function (e) {
- if (!$(e.target).closest(".gm-help-window, .help-btn").length) {
- hideGmHelp();
- }
- });
- }
- }
- // 隐藏GM命令帮助窗口
- function hideGmHelp() {
- $("#gmHelpWindow").hide();
- $(document).off("click.gmHelp");
- }
- // 统一的提交方法
- function submitForm(commond) {
- // 获取全局的服务器ID和玩家ID
- var gameNodeID = $("#gameNodeID").val();
- var toUid = $("#toUid").val();
- // 校验必填字段
- if (!gameNodeID || !toUid) {
- layer.msg("请填写服务器ID", { icon: 3 });
- return;
- }
- if (!toUid) {
- layer.msg("请填写玩家ID", { icon: 3 });
- return;
- }
- // 根据模块类型发送请求
- $.ajax({
- url: "/game/gm/" + gameNodeID,
- type: "post",
- contentType: "application/json",
- data: JSON.stringify({
- "key": toUid,
- "value": commond
- }),
- success: function (r) {
- console.log(r)
- if (r.code == 0) {
- layer.msg("操作成功", { icon: 1 });
- } else {
- layer.msg("操作失败,状态码:" + r.code, { icon: 2 });
- }
- },
- error: function (e) {
- console.log(e)
- layer.msg("操作失败,状态码:" + e.code, { icon: 2 });
- }
- });
- }
- // 设置战斗验证开关(true = 开启, false = 关闭)
- function setBattleValidation(enable) {
- var gameNodeID = $("#gameNodeID").val();
- if (!gameNodeID) {
- layer.msg("请填写服务器ID", { icon: 3 });
- return;
- }
- $.ajax({
- url: "/game/setBattleValidation/" + gameNodeID,
- type: "post",
- contentType: "application/json",
- data: JSON.stringify({
- "value": enable
- }),
- success: function (r) {
- console.log(r);
- if (r && r.code == 0) {
- layer.msg(enable ? "已开启战斗验证" : "已关闭战斗验证", { icon: 1 });
- } else {
- layer.msg("操作失败,状态码:" + (r && r.code ? r.code : "unknown"), { icon: 2 });
- }
- },
- error: function (e) {
- console.log(e);
- layer.msg("操作失败,请检查网络或接口", { icon: 2 });
- }
- });
- }
- </script>
- </body>
- </html>
|