From cfe4fa7a92eece22575f96f6ef9b5df1d4c7d63d Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:46:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=BB=88=E7=AB=AF?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=85=8D=E7=BD=AE=20(#6208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/app/api/v2/setting.go | 37 +++ core/app/dto/setting.go | 10 + core/app/service/setting.go | 47 ++++ core/init/migration/migrate.go | 1 + core/init/migration/migrations/init.go | 28 ++ core/router/ro_setting.go | 2 + frontend/src/api/interface/setting.ts | 9 + frontend/src/api/modules/setting.ts | 6 + frontend/src/components/terminal/index.vue | 52 ++-- frontend/src/lang/modules/en.ts | 14 +- frontend/src/lang/modules/tw.ts | 14 +- frontend/src/lang/modules/zh.ts | 14 +- frontend/src/store/index.ts | 3 +- frontend/src/store/interface/index.ts | 10 + frontend/src/store/modules/terminal.ts | 42 +++ .../views/setting/backup-account/index.vue | 2 +- .../setting/backup-account/operate/index.vue | 2 +- frontend/src/views/terminal/index.vue | 27 ++ frontend/src/views/terminal/setting/index.vue | 241 ++++++++++++++++++ 19 files changed, 533 insertions(+), 28 deletions(-) create mode 100644 frontend/src/store/modules/terminal.ts create mode 100644 frontend/src/views/terminal/setting/index.vue diff --git a/core/app/api/v2/setting.go b/core/app/api/v2/setting.go index d1286b42b..a3b8c09db 100644 --- a/core/app/api/v2/setting.go +++ b/core/app/api/v2/setting.go @@ -29,6 +29,21 @@ func (b *BaseApi) GetSettingInfo(c *gin.Context) { helper.SuccessWithData(c, setting) } +// @Tags System Setting +// @Summary Load system terminal setting info +// @Description 加载系统终端配置信息 +// @Success 200 {object} dto.TerminalInfo +// @Security ApiKeyAuth +// @Router /core/settings/terminal/search [post] +func (b *BaseApi) GetTerminalSettingInfo(c *gin.Context) { + setting, err := settingService.GetTerminalInfo() + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, setting) +} + // @Tags System Setting // @Summary Load system available status // @Description 获取系统可用状态 @@ -61,6 +76,28 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) { helper.SuccessWithData(c, nil) } +// @Tags System Setting +// @Summary Update system terminal setting +// @Description 更新系统终端配置 +// @Accept json +// @Param request body dto.TerminalInfo true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Router /core/settings/terminal/update [post] +// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"修改系统终端配置","formatEN":"update system terminal setting"} +func (b *BaseApi) UpdateTerminalSetting(c *gin.Context) { + var req dto.TerminalInfo + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + + if err := settingService.UpdateTerminal(req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} + // @Tags System Setting // @Summary Update proxy setting // @Description 服务器代理配置 diff --git a/core/app/dto/setting.go b/core/app/dto/setting.go index d115135c4..98c76c203 100644 --- a/core/app/dto/setting.go +++ b/core/app/dto/setting.go @@ -196,3 +196,13 @@ type XpackHideMenu struct { Path string `json:"path,omitempty"` Children []XpackHideMenu `json:"children,omitempty"` } + +type TerminalInfo struct { + LineHeight string `json:"lineHeight"` + LetterSpacing string `json:"letterSpacing"` + FontSize string `json:"fontSize"` + CursorBlink string `json:"cursorBlink"` + CursorStyle string `json:"cursorStyle"` + Scrollback string `json:"scrollback"` + ScrollSensitivity string `json:"scrollSensitivity"` +} diff --git a/core/app/service/setting.go b/core/app/service/setting.go index 0523a0524..b5ddc2c55 100644 --- a/core/app/service/setting.go +++ b/core/app/service/setting.go @@ -36,6 +36,9 @@ type ISettingService interface { UpdateSSL(c *gin.Context, req dto.SSLUpdate) error LoadFromCert() (*dto.SSLInfo, error) HandlePasswordExpired(c *gin.Context, old, new string) error + + GetTerminalInfo() (*dto.TerminalInfo, error) + UpdateTerminal(req dto.TerminalInfo) error } func NewISettingService() ISettingService { @@ -338,6 +341,50 @@ func (u *SettingService) HandlePasswordExpired(c *gin.Context, old, new string) return constant.ErrInitialPassword } +func (u *SettingService) GetTerminalInfo() (*dto.TerminalInfo, error) { + setting, err := settingRepo.List() + if err != nil { + return nil, constant.ErrRecordNotFound + } + settingMap := make(map[string]string) + for _, set := range setting { + settingMap[set.Key] = set.Value + } + var info dto.TerminalInfo + arr, err := json.Marshal(settingMap) + if err != nil { + return nil, err + } + if err := json.Unmarshal(arr, &info); err != nil { + return nil, err + } + return &info, err +} +func (u *SettingService) UpdateTerminal(req dto.TerminalInfo) error { + if err := settingRepo.Update("LineHeight", req.LineHeight); err != nil { + return err + } + if err := settingRepo.Update("LetterSpacing", req.LetterSpacing); err != nil { + return err + } + if err := settingRepo.Update("FontSize", req.FontSize); err != nil { + return err + } + if err := settingRepo.Update("CursorBlink", req.CursorBlink); err != nil { + return err + } + if err := settingRepo.Update("CursorStyle", req.CursorStyle); err != nil { + return err + } + if err := settingRepo.Update("Scrollback", req.Scrollback); err != nil { + return err + } + if err := settingRepo.Update("ScrollSensitivity", req.ScrollSensitivity); err != nil { + return err + } + return nil +} + func (u *SettingService) UpdatePassword(c *gin.Context, old, new string) error { if err := u.HandlePasswordExpired(c, old, new); err != nil { return err diff --git a/core/init/migration/migrate.go b/core/init/migration/migrate.go index 8b76f7e9f..a7f453453 100644 --- a/core/init/migration/migrate.go +++ b/core/init/migration/migrate.go @@ -14,6 +14,7 @@ func Init() { migrations.InitOneDrive, migrations.InitMasterAddr, migrations.InitHost, + migrations.InitTerminalSetting, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/core/init/migration/migrations/init.go b/core/init/migration/migrations/init.go index d36af12a0..c8d8eebb2 100644 --- a/core/init/migration/migrations/init.go +++ b/core/init/migration/migrations/init.go @@ -205,3 +205,31 @@ var InitMasterAddr = &gormigrate.Migration{ return nil }, } + +var InitTerminalSetting = &gormigrate.Migration{ + ID: "20240814-init-terminal-setting", + Migrate: func(tx *gorm.DB) error { + if err := tx.Create(&model.Setting{Key: "LineHeight", Value: "1.2"}).Error; err != nil { + return err + } + if err := tx.Create(&model.Setting{Key: "LetterSpacing", Value: "0"}).Error; err != nil { + return err + } + if err := tx.Create(&model.Setting{Key: "FontSize", Value: "12"}).Error; err != nil { + return err + } + if err := tx.Create(&model.Setting{Key: "CursorBlink", Value: "enable"}).Error; err != nil { + return err + } + if err := tx.Create(&model.Setting{Key: "CursorStyle", Value: "block"}).Error; err != nil { + return err + } + if err := tx.Create(&model.Setting{Key: "Scrollback", Value: "1000"}).Error; err != nil { + return err + } + if err := tx.Create(&model.Setting{Key: "ScrollSensitivity", Value: "6"}).Error; err != nil { + return err + } + return nil + }, +} diff --git a/core/router/ro_setting.go b/core/router/ro_setting.go index 0b53931f5..55cd17f22 100644 --- a/core/router/ro_setting.go +++ b/core/router/ro_setting.go @@ -12,9 +12,11 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) { baseApi := v2.ApiGroupApp.BaseApi { settingRouter.POST("/search", baseApi.GetSettingInfo) + settingRouter.POST("/terminal/search", baseApi.GetTerminalSettingInfo) settingRouter.POST("/expired/handle", baseApi.HandlePasswordExpired) settingRouter.GET("/search/available", baseApi.GetSystemAvailable) settingRouter.POST("/update", baseApi.UpdateSetting) + settingRouter.POST("/terminal/update", baseApi.UpdateTerminalSetting) settingRouter.GET("/interface", baseApi.LoadInterfaceAddr) settingRouter.POST("/menu/update", baseApi.UpdateMenu) settingRouter.POST("/proxy/update", baseApi.UpdateProxy) diff --git a/frontend/src/api/interface/setting.ts b/frontend/src/api/interface/setting.ts index 8c163067d..e358879a7 100644 --- a/frontend/src/api/interface/setting.ts +++ b/frontend/src/api/interface/setting.ts @@ -59,6 +59,15 @@ export namespace Setting { proxyPasswd: string; proxyPasswdKeep: string; } + export interface TerminalInfo { + lineHeight: string; + letterSpacing: string; + fontSize: string; + cursorBlink: string; + cursorStyle: string; + scrollback: string; + scrollSensitivity: string; + } export interface SettingUpdate { key: string; value: string; diff --git a/frontend/src/api/modules/setting.ts b/frontend/src/api/modules/setting.ts index 298b65a7d..abd3b0e7e 100644 --- a/frontend/src/api/modules/setting.ts +++ b/frontend/src/api/modules/setting.ts @@ -33,6 +33,12 @@ export const loadDaemonJsonPath = () => { export const getSettingInfo = () => { return http.post(`/core/settings/search`); }; +export const getTerminalInfo = () => { + return http.post(`/core/settings/terminal/search`); +}; +export const UpdateTerminalInfo = (param: Setting.TerminalInfo) => { + return http.post(`/core/settings/terminal/update`, param); +}; export const getSystemAvailable = () => { return http.get(`/settings/search/available`); }; diff --git a/frontend/src/components/terminal/index.vue b/frontend/src/components/terminal/index.vue index 653ef9f3a..8137f3664 100644 --- a/frontend/src/components/terminal/index.vue +++ b/frontend/src/components/terminal/index.vue @@ -1,5 +1,5 @@ + +