protected override void OnViewLoaded(bool isFirstLoaded)
 {
     base.OnViewLoaded(isFirstLoaded);
     if (!isFirstLoaded)
     {
         return;
     }
     if (_selectedPostilId != null)
     {
         LoadPostilInfosAsync(_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.FirstOrDefault(t => t.PostilId == _selectedPostilId));
     }
     else
     {
         var pane        = Mg.Get <IMgDocking>().GetPane(typeof(PostilPanelListViewModel));
         var panelListVm = pane?.Content as PostilPanelListViewModel;
         if (panelListVm?.SelectedPostilInfoModel == null || panelListVm.PostilInfoModels.Count == 0)
         {
             LoadPostilInfosAsync(0);
         }
         else
         {
             var index = panelListVm.PostilInfoModels.IndexOf(panelListVm.SelectedPostilInfoModel);
             if (index == -1)
             {
                 _currentPageIndex = 0;
             }
             else
             {
                 _currentPageIndex = index / 8;
             }
             _selectedPostilId = panelListVm.SelectedPostilInfoModel._id;
             LoadPostilInfosAsync(_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.FirstOrDefault(t => t.PostilId == _selectedPostilId));
         }
     }
 }
        /// <summary>
        /// 批注增加的广播信息处理事件
        /// </summary>
        /// <param name="eventArgs"></param>
        private void DataAdd(WebMsgEventArgs eventArgs)
        {
            var index = SelectedViewPicModel?.SelectedPicIndex ?? 0;

            if (_currentPageIndex == 0)//最新的只会添加在前面
            {
                LoadPostilInfosAsync(_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.ElementAtOrDefault(index) ?? ViewPictureModels.LastOrDefault());
            }
        }
        private void OnRefresh()
        {
            var selectId = SelectedViewPicModel?.PostilId;

            SelectedViewPicModel = null;
            LoadPostilInfosAsync(_currentPageIndex, () =>
            {
                SelectedViewPicModel = ViewPictureModels.FirstOrDefault(t => t.PostilId == selectId) ?? ViewPictureModels.FirstOrDefault();
            });
        }
        /// <summary>
        /// 删除某条批注事件
        /// </summary>
        /// <param name="delPicModel"></param>
        private async void OnDeletePostilItem(PictureModel delPicModel)
        {
            if (delPicModel == null)
            {
                return;
            }
            if (this.ShowMessage("删除后将无法恢复信息,确定删除这条批注吗?", "警告", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
            {
                return;
            }
            var index    = delPicModel.SelectedPicIndex;
            var deleteId = delPicModel.PostilId;
            var result   = await DataApi.DeleteAsync(Hubs.Postil.T, new[] { deleteId });

            if (!result.IsOk)
            {
                Mg.Get <IMgLog>().Error("删除批注信息失败" + result.Message);
                Mg.Get <IMgDialog>().ShowDesktopAlert("删除批注信息失败", result.Message);
                return;
            }
            if (ViewPictureModels.Count == 8)
            {
                if (SelectedViewPicModel.PostilId == deleteId)
                {
                    LoadPostilInfosAsync(_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.ElementAtOrDefault(index) ?? ViewPictureModels.LastOrDefault());
                }
                else
                {
                    var selectId = SelectedViewPicModel.PostilId;
                    LoadPostilInfosAsync(_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.FirstOrDefault(t => t.PostilId == selectId) ?? ViewPictureModels.FirstOrDefault());
                }
            }
            else
            {
                var selectId = SelectedViewPicModel.PostilId;
                ViewPictureModels.Remove(delPicModel);
                for (var i = 0; i < ViewPictureModels.Count; i++)//重新给索引
                {
                    ViewPictureModels[i].SelectedPicIndex = i;
                }
                _listPostilInfoModel.Remove(_listPostilInfoModel.FirstOrDefault(t => t._id == deleteId));
                if (deleteId == selectId)
                {
                    SelectedViewPicModel = ViewPictureModels.ElementAtOrDefault(index) ?? ViewPictureModels.LastOrDefault();
                }
                if (ViewPictureModels.Count == 0 && _currentPageIndex != 0)
                {
                    LoadPostilInfosAsync(--_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.LastOrDefault());
                }
            }
            _isSelfDelPostil = true;
            await Mg.Get <IMgWeb>().SendWebMsgAsync("demoPostil/delete", deleteId.ToString(), BoardcastType.ProjectGroup);//发送广播
        }
        /// <summary>
        /// 加载指定页的批注信息
        /// </summary>
        private async void LoadPostilInfosAsync(int pageIndex, Action action = null)
        {
            IsBusy = true;
            var listParams = new ListParams
            {
                Search = Query.Eq(Hubs.Postil.ProjectId, Mg.Get <IMgContext>().ProjectId),
                Page   = new ListParams.PageInfo(pageIndex, 8),
                Sort   = new[] { new ListParams.SortProperty(Hubs.Postil.CreateTime, false) }
            };
            var dataResult = await DataApi.GetListAsync(Hubs.Postil.T, listParams);

            _listPostilInfoModel.Clear();
            if (!dataResult.IsOk)
            {
                Mg.Get <IMgLog>().Error("获取批注信息失败" + dataResult.Message);
                Mg.Get <IMgDialog>().ShowDesktopAlert("获取批注信息失败", dataResult.Message);
                IsBusy = false;
                return;
            }
            var models = dataResult.GetRecords().Select(t => t.As <PostilInfoModel>()).ToList();

            if (models.Count == 0)
            {
                IsBusy = false;
                return;
            }
            var urlDic = await Util.Data.GetPictureUrlsAsync(models.Select(t => t.FileId).ToArray());

            var userDic = await Util.Data.GetUserInfosAsync(models.Select(t => t.CreateUser).ToArray());

            foreach (var postilInfoModel in models)
            {
                postilInfoModel.ImageUrl   = urlDic?[postilInfoModel.FileId];
                postilInfoModel.PostilUser = userDic?[postilInfoModel.CreateUser];
                _listPostilInfoModel.Add(postilInfoModel);
            }
            ViewPictureModels.Clear();
            for (var index = 0; index < models.Count; index++)
            {
                var model = models[index];
                ViewPictureModels.Add(new PictureModel
                {
                    SelectedPicIndex = index,
                    PostilId         = model._id,
                    ImageUrl         = model.ImageUrl
                });
            }
            SelectedViewPicModel = ViewPictureModels.FirstOrDefault();
            action?.Invoke();
            LoadNextPageCountAsync();
            IsBusy = false;
        }
        private void DataDelete(WebMsgEventArgs eventArgs)
        {
            if (_isSelfDelPostil)
            {
                _isSelfDelPostil = false;
                return;
            }
            var deleteId = eventArgs.Data.As <Id>();

            if (deleteId == null)
            {
                return;
            }
            var model = ViewPictureModels.FirstOrDefault(t => t.PostilId == deleteId);

            if (model == null)
            {
                return;
            }
            if (ViewPictureModels.Count == 8)
            {
                if (SelectedViewPicModel.PostilId == deleteId)
                {
                    LoadPostilInfosAsync(_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.ElementAtOrDefault(model.SelectedPicIndex) ?? ViewPictureModels.LastOrDefault());
                }
                else
                {
                    var selectId = SelectedViewPicModel.PostilId;
                    LoadPostilInfosAsync(_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.FirstOrDefault(t => t.PostilId == selectId) ?? ViewPictureModels.FirstOrDefault());
                }
            }
            else
            {
                ViewPictureModels.Remove(model);
                for (var i = 0; i < ViewPictureModels.Count; i++)//重新给索引
                {
                    ViewPictureModels[i].SelectedPicIndex = i;
                }
                _listPostilInfoModel.Remove(_listPostilInfoModel.FirstOrDefault(t => t._id == deleteId));
                if (deleteId == SelectedViewPicModel.PostilId)
                {
                    SelectedViewPicModel = ViewPictureModels.ElementAtOrDefault(model.SelectedPicIndex) ?? ViewPictureModels.LastOrDefault();
                }
                if (ViewPictureModels.Count == 0 && _currentPageIndex != 0)
                {
                    LoadPostilInfosAsync(--_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.LastOrDefault());
                }
            }
        }
        private void OnNextPicture()
        {
            if (!CanNextPicture())
            {
                return;
            }
            var index = SelectedViewPicModel.SelectedPicIndex;

            if (index != ViewPictureModels.Count - 1)
            {
                SelectedViewPicModel = ViewPictureModels.ElementAt(index + 1);
            }
            else
            {
                LoadPostilInfosAsync(++_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.FirstOrDefault());
            }
        }
        private void OnPreviousPicture()
        {
            if (!CanPreviousPicture())
            {
                return;
            }
            var index = SelectedViewPicModel.SelectedPicIndex;

            if (index == 0 && _currentPageIndex != 0)
            {
                LoadPostilInfosAsync(--_currentPageIndex, () => SelectedViewPicModel = ViewPictureModels.LastOrDefault());
            }
            else
            {
                SelectedViewPicModel = ViewPictureModels.ElementAt(index - 1);
            }
        }