增加模板语法和mysql设置页

pull/30/head
陶士涵 4 years ago
parent 47c767247c
commit 208541b9b3

@ -1,10 +1,17 @@
package controller
import (
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/tmpl"
"net/http"
)
func MysqlGetConf(c *gin.Context) {
c.JSON(200, gin.H{
"code": 200,
"msg": "验证成功",
})
}
func ActionMysqlSet(w http.ResponseWriter, r *http.Request) {
render := tmpl.NewSettingHtml(w)
render.SetLeft("setting_left")

@ -31,6 +31,11 @@ func main() {
engine.POST("/check_auth",middleware.JwtApiMiddleware, controller.MainCheckAuth)
//前后聊天
engine.GET("/chat_server", controller.NewChatServer)
//设置页
engine.GET("/setting", tmpl.PageSetting)
//设置mysql
engine.GET("/setting_mysql", tmpl.PageSettingMysql)
engine.GET("/get_setting_mysql",middleware.JwtApiMiddleware, controller.MysqlGetConf)
//------------------old code-----------------------------
mux := &http.ServeMux{}
//根路径

@ -1,3 +1,4 @@
{{define "header"}}
<html lang="cn">
<head>
<meta charset="utf-8">
@ -51,4 +52,5 @@
</style>
</head>
<body class="text-center">
<body class="text-center">
{{end}}

@ -1,9 +1,9 @@
{{.Header}}
{{template "header" }}
<div id="app" style="width:100%">
<template>
<el-container v-loading.fullscreen.lock="fullscreenLoading">
<el-aside>
{{.Left}}
{{template "setting_left" .}}
</el-aside>
<el-main class="mainMain">
@ -30,4 +30,4 @@
var Password="{{.Password}}";
var Username="{{.Username}}";
</script>
{{.Bottom}}
{{template "setting_bottom" .}}

@ -1,3 +1,4 @@
{{define "setting_bottom"}}
<script>
var app=new Vue({
el: '#app',
@ -9,7 +10,23 @@
username: Username,
password: Password,
},
mysql: {
server: "",
port: "",
database: "",
username: "",
password: "",
},
rules: {
server: [
{ required: true, message: '请输入服务地址', trigger: 'blur' },
],
port: [
{ required: true, message: '请输入端口号', trigger: 'blur' },
],
database: [
{ required: true, message: '请输入数据库名', trigger: 'blur' },
],
username: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
],
@ -43,6 +60,29 @@
}
});
},
//设置mysql
setMysql(formName){
let _this=this;
this.$refs[formName].validate((valid) => {
if (valid) {
$.post("/setting_mysql",_this.account,function(data){
if(data.code==200){
_this.$message({
message: data.msg,
type: 'success'
});
}else{
_this.$message({
message: data.msg,
type: 'error'
});
}
});
} else {
return false;
}
});
},
//重置表单
resetForm(formName) {
this.loading=false;
@ -61,12 +101,30 @@
duration:'8000',
showClose:true,
});
},
//初始化数据
initInfo(){
{{if eq .action "setting_mysql"}}
let _this=this;
$.ajax({
type:"get",
url:"/get_setting_mysql",
headers:{
"token":localStorage.getItem("token")
},
success: function(data) {
}
});
{{end}}
}
},
created: function () {
this.showNotice();
this.initInfo();
}
})
</script>
</html>
</html>
{{end}}

@ -1,4 +1,5 @@
<el-menu default-active="1-3" :default-openeds="openIndex">
{{define "setting_left"}}
<el-menu default-active="{{.tab_index}}" :default-openeds="openIndex">
<el-submenu index="1">
<template slot="title">
<i class="el-icon-s-custom"></i>
@ -7,8 +8,9 @@
<el-menu-item-group>
<el-menu-item index="1-1">设置smtp</el-menu-item>
<el-menu-item index="1-2">设置imap</el-menu-item>
<el-menu-item index="1-3">设置登陆账号</el-menu-item>
<el-menu-item index="1-3" v-on:click="openUrl('/setting')">设置登陆账号</el-menu-item>
<el-menu-item index="1-4" v-on:click="openUrl('/setting_mysql')">设置mysql</el-menu-item>
</el-menu-item-group>
</el-submenu>
</el-menu>
</el-menu>
{{end}}

@ -1,7 +1,23 @@
package tmpl
import "net/http"
import (
"github.com/gin-gonic/gin"
"net/http"
)
//设置界面
func PageSetting(c *gin.Context) {
c.HTML(http.StatusOK, "setting.html", gin.H{
"tab_index":"1-3",
"action":"setting",
})
}
//设置mysql
func PageSettingMysql(c *gin.Context) {
c.HTML(http.StatusOK, "setting_mysql.html", gin.H{
"tab_index":"1-4",
"action":"setting_mysql",
})
}
type SettingHtml struct {
*CommonHtml
Username, Password string

Loading…
Cancel
Save