完成了分享下载全部流程

This commit is contained in:
2024-10-12 13:37:49 +08:00
parent e6f5aaa02f
commit 7862b1d88e
11 changed files with 342 additions and 30 deletions
+75 -4
View File
@@ -1,10 +1,14 @@
package views
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"time"
"work_cation/global"
"work_cation/models"
"work_cation/repo"
@@ -18,11 +22,11 @@ func otherUser(w fyne.Window) fyne.CanvasObject {
return widget.NewLabel("网络异常请稍后尝试")
}
go func() {
for online := range findService {
for _, online := range findService {
var (
onlineCopy = online
)
baseCardV, err := itemOnlineUserView(w, onlineCopy)
baseCardV, err := itemOnlineUserView(w, &onlineCopy)
if err != nil {
continue
}
@@ -69,9 +73,76 @@ func itemOnlineUserView(w fyne.Window, data *models.Online) (fyne.CanvasObject,
})
showErrButton := widget.NewButton("查看主页", func() {
dialog.ShowInformation("错误", "", w)
otherUserIndexWin(user, data)
})
card := widget.NewCard(user.Name, user.Ip, container.NewVBox(followLabel, showErrButton, followButton))
return card, nil
}
func otherUserIndexWin(user *models.Users, data *models.Online) {
myApp := fyne.CurrentApp()
myWindow := myApp.NewWindow(user.Name)
myWindow.CenterOnScreen()
myWindow.Resize(fyne.NewSize(620, 500))
myWindow.SetContent(otherUserIndexView(myWindow, data))
myWindow.Show()
}
func otherUserIndexView(w fyne.Window, online *models.Online) fyne.CanvasObject {
gridWrap := container.NewGridWrap(fyne.NewSize(200, 200))
cards, _ := service.Client.GetCards(online)
for _, baseCard := range cards {
var baseCardCopy = baseCard
baseCardV := baseOtherCardView(w, baseCardCopy, online)
gridWrap.Add(baseCardV)
}
scroll := container.NewScroll(gridWrap)
return container.NewBorder(nil, nil, nil, nil, scroll)
}
func baseOtherCardView(w fyne.Window, baseCardCopy models.BaseCard, online *models.Online) *widget.Card {
saveCard := repo.BaseCard.Find(global.DB, baseCardCopy.UUID)
infoWid := container.NewVBox(
widget.NewLabel(baseCardCopy.ToolType),
widget.NewLabel(fmt.Sprintf("本地:%s", saveCard.UpdateTx.Format(time.DateTime))),
widget.NewLabel(fmt.Sprintf("作者:%s", baseCardCopy.UpdateTx.Format(time.DateTime))),
)
baseCardV := widget.NewCard(baseCardCopy.Title, baseCardCopy.Text, container.NewBorder(nil, widget.NewToolbar(
widget.NewToolbarAction(theme.DownloadIcon(), func() {
b := saveCard.UpdateTx.Unix() == baseCardCopy.UpdateTx.Unix()
fmt.Println(saveCard.UpdateTx, baseCardCopy.UpdateTx)
if b {
dialog.ShowInformation("结果", "已下载本地", w)
return
}
// 下载到本地 若没关注自动关注
progress := binding.NewFloat()
progress.Set(0)
progressBar := widget.NewProgressBarWithData(progress)
progressBar.Max = 100
smaillWin := dialog.NewCustom("下载中", "关闭", progressBar, w)
smaillWin.Show()
err := service.Client.Download(online, baseCardCopy.UUID, progress)
if err != nil {
smaillWin.SetDismissText("失败")
return
}
// 修改数据
progress.Set(99)
saveCard.UpdateTx = baseCardCopy.UpdateTx
err = repo.BaseCard.CreateOrSave(global.DB, &baseCardCopy)
if err != nil {
smaillWin.SetDismissText("失败")
return
}
progress.Set(100)
smaillWin.SetDismissText("完成 请去[我的]查看")
}),
), nil, nil, infoWid))
return baseCardV
}