增加配置选项参数后台设置

pull/23/head
taoshihan1991 4 years ago
parent 9e481387fb
commit 2596e46821

@ -1,61 +1,33 @@
package controller
import (
"encoding/json"
"fmt"
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/tmpl"
"github.com/taoshihan1991/imaptool/tools"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/models"
)
func ActionSetting(w http.ResponseWriter, r *http.Request) {
render := tmpl.NewSettingHtml(w)
render.SetLeft("setting_left")
render.SetBottom("setting_bottom")
account := config.GetAccount()
render.Username = account["Username"]
render.Password = account["Password"]
render.Display("setting", render)
}
func SettingAccount(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "text/json;charset=utf-8;")
username := r.PostFormValue("username")
password := r.PostFormValue("password")
isExist, _ := tools.IsFileExist(config.Dir)
if !isExist {
os.Mkdir(config.Dir, os.ModePerm)
}
fileConfig := config.AccountConf
file, _ := os.OpenFile(fileConfig, os.O_RDWR|os.O_CREATE, os.ModePerm)
format := `{
"Username":"%s",
"Password":"%s"
}
`
data := fmt.Sprintf(format, username, password)
file.WriteString(data)
msg, _ := json.Marshal(tools.JsonResult{Code: 200, Msg: "操作成功!"})
w.Write(msg)
func GetConfigs(c *gin.Context) {
configs:=models.FindConfigs()
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":configs,
})
}
func SettingGetAccount(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "text/json;charset=utf-8;")
mailServer := tools.GetMailServerFromCookie(r)
if mailServer == nil {
msg, _ := json.Marshal(tools.JsonResult{Code: 400, Msg: "验证失败"})
w.Write(msg)
func PostConfig(c *gin.Context){
key:=c.PostForm("key")
value:=c.PostForm("value")
if key==""||value==""{
c.JSON(200, gin.H{
"code": 400,
"msg": "error",
})
return
}
result := config.GetAccount()
msg, _ := json.Marshal(tools.JsonListResult{
JsonResult: tools.JsonResult{Code: 200, Msg: "获取成功"},
Result: result,
models.UpdateConfig(key,value)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":"",
})
w.Write(msg)
}
}

@ -7,7 +7,12 @@ type Config struct{
ConfKey string `json:"conf_key"`
ConfValue string `json:"conf_value"`
}
func UpdateConfig(key string,value string){
c:=&Config{
ConfValue: value,
}
DB.Model(c).Where("conf_key = ?",key).Update(c)
}
func FindConfigs()[]Config{
var config []Config
DB.Find(&config)

@ -54,6 +54,8 @@ func InitApiRouter(engine *gin.Engine){
engine.POST("/ipblack",middleware.JwtApiMiddleware,controller.PostIpblack)
engine.DELETE("/ipblack",middleware.JwtApiMiddleware,controller.DelIpblack)
engine.GET("/ipblacks_all",middleware.JwtApiMiddleware,controller.GetIpblacks)
engine.GET("/configs",middleware.JwtApiMiddleware,middleware.RbacAuth,controller.GetConfigs)
engine.POST("/config",middleware.JwtApiMiddleware,middleware.RbacAuth,controller.PostConfig)
//微信接口
engine.GET("/micro_program",controller.GetCheckWeixinSign)
}

@ -20,6 +20,7 @@ func InitViewRouter(engine *gin.Engine){
engine.GET("/setting_deploy", tmpl.PageSettingDeploy)
engine.GET("/setting_kefu_list",tmpl.PageKefuList)
engine.GET("/setting_ipblack",tmpl.PageIpblack)
engine.GET("/setting_config",tmpl.PageConfig)
engine.GET("/mail_list", tmpl.PageMailList)
engine.GET("/roles_list", tmpl.PageRoleList)
engine.GET("/webjs", tmpl.PageWebJs)

@ -67,6 +67,7 @@
role_id:"",
},
roleList:[],
configList:[],
roleDialog:false,
noticeList:[],
welcomeDialog:false,
@ -200,6 +201,11 @@
_this.ipblackList=result.list;
});
}
if(ACTION=="setting_config"){
this.sendAjax("/configs","get",{},function(result){
_this.configList=result;
});
}
},
sendAjax(url,method,params,callback){
let _this=this;
@ -327,6 +333,15 @@
this.roleForm.path=path
this.roleDialog=true;
},
//设置配置项
setConfigItem(key,value){
let _this=this;
this.sendAjax("/config","POST",{key:key,value:value},function(result){
_this.sendAjax("/configs","get",{},function(result){
_this.configList=result;
});
});
},
//提交角色表单
submitRoleForm(formName){
let _this=this;

@ -0,0 +1,36 @@
{{template "header" }}
<div id="app" style="width:100%">
<template>
<el-container v-loading.fullscreen.lock="fullscreenLoading">
{{template "setting_left" .}}
<el-main class="mainMain">
<el-table
:data="configList"
border
style="width: 100%">
<el-table-column
prop="conf_name"
label="配置参数">
</el-table-column>
<el-table-column
prop="conf_key"
label="配置key">
</el-table-column>
<el-table-column
prop="id"
label="操作">
<template slot-scope="scope">
<el-input @change="setConfigItem(scope.row.conf_key,scope.row.conf_value)" v-model="scope.row.conf_value"></el-input>
</template>
</el-table-column>
</el-table>
</el-main>
</el-container>
</template>
</div>
</body>
{{template "setting_bottom" .}}

@ -35,6 +35,7 @@
<el-menu-item style="display:none" index="2-2">设置imap</el-menu-item>
<el-menu-item style="display:none" index="2-3" v-on:click="openUrl('/setting')">设置登陆账号</el-menu-item>
<el-menu-item style="display:none" index="2-4" v-on:click="openUrl('/setting_mysql')">设置mysql</el-menu-item>
<el-menu-item index="4-6" v-on:click="openUrl('/setting_config')">配置参数</el-menu-item>
<el-menu-item index="4-5" v-on:click="openUrl('/setting_ipblack')">IP黑名单</el-menu-item>
<el-menu-item index="2-5" v-on:click="openUrl('/setting_deploy')">设置网页部署</el-menu-item>
</el-menu-item-group>

@ -67,14 +67,5 @@ func PageConfig(c *gin.Context) {
"action":"setting_config",
})
}
type SettingHtml struct {
*CommonHtml
Username, Password string
}
func NewSettingHtml(w http.ResponseWriter) *SettingHtml {
obj := new(SettingHtml)
parent := NewRender(w)
obj.CommonHtml = parent
return obj
}

Loading…
Cancel
Save