feat(admin): 添加服务器配置列表接口并优化前端展示
- 后端新增 listConfig 函数,用于获取服务器配置列表 - 前端新增 getSites 方法,通过 REST API 获取站点配置 - 修改 config.json 中的 admin 服务器地址为 localhost - 优化前端站点配置的展示逻辑
This commit is contained in:
parent
b92ca64cf8
commit
949de14d47
|
@ -65,6 +65,12 @@ func getServerConfigure(c *gin.Context) {
|
||||||
http.NotFound(c.Writer, c.Request)
|
http.NotFound(c.Writer, c.Request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func listConfig(c *gin.Context) {
|
||||||
|
data := model.GetConfig().Servers
|
||||||
|
// c.JSON(http.StatusOK, server.NewSuccessResult(data))
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, server.NewResultObj(data))
|
||||||
|
}
|
||||||
|
|
||||||
func getStatus(c *gin.Context) {
|
func getStatus(c *gin.Context) {
|
||||||
runtime := runtime.NumGoroutine()
|
runtime := runtime.NumGoroutine()
|
||||||
|
@ -131,6 +137,7 @@ func InitAdminApi(conf *model.HttpServerConfig) {
|
||||||
configGroup := api.Group("config")
|
configGroup := api.Group("config")
|
||||||
{
|
{
|
||||||
configGroup.POST("", setConfig)
|
configGroup.POST("", setConfig)
|
||||||
|
configGroup.GET("", listConfig)
|
||||||
configGroup.GET(":name", getServerConfigure)
|
configGroup.GET(":name", getServerConfigure)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,13 @@ new Vue({
|
||||||
serverConfig: JSON.parse(localStorage.getItem('serverConfig')) || {
|
serverConfig: JSON.parse(localStorage.getItem('serverConfig')) || {
|
||||||
sites: [
|
sites: [
|
||||||
{
|
{
|
||||||
id: Date.now(),
|
|
||||||
name: '示例网站',
|
name: '示例网站',
|
||||||
domain: 'example.com',
|
server: 'example.com',
|
||||||
port: 8080,
|
port: 8080,
|
||||||
ssl: false,
|
enable_ssl: false,
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
routes: [
|
paths: [
|
||||||
{
|
{
|
||||||
path: '/static',
|
path: '/static',
|
||||||
type: 'static',
|
type: 'static',
|
||||||
|
@ -186,6 +186,17 @@ new Vue({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//get site
|
||||||
|
getSites() {
|
||||||
|
//visit REST API to get sites, url is /api/config
|
||||||
|
//return this.serverConfig.sites;
|
||||||
|
this.$axios.get('/api/config').then(response => {
|
||||||
|
this.sites = response.data;
|
||||||
|
this.siteIndex = siteIndex;
|
||||||
|
this.getRoutes(siteIndex);
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
// 路由管理
|
// 路由管理
|
||||||
addRoute(siteIndex) {
|
addRoute(siteIndex) {
|
||||||
this.routeDialog = {
|
this.routeDialog = {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
},
|
},
|
||||||
"admin": {
|
"admin": {
|
||||||
"name": "admin",
|
"name": "admin",
|
||||||
"server":"admin",
|
"server":"localhost",
|
||||||
"port": 8088,
|
"port": 8088,
|
||||||
"username": "admin",
|
"username": "admin",
|
||||||
"password": "admin",
|
"password": "admin",
|
||||||
|
|
|
@ -34,3 +34,10 @@ func NewSuccessResult(data interface{}) []byte {
|
||||||
ret, _ := json.Marshal(result)
|
ret, _ := json.Marshal(result)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewResultObj(data interface{}) RestResult {
|
||||||
|
result := ResultSuccess
|
||||||
|
result.Data = data
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue