添加服务器 & 展示服务器
This commit is contained in:
parent
d8c4364653
commit
1b18e7103e
@ -26,7 +26,10 @@ func (cp *commonPage) home(c *gin.Context) {
|
|||||||
if ok && isLogin.(bool) {
|
if ok && isLogin.(bool) {
|
||||||
admin = dao.Admin
|
admin = dao.Admin
|
||||||
}
|
}
|
||||||
|
var servers []model.Server
|
||||||
|
dao.DB.Find(&servers)
|
||||||
c.HTML(http.StatusOK, "page/home", mygin.CommonEnvironment(c, gin.H{
|
c.HTML(http.StatusOK, "page/home", mygin.CommonEnvironment(c, gin.H{
|
||||||
"Admin": admin,
|
"Admin": admin,
|
||||||
|
"Servers": servers,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,10 @@ import (
|
|||||||
|
|
||||||
// ServeWeb ..
|
// ServeWeb ..
|
||||||
func ServeWeb() {
|
func ServeWeb() {
|
||||||
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
if dao.Conf.Debug {
|
||||||
|
gin.SetMode(gin.DebugMode)
|
||||||
|
}
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.Use(mygin.RecordPath)
|
r.Use(mygin.RecordPath)
|
||||||
r.SetFuncMap(template.FuncMap{
|
r.SetFuncMap(template.FuncMap{
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/naiba/com"
|
||||||
|
|
||||||
"github.com/p14yground/nezha/model"
|
"github.com/p14yground/nezha/model"
|
||||||
"github.com/p14yground/nezha/pkg/mygin"
|
"github.com/p14yground/nezha/pkg/mygin"
|
||||||
@ -27,6 +28,33 @@ func (ma *memberAPI) serve() {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
mr.POST("/logout", ma.logout)
|
mr.POST("/logout", ma.logout)
|
||||||
|
mr.POST("/server", ma.addServer)
|
||||||
|
}
|
||||||
|
|
||||||
|
type serverForm struct {
|
||||||
|
Name string `binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ma *memberAPI) addServer(c *gin.Context) {
|
||||||
|
var sf serverForm
|
||||||
|
err := c.ShouldBindJSON(&sf)
|
||||||
|
if err == nil {
|
||||||
|
var s model.Server
|
||||||
|
s.Name = sf.Name
|
||||||
|
s.Secret = com.MD5(fmt.Sprintf("%s%s%d", time.Now(), sf.Name, dao.Admin.ID))
|
||||||
|
s.Secret = s.Secret[:10]
|
||||||
|
err = dao.DB.Create(&s).Error
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, model.Response{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
Message: fmt.Sprintf("请求错误:%s", err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, model.Response{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type logoutForm struct {
|
type logoutForm struct {
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/p14yground/nezha/model"
|
||||||
"github.com/p14yground/nezha/pkg/mygin"
|
"github.com/p14yground/nezha/pkg/mygin"
|
||||||
|
"github.com/p14yground/nezha/service/dao"
|
||||||
)
|
)
|
||||||
|
|
||||||
type memberPage struct {
|
type memberPage struct {
|
||||||
@ -18,4 +22,14 @@ func (mp *memberPage) serve() {
|
|||||||
Btn: "点此登录",
|
Btn: "点此登录",
|
||||||
Redirect: "/login",
|
Redirect: "/login",
|
||||||
}))
|
}))
|
||||||
|
mr.GET("/server", mp.server)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *memberPage) server(c *gin.Context) {
|
||||||
|
var servers []model.Server
|
||||||
|
dao.DB.Find(&servers)
|
||||||
|
c.HTML(http.StatusOK, "page/server", mygin.CommonEnvironment(c, gin.H{
|
||||||
|
"Title": "服务器管理",
|
||||||
|
"Servers": servers,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,16 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
if dao.Conf.Debug {
|
||||||
|
dao.DB = dao.DB.Debug()
|
||||||
|
}
|
||||||
dao.Cache = cache.New(5*time.Minute, 10*time.Minute)
|
dao.Cache = cache.New(5*time.Minute, 10*time.Minute)
|
||||||
|
|
||||||
|
initDB()
|
||||||
|
}
|
||||||
|
|
||||||
|
func initDB() {
|
||||||
|
dao.DB.AutoMigrate(model.Server{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
8
model/server.go
Normal file
8
model/server.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
// Server ..
|
||||||
|
type Server struct {
|
||||||
|
Common
|
||||||
|
Name string
|
||||||
|
Secret string
|
||||||
|
}
|
@ -20,38 +20,8 @@
|
|||||||
margin-top: 75px;
|
margin-top: 75px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.avatar-list img {
|
.footer.segment {
|
||||||
width: 2.6rem !important;
|
margin-top: 40px !important;
|
||||||
height: 2.6rem !important;
|
padding-top: 40px;
|
||||||
background-color: white;
|
padding-bottom: 40px;
|
||||||
}
|
|
||||||
|
|
||||||
.card-list {
|
|
||||||
width: 100% !important;
|
|
||||||
padding-right: unset !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card-list .card {
|
|
||||||
width: calc(33.33333333% - 1.1em) !important;
|
|
||||||
margin-right: unset !important;
|
|
||||||
margin-top: unset !important;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.card-list .card:nth-child(1) {
|
|
||||||
margin-top: 0.875em !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card-list .card:nth-child(2) {
|
|
||||||
margin-top: 0.875em !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card-list .card:nth-child(3) {
|
|
||||||
margin-top: 0.875em !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.grid-list>.grid>.row {
|
|
||||||
border-bottom: solid gainsboro 2px;
|
|
||||||
padding-bottom: .6em;
|
|
||||||
margin-bottom: .6em;
|
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
$('.ui.checkbox').checkbox();
|
$('.ui.checkbox').checkbox();
|
||||||
$('.ui.dropdown').dropdown();
|
|
||||||
|
|
||||||
const confirmBtn = $('.mini.confirm.modal .positive.button')
|
const confirmBtn = $('.mini.confirm.modal .positive.button')
|
||||||
function showConfirm(title, content, callFn, extData) {
|
function showConfirm(title, content, callFn, extData) {
|
||||||
@ -32,7 +31,7 @@ function showFormModal(modelSelector, formID, URL, getData) {
|
|||||||
form.children('.message').remove()
|
form.children('.message').remove()
|
||||||
btn.toggleClass('loading')
|
btn.toggleClass('loading')
|
||||||
const data = getData ? getData() : $(formID).serializeArray().reduce(function (obj, item) {
|
const data = getData ? getData() : $(formID).serializeArray().reduce(function (obj, item) {
|
||||||
obj[item.name] = (item.name.endsWith('_id') || item.name === 'id' || item.name === 'permission') ? parseInt(item.value) : item.value;
|
obj[item.name] = (item.name.endsWith('_id') || item.name === 'id') ? parseInt(item.value) : item.value;
|
||||||
return obj;
|
return obj;
|
||||||
}, {});
|
}, {});
|
||||||
$.post(URL, JSON.stringify(data)).done(function (resp) {
|
$.post(URL, JSON.stringify(data)).done(function (resp) {
|
||||||
@ -54,6 +53,10 @@ function showFormModal(modelSelector, formID, URL, getData) {
|
|||||||
}).modal('show')
|
}).modal('show')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addServer() {
|
||||||
|
showFormModal('.server.modal', '#serverForm', '/api/server')
|
||||||
|
}
|
||||||
|
|
||||||
function logout(id) {
|
function logout(id) {
|
||||||
$.post('/api/logout', JSON.stringify({ id: id })).done(function (resp) {
|
$.post('/api/logout', JSON.stringify({ id: id })).done(function (resp) {
|
||||||
if (resp.code == 200) {
|
if (resp.code == 200) {
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
{{define "common/footer"}}
|
{{define "common/footer"}}
|
||||||
|
<div class="ui inverted vertical footer segment">
|
||||||
|
<div class="ui center aligned text container">
|
||||||
|
本系统由 <a href="https://github.com/p14yground/nezha" target="_blank">哪吒面板</a> 强力驱动
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<script src="https://cdnjs.loli.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
<script src="https://cdnjs.loli.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
<script src="https://cdnjs.loli.net/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
|
<script src="https://cdnjs.loli.net/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
|
||||||
<script src="/static/semantic-ui-alerts.min.js"></script>
|
<script src="/static/semantic-ui-alerts.min.js"></script>
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
<img src="/static/logo.png">
|
<img src="/static/logo.png">
|
||||||
</div>
|
</div>
|
||||||
<a class="item{{if eq .MatchedPath "/"}} active{{end}}" href="/">首页</a>
|
<a class="item{{if eq .MatchedPath "/"}} active{{end}}" href="/">首页</a>
|
||||||
|
{{if .Admin}}
|
||||||
|
<a class="item{{if eq .MatchedPath "/server"}} active{{end}}" href="/server">服务器</a>
|
||||||
|
{{end}}
|
||||||
<div class="right menu">
|
<div class="right menu">
|
||||||
<a class="item" href="https://github.com/p14yground/nezha/issues" target="_blank">反馈</a>
|
<a class="item" href="https://github.com/p14yground/nezha/issues" target="_blank">反馈</a>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
|
18
resource/template/component/server.html
Normal file
18
resource/template/component/server.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{{define "component/server"}}
|
||||||
|
<div class="ui tiny server modal transition hidden">
|
||||||
|
<div class="header">添加服务器</div>
|
||||||
|
<div class="content">
|
||||||
|
<form id="serverForm" class="ui form">
|
||||||
|
<div class="field">
|
||||||
|
<label>备注</label>
|
||||||
|
<input type="text" name="name" placeholder="爱因斯坦-光速1号">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<div class="ui negative button">取消</div>
|
||||||
|
<button class="ui positive right labeled icon button">绑定<i class="checkmark icon"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
@ -3,7 +3,23 @@
|
|||||||
{{template "common/menu" .}}
|
{{template "common/menu" .}}
|
||||||
<div class="nb-container">
|
<div class="nb-container">
|
||||||
<div class="ui container">
|
<div class="ui container">
|
||||||
{{.Admin}}
|
<div class="ui four cards">
|
||||||
|
{{range $server := .Servers}}
|
||||||
|
<div class="card">
|
||||||
|
<div class="content">
|
||||||
|
<div class="header">{{.Name}}</div>
|
||||||
|
<div class="description">
|
||||||
|
<div class="ui active progress">
|
||||||
|
<div class="bar">
|
||||||
|
<div class="progress"></div>
|
||||||
|
</div>
|
||||||
|
<div class="label">CPU</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{template "common/footer" .}}
|
{{template "common/footer" .}}
|
||||||
|
30
resource/template/page/server.html
Normal file
30
resource/template/page/server.html
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{{define "page/server"}}
|
||||||
|
{{template "common/header" .}}
|
||||||
|
{{template "common/menu" .}}
|
||||||
|
<div class="nb-container">
|
||||||
|
<div class="ui container">
|
||||||
|
<button class="ui right labeled positive icon button" onclick="addServer()"><i class="add icon"></i> 添加服务器
|
||||||
|
</button>
|
||||||
|
<table class="ui very basic table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>备注</th>
|
||||||
|
<th>密钥</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{range $server := .Servers}}
|
||||||
|
<tr>
|
||||||
|
<td>{{$server.ID}}</td>
|
||||||
|
<td>{{$server.Name}}</td>
|
||||||
|
<td>{{$server.Secret}}</td>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{template "component/server"}}
|
||||||
|
{{template "common/footer" .}}
|
||||||
|
{{end}}
|
Loading…
Reference in New Issue
Block a user