/// <summary> /// 分页加载信息 /// </summary> /// <param name="e"></param> void OnNextPage(PageData e) { int cnt = AtState.GetScalar <int>("select count(*) from Letter where otherid=@otherid and loginid=@loginid", new Dict { { "otherid", OtherID }, { "loginid", Kit.UserID } }); int start = cnt - (e.PageNo + 1) * e.PageSize; int limit = e.PageSize; if (start < 0) { limit = cnt - e.PageNo * e.PageSize; } Nl <Letter> data = new Nl <Letter>(); var ls = AtState.Each <Letter>($"select * from Letter where otherid={OtherID} and loginid={Kit.UserID} order by stime limit {limit} offset {start}"); foreach (var l in ls) { var photo = l.IsReceived ? _other.Photo : Kit.UserPhoto; if (string.IsNullOrEmpty(photo)) { photo = "photo/profilephoto.jpg"; } l.Photo = photo; data.Add(l); } e.LoadPageData(data); }
void LoadHisItems() { var his = AtState.Each <SearchFvHis>($"select * from SearchFvHis where BaseUri='{_baseUri}' order by id desc"); foreach (var item in his) { Grid grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); grid.DataContext = item; Button btn = new Button { Content = item.Content, HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Left }; btn.Click += OnClickHis; grid.Children.Add(btn); btn = new Button { Content = "\uE009", Style = Res.字符按钮 }; btn.Click += OnDelHis; Grid.SetColumn(btn, 1); grid.Children.Add(btn); Items.Add(grid); } }
/// <summary> /// 加载当前登录用户的菜单,性能已调优 /// </summary> public static async Task LoadMenus() { // 所有可访问项 List <long> idsAll = await GetAllUserMenus(); // 常用组菜单项:固定项 + 点击次数最多的前n项,总项数 <= 8 _favMenus.Clear(); var fixedMenus = Kit.Stub.FixedMenus; if (fixedMenus != null) { // 固定项 foreach (var om in fixedMenus) { _favMenus.Add(om); } } // 点击次数最多的前n项 int maxFav = 8; if (_favMenus.Count < maxFav) { var favMenu = AtState.Each <MenuFav>($"select menuid from menufav where userid={Kit.UserID} order by clicks desc LIMIT {maxFav}"); foreach (var fav in favMenu) { // 过滤无权限的项 if (idsAll.Contains(fav.MenuID)) { var om = AtModel.First <OmMenu>($"select * from OmMenu where id={fav.MenuID}"); _favMenus.Add(om); idsAll.Remove(fav.MenuID); if (_favMenus.Count >= maxFav) { break; } } } } // 根页面菜单 _rootPageMenus = new Nl <GroupData <OmMenu> >(); // 除根页面的剩余项 _leaveMenus = new List <OmMenu>(); // 所有一级项 var roots = new List <OmMenu>(); // 整理菜单项 foreach (var item in AtModel.Each <OmMenu>("select * from OmMenu")) { // 过滤无权限的项,保留所有分组 if (!item.IsGroup && !idsAll.Contains(item.ID)) { continue; } // 一级项和其他分开 if (!item.ParentID.HasValue) { roots.Add(item); } else { _leaveMenus.Add(item); } } // 根页面常用组 if (_favMenus.Count > 0) { _rootPageMenus.Add(_favMenus); } // 移除无用的分组 int index = 0; while (index < _leaveMenus.Count) { var om = _leaveMenus[index]; if (!om.IsGroup || IsExistChild(om)) { index++; } else { _leaveMenus.RemoveAt(index); } } // 整理一级菜单 GroupData <OmMenu> grpLast = null; foreach (var om in roots) { // 一级的实体菜单项 if (!om.IsGroup) { if (grpLast == null) { grpLast = new GroupData <OmMenu>() { Title = "其它" } } ; grpLast.Add(om); continue; } // 一级为分组,处理二级 GroupData <OmMenu> grpCur = new GroupData <OmMenu>() { Title = om.Name }; index = 0; while (index < _leaveMenus.Count) { var ch = _leaveMenus[index]; if (ch.ParentID == om.ID) { // 二级菜单 grpCur.Add(ch); _leaveMenus.RemoveAt(index); } else { index++; } } if (grpCur.Count > 0) { _rootPageMenus.Add(grpCur); } } // 一级实体项放在最后 if (grpLast != null) { _rootPageMenus.Add(grpLast); } }