using FineUIPro;
|
using iWareCommon.Common.Entity;
|
using iWareDataCore.RBAC.Entity;
|
using iWareDataCore.RBAC.Service;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Web.Security;
|
|
namespace iWareWms
|
{
|
public partial class index : PageBase
|
{
|
|
private JObject GetClientIDS(params ControlBase[] ctrls)
|
{
|
JObject jo = new JObject();
|
foreach (ControlBase ctrl in ctrls)
|
{
|
jo.Add(ctrl.ID, ctrl.ClientID);
|
}
|
|
return jo;
|
}
|
|
protected void Page_Load(object sender, EventArgs e)
|
{
|
|
if (!IsPostBack)
|
{
|
Session.Timeout = 7200;
|
var user = Session["UserInfo"] == null ? null : (UserEntity)Session["UserInfo"];
|
|
|
if (user == null)
|
{
|
FormsAuthentication.SignOut();
|
Session.Abandon();
|
FormsAuthentication.RedirectToLoginPage();
|
return;
|
}
|
|
btnChangeUserInfo.OnClientClick = Window1.GetShowReference(string.Format("~/View/RBAC/User/UserInfo.aspx"), "修改个人信息");
|
//if (!string.IsNullOrEmpty(user.Photo))
|
//{
|
// userIcon.ImageUrl = "~/NonAuth/Image.aspx?path=" + user.Photo;
|
//}
|
|
// 注册客户端脚本,服务器端控件ID和客户端ID的映射关系
|
JObject jObjects = GetClientIDS(RegionPanel, regionTop, mainTabStrip, txtUser, txtCurrentTime, BtnRefresh);
|
jObjects.Add("userName", user.Name);
|
|
|
Accordion accordionMenu = InitAccordionMenu(new List<ContentValueEntity>(user.Contents));
|
jObjects.Add("treeMenu", accordionMenu.ClientID);
|
jObjects.Add("menuType", "accordion");
|
|
string idsScriptStr = String.Format("window.DATA={0};", jObjects.ToString(Newtonsoft.Json.Formatting.None));
|
|
|
|
PageContext.RegisterStartupScript(idsScriptStr);
|
|
}
|
|
}
|
protected void BtnExit_Click(object sender, EventArgs e)
|
{
|
FormsAuthentication.SignOut();
|
Session.Abandon();
|
FormsAuthentication.RedirectToLoginPage();
|
Response.Write("<script language='javascript'>window.location='login.aspx'</script>");
|
}
|
|
protected override void WindowClose(object sender, EventArgs e)
|
{
|
string msg;
|
var user = GetLoginPerson();
|
var users = UserService.GetInstance().QueryByParam(new QueryParam { Filter = new Dictionary<string, object> { { "Id", user.Id } } }, out msg);
|
Session["UserInfo"] = users.Count > 0 ? users[0] : user;
|
//if (!string.IsNullOrEmpty(user.Photo))
|
//{
|
// userIcon.ImageUrl = "~/NonAuth/Image.aspx?path=" + users[0].Photo;
|
//}
|
|
txtUser.Text = users[0].Name;
|
}
|
|
|
#region 初始化手风琴菜单
|
|
/// <summary>
|
/// 创建手风琴菜单
|
/// </summary>
|
/// <param name="menus"></param>
|
/// <returns></returns>
|
private Accordion InitAccordionMenu(List<ContentValueEntity> menus)
|
{
|
var accordionMenu = new Accordion
|
{
|
ID = "accordionMenu",
|
EnableFill = true,
|
ShowBorder = false,
|
ShowHeader = false
|
};
|
regionLeft.Items.Add(accordionMenu);
|
|
for (var i = 0; i < menus.Count; i++)
|
{
|
AccordionPane accordionPane = new AccordionPane
|
{
|
Title = menus[i].Name,
|
Layout = LayoutType.Fit,
|
ShowBorder = false,
|
BodyPadding = "2px 0 0 0"
|
};
|
|
Tree innerTree = new Tree
|
{
|
ShowBorder = false,
|
ShowHeader = false,
|
EnableIcons = true,
|
AutoScroll = true,
|
EnableSingleClickExpand = true,
|
EnableNodeHyperLink = true
|
};
|
|
// 生成树
|
int nodeCount = ResolveMenuTree(new List<ContentValueEntity>(menus[i].Children), innerTree.Nodes);
|
|
|
if (nodeCount > 0)
|
{
|
accordionPane.Items.Add(innerTree);
|
accordionMenu.Items.Add(accordionPane);
|
}
|
}
|
return accordionMenu;
|
}
|
|
#endregion
|
|
|
#region 初始化菜单树
|
|
/// <summary>
|
/// 生成菜单树
|
/// </summary>
|
/// <param name="menus"></param>
|
/// <param name="parentMenuId"></param>
|
/// <param name="nodes"></param>
|
private int ResolveMenuTree(List<ContentValueEntity> menus, FineUIPro.TreeNodeCollection nodes)
|
{
|
int count = 0;
|
for (var i = 0; i < menus.Count; i++)
|
{
|
FineUIPro.TreeNode node = new FineUIPro.TreeNode();
|
nodes.Add(node);
|
count++;
|
node.Text = menus[i].Name;
|
node.IconUrl = menus[i].Image;
|
if (!string.IsNullOrEmpty(menus[i].Url))
|
{
|
|
node.NavigateUrl = ResolveUrl(menus[i].Url);
|
}
|
if (menus[i].Children.Count > 0)
|
{
|
int childCount = ResolveMenuTree(new List<ContentValueEntity>(menus[i].Children), node.Nodes);
|
}
|
|
}
|
return count;
|
}
|
|
#endregion
|
|
|
#region Session过期自动跳转到登录界面
|
|
protected void Timer1_Tick(object sender, EventArgs e)
|
{
|
|
if (Session["UserInfo"] == null)
|
{
|
|
FormsAuthentication.SignOut();
|
Session.Abandon();
|
FormsAuthentication.RedirectToLoginPage();
|
}
|
|
}
|
#endregion
|
}
|
}
|