schangxiang@126.com
2025-08-20 b7bb4bf8ee6d007e0e7c3cacfc4fab77049beb58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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
    }
}