From e543974e8cf1526ee009eed521e5dccb330fa3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E5=A3=AB=E6=B6=B5?= <630892807@qq.com> Date: Mon, 1 Jun 2020 23:28:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ewebsocket=E7=9A=84=E6=96=B0?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/notice.go | 14 +++++++++----- static/html/main.html | 7 ++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/controller/notice.go b/controller/notice.go index 45332ec..627f99b 100644 --- a/controller/notice.go +++ b/controller/notice.go @@ -1,7 +1,7 @@ package controller -import( + +import ( "encoding/json" - "fmt" "github.com/gorilla/websocket" "github.com/taoshihan1991/imaptool/tools" "log" @@ -35,11 +35,15 @@ func PushMailServer(w http.ResponseWriter, r *http.Request){ } }else{ folders:=tools.GetMailNum(mailServer.Server, mailServer.Email, mailServer.Password) - log.Println(folders) - log.Println(oldFolders) for name,num:=range folders{ if oldFolders[name]!=num{ - msg, _ = json.Marshal(tools.JsonResult{Code: 200, Msg: fmt.Sprintf("%s:%d",name,num)}) + result := make(map[string]interface{}) + result["folder_name"] = name + result["new_num"] = num-oldFolders[name] + msg, _ := json.Marshal(tools.JsonListResult{ + JsonResult: tools.JsonResult{Code: 200, Msg: "获取成功"}, + Result: result, + }) c.WriteMessage(mt,msg) } } diff --git a/static/html/main.html b/static/html/main.html index 93f0e97..9900071 100644 --- a/static/html/main.html +++ b/static/html/main.html @@ -116,9 +116,10 @@ const redata = JSON.parse(e.data); if (redata.code==200){ this.$notify({ - title: '新邮件', - message: redata.msg, - type: 'success' + title: redata.result.folder_name, + message: "新邮件:"+redata.result.new_num, + type: 'success', + duration: 0, }); } },