From 8870b92cebb9dbaa97352ad7e88b599da912db60 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 15 May 2024 23:02:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Redis=20=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BF=AB=E9=80=9F=E5=91=BD=E4=BB=A4=20(#5018?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #3220 --- backend/app/api/v1/command.go | 86 +++++++++ backend/app/dto/command.go | 6 + backend/app/model/command.go | 6 + backend/app/repo/command.go | 50 ++++++ backend/app/service/command.go | 62 +++++++ backend/init/migration/migrate.go | 1 + backend/init/migration/migrations/v_1_10.go | 10 ++ backend/router/ro_host.go | 5 + cmd/server/docs/docs.go | 164 ++++++++++++++++++ cmd/server/docs/swagger.json | 164 ++++++++++++++++++ cmd/server/docs/swagger.yaml | 104 +++++++++++ frontend/src/api/interface/command.ts | 5 + frontend/src/api/modules/host.ts | 13 ++ frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/tw.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + .../views/database/redis/command/index.vue | 164 ++++++++++++++++++ frontend/src/views/database/redis/index.vue | 80 ++++++--- 18 files changed, 899 insertions(+), 24 deletions(-) create mode 100644 frontend/src/views/database/redis/command/index.vue diff --git a/backend/app/api/v1/command.go b/backend/app/api/v1/command.go index 6dcf220c3..c6f477216 100644 --- a/backend/app/api/v1/command.go +++ b/backend/app/api/v1/command.go @@ -29,6 +29,28 @@ func (b *BaseApi) CreateCommand(c *gin.Context) { helper.SuccessWithData(c, nil) } +// @Tags Redis Command +// @Summary Create redis command +// @Description 创建 Redis 快速命令 +// @Accept json +// @Param request body dto.RedisCommand true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Router /hosts/command/redis [post] +// @x-panel-log {"bodyKeys":["name","command"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建 redis 快捷命令 [name][command]","formatEN":"create quick command for redis [name][command]"} +func (b *BaseApi) CreateRedisCommand(c *gin.Context) { + var req dto.RedisCommand + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + + if err := commandService.CreateRedisCommand(req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} + // @Tags Command // @Summary Page commands // @Description 获取快速命令列表分页 @@ -55,6 +77,32 @@ func (b *BaseApi) SearchCommand(c *gin.Context) { }) } +// @Tags Redis Command +// @Summary Page redis commands +// @Description 获取 redis 快速命令列表分页 +// @Accept json +// @Param request body dto.SearchWithPage true "request" +// @Success 200 {object} dto.PageResult +// @Security ApiKeyAuth +// @Router /hosts/command/redis/search [post] +func (b *BaseApi) SearchRedisCommand(c *gin.Context) { + var req dto.SearchWithPage + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + + total, list, err := commandService.SearchRedisCommandWithPage(req) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + + helper.SuccessWithData(c, dto.PageResult{ + Items: list, + Total: total, + }) +} + // @Tags Command // @Summary Tree commands // @Description 获取快速命令树 @@ -72,6 +120,22 @@ func (b *BaseApi) SearchCommandTree(c *gin.Context) { helper.SuccessWithData(c, list) } +// @Tags Redis Command +// @Summary List redis commands +// @Description 获取 redis 快速命令列表 +// @Success 200 {Array} dto.RedisCommand +// @Security ApiKeyAuth +// @Router /hosts/command/redis [get] +func (b *BaseApi) ListRedisCommand(c *gin.Context) { + list, err := commandService.ListRedisCommand() + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + + helper.SuccessWithData(c, list) +} + // @Tags Command // @Summary List commands // @Description 获取快速命令列表 @@ -110,6 +174,28 @@ func (b *BaseApi) DeleteCommand(c *gin.Context) { helper.SuccessWithData(c, nil) } +// @Tags Redis Command +// @Summary Delete redis command +// @Description 删除 redis 快速命令 +// @Accept json +// @Param request body dto.BatchDeleteReq true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Router /hosts/command/redis/del [post] +// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ids","isList":true,"db":"redis_commands","output_column":"name","output_value":"names"}],"formatZH":"删除 redis 快捷命令 [names]","formatEN":"delete quick command of redis [names]"} +func (b *BaseApi) DeleteRedisCommand(c *gin.Context) { + var req dto.BatchDeleteReq + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + + if err := commandService.DeleteRedisCommand(req.Ids); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} + // @Tags Command // @Summary Update command // @Description 更新快速命令 diff --git a/backend/app/dto/command.go b/backend/app/dto/command.go index caa9115c6..2d5c29fe2 100644 --- a/backend/app/dto/command.go +++ b/backend/app/dto/command.go @@ -30,3 +30,9 @@ type CommandTree struct { Label string `json:"label"` Children []CommandInfo `json:"children"` } + +type RedisCommand struct { + ID uint `json:"id"` + Name string `json:"name"` + Command string `json:"command"` +} diff --git a/backend/app/model/command.go b/backend/app/model/command.go index a95fbe41f..9f00558d4 100644 --- a/backend/app/model/command.go +++ b/backend/app/model/command.go @@ -6,3 +6,9 @@ type Command struct { GroupID uint `gorm:"type:decimal" json:"groupID"` Command string `gorm:"type:varchar(256);not null" json:"command"` } + +type RedisCommand struct { + BaseModel + Name string `gorm:"type:varchar(64);unique;not null" json:"name"` + Command string `gorm:"type:varchar(256);not null" json:"command"` +} diff --git a/backend/app/repo/command.go b/backend/app/repo/command.go index 4abe27335..7c95b1f52 100644 --- a/backend/app/repo/command.go +++ b/backend/app/repo/command.go @@ -17,6 +17,12 @@ type ICommandRepo interface { Delete(opts ...DBOption) error Get(opts ...DBOption) (model.Command, error) WithLikeName(name string) DBOption + + PageRedis(limit, offset int, opts ...DBOption) (int64, []model.RedisCommand, error) + GetRedis(opts ...DBOption) (model.RedisCommand, error) + GetRedisList(opts ...DBOption) ([]model.RedisCommand, error) + CreateRedis(command *model.RedisCommand) error + DeleteRedis(opts ...DBOption) error } func NewICommandRepo() ICommandRepo { @@ -33,6 +39,16 @@ func (u *CommandRepo) Get(opts ...DBOption) (model.Command, error) { return command, err } +func (u *CommandRepo) GetRedis(opts ...DBOption) (model.RedisCommand, error) { + var command model.RedisCommand + db := global.DB + for _, opt := range opts { + db = opt(db) + } + err := db.First(&command).Error + return command, err +} + func (u *CommandRepo) Page(page, size int, opts ...DBOption) (int64, []model.Command, error) { var users []model.Command db := global.DB.Model(&model.Command{}) @@ -45,6 +61,18 @@ func (u *CommandRepo) Page(page, size int, opts ...DBOption) (int64, []model.Com return count, users, err } +func (u *CommandRepo) PageRedis(page, size int, opts ...DBOption) (int64, []model.RedisCommand, error) { + var users []model.RedisCommand + db := global.DB.Model(&model.RedisCommand{}) + for _, opt := range opts { + db = opt(db) + } + count := int64(0) + db = db.Count(&count) + err := db.Limit(size).Offset(size * (page - 1)).Find(&users).Error + return count, users, err +} + func (u *CommandRepo) GetList(opts ...DBOption) ([]model.Command, error) { var commands []model.Command db := global.DB.Model(&model.Command{}) @@ -55,6 +83,16 @@ func (u *CommandRepo) GetList(opts ...DBOption) ([]model.Command, error) { return commands, err } +func (u *CommandRepo) GetRedisList(opts ...DBOption) ([]model.RedisCommand, error) { + var commands []model.RedisCommand + db := global.DB.Model(&model.RedisCommand{}) + for _, opt := range opts { + db = opt(db) + } + err := db.Find(&commands).Error + return commands, err +} + func (c *CommandRepo) WithByInfo(info string) DBOption { return func(g *gorm.DB) *gorm.DB { if len(info) == 0 { @@ -69,6 +107,10 @@ func (u *CommandRepo) Create(command *model.Command) error { return global.DB.Create(command).Error } +func (u *CommandRepo) CreateRedis(command *model.RedisCommand) error { + return global.DB.Create(command).Error +} + func (u *CommandRepo) Update(id uint, vars map[string]interface{}) error { return global.DB.Model(&model.Command{}).Where("id = ?", id).Updates(vars).Error } @@ -81,6 +123,14 @@ func (u *CommandRepo) Delete(opts ...DBOption) error { return db.Delete(&model.Command{}).Error } +func (u *CommandRepo) DeleteRedis(opts ...DBOption) error { + db := global.DB + for _, opt := range opts { + db = opt(db) + } + return db.Delete(&model.RedisCommand{}).Error +} + func (a CommandRepo) WithLikeName(name string) DBOption { return func(g *gorm.DB) *gorm.DB { if len(name) == 0 { diff --git a/backend/app/service/command.go b/backend/app/service/command.go index 67f5c656b..d8dafd8fe 100644 --- a/backend/app/service/command.go +++ b/backend/app/service/command.go @@ -16,6 +16,11 @@ type ICommandService interface { Create(commandDto dto.CommandOperate) error Update(id uint, upMap map[string]interface{}) error Delete(ids []uint) error + + SearchRedisCommandWithPage(search dto.SearchWithPage) (int64, interface{}, error) + ListRedisCommand() ([]dto.RedisCommand, error) + CreateRedisCommand(commandDto dto.RedisCommand) error + DeleteRedisCommand(ids []uint) error } func NewICommandService() ICommandService { @@ -115,3 +120,60 @@ func (u *CommandService) Delete(ids []uint) error { func (u *CommandService) Update(id uint, upMap map[string]interface{}) error { return commandRepo.Update(id, upMap) } + +func (u *CommandService) SearchRedisCommandWithPage(search dto.SearchWithPage) (int64, interface{}, error) { + total, commands, err := commandRepo.PageRedis(search.Page, search.PageSize, commandRepo.WithLikeName(search.Info)) + if err != nil { + return 0, nil, err + } + var dtoCommands []dto.RedisCommand + for _, command := range commands { + var item dto.RedisCommand + if err := copier.Copy(&item, &command); err != nil { + return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error()) + } + dtoCommands = append(dtoCommands, item) + } + return total, dtoCommands, err +} + +func (u *CommandService) ListRedisCommand() ([]dto.RedisCommand, error) { + commands, err := commandRepo.GetRedisList() + if err != nil { + return nil, constant.ErrRecordNotFound + } + var dtoCommands []dto.RedisCommand + for _, command := range commands { + var item dto.RedisCommand + if err := copier.Copy(&item, &command); err != nil { + return nil, errors.WithMessage(constant.ErrStructTransform, err.Error()) + } + dtoCommands = append(dtoCommands, item) + } + return dtoCommands, err +} + +func (u *CommandService) CreateRedisCommand(commandDto dto.RedisCommand) error { + command, _ := commandRepo.GetRedis(commonRepo.WithByName(commandDto.Name)) + if command.ID != 0 { + return constant.ErrRecordExist + } + if err := copier.Copy(&command, &commandDto); err != nil { + return errors.WithMessage(constant.ErrStructTransform, err.Error()) + } + if err := commandRepo.CreateRedis(&command); err != nil { + return err + } + return nil +} + +func (u *CommandService) DeleteRedisCommand(ids []uint) error { + if len(ids) == 1 { + command, _ := commandRepo.GetRedis(commonRepo.WithByID(ids[0])) + if command.ID == 0 { + return constant.ErrRecordNotFound + } + return commandRepo.DeleteRedis(commonRepo.WithByID(ids[0])) + } + return commandRepo.DeleteRedis(commonRepo.WithIdsIn(ids)) +} diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index 45468d033..1eedb99d1 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -84,6 +84,7 @@ func Init() { migrations.AddDeveloperSetting, migrations.AddWebsiteSSLColumn, + migrations.AddRedisCommand, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/v_1_10.go b/backend/init/migration/migrations/v_1_10.go index 4562d4941..9bc525f64 100644 --- a/backend/init/migration/migrations/v_1_10.go +++ b/backend/init/migration/migrations/v_1_10.go @@ -164,3 +164,13 @@ var AddWebsiteSSLColumn = &gormigrate.Migration{ return nil }, } + +var AddRedisCommand = &gormigrate.Migration{ + ID: "20240515-add-redis-command", + Migrate: func(tx *gorm.DB) error { + if err := tx.AutoMigrate(&model.RedisCommand{}); err != nil { + return err + } + return nil + }, +} diff --git a/backend/router/ro_host.go b/backend/router/ro_host.go index 6b0159620..fb34f9357 100644 --- a/backend/router/ro_host.go +++ b/backend/router/ro_host.go @@ -56,6 +56,11 @@ func (s *HostRouter) InitRouter(Router *gin.RouterGroup) { hostRouter.GET("/command/tree", baseApi.SearchCommandTree) hostRouter.POST("/command/update", baseApi.UpdateCommand) + hostRouter.GET("/command/redis", baseApi.ListRedisCommand) + hostRouter.POST("/command/redis", baseApi.CreateRedisCommand) + hostRouter.POST("/command/redis/search", baseApi.SearchRedisCommand) + hostRouter.POST("/command/redis/del", baseApi.DeleteRedisCommand) + hostRouter.POST("/tool", baseApi.GetToolStatus) hostRouter.POST("/tool/init", baseApi.InitToolConfig) hostRouter.POST("/tool/operate", baseApi.OperateTool) diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index ad4f4ddc6..99dd6905b 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -7647,6 +7647,156 @@ const docTemplate = `{ } } }, + "/hosts/command/redis": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "获取 redis 快速命令列表", + "tags": [ + "Redis Command" + ], + "summary": "List redis commands", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "Array" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "创建 Redis 快速命令", + "consumes": [ + "application/json" + ], + "tags": [ + "Redis Command" + ], + "summary": "Create redis command", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.RedisCommand" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [], + "bodyKeys": [ + "name", + "command" + ], + "formatEN": "create quick command for redis [name][command]", + "formatZH": "创建 redis 快捷命令 [name][command]", + "paramKeys": [] + } + } + }, + "/hosts/command/redis/del": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "删除 redis 快速命令", + "consumes": [ + "application/json" + ], + "tags": [ + "Redis Command" + ], + "summary": "Delete redis command", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.BatchDeleteReq" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [ + { + "db": "redis_commands", + "input_column": "id", + "input_value": "ids", + "isList": true, + "output_column": "name", + "output_value": "names" + } + ], + "bodyKeys": [ + "ids" + ], + "formatEN": "delete quick command of redis [names]", + "formatZH": "删除 redis 快捷命令 [names]", + "paramKeys": [] + } + } + }, + "/hosts/command/redis/search": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "获取 redis 快速命令列表分页", + "consumes": [ + "application/json" + ], + "tags": [ + "Redis Command" + ], + "summary": "Page redis commands", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.SearchWithPage" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.PageResult" + } + } + } + } + }, "/hosts/command/search": { "post": { "security": [ @@ -17324,6 +17474,20 @@ const docTemplate = `{ } } }, + "dto.RedisCommand": { + "type": "object", + "properties": { + "command": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "dto.RedisConf": { "type": "object", "required": [ diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index f4f21730a..2180943b8 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -7640,6 +7640,156 @@ } } }, + "/hosts/command/redis": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "获取 redis 快速命令列表", + "tags": [ + "Redis Command" + ], + "summary": "List redis commands", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "Array" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "创建 Redis 快速命令", + "consumes": [ + "application/json" + ], + "tags": [ + "Redis Command" + ], + "summary": "Create redis command", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.RedisCommand" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [], + "bodyKeys": [ + "name", + "command" + ], + "formatEN": "create quick command for redis [name][command]", + "formatZH": "创建 redis 快捷命令 [name][command]", + "paramKeys": [] + } + } + }, + "/hosts/command/redis/del": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "删除 redis 快速命令", + "consumes": [ + "application/json" + ], + "tags": [ + "Redis Command" + ], + "summary": "Delete redis command", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.BatchDeleteReq" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [ + { + "db": "redis_commands", + "input_column": "id", + "input_value": "ids", + "isList": true, + "output_column": "name", + "output_value": "names" + } + ], + "bodyKeys": [ + "ids" + ], + "formatEN": "delete quick command of redis [names]", + "formatZH": "删除 redis 快捷命令 [names]", + "paramKeys": [] + } + } + }, + "/hosts/command/redis/search": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "获取 redis 快速命令列表分页", + "consumes": [ + "application/json" + ], + "tags": [ + "Redis Command" + ], + "summary": "Page redis commands", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/dto.SearchWithPage" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.PageResult" + } + } + } + } + }, "/hosts/command/search": { "post": { "security": [ @@ -17317,6 +17467,20 @@ } } }, + "dto.RedisCommand": { + "type": "object", + "properties": { + "command": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "dto.RedisConf": { "type": "object", "required": [ diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index c64f47278..dacdd34b5 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -2225,6 +2225,15 @@ definitions: - page - pageSize type: object + dto.RedisCommand: + properties: + command: + type: string + id: + type: integer + name: + type: string + type: object dto.RedisConf: properties: containerName: @@ -9958,6 +9967,101 @@ paths: formatEN: delete quick command [names] formatZH: 删除快捷命令 [names] paramKeys: [] + /hosts/command/redis: + get: + description: 获取 redis 快速命令列表 + responses: + "200": + description: OK + schema: + type: Array + security: + - ApiKeyAuth: [] + summary: List redis commands + tags: + - Redis Command + post: + consumes: + - application/json + description: 创建 Redis 快速命令 + parameters: + - description: request + in: body + name: request + required: true + schema: + $ref: '#/definitions/dto.RedisCommand' + responses: + "200": + description: OK + security: + - ApiKeyAuth: [] + summary: Create redis command + tags: + - Redis Command + x-panel-log: + BeforeFunctions: [] + bodyKeys: + - name + - command + formatEN: create quick command for redis [name][command] + formatZH: 创建 redis 快捷命令 [name][command] + paramKeys: [] + /hosts/command/redis/del: + post: + consumes: + - application/json + description: 删除 redis 快速命令 + parameters: + - description: request + in: body + name: request + required: true + schema: + $ref: '#/definitions/dto.BatchDeleteReq' + responses: + "200": + description: OK + security: + - ApiKeyAuth: [] + summary: Delete redis command + tags: + - Redis Command + x-panel-log: + BeforeFunctions: + - db: redis_commands + input_column: id + input_value: ids + isList: true + output_column: name + output_value: names + bodyKeys: + - ids + formatEN: delete quick command of redis [names] + formatZH: 删除 redis 快捷命令 [names] + paramKeys: [] + /hosts/command/redis/search: + post: + consumes: + - application/json + description: 获取 redis 快速命令列表分页 + parameters: + - description: request + in: body + name: request + required: true + schema: + $ref: '#/definitions/dto.SearchWithPage' + responses: + "200": + description: OK + schema: + $ref: '#/definitions/dto.PageResult' + security: + - ApiKeyAuth: [] + summary: Page redis commands + tags: + - Redis Command /hosts/command/search: post: consumes: diff --git a/frontend/src/api/interface/command.ts b/frontend/src/api/interface/command.ts index b59757320..fb81dc181 100644 --- a/frontend/src/api/interface/command.ts +++ b/frontend/src/api/interface/command.ts @@ -11,4 +11,9 @@ export namespace Command { groupID: number; command: string; } + export interface RedisCommand { + id: number; + name: string; + command: string; + } } diff --git a/frontend/src/api/modules/host.ts b/frontend/src/api/modules/host.ts index 6bdb6963b..768d1fe18 100644 --- a/frontend/src/api/modules/host.ts +++ b/frontend/src/api/modules/host.ts @@ -72,6 +72,19 @@ export const deleteCommand = (params: { ids: number[] }) => { return http.post(`/hosts/command/del`, params); }; +export const getRedisCommandList = () => { + return http.get>(`/hosts/command/redis`, {}); +}; +export const getRedisCommandPage = (params: SearchWithPage) => { + return http.post>(`/hosts/command/redis/search`, params); +}; +export const addRedisCommand = (params: Command.RedisCommand) => { + return http.post(`/hosts/command/redis`, params); +}; +export const deleteRedisCommand = (params: { ids: number[] }) => { + return http.post(`/hosts/command/redis/del`, params); +}; + // firewall export const loadFireBaseInfo = () => { return http.get(`/hosts/firewall/base`); diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 75ae02050..73d25433c 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -515,6 +515,7 @@ const message = { hit: 'Find the database key hit ratio', latestForkUsec: 'The number of microseconds spent on the last fork() operation', redisCliHelper: 'redis-cli service not detected, please enable the service first!', + redisQuickCmd: 'Redis quick command', recoverHelper: 'Data is about to be overwritten with [{0}]. Do you want to continue?', submitIt: 'Overwrite the data', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 029175fce..c00b0457a 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -503,6 +503,7 @@ const message = { hit: '查找數據庫鍵命中率', latestForkUsec: '最近一次 fork() 操作耗費的微秒數', redisCliHelper: '未檢測到 redis-cli 服務,請先啟用服務!', + redisQuickCmd: 'Redis 快速命令', recoverHelper: '即將使用 [{0}] 對數據進行覆蓋,是否繼續?', submitIt: '覆蓋數據', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 6a4f9f7c7..0114ea2c7 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -503,6 +503,7 @@ const message = { hit: '查找数据库键命中率', latestForkUsec: '最近一次 fork() 操作耗费的微秒数', redisCliHelper: '未检测到 redis-cli 服务,请先启用服务!', + redisQuickCmd: 'Redis 快速命令', recoverHelper: '即将使用 [{0}] 对数据进行覆盖,是否继续?', submitIt: '覆盖数据', diff --git a/frontend/src/views/database/redis/command/index.vue b/frontend/src/views/database/redis/command/index.vue new file mode 100644 index 000000000..ddf2a1660 --- /dev/null +++ b/frontend/src/views/database/redis/command/index.vue @@ -0,0 +1,164 @@ + + + diff --git a/frontend/src/views/database/redis/index.vue b/frontend/src/views/database/redis/index.vue index 383ee76d9..3f3adcd33 100644 --- a/frontend/src/views/database/redis/index.vue +++ b/frontend/src/views/database/redis/index.vue @@ -8,7 +8,7 @@ - + - +
+ + + + {{ $t('commons.button.enable') }} + + +
+ + + + + + {{ $t('commons.button.set') }} + +
+
+ + @@ -116,6 +127,7 @@ import Password from '@/views/database/redis/password/index.vue'; import Terminal from '@/components/terminal/index.vue'; import AppStatus from '@/components/app-status/index.vue'; import PortJumpDialog from '@/components/port-jump/index.vue'; +import QuickCmd from '@/views/database/redis/command/index.vue'; import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue'; import { CheckAppInstalled, GetAppPort } from '@/api/modules/app'; import router from '@/routers'; @@ -124,6 +136,7 @@ import { listDatabases, checkRedisCli, installRedisCli } from '@/api/modules/dat import { Database } from '@/api/interface/database'; import { MsgSuccess } from '@/utils/message'; import i18n from '@/lang'; +import { getRedisCommandList } from '@/api/modules/host'; const globalStore = GlobalStore(); const loading = ref(false); @@ -148,6 +161,10 @@ const dbOptionsRemote = ref>([]); const currentDB = ref(); const currentDBName = ref(); +const quickCmd = ref(); +const quickCmdList = ref([]); +const dialogQuickCmdRef = ref(); + const dialogPortJumpRef = ref(); const isRefresh = ref(); @@ -160,7 +177,7 @@ const onSetting = async () => { }; const loadHeight = () => { - return globalStore.openMenuTabs ? '470px' : '440px'; + return globalStore.openMenuTabs ? '470px' : '380px'; }; const goDashboard = async () => { @@ -288,7 +305,6 @@ const initTerminal = async () => { .then((res) => { redisIsExist.value = res.data.isExist; redisStatus.value = res.data.status; - console.log(redisStatus.value); loading.value = false; nextTick(() => { if (res.data.status === 'Running') { @@ -331,8 +347,24 @@ const installCli = async () => { }); }; +const loadQuickCmd = async () => { + const res = await getRedisCommandList(); + quickCmdList.value = res.data || []; +}; + +const quickInput = (val: any) => { + if (val) { + terminalRef.value?.sendMsg(val + '\n'); + } +}; + +const onSetQuickCmd = () => { + dialogQuickCmdRef.value.acceptParams(); +}; + onMounted(() => { loadDBOptions(); + loadQuickCmd(); loadDashboardPort(); checkCliValid(); });