新增websocket的新邮件提醒

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

@ -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)
}
}

@ -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,
});
}
},

Loading…
Cancel
Save