From 6cb51f5b70045ade372583e72ae48d783496a162 Mon Sep 17 00:00:00 2001
From: taoshihan1991 <630892807@qq.com>
Date: Wed, 27 May 2020 19:56:43 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A8=A1=E6=9D=BF=E9=83=A8?=
=?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
server.go | 4 +-
static/html/nav.html | 9 ++++
static/html/view.html | 67 +-----------------------------
static/html/write.html | 93 ++++++++++++++++++++++++++----------------
tmpl/common.go | 27 ++++++++++++
tmpl/index.go | 8 +---
tmpl/view.go | 82 +++++--------------------------------
tmpl/write.go | 9 ++++
tools/types.go | 1 +
9 files changed, 119 insertions(+), 181 deletions(-)
create mode 100644 static/html/nav.html
create mode 100644 tmpl/common.go
create mode 100644 tmpl/write.go
diff --git a/server.go b/server.go
index b107822..c4d0294 100644
--- a/server.go
+++ b/server.go
@@ -80,7 +80,7 @@ func view(w http.ResponseWriter, r *http.Request) {
//
//mailServer:=tools.GetMailServerFromCookie(r)
//var wg sync.WaitGroup
- var render = new(tools.ViewData)
+ var render = new(tmpl.ViewHtml)
render.Fid = fid
render.Id = uint32(id)
//wg.Add(1)
@@ -110,7 +110,7 @@ func login(w http.ResponseWriter, r *http.Request) {
}
//写信界面
func write(w http.ResponseWriter, r *http.Request) {
- render:=new(tools.ViewHtml)
+ render:=new(tmpl.CommonHtml)
tmpl.RenderWrite(w, render)
}
//验证接口
diff --git a/static/html/nav.html b/static/html/nav.html
new file mode 100644
index 0000000..8d37479
--- /dev/null
+++ b/static/html/nav.html
@@ -0,0 +1,9 @@
+
+ GO-IMAP
+ 收信
+
+ 写信
+ 退出
+
\ No newline at end of file
diff --git a/static/html/view.html b/static/html/view.html
index 8585e46..62fb161 100644
--- a/static/html/view.html
+++ b/static/html/view.html
@@ -1,71 +1,8 @@
-
-
-
-
-
-
- GO-IMAP网页版邮箱imap工具
-
-
-
-
-
-
-
-
+{{.Header}}
-
- GO-IMAP
- 收信
-
- 写信
-
- 退出
-
-
+ {{.Nav}}
-
- GO-IMAP
- 收信
-
- 写信
- 退出
-
+ {{.Nav}}
- bbb
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 立即发送
+ 取消
+
+
@@ -38,38 +47,37 @@
data: {
fullscreenLoading:true,
folders:[],
- mails:[],
- mailTotal:0,
- page:1,
- pagesize:10,
fid:"",
+ mailTotal:0,
+ form: {
+ smtp: '',
+ email: '',
+ subject: '',
+ content: '',
+ },
+ rules: {
+ smtp: [
+ { required: true, message: 'SMTP服务器如"smtp.sina.net:25"包含端口号', trigger: 'blur' },
+ ],
+ email: [
+ { required: true, message: '邮箱地址', trigger: 'blur' },
+ ],
+ subject: [
+ { required: true, message: '主题', trigger: 'blur' },
+ ],
+ content: [
+ { required: true, message: '内容', trigger: 'blur' },
+ ],
+ },
},
methods: {
//获取邮件夹
- getFolders: function (page,fid,isLeft) {
+ getFolders: function () {
this.fullscreenLoading=true;
- if(typeof(page)=="undefined" || page==""){
- page=1;
- }else{
- this.page=page;
- }
- let data={};
- data.page=page;
- 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) {
- if(!isLeft){
- _this.folders=rs.result.folders;
- }
- _this.mails=rs.result.mails
+ $.get('/folders', function (rs) {
+ _this.folders=rs.result.folders;
_this.mailTotal=rs.result.total;
- _this.pagesize=rs.result.pagesize;
- _this.fid=rs.result.fid;
_this.fullscreenLoading=false;
}).then(()=>{
_this.fullscreenLoading=false;
@@ -79,6 +87,21 @@
openUrl(url){
window.location.href=url;
},
+ //提交表单
+ submitForm(formName){
+ let _this=this;
+ this.$refs[formName].validate((valid) => {
+ if (valid) {
+ } else {
+ return false;
+ }
+ });
+ },
+ //重置表单
+ resetForm(formName) {
+ this.loading=false;
+ this.$refs[formName].resetFields();
+ },
},
created: function () {
this.getFolders();
diff --git a/tmpl/common.go b/tmpl/common.go
new file mode 100644
index 0000000..57b5207
--- /dev/null
+++ b/tmpl/common.go
@@ -0,0 +1,27 @@
+package tmpl
+
+import (
+ "github.com/taoshihan1991/imaptool/tools"
+ "html/template"
+ "net/http"
+)
+
+type CommonHtml struct{
+ Header template.HTML
+ Nav template.HTML
+ Rw http.ResponseWriter
+}
+func NewRender(rw http.ResponseWriter)*CommonHtml{
+ obj:=new(CommonHtml)
+ obj.Rw=rw
+ header := tools.FileGetContent("html/header.html")
+ nav := tools.FileGetContent("html/nav.html")
+ obj.Header=template.HTML(header)
+ obj.Nav=template.HTML(nav)
+ return obj
+}
+func (obj *CommonHtml)Display(file string,data interface{}){
+ main := tools.FileGetContent("html/"+file+".html")
+ t, _ := template.New(file).Parse(main)
+ t.Execute(obj.Rw, data)
+}
\ No newline at end of file
diff --git a/tmpl/index.go b/tmpl/index.go
index 381ff62..54d64c1 100644
--- a/tmpl/index.go
+++ b/tmpl/index.go
@@ -13,10 +13,4 @@ func RenderList(w http.ResponseWriter, render interface{}) {
render.(*tools.IndexData).Header=template.HTML(header)
t.Execute(w, render)
}
-func RenderWrite(w http.ResponseWriter, render interface{}){
- header := tools.FileGetContent("html/header.html")
- html := tools.FileGetContent("html/write.html")
- t, _ := template.New("write").Parse(html)
- render.(*tools.ViewHtml).Header=template.HTML(header)
- t.Execute(w, render)
-}
+
diff --git a/tmpl/view.go b/tmpl/view.go
index 1f4ef63..2820db0 100644
--- a/tmpl/view.go
+++ b/tmpl/view.go
@@ -1,78 +1,16 @@
package tmpl
import (
- "github.com/taoshihan1991/imaptool/tools"
- "html/template"
"net/http"
)
-
-func RenderView(w http.ResponseWriter, render interface{}) {
- const html = `
-
-
-
-
-
-
-
-
- 邮箱IMAP-详情
-
-
-
-
-
-
-
-
-
-
- - 邮件夹
- {{ range $key, $value := .Folders}}
- -
- {{$key}}
- {{if ne $value 0 }}{{$value}}{{end}}
-
- {{end}}
-
-
-
-
-
-
- 日期: |
- {{.Date}} |
-
-
- 发件人: |
- {{.From}} |
-
-
- 收件人: |
- {{.To}} |
-
-
- 主题: |
- {{.Subject}} |
-
-
- 内容: |
-
- {{.HtmlBody}}
- |
-
-
-
-
-
-
-
-`
- html1 := tools.FileGetContent("html/view.html")
- t, _ := template.New("view").Parse(html1)
- t.Execute(w, render)
+type ViewHtml struct{
+ CommonHtml
+ Fid string
+ Id uint32
+}
+func RenderView(w http.ResponseWriter, data interface{}) {
+ render:=NewRender(w)
+ data.(*ViewHtml).Nav=render.Nav
+ data.(*ViewHtml).Header=render.Header
+ render.Display("view",data)
}
diff --git a/tmpl/write.go b/tmpl/write.go
new file mode 100644
index 0000000..cce2bb4
--- /dev/null
+++ b/tmpl/write.go
@@ -0,0 +1,9 @@
+package tmpl
+
+import (
+ "net/http"
+)
+func RenderWrite(w http.ResponseWriter, data interface{}) {
+ render:=NewRender(w)
+ render.Display("write",render)
+}
diff --git a/tools/types.go b/tools/types.go
index 9442011..511da84 100644
--- a/tools/types.go
+++ b/tools/types.go
@@ -7,6 +7,7 @@ type MailServer struct {
}
type ViewHtml struct{
Header template.HTML
+ Nav template.HTML
}
type IndexData struct {
ViewHtml