diff --git a/src/main/resources/js/logs.js b/src/main/resources/js/logs.js
index 66c35c76..5646a7e9 100644
--- a/src/main/resources/js/logs.js
+++ b/src/main/resources/js/logs.js
@@ -17,78 +17,126 @@
* along with this program. If not, see .
*/
var Logs = {
+ init: function () {
+ Logs.connectWS();
+ Logs.more();
+ },
- init: function () {
- Logs.connectWS();
- Logs.more();
- },
+ connectWS: function () {
+ // 连接WS
+ Logs.ws = new WebSocket(logsChannelURL);
+ Logs.ws.onopen = function () {
+ console.log("Connected to logs channel websocket.");
+ };
+ Logs.ws.onmessage = function (evt) {
+ var data = JSON.parse(evt.data);
+ switch (data.type) {
+ case "simple":
+ Logs.prependLog(data.key1, data.key2, data.key3, data.data);
+ break;
+ }
+ };
+ Logs.ws.onclose = function () {
+ console.log("Disconnected to logs channel websocket.");
+ };
+ Logs.ws.onerror = function (err) {
+ console.log("ERROR", err);
+ };
+ },
- connectWS: function () {
- // 连接WS
- Logs.ws = new WebSocket(logsChannelURL);
- Logs.ws.onopen = function () {
- console.log("Connected to logs channel websocket.");
- }
- Logs.ws.onmessage = function (evt) {
- var data = JSON.parse(evt.data);
- switch (data.type) {
- case 'simple':
- Logs.prependLog(data.key1, data.key2, data.key3, data.data);
- break;
- }
- }
- Logs.ws.onclose = function () {
- console.log("Disconnected to logs channel websocket.");
- }
- Logs.ws.onerror = function (err) {
- console.log('ERROR', err);
- }
- },
+ appendLog: function (key1, key2, key3, data) {
+ let result = Logs.sumResult(key1, key2, key3, data);
+ $("#logsContent").append(result);
+ },
- appendLog: function (key1, key2, key3, data) {
- let result = Logs.sumResult(key1, key2, key3, data);
- $("#logsContent").append(result);
- },
+ prependLog: function (key1, key2, key3, data) {
+ let result = Logs.sumResult(key1, key2, key3, data);
+ $("#logsContent").prepend(result);
+ },
- prependLog: function (key1, key2, key3, data) {
- let result = Logs.sumResult(key1, key2, key3, data);
- $("#logsContent").prepend(result);
- },
+ sumResult: function (key1, key2, key3, data) {
+ // let result = '
';
+ // result += '【 ' + key1 + ' ';
+ // result += '' + key2 + ' 】
';
+ // result += '「' + key3 + '」 ';
+ // result += '' + data + ' ';
+ // result += '
';
+ // return result;
- sumResult: function (key1, key2, key3, data) {
- let result = '';
- result += '【 ' + key1 + ' ';
- result += '' + key2 + ' 】
';
- result += '「' + key3 + '」 ';
- result += '' + data + ' ';
- result += '
';
- return result;
- },
-
- page: 1,
- more: function () {
- $.ajax({
- url: Label.servePath + '/logs/more?page=' + Logs.page + '&pageSize=30',
- type: 'GET',
- async: false,
- success: function (result) {
- if (0 === result.code) {
- let data = result.data;
- if (data.length === 0) {
- $("#loadMoreBtn").html("没有更多内容了");
- } else {
- data.forEach((log) => {
- Logs.appendLog(log.key1, log.key2, log.key3, log.data);
- });
- }
- }
- }
- });
- Logs.page++;
+ /**
+ * 根据key3值不同显示不同颜色 增加(tag)
+ * 增加积分 绿色 tag:add
+ * 扣除积分 红色 tag:reduce
+ * 发送弹幕 #6A5ACD tag:post
+ *
+ * 其他key值统一为 #6A5ACD tag:handle
+ */
+ let result = "";
+ switch (key3) {
+ case key3 === "增加积分":
+ result = '';
+ result += '【 ' + key1 + " ";
+ result += '' + key2 + " 】
";
+ result +=
+ '「' + "(add)" + key3 + "」 ";
+ result += '' + data + " ";
+ result += "
";
+ break;
+ case key3 === "扣除积分":
+ result = '';
+ result += '【 ' + key1 + " ";
+ result += '' + key2 + " 】
";
+ result +=
+ '「' + "(reduce)" + key3 + "」 ";
+ result += '' + data + " ";
+ result += "
";
+ break;
+ case key3 === "发送弹幕":
+ result = '';
+ result += '【 ' + key1 + " ";
+ result += '' + key2 + " 】
";
+ result +=
+ '「' + "(post)" + key3 + "」 ";
+ result += '' + data + " ";
+ result += "
";
+ break;
+ default:
+ result = '';
+ result += '【 ' + key1 + " ";
+ result += '' + key2 + " 】
";
+ result +=
+ '「' + "(handle)" + key3 + "」 ";
+ result += '' + data + " ";
+ result += "
";
+ break;
}
-}
+ return result;
+ },
+
+ page: 1,
+ more: function () {
+ $.ajax({
+ url: Label.servePath + "/logs/more?page=" + Logs.page + "&pageSize=30",
+ type: "GET",
+ async: false,
+ success: function (result) {
+ if (0 === result.code) {
+ let data = result.data;
+ if (data.length === 0) {
+ $("#loadMoreBtn").html("没有更多内容了");
+ } else {
+ data.forEach((log) => {
+ Logs.appendLog(log.key1, log.key2, log.key3, log.data);
+ });
+ }
+ }
+ },
+ });
+ Logs.page++;
+ },
+};
$(document).ready(function () {
- Logs.init();
+ Logs.init();
});