拓展类型

This commit is contained in:
2024-09-25 17:45:38 +08:00
parent a0e898e46c
commit 3b69ba93ad
15 changed files with 214 additions and 40 deletions
+30
View File
@@ -0,0 +1,30 @@
package views
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"sort"
)
// CreateCards 创建卡片列表
func CreateCards(w fyne.Window) fyne.CanvasObject {
var itemList []fyne.CanvasObject
keys := make([]string, 0, len(CardTypeMap))
for key, _ := range CardTypeMap {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
info := CardTypeMap[key]
itemList = append(itemList, widget.NewButton(info.Name, func() {
info := CardTypeMap[key]
cWin := fyne.CurrentApp().NewWindow(info.Name)
cWin.SetContent(info.createView(cWin))
cWin.Resize(info.createSize)
cWin.CenterOnScreen()
cWin.Show()
}))
}
return container.NewCenter(container.NewVBox(itemList...))
}
@@ -1,4 +1,4 @@
package views
package createView
import (
"fmt"
@@ -9,8 +9,10 @@ import (
"fyne.io/fyne/v2/widget"
"regexp"
"strings"
"work_cation/global"
"work_cation/models"
"work_cation/pkg/utils"
"work_cation/repo"
"work_cation/service"
)
@@ -20,7 +22,7 @@ func CreateErlangCard(w fyne.Window) fyne.CanvasObject {
if erlangCard == nil {
erlangCard = &models.ErlangCards{
UUID: utils.Uuid.CreateUUID(),
UserIp: utils.IP.Get192Ip(),
UserID: repo.User.GetUserInfo(global.DB).ID,
}
}
var (
+57
View File
@@ -0,0 +1,57 @@
package createView
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"work_cation/global"
"work_cation/models"
"work_cation/pkg/utils"
"work_cation/repo"
"work_cation/service"
)
func CreateExecFile(w fyne.Window) fyne.CanvasObject {
if erlangCard == nil {
erlangCard = &models.ErlangCards{
UUID: utils.Uuid.CreateUUID(),
UserID: repo.User.GetUserInfo(global.DB).ID,
}
}
var (
// 基础表单
formBase = &widget.Form{}
// 变量表单
formVars = &widget.Form{}
)
formBase.AppendItem(&widget.FormItem{Text: "名称", Widget: newDefaultEntry(&erlangCard.Title)})
formBase.AppendItem(&widget.FormItem{Text: "描述", Widget: newDefaultEntry(&erlangCard.Text)})
formBase.AppendItem(&widget.FormItem{Text: "封面", Widget: newDefaultEntry(&erlangCard.Covers), HintText: "暂未支持可不填"})
formBase.AppendItem(&widget.FormItem{Text: "是否默认展示", Widget: newDefaultEntry(&erlangCard.IsShowOut)})
formBase.AppendItem(&widget.FormItem{Text: "模版内容", Widget: newDefaultEntryCallback(&erlangCard.Template, func() { generateVariableForm1(erlangCard, formVars) })})
// 刷新变量表单
generateVariableForm1(erlangCard, formVars)
// 保存按钮
buttonSave := widget.NewButton("保存", func() {
err := service.ErlangCard.Create(erlangCard)
if err != nil {
dialog.ShowError(err, w)
return
}
dialog.ShowInformation("ok", "创建成功", w)
// 更换
erlangCard.UUID = utils.Uuid.CreateUUID()
})
return container.NewBorder(container.NewHBox(widget.NewLabel("新建"), widget.NewSeparator()),
nil, nil, nil, container.NewScroll(
container.NewVBox(
formBase,
formVars,
buttonSave,
)))
}
+18 -1
View File
@@ -2,6 +2,8 @@ package views
import (
"fyne.io/fyne/v2"
"work_cation/models"
"work_cation/views/createView"
)
// Tutorial 定义教程的数据结构
@@ -16,7 +18,7 @@ var (
Tutorials = map[string]Tutorial{
"welcome": {"主页", "", UserViews, true},
"canvas": {"我的", "", myCardsViews, true},
"create": {"新建", "", CreateErlangCard, true},
"create": {"新建", "", CreateCards, true},
}
// TutorialIndex 定义我们的教程应该如何在索引树中布局
@@ -27,3 +29,18 @@ var (
//"widgets": {"accordion", "button", "card", "entry", "form", "input", "progress", "text", "toolbar"},
}
)
type cardInfo struct {
Name string
createView func(w fyne.Window) fyne.CanvasObject
createSize fyne.Size
}
var (
CardTypeMap = map[string]cardInfo{
models.ToolTypeErlang: {"erlang代码脚本1", createView.CreateErlangCard, fyne.NewSize(600, 400)},
"2": {"erlang代码脚本2", createView.CreateErlangCard, fyne.NewSize(600, 400)},
"3": {"erlang代码脚本3", createView.CreateErlangCard, fyne.NewSize(600, 400)},
"4": {"erlang代码脚本4", createView.CreateErlangCard, fyne.NewSize(600, 400)},
}
)
+23
View File
@@ -0,0 +1,23 @@
package views
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"work_cation/global"
"work_cation/models"
"work_cation/repo"
"work_cation/views/showView"
)
func myCardsViews(w fyne.Window) fyne.CanvasObject {
var items []fyne.CanvasObject
for _, baseCard := range repo.BaseCard.FindAll(global.DB) {
switch baseCard.ToolType {
case models.ToolTypeErlang:
erlangCard := repo.ErlangCardRepo.Find(global.DB, baseCard.UUID)
items = append(items, showView.ErlangCardView(w, &erlangCard))
}
}
return container.NewBorder(nil, nil, nil, nil, container.NewScroll(
container.NewGridWrap(fyne.NewSize(200, 200), items...)))
}
@@ -1,4 +1,4 @@
package views
package showView
import (
"fyne.io/fyne/v2"
@@ -8,33 +8,10 @@ import (
"fyne.io/fyne/v2/widget"
"github.com/atotto/clipboard"
"strings"
"work_cation/global"
"work_cation/models"
"work_cation/pkg/utils"
"work_cation/repo"
)
func myCardsViews(w fyne.Window) fyne.CanvasObject {
var items []fyne.CanvasObject
for _, i := range repo.ErlangCardRepo.FindAll(global.DB) {
var i2 = i
items = append(items, ErlangCardView(w, &i2))
}
return container.NewBorder(nil, nil, nil, nil, container.NewScroll(
container.NewGridWrap(fyne.NewSize(200, 200), items...)))
}
func ErlangCardView(w fyne.Window, data *models.ErlangCards) fyne.CanvasObject {
if data == nil {
data = &models.ErlangCards{
UUID: utils.Uuid.CreateUUID(),
Title: "玩家获取",
Text: "玩家获取脚本",
VarName: []string{"服务器ID", "玩家UID"},
Template: "z_db_lib:get(z_db_lib:get_table('role', $var), $var).",
}
}
if len(data.VarName) == 0 {
return widget.NewCard(data.Title, data.Text, widget.NewButton("复制", func() {
err := clipboard.WriteAll(data.Template)