const { ipcRenderer } = require("electron"); class Index { constructor() { this.color = ""; this.size = "13px"; this.background = ""; // 获取本地存储的数据 this.UserInfo = JSON.parse(localStorage.getItem("userInfo")); this.socket = io("ws://127.0.0.1:3000"); this.socketEmit(); this.bindEvent() } socketEmit() { // 将本地存储的数据传给后端 this.socket.emit("UserLogin", this.UserInfo) //将用户在线数发给后端 this.socket.emit("getOnlineUser", this.UserInfo) //监听后端传来的PushMessage this.socket.on("PushMessage", (arg) => { this.sendMessage(arg, "") //再次调用sendMessage 把arg 和一个空数组传过去 当那边type为空时就是消息显示在左边 }) // 监听抖动 this.socket.on("PushShake", (arg) => { ipcRenderer.send("startShake") }) //监听后端传来的PushOnlineUser this.socket.on("PushOnlineUser", (arg) => { $(".content_right .title").text(`群成员 ${arg.length}`) $(".content_right ul").empty() //先将父容器的容易清空再添加 arg.forEach(v => { $(".content_right ul").append(`
`)
}
// 添加到输入框的时候用.clone()创建个副本添加
$(".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`
})
}
);
// 添加到输入框的时候用.clone()创建个副本添加
$(".smiling img").click(function() {
$(".footer_input").append($(this).clone())
});
// 对输入框上面的图片添加点击事件
// 如果li标签包含active 也就是已经激活的状态那么就是使弹窗隐藏并且移除所有的active
$(".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()
}
})
//监听input方法
$(".font input").on("input", function () {
self.color = $(this).val()
})
//监听select方法
$(".font select").on("change", function () {
self.size = $(this).val()
})
//监听qipao input方法
$(".qipao input").on("input", function () {
self.background = $(this).val()
})
$(".icon-zhendong").click(function () {
self.socket.emit("SetShake", self.UserInfo)
})
}
//创建sendMessage接收this.UserInfo为data
sendMessage(data,type = "right") {
$(".content_left").append(`