From c639d6359e338b49d02ee2c0ce649048bb8c5983 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Sat, 7 Jan 2023 17:14:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=B7=A5=E5=85=B7=E8=B7=A8?= =?UTF-8?q?=E6=9C=8D=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/v2/lib/storage/config.go | 39 ++++++++++------- cmd/v2/ui/mainwindow.go | 80 +++++++++++++++++++++++++++++++---- modules/user/model_session.go | 2 +- 3 files changed, 97 insertions(+), 24 deletions(-) diff --git a/cmd/v2/lib/storage/config.go b/cmd/v2/lib/storage/config.go index d9f83c29a..d811d7f34 100644 --- a/cmd/v2/lib/storage/config.go +++ b/cmd/v2/lib/storage/config.go @@ -8,19 +8,22 @@ func newDefaultConfig() *Config { Concurrency: 10, DurationS: 5, }, - UserCount: 100, + UserCount: 100, + UpgradeUrl: "http://10.0.0.9:8080/", } } type Config struct { - Pressure PressureConfig `json:"Pressure,omitempty"` - UserCount int32 `json:"UserCount,omitempty"` //用户数 - SId string `json:"sid,omitempty"` //区服ID - WsAddr string `json:"wsAddr,omitempty"` //websocket addr - IntervalS int32 `json:"intervalS,omitempty"` //间隔时间s - LubanConf *LubanConfig `json:"lubanConf,omitempty"` //luban工具配置 - PbConf *ProtobufConfig `json:"pbConf,omitempty"` //Pb配置 - SyncConf *SyncConfig `json:"syncConf,omitempty"` //同步配置 + Pressure PressureConfig `json:"Pressure,omitempty"` + UserCount int32 `json:"UserCount,omitempty"` //用户数 + SId string `json:"sid,omitempty"` //区服ID + WsAddr string `json:"wsAddr,omitempty"` //websocket addr + IntervalS int32 `json:"intervalS,omitempty"` //间隔时间s + LubanConf *LubanConfig `json:"lubanConf,omitempty"` //luban工具配置 + PbConf *ProtobufConfig `json:"pbConf,omitempty"` //Pb配置 + SyncConf *SyncConfig `json:"syncConf,omitempty"` //同步配置 + UpgradeUrl string `json:"upgradeUrl,omitempty"` //升级服务 + Servers []*ServerConfig `json:"servers,omitempty"` //区服配置 } //压测配置 @@ -55,14 +58,20 @@ type SyncConfig struct { Password string LocalDir string RemoteDir string - - ServerIp string - WorkDir string - LubanCli string - DataDir string - JsonDir string + + ServerIp string + WorkDir string + LubanCli string + DataDir string + JsonDir string SaveDir string //保存目录 LogDir string //远程日志目录 Editor string //编辑器 } + +type ServerConfig struct { + SId string + Name string + Url string +} diff --git a/cmd/v2/ui/mainwindow.go b/cmd/v2/ui/mainwindow.go index bc6dd78df..a10135256 100644 --- a/cmd/v2/ui/mainwindow.go +++ b/cmd/v2/ui/mainwindow.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" "go_dreamfactory/cmd/v2/lib/common" - "go_dreamfactory/cmd/v2/service" + "go_dreamfactory/cmd/v2/lib/storage" "go_dreamfactory/cmd/v2/service/observer" "go_dreamfactory/comm" "go_dreamfactory/modules/user" @@ -158,11 +158,43 @@ func (ui *MainWindowImpl) createChooseServerPopUp(w fyne.Window) error { return nil } +func (ui *MainWindowImpl) configForm(w fyne.Window, call func()) *widget.Form { + //区服编号 + sId := widget.NewEntry() + //区服地址 + sAddr := widget.NewEntry() + //区服名称 + sName := widget.NewEntry() + configForm := widget.NewForm() + configForm.AppendItem(widget.NewFormItem("区服编号", sId)) + configForm.AppendItem(widget.NewFormItem("区服地址", sAddr)) + configForm.AppendItem(widget.NewFormItem("区服名称", sName)) + + configForm.OnSubmit = func() { + defer func() { + w.Close() + call() + }() + ui.config.Servers = append(ui.config.Servers, &storage.ServerConfig{ + Name: sName.Text, + SId: sId.Text, + Url: sAddr.Text, + }) + if err := ui.storage.StoreConfig(ui.config); err != nil { + dialog.ShowError(err, w) + return + } + } + configForm.SubmitText = "保存配置" + configForm.Refresh() + return configForm +} + // createChooseServerWindow func (ui *MainWindowImpl) createChooseServerWindow(title string, ch chan string) fyne.Window { w := fyne.CurrentApp().NewWindow(title) // choose server button func - makeButton := func(s *service.ServiceConf, parent fyne.Window) *widget.Button { + makeButton := func(s *storage.ServerConfig, parent fyne.Window) *widget.Button { btn := widget.NewButton(s.Name, func() { d := dialog.NewInformation("", common.INFO_WAIT, parent) d.SetDismissText(common.BUTTON_CANCEL) @@ -181,15 +213,47 @@ func (ui *MainWindowImpl) createChooseServerWindow(title string, ch chan string) } sGrid := container.NewGridWithColumns(2) - config := ui.configService.GetConfig() - if config != nil { - for _, s := range config.Services { - box := makeButton(s.Service, w) - sGrid.Add(box) + servers := ui.config.Servers + if len(servers) != 0 { + for _, s := range servers { + box := makeButton(s, w) + sGrid.Add(container.NewBorder(nil, nil, nil, widget.NewButtonWithIcon("", theme.DeleteIcon(), func() { + defer func() { + w.Close() + ui.parent.Show() + }() + txt := box.Text + for i, ss := range servers { + if txt == ss.Name { + ui.config.Servers = append(ui.config.Servers[:i], ui.config.Servers[i+1:]...) + i-- + } + } + if err := ui.storage.StoreConfig(ui.config); err != nil { + dialog.ShowError(err, w) + } + + }), box)) } + sGrid.Add(widget.NewButtonWithIcon("", theme.ContentAddIcon(), func() { + addWin := fyne.CurrentApp().NewWindow("添加区服") + addWin.SetContent(ui.configForm(addWin, func() { + w.Close() + ui.parent.Show() + })) + addWin.SetFixedSize(true) + addWin.Resize(fyne.NewSize(500, 200)) + addWin.Show() + addWin.CenterOnScreen() + })) + w.SetContent(sGrid) + } else { + w.SetContent(ui.configForm(w, func() { + w.Close() + ui.parent.Show() + })) } - w.SetContent(sGrid) w.SetFixedSize(true) w.Resize(fyne.NewSize(500, 200)) w.Show() diff --git a/modules/user/model_session.go b/modules/user/model_session.go index aba4bbab4..4f17209e6 100644 --- a/modules/user/model_session.go +++ b/modules/user/model_session.go @@ -52,7 +52,7 @@ func (this *ModelSession) addUserSession(uid string, session comm.IUserSession) "gatewayServiceId": session.GetGatewayServiceId(), "ip": session.GetIP(), }, db.SetDBMgoLog(false)); err != nil { - log.Debugf("setUserSession err:%v", err) + log.Debug("setUserSession err:%v", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err}) return } return