feat(admin): 添加服务器配置列表接口并优化前端展示

- 后端新增 listConfig 函数,用于获取服务器配置列表
- 前端新增 getSites 方法,通过 REST API 获取站点配置
- 修改 config.json 中的 admin 服务器地址为 localhost
- 优化前端站点配置的展示逻辑
This commit is contained in:
kingecg 2025-06-15 22:15:45 +08:00
parent b92ca64cf8
commit 949de14d47
4 changed files with 30 additions and 5 deletions

View File

@ -65,6 +65,12 @@ func getServerConfigure(c *gin.Context) {
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) {
runtime := runtime.NumGoroutine()
@ -131,6 +137,7 @@ func InitAdminApi(conf *model.HttpServerConfig) {
configGroup := api.Group("config")
{
configGroup.POST("", setConfig)
configGroup.GET("", listConfig)
configGroup.GET(":name", getServerConfigure)
}

View File

@ -7,13 +7,13 @@ new Vue({
serverConfig: JSON.parse(localStorage.getItem('serverConfig')) || {
sites: [
{
id: Date.now(),
name: '示例网站',
domain: 'example.com',
server: 'example.com',
port: 8080,
ssl: false,
enable_ssl: false,
collapsed: false,
routes: [
paths: [
{
path: '/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) {
this.routeDialog = {

View File

@ -23,7 +23,7 @@
},
"admin": {
"name": "admin",
"server":"admin",
"server":"localhost",
"port": 8088,
"username": "admin",
"password": "admin",

View File

@ -34,3 +34,10 @@ func NewSuccessResult(data interface{}) []byte {
ret, _ := json.Marshal(result)
return ret
}
func NewResultObj(data interface{}) RestResult {
result := ResultSuccess
result.Data = data
return result
}