新加ip接口

pull/30/head
taoshihan1991 4 years ago
parent 68c6633742
commit 664e0a8454

@ -0,0 +1,16 @@
package controller
import (
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/models"
)
func PostIpblack(c *gin.Context) {
ip := c.PostForm("ip")
kefuId, _ := c.Get("kefu_name")
models.CreateIpblack(ip,kefuId)
c.JSON(200, gin.H{
"code": 200,
"msg": "添加黑名单成功!",
})
}

@ -8,3 +8,12 @@ type Ipblack struct{
KefuId string `json:"kefu_id"` KefuId string `json:"kefu_id"`
CreateAt time.Time `json:"create_at"` CreateAt time.Time `json:"create_at"`
} }
func CreateIpblack(ip string,kefuId interface{})uint{
black:=&Ipblack{
IP:ip,
KefuId: kefuId,
CreateAt: time.Now(),
}
DB.Create(black)
return black.ID
}

@ -49,4 +49,5 @@ func InitApiRouter(engine *gin.Engine){
engine.POST("/notice",middleware.JwtApiMiddleware, controller.PostNotice) engine.POST("/notice",middleware.JwtApiMiddleware, controller.PostNotice)
engine.DELETE("/notice",middleware.JwtApiMiddleware, controller.DelNotice) engine.DELETE("/notice",middleware.JwtApiMiddleware, controller.DelNotice)
engine.GET("/notices",middleware.JwtApiMiddleware, controller.GetNotices) engine.GET("/notices",middleware.JwtApiMiddleware, controller.GetNotices)
engine.POST("/ipblack",controller.PostIpblack)
} }

@ -142,13 +142,13 @@
<el-tab-pane label="访客信息" name="visitorInfo"> <el-tab-pane label="访客信息" name="visitorInfo">
<el-menu> <el-menu>
<el-tooltip content="点击加入黑名单" placement="left"> <el-tooltip content="点击加入黑名单" placement="left">
<el-menu-item title="点击加入黑名单" style="padding-left:2px;"> <el-menu-item v-on:click="addIpblack(visitor.source_ip)" title="点击加入黑名单" style="padding-left:2px;">
<i class="el-icon-s-tools"></i> <i class="el-icon-s-tools"></i>
<span slot="title">ClientIP<{visitor.source_ip}></span> <span slot="title">ClientIP<{visitor.source_ip}></span>
</el-menu-item> </el-menu-item>
</el-tooltip> </el-tooltip>
<el-tooltip content="点击加入黑名单" placement="left"> <el-tooltip content="点击加入黑名单" placement="left">
<el-menu-item title="点击加入黑名单" style="padding-left:2px;"> <el-menu-item v-on:click="addIpblack(visitor.client_ip)" title="点击加入黑名单" style="padding-left:2px;">
<i class="el-icon-s-tools"></i> <i class="el-icon-s-tools"></i>
<span slot="title">IP<{visitor.client_ip}></span> <span slot="title">IP<{visitor.client_ip}></span>
</el-menu-item> </el-menu-item>
@ -626,6 +626,30 @@
}); });
}); });
}, },
addIpblack(ip){
let _this=this;
$.ajax({
type:"post",
url:"/ipblack",
data:{ip:ip},
headers:{
"token":localStorage.getItem("token")
},
success: function(data) {
if(data.code!=200){
_this.$message({
message: data.msg,
type: 'error'
});
}else{
_this.$message({
message: data.msg,
type: 'success'
});
}
}
});
},
}, },
created: function () { created: function () {
//jquery //jquery

Loading…
Cancel
Save