实现了erlang 脚本的展示使用部分
This commit is contained in:
@@ -7,6 +7,7 @@ require fyne.io/fyne/v2 v2.5.1
|
|||||||
require (
|
require (
|
||||||
fyne.io/systray v1.11.0 // indirect
|
fyne.io/systray v1.11.0 // indirect
|
||||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||||
|
github.com/atotto/clipboard v0.1.4 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/fredbi/uri v1.1.0 // indirect
|
github.com/fredbi/uri v1.1.0 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
@@ -18,6 +19,7 @@ require (
|
|||||||
github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b // indirect
|
github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b // indirect
|
||||||
github.com/go-text/typesetting v0.1.0 // indirect
|
github.com/go-text/typesetting v0.1.0 // indirect
|
||||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||||
github.com/jeandeaual/go-locale v0.0.0-20240223122105-ce5225dcaa49 // indirect
|
github.com/jeandeaual/go-locale v0.0.0-20240223122105-ce5225dcaa49 // indirect
|
||||||
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
|
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
|
|||||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||||
|
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||||
|
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||||
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
|
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
@@ -166,6 +168,8 @@ github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8
|
|||||||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
|
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
|
||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
|
|||||||
@@ -4,25 +4,30 @@ import (
|
|||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/widget"
|
|
||||||
"work_cation/assets"
|
"work_cation/assets"
|
||||||
"work_cation/version"
|
"work_cation/version"
|
||||||
|
"work_cation/views"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a := app.NewWithID("io.fyne.workCation")
|
a := app.NewWithID("io.fyne.workCation")
|
||||||
a.Settings().SetTheme(&assets.MyTheme{})
|
a.Settings().SetTheme(&assets.MyTheme{})
|
||||||
a.SetIcon(assets.LogoDataSR)
|
a.SetIcon(assets.LogoDataSR)
|
||||||
|
w := a.NewWindow("主页 " + version.NowVersion)
|
||||||
w := a.NewWindow("主页")
|
|
||||||
w.Resize(fyne.NewSize(380, 300))
|
w.Resize(fyne.NewSize(380, 300))
|
||||||
w.SetContent(view(w))
|
w.SetContent(mainView(w))
|
||||||
|
w.CenterOnScreen()
|
||||||
|
w.SetMaster()
|
||||||
w.Show()
|
w.Show()
|
||||||
|
|
||||||
a.Run()
|
a.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func view(_ fyne.Window) fyne.CanvasObject {
|
func mainView(w fyne.Window) fyne.CanvasObject {
|
||||||
content := widget.NewLabel(version.NowVersion + "-->" + version.NewVersion)
|
return container.NewBorder(nil, nil, nil, nil,
|
||||||
return container.NewBorder(nil, nil, nil, nil, container.NewCenter(content))
|
container.NewVBox(
|
||||||
|
views.ErlangCardView(w, nil),
|
||||||
|
views.ErlangCardView(w, nil),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type ErlangCardCollections struct {
|
||||||
|
ErlangCards
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type ErlangCards struct {
|
||||||
|
UUID string `json:"uuid"` // id ip加时间戳生成
|
||||||
|
UserIp string `json:"user_ip"` // 用户ip
|
||||||
|
Title string `json:"title"` // 标题
|
||||||
|
Text string `json:"text"` // 内容
|
||||||
|
Covers []string `json:"covers"` // 封面
|
||||||
|
Template string `json:"template"` // 模版
|
||||||
|
VarName []string `json:"var_name"` // 变量
|
||||||
|
VarContent []string `json:"var_content"` // 变量内容
|
||||||
|
IsShowOut bool `json:"is_show_out"` // 是否展示
|
||||||
|
|
||||||
|
Number string `json:"number"` // 数量
|
||||||
|
Goods string `json:"goods"` // 点赞
|
||||||
|
Collection string `json:"collection"` // 收藏
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type History struct {
|
||||||
|
UUID string `json:"uuid"`
|
||||||
|
Vars []string `json:"vars"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Users struct {
|
||||||
|
Ip string `json:"ip"`
|
||||||
|
Name string `json:"name"` // 昵称
|
||||||
|
Avatar string `json:"avatar"` // 头像
|
||||||
|
Cover string `json:"cover"` // 封面
|
||||||
|
Email string `json:"email"`
|
||||||
|
Phone string `json:"phone"`
|
||||||
|
Address string `json:"address"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
// UserFollows 关注用户
|
||||||
|
type UserFollows struct {
|
||||||
|
Users
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var uuidint = 0
|
||||||
|
var lock sync.Mutex
|
||||||
|
|
||||||
|
func CreateUUID() string {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
// 生成基于字符串的 UUID
|
||||||
|
key := fmt.Sprintln(Get192Ip(), time.Now().Format("2006-01-02_15-04-05"), uuidint)
|
||||||
|
uuidint++
|
||||||
|
fmt.Println("key:", key)
|
||||||
|
u1 := uuid.NewSHA1(uuid.Nil, []byte(key))
|
||||||
|
return u1.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func Get192Ip() string {
|
||||||
|
interfaces, err := net.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
for _, iface := range interfaces {
|
||||||
|
addrs, err := iface.Addrs()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, addr := range addrs {
|
||||||
|
ip, _, _ := net.ParseCIDR(addr.String())
|
||||||
|
if ip != nil {
|
||||||
|
ipStr := ip.String()
|
||||||
|
if strings.HasPrefix(ipStr, "192") {
|
||||||
|
return ipStr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
+1
-26
@@ -2,7 +2,6 @@ package version
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -21,33 +20,9 @@ const (
|
|||||||
versionSave = "version.txt"
|
versionSave = "version.txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var NowVersion = "0.0.0"
|
var NowVersion = "0.0.1"
|
||||||
var NewVersion = "0.0.0"
|
var NewVersion = "0.0.0"
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
NowVersion, err = GetFile(versionSave)
|
|
||||||
if err != nil {
|
|
||||||
WriteFile(versionSave, defaultVersion)
|
|
||||||
NowVersion = defaultVersion
|
|
||||||
}
|
|
||||||
NewVersion, err = GetNewVersion(versionPath)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
newV, err := PauseVersion(NewVersion)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
nowV, err := PauseVersion(NowVersion)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Print("版本", newV, nowV)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetNewVersion(path string) (string, error) {
|
func GetNewVersion(path string) (string, error) {
|
||||||
return GetUrl(path)
|
return GetUrl(path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package views
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/data/binding"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"github.com/atotto/clipboard"
|
||||||
|
"strings"
|
||||||
|
"work_cation/models"
|
||||||
|
"work_cation/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ErlangCardView(_ fyne.Window, data *models.ErlangCards) fyne.CanvasObject {
|
||||||
|
if data == nil {
|
||||||
|
data = &models.ErlangCards{
|
||||||
|
UUID: utils.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(data.Template, func() {
|
||||||
|
fmt.Print("复制:", data.UUID)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
txtBound := binding.NewString()
|
||||||
|
txtBound.Set(data.Template)
|
||||||
|
txtWid := widget.NewEntryWithData(txtBound)
|
||||||
|
|
||||||
|
txtWid.Wrapping = fyne.TextWrapOff
|
||||||
|
card := widget.NewCard(data.Title, data.Text, widget.NewButton("OPEN", func() {
|
||||||
|
go UseErlangCard(data)
|
||||||
|
}))
|
||||||
|
//card.SetImage(assets.LogoDataSR)
|
||||||
|
return card
|
||||||
|
}
|
||||||
|
|
||||||
|
func UseErlangCard(data *models.ErlangCards) {
|
||||||
|
var template = data.Template
|
||||||
|
var vars = data.VarName
|
||||||
|
|
||||||
|
myApp := fyne.CurrentApp()
|
||||||
|
myWindow := myApp.NewWindow(data.Title)
|
||||||
|
myWindow.CenterOnScreen()
|
||||||
|
myWindow.Resize(fyne.NewSize(500, 0))
|
||||||
|
|
||||||
|
var items []*widget.FormItem
|
||||||
|
for index, key := range vars {
|
||||||
|
wid := widget.NewEntry()
|
||||||
|
if len(data.VarContent) > index {
|
||||||
|
wid.SetText(data.VarContent[index])
|
||||||
|
}
|
||||||
|
items = append(items, &widget.FormItem{Text: key, Widget: wid})
|
||||||
|
}
|
||||||
|
|
||||||
|
var text string
|
||||||
|
if data.IsShowOut {
|
||||||
|
text = replaceVars(template, data.VarContent)
|
||||||
|
}
|
||||||
|
showErlang := widget.NewLabel(text)
|
||||||
|
showButton := widget.NewButton("...", nil)
|
||||||
|
upOut := func() {
|
||||||
|
if data.IsShowOut {
|
||||||
|
text = replaceVars(template, data.VarContent)
|
||||||
|
showErlang.SetText(text)
|
||||||
|
showButton.SetText("隐藏输出")
|
||||||
|
} else {
|
||||||
|
text = ""
|
||||||
|
showErlang.SetText(text)
|
||||||
|
showButton.SetText("展示输出")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
upOut()
|
||||||
|
showButton.OnTapped = func() {
|
||||||
|
data.IsShowOut = !data.IsShowOut
|
||||||
|
upOut()
|
||||||
|
}
|
||||||
|
|
||||||
|
form := &widget.Form{
|
||||||
|
Items: items,
|
||||||
|
SubmitText: "生成并复制",
|
||||||
|
OnSubmit: func() {
|
||||||
|
var values []string
|
||||||
|
for _, item := range items {
|
||||||
|
values = append(values, item.Widget.(*widget.Entry).Text)
|
||||||
|
}
|
||||||
|
data.VarContent = values
|
||||||
|
//out.SetText(replaceVars(template, data.VarContent))
|
||||||
|
err := clipboard.WriteAll(replaceVars(template, data.VarContent))
|
||||||
|
fmt.Print("复制:", replaceVars(template, data.VarContent), err)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
title := widget.NewCard(data.Title, data.Text, nil)
|
||||||
|
|
||||||
|
content := container.NewVBox(
|
||||||
|
title,
|
||||||
|
widget.NewLabel("输入模版参数:"),
|
||||||
|
form,
|
||||||
|
widget.NewLabel("输出:"),
|
||||||
|
showErlang,
|
||||||
|
showButton,
|
||||||
|
)
|
||||||
|
|
||||||
|
myWindow.SetContent(content)
|
||||||
|
myWindow.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func replaceVars(input string, replacements []string) string {
|
||||||
|
varIndex := 0
|
||||||
|
result := input
|
||||||
|
|
||||||
|
for strings.Contains(result, "$var") && varIndex < len(replacements) {
|
||||||
|
result = strings.Replace(result, "$var", replacements[varIndex], 1)
|
||||||
|
varIndex++
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user