const { ipcRenderer } = require("electron"); class Index { constructor() { this.color = ""; this.size = "13px"; this.UserInfo = JSON.parse(localStorage.getItem("userInfo")); this.socket = io("ws://127.0.0.1:3000"); // console.log(this.socket); this.socketEmit() this.bindEvent() } socketEmit() { this.socket.emit("UserLogin", this.UserInfo) this.socket.emit("getOnlineUser", this.UserInfo) this.socket.on("PushMessage", (arg) => { this.sendMessage(arg, "") }) this.socket.on("PushShake", (arg) => { ipcRenderer.send("startShake") }) this.socket.on("PushOnlineUser", (arg) => { $(".content_right .title").text(`群成员 ${arg.length}`) $(".content_right ul").empty() arg.forEach(v => { $(".content_right ul").append(`
  • ${v.name}
    ${ v.type == 1 ? `` : v.type == 2 ? `` : '' }
  • `) }); }) this.socket.on("SystemMessage", (arg) => { $(".content_left").append(`
  • ${arg}
  • `) }) } bindEvent() { var self = this; $(".header_left img").attr("src", this.UserInfo.img) $(".header_left span").text(this.UserInfo.name) $(".header_text").text(this.UserInfo.room) $(".footer_input").keydown((e) => { if (e.keyCode == 13 || e.keyCode == 108) { e.preventDefault(); this.UserInfo.content = `
    ${$(".footer_input").html()}
    ` $(".footer_input").html("") this.socket.emit("sendMessage", this.UserInfo) this.sendMessage(this.UserInfo); } }) $(".menu_footer li").click(function() { $(this).addClass("active").siblings().removeClass("active") $(".menu_content div").eq($(this).index()).addClass("active").siblings().removeClass("active") $(".menu_title").text($(this).text()) }) for (var i = 0; i <= 274; i++ ) { $(".smiling").append(` `) } for (var i = 0; i <= 12; i++ ) { $(".gif").append(` `) } $(".gif img").click(function() { $(".footer_input").append($(this).clone()) }) $(".smiling img").hover( function() { $(this).attr({ src: `./img/icon/${$(this).index()}@2x.gif` }) }, function() { $(this).attr({ src: `./img/icon/${$(this).index()}fix@2x.png` }) } ); $(".smiling img").click(function() { $(".footer_input").append($(this).clone()) }); $(".footer_menu .aaa").click(function() { if ($(".menu_footer li").eq($(this).index()).hasClass("active")) { $(".footer_topmenu").hide() $(".menu_footer li").eq($(this).index()).removeClass("active") } else { $(".footer_topmenu").show() $(".menu_footer li").eq($(this).index()).click() } }) $(".font input").on("input", function () { self.color = $(this).val() }) $(".font select").on("change", function () { self.size = $(this).val() }) $(".icon-shake").click(function () { self.socket.emit("SetShake", self.UserInfo) }) } sendMessage(data,type = "right") { $(".content_left").append(`
  • ${data.name}
    ${data.content}
  • `) } } new Index();