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/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) form := widget.NewForm( widget.NewFormItem("超时(ms)", timeoutEntry), widget.NewFormItem("并发量", lpsEntry), widget.NewFormItem("持续时间(s)", durationEntry), widget.NewFormItem("用户数", userCountEntry), widget.NewFormItem("服务地址", wsAddrEntry), ) form.OnSubmit = func() { //校验表单数据 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 if err := perfWin.UIImpl.storage.StoreConfig(app.conf); err != nil { logrus.Error(err) } //next openApp3(perfWin.tabs, common.TOOLBAR_PERF_PB) } form.SubmitText = "下一步" form.OnCancel = func() { timeoutEntry.Text = "" lpsEntry.Text = "" durationEntry.Text = "" userCountEntry.Text = "" wsAddrEntry.Text = "" form.Refresh() } form.CancelText = "重置" content.Objects = append(content.Objects, form) app.tabItem.Content = content return nil } func (a *perfConf) GetAppName() string { return common.TOOLBAR_PERF_CONF }