新增websocket的新邮件提醒

pull/30/head
陶士涵 5 years ago
parent 4547cbd766
commit e543974e8c

@ -1,7 +1,7 @@
package controller package controller
import(
import (
"encoding/json" "encoding/json"
"fmt"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/taoshihan1991/imaptool/tools" "github.com/taoshihan1991/imaptool/tools"
"log" "log"
@ -35,11 +35,15 @@ func PushMailServer(w http.ResponseWriter, r *http.Request){
} }
}else{ }else{
folders:=tools.GetMailNum(mailServer.Server, mailServer.Email, mailServer.Password) folders:=tools.GetMailNum(mailServer.Server, mailServer.Email, mailServer.Password)
log.Println(folders)
log.Println(oldFolders)
for name,num:=range folders{ for name,num:=range folders{
if oldFolders[name]!=num{ 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) c.WriteMessage(mt,msg)
} }
} }

@ -116,9 +116,10 @@
const redata = JSON.parse(e.data); const redata = JSON.parse(e.data);
if (redata.code==200){ if (redata.code==200){
this.$notify({ this.$notify({
title: '新邮件', title: redata.result.folder_name,
message: redata.msg, message: "新邮件:"+redata.result.new_num,
type: 'success' type: 'success',
duration: 0,
}); });
} }
}, },

Loading…
Cancel
Save