完善聊天功能 初步构建十子棋功能

This commit is contained in:
2024-10-15 21:13:17 +08:00
parent 245875881c
commit b3cf948fd2
15 changed files with 303 additions and 84 deletions
+28
View File
@@ -1,10 +1,15 @@
package service
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"gorm.io/gorm"
"os"
"path/filepath"
"work_cation/cfg"
"work_cation/global"
"work_cation/models"
"work_cation/repo"
)
@@ -30,3 +35,26 @@ func (*BaseCardService) Delete(db *gorm.DB, deleteCard models.BaseCard) error {
err = db.Model(&models.BaseCard{}).Where("uuid = ?", deleteCard.UUID).Delete(&deleteCard).Error
return err
}
func (*BaseCardService) DownloadCard(w fyne.Window, baseCardCopy models.BaseCard, online *models.Online) {
progress := binding.NewFloat()
progress.Set(0)
progressBar := widget.NewProgressBarWithData(progress)
progressBar.Max = 120
smaillWin := dialog.NewCustom("下载中", "关闭", progressBar, w)
smaillWin.Show()
err := Client.Download(online, baseCardCopy.UUID, progress)
if err != nil {
smaillWin.SetDismissText("失败")
return
}
// 修改数据
progress.Set(110)
err = repo.BaseCard.CreateOrSave(global.DB, &baseCardCopy)
if err != nil {
smaillWin.SetDismissText("失败")
return
}
progress.Set(120)
smaillWin.SetDismissText("完成 请去[我的]查看")
}
+1 -1
View File
@@ -127,7 +127,7 @@ func (c *ClientService) Chat(online *models.Online, text string) (string, error)
return "", err
}
res.Header.Set("Content-Type", "application/json")
res.Header.Set("User-ID", user.ID)
res.Header.Set("User-UserID", user.ID)
resp, err := http.DefaultClient.Do(res)
if err != nil {
return "", err
+4 -9
View File
@@ -10,7 +10,6 @@ import (
"net/http"
"os"
"path/filepath"
"time"
"work_cation/cfg"
"work_cation/global"
"work_cation/models"
@@ -86,7 +85,7 @@ func (s *serverService) StartListenServer() error {
})
router.POST("/chat", func(c *gin.Context) {
uuid := c.GetHeader("User-ID")
uuid := c.GetHeader("User-UserID")
user := repo.UserFollow.GetUser(global.DB, uuid)
if user.Ip != c.ClientIP() {
c.JSON(200, gin.H{"message": "对方未关注你"})
@@ -98,13 +97,9 @@ func (s *serverService) StartListenServer() error {
return
}
message := &models.Message{
Cmd: "chat",
User: *user,
ChatMessage: models.ChatMessage{
User: user.Users,
Time: time.Now(),
Text: msg["text"].(string),
},
Cmd: "chat",
User: *user,
ChatMessage: *models.NewTextChatMsg(&user.Users, msg["text"].(string)),
}
global.Send.SendChan <- message
c.JSON(200, gin.H{"message": "ok"})