win
This commit is contained in:
parent
a8ecc59a04
commit
619c25e53a
@ -29,7 +29,7 @@ var (
|
||||
fmt.Printf("%v \n", v)
|
||||
}
|
||||
},
|
||||
// enabled: true,
|
||||
enabled: true,
|
||||
next: func(robot *Robot, rsp proto.Message) {
|
||||
tcs := []*TestCase{}
|
||||
if _, ok := rsp.(*pb.TaskListResp); ok {
|
||||
|
101
cmd/win/main.go
101
cmd/win/main.go
@ -1,50 +1,93 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go_dreamfactory/cmd/robot"
|
||||
"go_dreamfactory/cmd/win/assets/font"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a := app.NewWithID("dreamfactory")
|
||||
a.Settings().SetTheme(&font.MyTheme{})
|
||||
win := a.NewWindow("昊天锤")
|
||||
win.Resize(fyne.NewSize(1366, 768))
|
||||
win.CenterOnScreen()
|
||||
ShowLoginFormDialog(win)
|
||||
win.ShowAndRun()
|
||||
type MyApp struct {
|
||||
app fyne.App
|
||||
loginWin fyne.Window
|
||||
mainWin fyne.Window
|
||||
}
|
||||
|
||||
// loginform
|
||||
func ShowLoginFormDialog(win fyne.Window) {
|
||||
username := widget.NewEntry()
|
||||
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"
|
||||
func main() {
|
||||
app := NewApp()
|
||||
app.Run()
|
||||
}
|
||||
|
||||
func NewApp() *MyApp {
|
||||
a := app.NewWithID("dreamfactory")
|
||||
a.Settings().SetTheme(&font.MyTheme{})
|
||||
return &MyApp{app: a}
|
||||
}
|
||||
|
||||
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 {
|
||||
return
|
||||
}
|
||||
}, this.mainWin)
|
||||
cnf.SetConfirmText("确定")
|
||||
cnf.SetDismissText("取消")
|
||||
cnf.Show()
|
||||
})
|
||||
this.mainWin.Show()
|
||||
}
|
||||
|
||||
// 登录窗口
|
||||
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("账号", username),
|
||||
widget.NewFormItem("区服", sid),
|
||||
widget.NewFormItem("账号", accountEntry),
|
||||
widget.NewFormItem("区服", sidEntry),
|
||||
}
|
||||
|
||||
dialog.ShowForm("登录", "Log In", "取消", items, func(b bool) {
|
||||
if !b {
|
||||
return
|
||||
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()
|
||||
}
|
||||
|
||||
if username.Text != "admin" {
|
||||
// widget.NewButton("Error", func() {
|
||||
err := errors.New("account 错误")
|
||||
dialog.ShowError(err, win)
|
||||
// })
|
||||
}
|
||||
}, win)
|
||||
}
|
||||
|
||||
w.Resize(fyne.Size{300, 160})
|
||||
w.SetFixedSize(true)
|
||||
w.SetContent(f)
|
||||
w.CenterOnScreen()
|
||||
w.Show()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user