前五章均是从整体上讲述了Web应用程序的多用户权限控制实现流程,本章讲述Web权限管理系统的基本模块-用户模块。用户模块涉及到的数据表为用户表。

1.1用户域

为了更规范和方便后期系统的二次开发和维护,对应特定的业务模块采用Area(域)的方式开发,用户模块的开发域如下图所示:

Web应用程序系统的多用户权限控制设计及实现-用户模块【7】

由于在Areas下还建立了一个新的目录SystemManage,故需要改变原来的路由。用户模块的路由文件名称为OperatorManageAreaRegistration。改变路由代码的文件名称为如下:

using System.Web.Mvc;
namespace CodeForMvcTest.Areas.OperatorManage
{
    public class OperatorManageAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "SystemManage/OperatorManage";
            }
        }
        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "SystemManage_OperatorManage_default",
                "SystemManage/OperatorManage/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

 1.2Model

分组模块的Model可参看第三章项目架构的系统共有类,对应model为AccountInfo.cs。文件路径为Areas/SystemManage/Models。

 1.3视图

用户模块的视图包含在用户域中,文件路径为Areas/SystemManage/OperatorManage/Views/OperatorManage,视图名称为OperatorManage.cshtml。视图的完整代码如下:

  1 @{
  2     ViewBag.Title = "用户管理";
  3     Layout = "~/Views/Shared/_BaseLayout.cshtml";
  4 }
  5 
  6 <div class="easyui-layout" data-options="fit:true">
  7 
  8     <div data-options="region:'north',split:true" style="height: 50px;">
  9         <form id="searchForm" method="POST" action="@Url.Action("OperatorManage", "OperatorManage")">
 10             <!--筛选栏-->
 11             <table style="margin-left: 5px; margin-top: 5px;">
 12                 <tr>
 13                     <td><span>用户组:</span></td>
 14                     <td>
 15                         <select class="easyui-combobox" name="groupId" id="groupId" style="width: 150px;"
 16                             data-options="editable:false,valueField:'GroupId',textField:'GroupName'">
 17                             @Html.Raw(ViewBag.GroupListWithAll)
 18                         </select>
 19                     </td>
 20                     <td><span style="margin-left: 10px;">用户账号:</span></td>
 21                     <td>
 22                         <input class="easyui-textbox" id="operatorId" name="operatorId" />
 23                     </td>
 24                     <td><span style="margin-left: 10px;">名称:</span></td>
 25                     <td>
 26                         <input class="easyui-textbox" id="operatorName" name="operatorName" />
 27                     </td>
 28                     <td>
 29                         <input type="submit" value="查找" id="btn_submit" style="margin-left: 10px; margin-right: 10px;" />
 30                     </td>
 31                 </tr>
 32             </table>
 33         </form>
 34     </div>
 35 
 36     <div data-options="region:'center',split:true" style="padding-bottom: 10px;" id="centerDiv">
 37         <table id="dataGrid">
 38             <thead>
 39                 <tr>
 40                     <th data-options="field:'OperatorId',align:'left'">用户账号</th>
 41                     <th data-options="field:'OperatorName',align:'left'">名称</th>
 42                     <th data-options="field:'OperatorGroupName',align:'left'">所属用户组</th>
 43                     <th data-options="field:'Sex',align:'center'">性别</th>
 44                     <th data-options="field:'IsOnStaff',align:'center',formatter:statusformater">状态</th>
 45                     <th data-options="field:'AliasName',align:'center',formatter:operateFormater">操作</th>
 46                 </tr>
 47             </thead>
 48             <tbody>
 49                
 50             </tbody>
 51         </table>
 52         <br />
 53     </div>
 54 
 55 </div>
 56 
 57 <!--属性组工具栏-->
 58 <div id="operator_tb" style="height: auto">
 59     <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="openAddWindow();">添加用户</a>
 60 </div>
 61 
 62 
 63 <!--用户信息编辑窗体-->
 64 <div id="operatorEditWin" title="修改用户信息" style="width: 450px; height: 500px; padding: 20px; text-align: center;">
 65     <form id="operatorEditForm" method="POST" action="@Url.Action("UpdateOperator", "OperatorManage")">
 66         <table style="margin: auto;">
 67             <tr>
 68                 <td style="text-align: right;"><span>用户账号:</span></td>
 69                 <td>
 70                     <input class="easyui-validatebox" data-options="required:true" id="e_operatorId" name="operatorId" />
 71                 </td>
 72             </tr>
 73             <tr style="height: 40px;">
 74                 <td style="text-align: right;"><span>名称:</span></td>
 75                 <td>
 76                     <input class="easyui-validatebox" id="e_operatorName" name="operatorName" data-options="required:true" />
 77                 </td>
 78             </tr>
 79             <tr style="height: 30px;">
 80                 <td style="text-align: right;"><span>用户组:</span></td>
 81                 <td>
 82                     <select class="easyui-combobox" name="groupId" id="e_groupId" style="width: 150px;"
 83                         data-options="editable:false,required:true,multiple:true">
 84                         @Html.Raw(ViewBag.GroupList)
 85                     </select>
 86                 </td>
 87             </tr>
 88          
 89             <tr style="height: 40px;">
 90                 <td style="text-align: right;"><span>性别:</span></td>
 91                 <td>
 92                     <select class="easyui-combobox" name="sex" id="e_sex" style="width: 150px;"
 93                         data-options="editable:false,required:true">
 94                         <option value="0"></option>
 95                         <option value="1"></option>
 96                     </select>
 97                 </td>
 98             </tr>
 99             <tr style="height: 40px;">
100                 <td style="text-align: right;"><span>状态:</span></td>
101                 <td>
102                     <select class="easyui-combobox" name="state" id="e_state" style="width: 150px;"
103                         data-options="editable:false,required:true">
104                         <option value="0">禁用</option>
105                         <option value="1">启用</option>
106                     </select>
107                 </td>
108             </tr>
109             <tr style="height: 50px;">
110                 <td colspan="2" style="text-align: right;">
111                     <input type="hidden" id="oldId" name="oldId" />
112                     <input type="submit" value="提交" id="btn_editsubmit" style="margin-left: 10px; margin-right: 10px;" />
113                     <input type="button" value="取消" id="btn_editCancel" onclick="javascript: return $('#operatorEditWin').window('close');"
114                         style="margin-left: 10px; margin-right: 10px;" />
115                 </td>
116             </tr>
117         </table>
118     </form>
119 </div>
120 
121 
122 
123 <!--用户添加窗体-->
124 <div id="operatorAddWin" title="添加用户" style="width: 450px; height: 500px; padding: 20px; text-align: center;">
125     <form id="operatorAddForm" method="POST" action="@Url.Action("AddOperator", "OperatorManage")">
126         <table style="margin: auto;">
127             <tr>
128                 <td style="text-align: right;"><span>用户账号:</span></td>
129                 <td>
130                     <input class="easyui-validatebox" data-options="required:true" id="a_operatorId" name="operatorId" />
131                 </td>
132             </tr>
133             <tr style="height: 30px;">
134                 <td style="text-align: right;"><span>名称:</span></td>
135                 <td>
136                     <input class="easyui-validatebox" id="a_operatorName" name="operatorName" data-options="required:true" />
137                 </td>
138             </tr>
139             <tr style="height: 30px;">
140                 <td style="text-align: right;"><span>密码:</span></td>
141                 <td>
142                     <input type="password" id="a_password" name="password" data-options="required:true" />
143                 </td>
144             </tr>
145             <tr style="height: 30px;">
146                 <td style="text-align: right;"><span>确认密码:</span></td>
147                 <td>
148                     <input type="password" id="a_passwordconfirm" name="passwordconfirm" data-options="required:true" />
149                 </td>
150             </tr>
151             <tr style="height: 30px;">
152                 <td style="text-align: right;"><span>用户组:</span></td>
153                 <td>
154                     <select class="easyui-combobox" name="groupId" id="a_groupId" style="width: 150px;"
155                         data-options="editable:false,required:true,multiple:true">
156                         @Html.Raw(ViewBag.GroupList)
157                     </select>
158                 </td>
159             </tr>
160          
161             
162             <tr style="height: 30px;">
163                 <td style="text-align: right;"><span>性别:</span></td>
164                 <td>
165                     <select class="easyui-combobox" name="sex" id="a_sex" style="width: 150px;"
166                         data-options="editable:false,required:true">
167                         <option value="0"></option>
168                         <option value="1"></option>
169                     </select>
170                 </td>
171             </tr>
172             <tr style="height: 30px;">
173                 <td style="text-align: right;"><span>状态:</span></td>
174                 <td>
175                     <select class="easyui-combobox" name="state" id="a_state" style="width: 150px;"
176                         data-options="editable:false,required:true">
177                         <option value="0">禁用</option>
178                         <option value="1">启用</option>
179                     </select>
180                 </td>
181             </tr>
182             <tr style="height: 50px;">
183                 <td colspan="2" style="text-align: right;">
184                     <input type="submit" value="提交" id="btn_addsubmit" style="margin-left: 10px; margin-right: 10px;" />
185                     <input type="button" value="取消" id="btn_addCancel" onclick="javascript: return $('#operatorAddWin').window('close');"
186                         style="margin-left: 10px; margin-right: 10px;" />
187                 </td>
188             </tr>
189         </table>
190     </form>
191 </div>
192 
193 
194 
195 @section scripts
196 {
197     <script type="text/javascript" src="/Areas/SystemManage/SystemJS/operatorManage.js"></script>
198 }
OperatorMange.cshtml

相关文章:

  • 2022-01-07
  • 2021-08-17
猜你喜欢
  • 2021-07-26
  • 2021-11-23
  • 2022-01-12
  • 2022-02-01
  • 2021-08-10
  • 2021-08-03
  • 2021-06-13
相关资源
相似解决方案