修复页码跳转问题和简化获取get代码

pull/30/head
陶士涵 5 years ago
parent a450c67b96
commit 4f7d80241a

@ -120,27 +120,7 @@ func view(w http.ResponseWriter, r *http.Request) {
//登陆界面
func login(w http.ResponseWriter, r *http.Request) {
email := r.PostFormValue("email")
server := r.PostFormValue("server")
password := r.PostFormValue("password")
var errStr string
if email != "" && server != "" && password != "" {
res := tools.CheckEmailPassword(server, email, password)
if !res {
errStr = "连接或验证失败"
tmpl.RenderLogin(w, errStr)
} else {
auth := fmt.Sprintf("%s|%s|%s", server, email, password)
cookie := http.Cookie{
Name: "auth",
Value: auth,
}
http.SetCookie(w, &cookie)
http.Redirect(w, r, "/", 302)
}
} else {
tmpl.RenderLogin(w, errStr)
}
tmpl.RenderLogin(w, nil)
}
//验证接口
@ -168,15 +148,9 @@ func check(w http.ResponseWriter, r *http.Request) {
//邮件夹接口
func folders(w http.ResponseWriter, r *http.Request) {
values := r.URL.Query()
fid := ""
currentPage := 0
if len(values["fid"]) != 0 {
fid = values["fid"][0]
}
if len(values["page"]) != 0 {
currentPage, _ = strconv.Atoi(values["page"][0])
}
fid:=tools.GetUrlArg(r,"fid")
currentPage, _ :=strconv.Atoi(tools.GetUrlArg(r,"page"))
if fid == "" {
fid = "INBOX"
}
@ -219,20 +193,8 @@ func folders(w http.ResponseWriter, r *http.Request) {
//邮件接口
func mail(w http.ResponseWriter, r *http.Request) {
values := r.URL.Query()
fid := ""
if len(values["fid"]) != 0 {
fid = values["fid"][0]
} else {
fid = "INBOX"
}
var id uint32
if len(values["id"]) != 0 {
i, _ := strconv.Atoi(values["id"][0])
id = uint32(i)
} else {
id = 0
}
fid:=tools.GetUrlArg(r,"fid")
id, _ :=strconv.Atoi(tools.GetUrlArg(r,"id"))
mailServer := tools.GetMailServerFromCookie(r)
w.Header().Set("content-type", "text/json;charset=utf-8;")
@ -252,7 +214,7 @@ func mail(w http.ResponseWriter, r *http.Request) {
}()
go func() {
defer wg.Done()
mail := tools.GetMessage(mailServer.Server, mailServer.Email, mailServer.Password, fid, id)
mail := tools.GetMessage(mailServer.Server, mailServer.Email, mailServer.Password, fid, uint32(id))
result["from"] = mail.From
result["to"] = mail.To
result["subject"] = mail.Subject

@ -65,7 +65,7 @@
<el-aside>
<el-menu
:default-active="fid">
<el-menu-item :index="v" v-for="(f,v) in folderlist.folders" v-bind:key="v" v-on:click="getFolders(1,v)">
<el-menu-item :index="v" v-for="(f,v) in folders" v-bind:key="v" v-on:click="getFolders(1,v,true)">
<i class="el-icon-menu"></i>
<span slot="title"><{v}></span>
</el-menu-item>
@ -75,7 +75,7 @@
<el-main class="mainMain">
<div class="block">
<el-timeline :reverse="true">
<el-timeline-item v-for="item in folderlist.mails" v-bind:key="item.Id" :timestamp="item.Date" placement="top">
<el-timeline-item v-for="item in mails" v-bind:key="item.Id" :timestamp="item.Date" placement="top">
<el-card v-on:click.native="openUrl('/view?fid='+fid+'&id='+item.Id)">
<h4><{item.Subject}></h4>
<p><{item.From}> 发送于 <{item.Date}></p>
@ -104,28 +104,36 @@
delimiters:["<{","}>"],
data: {
fullscreenLoading:true,
folderlist:[],
folders:[],
mails:[],
mailTotal:0,
page:1,
pagesize:10,
fid:"INBOX",
fid:"",
},
methods: {
//获取邮件夹
getFolders: function (page,fid) {
getFolders: function (page,fid,isLeft) {
this.fullscreenLoading=true;
if(page==""){
if(typeof(page)=="undefined" || page==""){
page=1;
}else{
this.page=page;
}
var data={};
let data={};
data.page=page;
if(fid!=""){
if(typeof(fid)!="undefined" && fid!=""){
data.fid=fid;
this.fid=fid;
}else if(this.fid!=""){
data.fid=this.fid;
}
let _this = this;
$.get('/folders',data, function (rs) {
_this.folderlist=rs.result;
if(!isLeft){
_this.folders=rs.result.folders;
}
_this.mails=rs.result.mails
_this.mailTotal=rs.result.total;
_this.pagesize=rs.result.pagesize;
_this.fid=rs.result.fid;

@ -8,9 +8,16 @@ import (
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
"io/ioutil"
"net/http"
"strings"
)
//获取URL的GET参数
func GetUrlArg(r *http.Request,name string)string{
var arg string
values := r.URL.Query()
arg=values.Get(name)
return arg
}
// Reverse 将其实参字符串以符文为单位左右反转。
func Reverse(s string) string {
r := []rune(s)
@ -38,6 +45,7 @@ func DetermineEncoding(html string) (encoding.Encoding, string) {
e, name, _ := charset.DetermineEncoding([]byte(html), "")
return e, name
}
//获取文件内容,可以打包到二进制
func FileGetContent(file string) string {
str := ""
box := packr.NewBox("../static")

Loading…
Cancel
Save