修复列表数据重复

This commit is contained in:
wh_zcy 2022-10-09 18:14:43 +08:00
parent 485021f72f
commit d3ae4591aa
8 changed files with 43 additions and 22 deletions

View File

@ -4,5 +4,5 @@ Website = "http://legu.cc"
Icon = "app.png" Icon = "app.png"
Name = "RobotGUI" Name = "RobotGUI"
ID = "cc.legu.app" ID = "cc.legu.app"
Version = "1.0.13" Version = "1.0.14"
Build = 16 Build = 17

View File

@ -56,6 +56,10 @@ func (f *ItemList) CreateList() *widget.List {
f.SelItemIds = append(f.SelItemIds, selId) f.SelItemIds = append(f.SelItemIds, selId)
return return
} }
f.ItemList.OnUnselected = func(id widget.ListItemID) {
f.SelItemIds = append(f.SelItemIds[:id], f.SelItemIds[id+1:]...)
}
return f.ItemList return f.ItemList
} }

View File

@ -5,7 +5,6 @@ import (
"go_dreamfactory/cmd/v2/lib/common" "go_dreamfactory/cmd/v2/lib/common"
"go_dreamfactory/cmd/v2/model" "go_dreamfactory/cmd/v2/model"
"go_dreamfactory/cmd/v2/service/observer" "go_dreamfactory/cmd/v2/service/observer"
"time"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
@ -74,7 +73,6 @@ func (a appMonitor) OnClose() bool {
func (this *appMonitor) Run() { func (this *appMonitor) Run() {
this.obs.AddListener(observer.EVENT_APP_MONI, observer.Listener{ this.obs.AddListener(observer.EVENT_APP_MONI, observer.Listener{
OnNotify: func(d interface{}, args ...interface{}) { OnNotify: func(d interface{}, args ...interface{}) {
time.Sleep(time.Millisecond * 20)
data := d.(*model.PushModel) data := d.(*model.PushModel)
this.monitorData.DataList = append(this.monitorData.DataList, data) this.monitorData.DataList = append(this.monitorData.DataList, data)
this.reloadMonitorData() this.reloadMonitorData()
@ -88,7 +86,6 @@ func (this *appMonitor) reloadMonitorData() {
d := this.monitorData.AsInterfaceArray() d := this.monitorData.AsInterfaceArray()
this.monitorBinding.Set(d) this.monitorBinding.Set(d)
} }
this.monitorList.ScrollToBottom()
} }
func (this *appMonitor) createMonitorList() { func (this *appMonitor) createMonitorList() {

View File

@ -19,6 +19,7 @@ import (
type FriendListView struct { type FriendListView struct {
ListBaseView //继承支持好友列表的基类 ListBaseView //继承支持好友列表的基类
friendList func() friendList func()
flag bool
} }
func (this *FriendListView) CreateView(t *model.TestCase) fyne.CanvasObject { func (this *FriendListView) CreateView(t *model.TestCase) fyne.CanvasObject {
@ -70,6 +71,9 @@ func (this *FriendListView) Load() {
} }
func (this *FriendListView) dataListener() { func (this *FriendListView) dataListener() {
if this.flag {
return
}
this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{ this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{
OnNotify: func(d interface{}, args ...interface{}) { OnNotify: func(d interface{}, args ...interface{}) {
data := d.(*pb.UserMessage) data := d.(*pb.UserMessage)
@ -95,4 +99,5 @@ func (this *FriendListView) dataListener() {
this.reloadListData() this.reloadListData()
}, },
}) })
this.flag = true
} }

View File

@ -21,6 +21,7 @@ type HeroListView struct {
ListBaseView ListBaseView
subWindows *SubWindowListView subWindows *SubWindowListView
heroList []*pb.DBHero heroList []*pb.DBHero
flag bool
} }
func (this *HeroListView) CreateView(t *model.TestCase) fyne.CanvasObject { func (this *HeroListView) CreateView(t *model.TestCase) fyne.CanvasObject {
@ -107,6 +108,9 @@ func (this *HeroListView) CreateView(t *model.TestCase) fyne.CanvasObject {
} }
func (this *HeroListView) dataListener() { func (this *HeroListView) dataListener() {
if this.flag {
return
}
this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{ this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{
OnNotify: func(d interface{}, args ...interface{}) { OnNotify: func(d interface{}, args ...interface{}) {
data := d.(*pb.UserMessage) data := d.(*pb.UserMessage)
@ -135,4 +139,5 @@ func (this *HeroListView) dataListener() {
this.reloadListData() this.reloadListData()
}, },
}) })
this.flag = true
} }

View File

@ -20,6 +20,7 @@ import (
type RtaskListView struct { type RtaskListView struct {
ListBaseView ListBaseView
flag bool
} }
func (this *RtaskListView) CreateView(t *model.TestCase) fyne.CanvasObject { func (this *RtaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
@ -77,6 +78,9 @@ func (this *RtaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
} }
func (this *RtaskListView) dataListener() { func (this *RtaskListView) dataListener() {
if this.flag {
return
}
this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{ this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{
OnNotify: func(d interface{}, args ...interface{}) { OnNotify: func(d interface{}, args ...interface{}) {
data := d.(*pb.UserMessage) data := d.(*pb.UserMessage)
@ -101,4 +105,5 @@ func (this *RtaskListView) dataListener() {
this.reloadListData() this.reloadListData()
}, },
}) })
this.flag = true
} }

View File

@ -21,16 +21,16 @@ import (
) )
type TaskActiveListView struct { type TaskActiveListView struct {
ListBaseView BaseformView
activeVal *widget.Label activeVal *widget.Label
itemList *common.ItemList
flag bool
} }
func (this *TaskActiveListView) CreateView(t *model.TestCase) fyne.CanvasObject { func (this *TaskActiveListView) CreateView(t *model.TestCase) fyne.CanvasObject {
// init required this.itemList = common.NewItemList()
this.initItemList()
// create friend list view this.itemList.ItemList = this.itemList.CreateList()
this.createItemList()
// select widget // select widget
tagSelect := getTaskTagSelect() tagSelect := getTaskTagSelect()
@ -50,20 +50,20 @@ func (this *TaskActiveListView) CreateView(t *model.TestCase) fyne.CanvasObject
//receive button //receive button
receiveBtn := widget.NewButtonWithIcon("领取", theme.ConfirmIcon(), func() { receiveBtn := widget.NewButtonWithIcon("领取", theme.ConfirmIcon(), func() {
if len(this.selItemIds) != 1 { if len(this.itemList.SelItemIds) != 1 {
dialog.ShowError(errors.New("请选择一项"), this.w) dialog.ShowError(errors.New("请选择一项"), this.w)
return return
} }
if err := service.GetPttService().SendToClient( if err := service.GetPttService().SendToClient(
t.MainType, "activereceive", t.MainType, "activereceive",
&pb.TaskActiveReceiveReq{Id: this.selItemIds[0], TaskTag: cast.ToInt32(tagSelect.Selected)}); err != nil { &pb.TaskActiveReceiveReq{Id: this.itemList.SelItemIds[0], TaskTag: cast.ToInt32(tagSelect.Selected)}); err != nil {
logrus.Error(err) logrus.Error(err)
return return
} }
}) })
// layout // layout
split := container.NewHSplit(this.dataListWidget, container.NewVBox(this.activeVal, this.form, taskListBtn, receiveBtn)) split := container.NewHSplit(this.itemList.ItemList, container.NewVBox(this.activeVal, this.form, taskListBtn, receiveBtn))
split.Offset = 1 split.Offset = 1
//data listener for //data listener for
@ -73,6 +73,9 @@ func (this *TaskActiveListView) CreateView(t *model.TestCase) fyne.CanvasObject
} }
func (this *TaskActiveListView) dataListener() { func (this *TaskActiveListView) dataListener() {
if this.flag {
return
}
this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{ this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{
OnNotify: func(d interface{}, args ...interface{}) { OnNotify: func(d interface{}, args ...interface{}) {
data := d.(*pb.UserMessage) data := d.(*pb.UserMessage)
@ -88,16 +91,15 @@ func (this *TaskActiveListView) dataListener() {
this.activeVal.SetText(fmt.Sprintf("当前活跃度:%v", rsp.Active)) this.activeVal.SetText(fmt.Sprintf("当前活跃度:%v", rsp.Active))
this.itemListData = model.NewItemModelList()
for _, v := range rsp.List { for _, v := range rsp.List {
fm := &model.ItemModel{ item := common.Item{
Id: cast.ToString(v.Id), Id: cast.ToString(v.Id),
Label: fmt.Sprintf("%s R:%d", cast.ToString(v.RId), v.Received), Text: fmt.Sprintf("%s R:%d", cast.ToString(v.RId), v.Received),
} }
this.itemListData.DataList = append(this.itemListData.DataList, fm) this.itemList.AddItem(item)
} }
this.reloadListData()
}, },
}) })
this.flag = true
} }

View File

@ -23,6 +23,7 @@ import (
type TaskListView struct { type TaskListView struct {
BaseformView BaseformView
itemList common.ItemList itemList common.ItemList
flag bool
} }
func (this *TaskListView) CreateView(t *model.TestCase) fyne.CanvasObject { func (this *TaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
@ -68,6 +69,9 @@ func (this *TaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
} }
func (this *TaskListView) dataListener() { func (this *TaskListView) dataListener() {
if this.flag {
return
}
this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{ this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{
OnNotify: func(d interface{}, args ...interface{}) { OnNotify: func(d interface{}, args ...interface{}) {
data := d.(*pb.UserMessage) data := d.(*pb.UserMessage)
@ -82,8 +86,6 @@ func (this *TaskListView) dataListener() {
return return
} }
this.itemList.Reset()
for _, v := range rsp.List { for _, v := range rsp.List {
item := common.Item{ item := common.Item{
Id: cast.ToString(v.Id), Id: cast.ToString(v.Id),
@ -93,4 +95,5 @@ func (this *TaskListView) dataListener() {
} }
}, },
}) })
this.flag = true
} }