服务发现基础逻辑
This commit is contained in:
+5
-4
@@ -17,14 +17,15 @@ type Tutorial struct {
|
||||
var (
|
||||
// Tutorials 定义每个教程的元数据
|
||||
Tutorials = map[string]Tutorial{
|
||||
"welcome": {"主页", "", mainUserViews, true},
|
||||
"canvas": {"我的", "", allCardsViews, true},
|
||||
"create": {"新建", "", allCreateCards, true},
|
||||
"welcome": {"主页", "", mainUserViews, true},
|
||||
"canvas": {"我的", "", allCardsViews, true},
|
||||
"create": {"新建", "", allCreateCards, true},
|
||||
"otherUsers": {"同事", "", otherUser, true},
|
||||
}
|
||||
|
||||
// TutorialIndex 定义我们的教程应该如何在索引树中布局
|
||||
TutorialIndex = map[string][]string{
|
||||
"": {"welcome", "canvas", "create"},
|
||||
"": {"welcome", "canvas", "otherUsers", "create"},
|
||||
//"collections": {"list", "table", "tree"},
|
||||
//"containers": {"apptabs", "border", "box", "center", "doctabs", "grid", "scroll", "split"},
|
||||
//"widgets": {"accordion", "button", "card", "entry", "form", "input", "progress", "text", "toolbar"}, 58 * 3 + 106 = 280
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package views
|
||||
|
||||
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/repo"
|
||||
"work_cation/service"
|
||||
)
|
||||
|
||||
func otherUser(w fyne.Window) fyne.CanvasObject {
|
||||
gridWrap := container.NewGridWrap(fyne.NewSize(200, 190))
|
||||
findService, err := service.Zeroconf.FindService()
|
||||
if err != nil {
|
||||
return widget.NewLabel("网络异常请稍后尝试")
|
||||
}
|
||||
go func() {
|
||||
for online := range findService {
|
||||
var (
|
||||
onlineCopy = online
|
||||
)
|
||||
baseCardV, err := itemOnlineUserView(w, onlineCopy)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
gridWrap.Add(baseCardV)
|
||||
}
|
||||
}()
|
||||
scroll := container.NewScroll(gridWrap)
|
||||
return container.NewBorder(nil, nil, nil, nil, scroll)
|
||||
}
|
||||
|
||||
func itemOnlineUserView(w fyne.Window, data *models.Online) (fyne.CanvasObject, error) {
|
||||
|
||||
u := repo.UserFollow.GetUser(global.DB, data.ID)
|
||||
|
||||
var followLabel *widget.Label
|
||||
const (
|
||||
noFollow = "未关注"
|
||||
isFollow = "已关注"
|
||||
)
|
||||
|
||||
if u == nil {
|
||||
followLabel = widget.NewLabel(noFollow)
|
||||
} else {
|
||||
followLabel = widget.NewLabel(isFollow)
|
||||
}
|
||||
|
||||
user, err := service.Client.GetUser(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
followButton := widget.NewButton("关注", func() {
|
||||
if followLabel.Text == isFollow {
|
||||
dialog.ShowInformation("结果", "已关注成功", w)
|
||||
return
|
||||
}
|
||||
err = repo.UserFollow.Follow(global.DB, &models.UserFollows{Users: *user})
|
||||
if err != nil {
|
||||
dialog.ShowInformation("关注失败", err.Error(), w)
|
||||
return
|
||||
}
|
||||
dialog.ShowInformation("结果", "关注成功", w)
|
||||
followLabel.SetText(isFollow)
|
||||
})
|
||||
|
||||
showErrButton := widget.NewButton("查看主页", func() {
|
||||
dialog.ShowInformation("错误", "", w)
|
||||
})
|
||||
|
||||
card := widget.NewCard(user.Name, user.Ip, container.NewVBox(followLabel, showErrButton, followButton))
|
||||
return card, nil
|
||||
}
|
||||
+28
-4
@@ -18,9 +18,10 @@ import (
|
||||
"work_cation/models"
|
||||
"work_cation/pkg/utils"
|
||||
"work_cation/repo"
|
||||
"work_cation/service"
|
||||
)
|
||||
|
||||
func mainUserViews(_ fyne.Window) fyne.CanvasObject {
|
||||
func mainUserViews(w fyne.Window) fyne.CanvasObject {
|
||||
var userCard = widget.NewCard("", "", nil)
|
||||
user1 := repo.User.GetUserInfo(global.DB)
|
||||
refresh := func(user *models.Users) {
|
||||
@@ -35,11 +36,34 @@ func mainUserViews(_ fyne.Window) fyne.CanvasObject {
|
||||
}
|
||||
image.FillMode = canvas.ImageFillContain
|
||||
userCard.SetImage(image)
|
||||
var status = ""
|
||||
if service.Server.Status == service.StatusOnline {
|
||||
status = "在线"
|
||||
} else {
|
||||
status = "离线"
|
||||
}
|
||||
userCard.SetContent(widget.NewLabel(fmt.Sprintf("状态:%s", status)))
|
||||
}
|
||||
refresh(user1)
|
||||
return container.NewBorder(widget.NewToolbar(widget.NewToolbarAction(theme.SettingsIcon(), func() {
|
||||
mainUserSetWin(refresh)
|
||||
})),
|
||||
return container.NewBorder(widget.NewToolbar(
|
||||
widget.NewToolbarAction(theme.SettingsIcon(), func() { mainUserSetWin(refresh) }),
|
||||
widget.NewToolbarAction(theme.LoginIcon(), func() {
|
||||
err := service.Server.Online()
|
||||
if err != nil {
|
||||
dialog.ShowInformation("登录失败", err.Error(), w)
|
||||
return
|
||||
}
|
||||
refresh(user1)
|
||||
}),
|
||||
widget.NewToolbarAction(theme.LogoutIcon(), func() {
|
||||
err := service.Server.StatusOffline()
|
||||
if err != nil {
|
||||
dialog.ShowInformation("离线失败", err.Error(), w)
|
||||
return
|
||||
}
|
||||
refresh(user1)
|
||||
}),
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
|
||||
Reference in New Issue
Block a user