This commit is contained in:
zhaocy 2022-07-27 14:23:01 +08:00
parent a8ecc59a04
commit 619c25e53a
2 changed files with 73 additions and 30 deletions

View File

@ -29,7 +29,7 @@ var (
fmt.Printf("%v \n", v) fmt.Printf("%v \n", v)
} }
}, },
// enabled: true, enabled: true,
next: func(robot *Robot, rsp proto.Message) { next: func(robot *Robot, rsp proto.Message) {
tcs := []*TestCase{} tcs := []*TestCase{}
if _, ok := rsp.(*pb.TaskListResp); ok { if _, ok := rsp.(*pb.TaskListResp); ok {

View File

@ -1,50 +1,93 @@
package main package main
import ( import (
"errors" "fmt"
"go_dreamfactory/cmd/robot"
"go_dreamfactory/cmd/win/assets/font" "go_dreamfactory/cmd/win/assets/font"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/app" "fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"github.com/spf13/cast"
) )
func main() { type MyApp struct {
a := app.NewWithID("dreamfactory") app fyne.App
a.Settings().SetTheme(&font.MyTheme{}) loginWin fyne.Window
win := a.NewWindow("昊天锤") mainWin fyne.Window
win.Resize(fyne.NewSize(1366, 768))
win.CenterOnScreen()
ShowLoginFormDialog(win)
win.ShowAndRun()
} }
// loginform func main() {
func ShowLoginFormDialog(win fyne.Window) { app := NewApp()
username := widget.NewEntry() app.Run()
username.SetPlaceHolder("输入账号") }
username.Size()
// username.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "username can only contain letters, numbers, '_', and '-'")
sid := widget.NewEntry()
sid.Text = "0"
// password.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "password can only contain letters, numbers, '_', and '-'")
items := []*widget.FormItem{ func NewApp() *MyApp {
widget.NewFormItem("账号", username), a := app.NewWithID("dreamfactory")
widget.NewFormItem("区服", sid), a.Settings().SetTheme(&font.MyTheme{})
} return &MyApp{app: a}
}
dialog.ShowForm("登录", "Log In", "取消", items, func(b bool) { func (this *MyApp) Run() {
this.ShowLoginWin()
this.app.Run()
}
// 主窗口
func (this *MyApp) ShowMainWin() {
this.mainWin = this.app.NewWindow("昊天锤")
this.mainWin.Resize(fyne.NewSize(1366, 768))
this.mainWin.CenterOnScreen()
this.mainWin.SetOnClosed(func() {
cnf := dialog.NewConfirm("退出", "确定退出程序吗?", func(b bool) {
if !b { if !b {
return return
} }
}, this.mainWin)
if username.Text != "admin" { cnf.SetConfirmText("确定")
// widget.NewButton("Error", func() { cnf.SetDismissText("取消")
err := errors.New("account 错误") cnf.Show()
dialog.ShowError(err, win) })
// }) this.mainWin.Show()
} }
}, win)
// 登录窗口
func (this *MyApp) ShowLoginWin() {
accountEntry := widget.NewEntry()
accountEntry.TextStyle = fyne.TextStyle{Bold: true}
accountEntry.SetPlaceHolder("输入账号")
// accountEntry.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "username can only contain letters, numbers, '_', and '-'")
sidEntry := widget.NewEntry()
sidEntry.Text = "0"
// password.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "password can only contain letters, numbers, '_', and '-'")
items := []*widget.FormItem{
widget.NewFormItem("账号", accountEntry),
widget.NewFormItem("区服", sidEntry),
}
w := fyne.CurrentApp().NewWindow("登录")
f := widget.NewForm(items...)
f.SubmitText = "登录"
f.OnSubmit = func() {
fmt.Println(accountEntry.Text)
if accountEntry.Text != "" {
w.Close()
this.ShowMainWin()
//
opts := robot.DefaultOpts()
opts.Account = accountEntry.Text
opts.ServerId = cast.ToInt32(sidEntry.Text)
robot.NewRobot(opts).Run()
}
}
w.Resize(fyne.Size{300, 160})
w.SetFixedSize(true)
w.SetContent(f)
w.CenterOnScreen()
w.Show()
} }