index.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  5. <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.6.8/css/layui.css">
  6. <link rel="stylesheet" href="css/styles.css">
  7. </head>
  8. <body class="gray-bg">
  9. <h2 class="layui-font-20 layui-text-center" style="margin: 20px 0;">游戏管理控制台</h2>
  10. <!-- 固定在头部的输入框 -->
  11. <div class="fixed-header">
  12. <form class="layui-form">
  13. <div class="layui-form-item">
  14. <label class="layui-form-label">命令:</label>
  15. <div class="layui-input-inline gm-input">
  16. <input type="text" id="gmCommand" placeholder="输入命令,如:/gm..." class="layui-input"
  17. autocomplete="off">
  18. <!-- 历史记录下拉菜单 -->
  19. <div class="history-dropdown" id="historyDropdown"></div>
  20. </div>
  21. <div class="layui-input-inline handle-gm-btn">
  22. <button class="layui-btn layui-btn-normal" type="button" onclick="handleGmCommand()">执行</button>
  23. </div>
  24. <div class="layui-input-inline">
  25. <button class="layui-btn layui-btn-normal help-btn" type="button" onclick="showGmHelp()">
  26. <i class="layui-icon">&#xe607;</i>
  27. </button>
  28. <!-- GM命令帮助窗口 -->
  29. <div class="gm-help-window" id="gmHelpWindow">
  30. <div class="help-header">
  31. <h3>GM命令列表</h3>
  32. <button class="close-btn" onclick="hideGmHelp()">&times;</button>
  33. </div>
  34. <div class="help-content">
  35. <div class="help-section">
  36. <h4>玩家管理</h4>
  37. <ul>
  38. <li>设置领主等级 等级为10</li>
  39. <li><code>/gm player level 10</code></li>
  40. <li>设置领主经验 添加1000经验</li>
  41. <li><code>/gm player exp 1000</code></li>
  42. </ul>
  43. </div>
  44. <div class="help-section">
  45. <h4>道具管理</h4>
  46. <ul>
  47. <li>添加道具 1道具ID 10数量</li>
  48. <li><code>/gm asset add 1 10</code></li>
  49. <li>扣除道具 1道具ID 10数量</li>
  50. <li><code>/gm asset add 1 -10</code></li>
  51. </ul>
  52. </div>
  53. <div class="help-section">
  54. <h4>部队管理</h4>
  55. <ul>
  56. <li>设置部队体力 1部队ID(0全部) 1位置(0全部) 10当前体力</li>
  57. <li><code>/gm team energy 1 1 10</code></li>
  58. <li>设置部队重伤 1部队ID(0全部) 1位置(0全部) 10重伤秒数</li>
  59. <li><code>/gm team state 1 1 10</code></li>
  60. </ul>
  61. </div>
  62. <div class="help-section">
  63. <h4>时间管理</h4>
  64. <ul>
  65. <li>设置日期和时间</li>
  66. <li><code>/gm time date 2025-10-10 14:30:00</code></li>
  67. <li>设置当天时间</li>
  68. <li><code>/gm time set 14:30:00</code></li>
  69. <li>时间偏移(秒)可为负值</li>
  70. <li><code>/gm time offset 3600</code></li>
  71. <li>重置offset时间</li>
  72. <li><code>/gm time reset</code></li>
  73. </ul>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </form>
  80. </div>
  81. <!-- 固定在左侧的表单(玩家ID和服务器ID) -->
  82. <div class="fixed-left">
  83. <form class="layui-form">
  84. <div class="layui-form-item">
  85. <label class="layui-form-label">服务器ID:</label>
  86. <div class="layui-input-block">
  87. <input type="text" id="gameNodeID" placeholder="服务器节点ID" class="layui-input" value="1">
  88. </div>
  89. </div>
  90. <div class="layui-form-item">
  91. <label class="layui-form-label">玩家ID:</label>
  92. <div class="layui-input-block">
  93. <input type="text" id="toUid" placeholder="玩家ID" class="layui-input">
  94. </div>
  95. </div>
  96. <!-- 战斗验证开关按钮 -->
  97. <div class="layui-form-item">
  98. <label class="layui-form-label">战斗校验:</label>
  99. <div class="layui-input-block">
  100. <div class="inline-btns">
  101. <!-- 参数:true = 开启,false = 关闭 -->
  102. <button class="layui-btn layui-btn-normal layui-btn-sm" type="button"
  103. onclick="setBattleValidation(true)">开启</button>
  104. <button class="layui-btn layui-btn-danger layui-btn-sm" type="button"
  105. onclick="setBattleValidation(false)">关闭</button>
  106. </div>
  107. </div>
  108. </div>
  109. </form>
  110. </div>
  111. <!-- 玩家管理模块 -->
  112. <div id="player-module" class="layui-row layui-container"></div>
  113. <!-- 道具管理模块 -->
  114. <div id="asset-module" class="layui-row layui-container"></div>
  115. <!-- 部队管理模块 -->
  116. <div id="team-module" class="layui-row layui-container"></div>
  117. <!-- 时间管理模块 -->
  118. <div id="time-module" class="layui-row layui-container"></div>
  119. <!-- 探险管理模块 -->
  120. <div id="chapter-module" class="layui-row layui-container"></div>
  121. <!-- 引入 LayUI JS -->
  122. <script src="https://www.layuicdn.com/layui-v2.6.8/layui.js"></script>
  123. <script>
  124. // 动态加载模块
  125. $(document).ready(function () {
  126. // 加载玩家管理模块
  127. $("#player-module").load("modules/player.html");
  128. // 加载道具管理模块
  129. $("#asset-module").load("modules/asset.html");
  130. // 加载队伍管理模块
  131. $("#team-module").load("modules/team.html");
  132. // 时间管理模块
  133. $("#time-module").load("modules/time.html");
  134. // 探险管理模块
  135. $("#chapter-module").load("modules/chapter.html");
  136. // 绑定输入框事件
  137. $("#gmCommand").on("focus", showHistory);
  138. $("#gmCommand").on("blur", function () {
  139. setTimeout(() => $("#historyDropdown").hide(), 200);
  140. });
  141. // 绑定输入事件,实现模糊查询
  142. $("#gmCommand").on("input", function () {
  143. const inputText = $(this).val().toLowerCase();
  144. if (inputText) {
  145. filterHistory(inputText);
  146. } else {
  147. showHistory();
  148. }
  149. });
  150. });
  151. // 显示历史记录
  152. function showHistory() {
  153. const history = JSON.parse(localStorage.getItem("gmCommandHistory") || "[]");
  154. const dropdown = $("#historyDropdown");
  155. dropdown.empty();
  156. if (history.length === 0) {
  157. dropdown.append("<div>暂无历史记录</div>");
  158. } else {
  159. history.forEach(cmd => {
  160. dropdown.append(`<div onclick="selectHistory('${cmd}')">${cmd}</div>`);
  161. });
  162. }
  163. dropdown.show();
  164. }
  165. // 模糊查询历史记录
  166. function filterHistory(inputText) {
  167. const history = JSON.parse(localStorage.getItem("gmCommandHistory") || "[]");
  168. const dropdown = $("#historyDropdown");
  169. dropdown.empty();
  170. if (history.length === 0) {
  171. dropdown.append("<div>暂无历史记录</div>");
  172. } else {
  173. const filteredHistory = history.filter(cmd =>
  174. cmd.toLowerCase().includes(inputText)
  175. );
  176. if (filteredHistory.length === 0) {
  177. dropdown.append("<div>未找到匹配记录</div>");
  178. } else {
  179. filteredHistory.forEach(cmd => {
  180. dropdown.append(`<div onclick="selectHistory('${cmd}')">${cmd}</div>`);
  181. });
  182. }
  183. }
  184. dropdown.show();
  185. }
  186. // 选择历史记录
  187. function selectHistory(cmd) {
  188. $("#gmCommand").val(cmd);
  189. $("#historyDropdown").hide();
  190. }
  191. // 保存历史记录
  192. function saveHistory(cmd) {
  193. const history = JSON.parse(localStorage.getItem("gmCommandHistory") || "[]");
  194. if (!history.includes(cmd)) {
  195. history.unshift(cmd); // 添加到开头
  196. if (history.length > 10) history.pop(); // 限制最多10条
  197. localStorage.setItem("gmCommandHistory", JSON.stringify(history));
  198. }
  199. }
  200. // 执行gm命令功能
  201. function handleGmCommand() {
  202. var gmCommand = $("#gmCommand").val();
  203. if (!gmCommand) {
  204. layer.msg("请输入操作命令", { icon: 3 });
  205. return;
  206. }
  207. if (!gmCommand.startsWith("/gm")) {
  208. layer.msg("请输入正确的操作命令 如:/gm ....", { icon: 3 });
  209. return;
  210. }
  211. // 保存历史记录
  212. saveHistory(gmCommand);
  213. // 提交命令
  214. submitForm(gmCommand);
  215. }
  216. // 显示GM命令帮助窗口
  217. function showGmHelp() {
  218. const helpWindow = $("#gmHelpWindow");
  219. if (helpWindow.is(":visible")) {
  220. hideGmHelp();
  221. } else {
  222. helpWindow.show();
  223. // 点击窗口外部关闭
  224. $(document).on("click.gmHelp", function (e) {
  225. if (!$(e.target).closest(".gm-help-window, .help-btn").length) {
  226. hideGmHelp();
  227. }
  228. });
  229. }
  230. }
  231. // 隐藏GM命令帮助窗口
  232. function hideGmHelp() {
  233. $("#gmHelpWindow").hide();
  234. $(document).off("click.gmHelp");
  235. }
  236. // 统一的提交方法
  237. function submitForm(commond) {
  238. // 获取全局的服务器ID和玩家ID
  239. var gameNodeID = $("#gameNodeID").val();
  240. var toUid = $("#toUid").val();
  241. // 校验必填字段
  242. if (!gameNodeID || !toUid) {
  243. layer.msg("请填写服务器ID", { icon: 3 });
  244. return;
  245. }
  246. if (!toUid) {
  247. layer.msg("请填写玩家ID", { icon: 3 });
  248. return;
  249. }
  250. // 根据模块类型发送请求
  251. $.ajax({
  252. url: "/game/gm/" + gameNodeID,
  253. type: "post",
  254. contentType: "application/json",
  255. data: JSON.stringify({
  256. "key": toUid,
  257. "value": commond
  258. }),
  259. success: function (r) {
  260. console.log(r)
  261. if (r.code == 0) {
  262. layer.msg("操作成功", { icon: 1 });
  263. } else {
  264. layer.msg("操作失败,状态码:" + r.code, { icon: 2 });
  265. }
  266. },
  267. error: function (e) {
  268. console.log(e)
  269. layer.msg("操作失败,状态码:" + e.code, { icon: 2 });
  270. }
  271. });
  272. }
  273. // 设置战斗验证开关(true = 开启, false = 关闭)
  274. function setBattleValidation(enable) {
  275. var gameNodeID = $("#gameNodeID").val();
  276. if (!gameNodeID) {
  277. layer.msg("请填写服务器ID", { icon: 3 });
  278. return;
  279. }
  280. $.ajax({
  281. url: "/game/setBattleValidation/" + gameNodeID,
  282. type: "post",
  283. contentType: "application/json",
  284. data: JSON.stringify({
  285. "value": enable
  286. }),
  287. success: function (r) {
  288. console.log(r);
  289. if (r && r.code == 0) {
  290. layer.msg(enable ? "已开启战斗验证" : "已关闭战斗验证", { icon: 1 });
  291. } else {
  292. layer.msg("操作失败,状态码:" + (r && r.code ? r.code : "unknown"), { icon: 2 });
  293. }
  294. },
  295. error: function (e) {
  296. console.log(e);
  297. layer.msg("操作失败,请检查网络或接口", { icon: 2 });
  298. }
  299. });
  300. }
  301. </script>
  302. </body>
  303. </html>