package ui import ( "go_dreamfactory/cmd/v2/lib/common" "go_dreamfactory/cmd/v2/lib/storage" "go_dreamfactory/cmd/v2/service" "go_dreamfactory/cmd/v2/service/observer" "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" "github.com/sirupsen/logrus" "github.com/spf13/cast" ) type perfConf struct { appAdapter obs observer.Observer conf *storage.Config } func (app *perfConf) LazyInit(ptService service.PttService, obs observer.Observer) error { app.obs = obs app.conf = perfWin.UIImpl.config app.tabItem = container.NewTabItemWithIcon(common.TOOLBAR_PERF_CONF, theme.ContentCopyIcon(), nil) content := container.NewMax() content.Objects = []fyne.CanvasObject{} // 压测form wsAddrEntry := widget.NewEntry() wsAddrEntry.PlaceHolder = "服务地址" wsAddrEntry.Text = app.conf.WsAddr timeoutEntry := widget.NewEntry() timeoutEntry.PlaceHolder = "毫秒数" timeoutEntry.Text = cast.ToString(app.conf.Pressure.TimeoutMs) lpsEntry := widget.NewEntry() lpsEntry.PlaceHolder = "并发数量" lpsEntry.Text = cast.ToString(app.conf.Pressure.Concurrency) durationEntry := widget.NewEntry() durationEntry.PlaceHolder = "秒数" durationEntry.Text = cast.ToString(app.conf.Pressure.DurationS) userCountEntry := widget.NewEntry() userCountEntry.PlaceHolder = "自动创建的用户数" userCountEntry.Text = cast.ToString(app.conf.UserCount) sidEntry := widget.NewEntry() sidEntry.PlaceHolder = "区服ID" sidEntry.Text = app.conf.SId intervalEntry := widget.NewEntry() intervalEntry.PlaceHolder = "间隔时间(s)" intervalEntry.Text = cast.ToString(app.conf.IntervalS) form := widget.NewForm( widget.NewFormItem("服务地址", wsAddrEntry), widget.NewFormItem("区服", sidEntry), widget.NewFormItem("用户数", userCountEntry), widget.NewFormItem("超时(ms)", timeoutEntry), widget.NewFormItem("并发量", lpsEntry), widget.NewFormItem("持续时间(s)", durationEntry), widget.NewFormItem("间隔时间(s)", intervalEntry), ) // btn nextBtn := widget.NewButtonWithIcon("下一步", theme.NavigateNextIcon(), nil) nextBtn.OnTapped = func() { //校验表单数据 if wsAddrEntry.Text == "" { common.ShowTip("服务地址必填") return } if sidEntry.Text == "" { common.ShowTip("区服ID必填") return } if timeoutEntry.Text == "" { common.ShowTip("超时时间必填") return } if lpsEntry.Text == "" { common.ShowTip("并发数必填") return } if durationEntry.Text == "" { common.ShowTip("持续时间") return } if userCountEntry.Text == "" { common.ShowTip("用户数至少是1") return } pressure := app.conf.Pressure pressure.TimeoutMs = cast.ToInt32(timeoutEntry.Text) pressure.Concurrency = cast.ToInt32(lpsEntry.Text) pressure.DurationS = cast.ToInt32(durationEntry.Text) app.conf.Pressure = pressure app.conf.UserCount = cast.ToInt32(userCountEntry.Text) app.conf.WsAddr = wsAddrEntry.Text app.conf.SId = sidEntry.Text if err := perfWin.UIImpl.storage.StoreConfig(app.conf); err != nil { logrus.Error(err) } //next defer closeApp3(perfWin.tabs, common.TOOLBAR_PERF_CONF) openApp3(perfWin.tabs, common.TOOLBAR_PERF_CHOOSE) } resetBtn := widget.NewButtonWithIcon("重置", theme.ContentRedoIcon(), nil) resetBtn.OnTapped = func() { timeoutEntry.Text = "" lpsEntry.Text = "" durationEntry.Text = "" userCountEntry.Text = "" wsAddrEntry.Text = "" sidEntry.Text = "" form.Refresh() } preBtn := widget.NewButtonWithIcon("上一步", theme.NavigateBackIcon(), nil) preBtn.OnTapped = func() { defer closeApp3(perfWin.tabs, common.TOOLBAR_PERF_CONF) openApp3(perfWin.tabs, common.TOOLBAR_PERF_TIP) } c := container.NewBorder(nil, container.NewHBox(layout.NewSpacer(), preBtn, resetBtn, nextBtn), nil, nil, form) content.Objects = append(content.Objects, c) app.tabItem.Content = content return nil } func (a *perfConf) GetAppName() string { return common.TOOLBAR_PERF_CONF } func (a *perfConf) OnClose() bool { return false } func (a *perfConf) OnDestroy() bool { return true }