123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- @using WeApp
- @using WeApp.Authorization
- @using WeApp.Configuration
- @using WeApp.Views.Shared.Modals
- @using WeApp.Views.Shared.SearchForm
- @using WeApp.Views.Shared.Table
- @{
- string activeMenu = PermissionNames.PagesSystemMgUserMg; //The menu item will be active for this page.
- ViewBag.ActiveMenu = activeMenu;
- ViewBag.Title = L("UserTitle");
- List<SelectListItem> userType = ViewBag.UserType;
- List<SelectListItem> activeType = ViewBag.IsActive;
- List<SelectListItem> accountType = ViewBag.AccountType;
- var searchItem = new List<SearchItem>()
- {
- new SearchItem("userName", L("userName")),
- new SearchItem("name", L("realName")),
- new SearchItem("userType", L("userType"), FieldType.I, ExpType.Equal).SetSelectItem(userType,true),
- new SearchItem("emailAddress", L("emailAddress")),
- new SearchItem("isActive", L("activeState"), FieldType.B, ExpType.Equal).SetSelectItem(activeType,true),
- //new SearchItem("lastLoginTime", "最后登陆时间", FieldType.Dn).SetDateItem(0),
- };
- if (AbpSession.AccountType == 1)
- {
- searchItem.Add(new SearchItem("accountType", L("accountType"), FieldType.In, ExpType.Equal).SetSelectItem(accountType, true));
- }
- var searchForm = new SearchFormViewModel(searchItem);
- var table = new TableViewModel(IwbConsts.ApiAppUrl + "Users/GetAll", activeMenu, searchForm).SetFields(new List<FieldItem>()
- {
- new FieldItem("userName", L("userName")),
- new FieldItem("name", L("realName")),
- new FieldItem("emailAddress", L("emailAddress")),
- new FieldItem("userType", L("userType"), "UserTypeFormatter"),
- new FieldItem("accountType", L("accountType"), "AccountTypeFormatter"),
- new FieldItem("", L("accountState"), "AccountStateFormatter"),
- new FieldItem("isActive", L("activeState"), "ActiveStateFormatter"),
- });
- }
- @section styles{
- <link href="~/Content/Libs/jstree/themes/default/style.min.css" rel="stylesheet" />
- }
- @Html.Partial("Table/_Table", table)
- @section modal{
- @{
- var inputs = new List<Input>()
- {
- new InputHide("id"),
- new InputHide("userName"),
- new Input("userType", L("userType")).SetSelectOptions(userType),
- new Input("name", L("realName")),
- new Input("emailAddress", L("emailAddress")),
- new Input("isActive", L("activeState")).SetSelectOptions(activeType)
- };
- if (AbpSession.AccountType == AccountTypeDefinition.System)
- {
- inputs.Add(new Input("accountType", L("accountType"))
- .SetSelectOptions(accountType));
- //inputs.Add(new Input("accountNo", InputTypes.List, "账号所属").SetNotRequired());
- }
- else
- {
- inputs.Add(new Input("accountType", value: AbpSession.AccountType + "", hide: true));
- inputs.Add(new Input("accountTypeName", L("accountType"), value: ViewBag.AccountTypeName).SetNotRequired());
- //inputs.Add(new Input("accountNo", InputTypes.List, "账号所属").SetNotRequired());
- }
- if (AbpSession.UserType == UsersAndRolesTypeDefinition.Supper || AbpSession.UserType == UsersAndRolesTypeDefinition.System)
- {
- inputs.Add(new Input("roleNames", L("roleInfos")).SetNotRequired()
- .SetSelectOptions((List<SelectListItem>)ViewBag.Roles, true));
- }
- var modal = new ModalViewModel(L("user"), new ModalBodyViewModel(inputs));
- }
- @Html.Partial("Modals/_Modal", modal)
- <section>
- <!--Auth Modal -->
- <div class="modal fade" id="auth_Modal" role="dialog" aria-labelledby="ModalLabel_AUTH" aria-hidden="true">
- <div class="modal-dialog" role="document" style="min-height: 700px; width: 500px;">
- <div class="modal-content" style="">
- @Html.Partial("Modals/_ModalHeader", new ModalHeaderViewModel(L("userAuthSetting"), ""))
- <form>
- <div class="modal-body" style=" padding: 10px 30px;">
- <div class="" id="auth-tree"></div>
- </div>
- </form>
- @Html.Partial("Modals/_ModalFooter", "0")
- </div>
- </div>
- </div>
- </section>
- }
- @section scripts
- {
- <script src="~/Content/Libs/jstree/jstree.min.js"></script>
- <script type="text/javascript">
- $(function() {
- var $table = LoadTable();
- var funs = window.iwbfuns || { none: function() { console.log("No type"); } };
- funs["btnCreate"] = function() {
- BtnCreate({
- data: { accountType: "@AbpSession.AccountType", accountTypeName: "@ViewBag.AccountTypeName" }
- });
- };
- @{
- var disabled = AbpSession.UserType == UsersAndRolesTypeDefinition.Supper ? "" : ",userType,accountType";
- }
- funs["btnUpdate"] = function() {
- var rows = $table.bootstrapTable("getSelections");
- if (rows.length === 1) {
- var userId = rows[0].id;
- $.iwbAjax4({
- url: abp.appUrl + 'Users/GetUserRoles?UserId=' + userId,
- dataType: "json",
- success: function(res) {
- var data = rows[0];
- data.roleNames = res;
- //console.log(data);
- //$("#accountType").off("change.accountType");
- BtnUpdate({ disabled: "userName@(Html.Raw(disabled))", data: data });
- //$("#accountType").on("change.accountType", ChangeAccountList);
- //ChangeAccountList(rows[0].accountNo);
- }
- });
- }
- };
- funs["btnResetLock"] = function(url) {
- var row = $table.bootstrapTable("getSelections")[0];
- if (row) {
- BtnConfirm(abp.localization.iwbZero("UserUnLockConfirmContent"), abp.localization.iwbZero("UserUnLockConfirm"), url, row);
- }
- };
- funs["btnAuth"] = function(url) {
- var rows = $table.bootstrapTable("getSelections");
- if (rows.length === 1) {
- abp.ui.setBusy();
- var userId = rows[0].id;
- $.iwbAjax4({
- url: abp.appUrl + 'Users/GetPermissions?userId=' + userId,
- success: function(res) {
- $("#auth_Modal").on('show.bs.modal',
- function() {
- AuthFormatter(res);
- $("#auth_Modal").find("button.save-btn").off("click").on("click",
- function() {
- var authData = GetAuthData(userId);
- $.iwbAjax1({
- url: url,
- success: function() { $("#auth_Modal").modal("hide"); },
- data: authData
- });
- });
- });
- $("#auth_Modal").modal("show");
- }
- });
- } else
- abp.message.warn(abp.localization.iwbZero("SelectRecordOperation"));
- };
- funs["btnResetPwd"] = function(url) {
- console.log("ResetPwd");
- var row = $table.bootstrapTable("getSelections")[0];
- if (row) {
- MsgConfirm(
- "确定重置 【" + row.name + "(" + row.userName + ") 】的密码吗?", "重置密码",
- function() {
- $.iwbAjax1({ url: url, data: { Id: row.id }, isValidate: false });
- });
- } else
- abp.message.warn(abp.localization.iwbZero("SelectRecordOperation"));
- };
- //ChangeAccountList(null,"@AbpSession.AccountType");
- // $("#accountType").on("change.accountType", ChangeAccountList);
- });
- //function ChangeAccountList(accountNo, accountType) {
- // accountType = accountType||$("#accountType").val();
- // if (accountType === "1") {
- // $("#accountNo").closest(".form-group-sm").css("display", "none");
- // } else {
- // var url = window.appUrl + (accountType === "2" ? "LawyerInfo/GetSelectStrForNoAccount" : "CustomerContact/GetSelectStrForNoAccount");
- // abp.ajax({
- // url: url,
- // type: 'POST',
- // dataType: "json",
- // success: function (res) {
- // console.log(res);
- // res = '<option value="">请选择...</option>' + res;
- // $("#accountNo").closest(".form-group-sm").css("display", "block");
- // if (accountNo) {
- // $("#accountNo").html(res).val(accountNo).select2();
- // } else {
- // $("#accountNo").html(res).select2();
- // }
- // }
- // });
- // }
- //}
- </script>
- <script>
- function AuthFormatter(data) {
- var authData = [];
- authData.push(data);
- authData = AuthDataConvert(authData).authData;
- console.log(authData);
- $("#auth-tree").jstree("destroy");
- $("#auth-tree").jstree({
- plugins: ["wholerow", "checkbox", "types"],
- core: {
- themes: {
- responsive: false
- },
- data: authData
- },
- types: {
- default:
- {
- icon: "fa fa-folder m--font-warning"
- },
- file: {
- icon: "fa fa-file m--font-warning"
- }
- }
- });
- //[{
- // text: "Same but with checkboxes",
- // children: [{
- // id:"",
- // text: "initially selected",
- // state: {
- // selected: !0
- // opened: !0
- // disabled: !0
- // }
- // }]
- // }]
- }
- function AuthDataConvert(data) {
- //console.log(data);
- var authData = [], j = 0;
- for (var i = 0; i < data.length; i++) {
- var item = data[i], newItem = {};
- newItem["id"] = item.name;
- newItem["text"] = item.permDisplayName;
- newItem["icon"] = item.icon + " m--font-warning ";
- newItem["state"] = {};
- newItem["state"].opened = item.isOpen;
- var childResult = { "authData": [], "isAuth": true };
- if (item.children && item.children.length > 0) {
- childResult = AuthDataConvert(item.children);
- newItem["children"] = childResult.authData;
- }
- if (!(item.isAuth && childResult.isAuth)) {
- j++;
- }
- newItem["state"].selected = item.isAuth && childResult.isAuth;
- authData.push(newItem);
- }
- var result = { "authData": authData, "isAuth": j === 0 };
- return result;
- }
- function GetAuthData(roleId) {
- var authData = { Id: roleId, PermissionNames: [] };
- var permissionNames = $('#auth-tree').jstree(true).get_selected(false); //获得所有选中节点,返回值为数组
- //console.log(1,permissionNames);
- //加上灰色的节点
- $(".jstree-undetermined").each(function() {
- permissionNames.push($(this).parent().parent().attr('id'));
- });
- //console.log(2,permissionNames);
- authData.PermissionNames = permissionNames;
- return authData;
- }
- </script>
- <script>
- function UserTypeFormatter(v) {
- var name = $('#modal #userType option[value="' + v + '"]').text();
- if (v === 0) {
- return '<span class="label label-danger">' + name + '</span>';
- } else if (v === 1) {
- return '<span class="label label-success">' + name + '</span>';
- } else if (v === 2) {
- return '<span class="label label-warning">' + name + '</span>';
- } else if (v === 3) {
- return '<span class="label label-primary">' + name + '</span>';
- }
- return v;
- }
- function AccountTypeFormatter(v) {
- var name = $('#hid-accountType option[value="' + v + '"]').text();
- if (v === 1) {
- return '<span class="label label-danger">' + name + '</span>';
- } else if (v === 2) {
- return '<span class="label label-success">' + name + '</span>';
- }
- return v;
- }
- function AccountStateFormatter(v, r) {
- if (r.accountType === 1) {
- return '<span class="label label-primary"> 不分配</span>';
- }
- if (v) {
- return '<span class="label label-success"> 已分配</span>';
- }
- return '<span class="label label-danger"> 未分配</span>';
- }
- function ActiveStateFormatter(v) {
- var name = $('#hid-activeType option[value="' + v + '"]').text();
- if (v) {
- return '<span class="label label-success"> ' + name + '</span>';
- }
- return '<span class="label label-danger"> ' + name + '</span>';
- }
- </script>
- }
- <section style="display:none">
- @Html.DropDownList("hid-accountType", accountType)
- @Html.DropDownList("hid-activeType", activeType)
- </section>
|