972 lines
38 KiB
Plaintext
972 lines
38 KiB
Plaintext
|
||
@{
|
||
ViewData["MainNum"] = "6";
|
||
ViewData["SubNum"] = "1";
|
||
ViewData["Title"] = "帳號管理";
|
||
}
|
||
|
||
<ol class="breadcrumb page-breadcrumb">
|
||
<li class="breadcrumb-item"><a href="javascript:void(0);">系統管理</a></li>
|
||
<li class="breadcrumb-item active">帳號管理</li>
|
||
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
|
||
</ol>
|
||
|
||
<div class="row">
|
||
<div class="col-xl-12">
|
||
<div id="panel-5" class="panel">
|
||
<div class="panel-container show">
|
||
<div class="panel-content">
|
||
<ul class="nav nav-tabs" id="tabs" role="tablist">
|
||
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#tab-user-manager" role="tab"><i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">帳號管理</span></a></li>
|
||
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#tab-role-manager" role="tab"><i class="fal fa-user text-primary"></i> <span class="hidden-sm-down ml-1">角色管理</span></a></li>
|
||
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#tab-role-auth" role="tab"><i class="fal fa-cog text-danger"></i> <span class="hidden-sm-down ml-1">角色權限</span></a></li>
|
||
</ul>
|
||
<div class="tab-content p-3">
|
||
<div class="tab-pane fade show active" id="tab-user-manager" role="tabpanel" aria-labelledby="tab-user-manager">
|
||
@Html.Partial("_UserManager")
|
||
</div>
|
||
|
||
<div class="tab-pane fade" id="tab-role-manager" role="tabpanel" aria-labelledby="tab-role-manager">
|
||
@Html.Partial("_RoleManager")
|
||
</div>
|
||
|
||
<div class="tab-pane fade" id="tab-role-auth" role="tabpanel" aria-labelledby="tab-role-auth">
|
||
@Html.Partial("_RoleAuth")
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
@section Scripts {
|
||
<script>
|
||
var userManagerTable;
|
||
var selected_id = "0";
|
||
|
||
$(function () {
|
||
|
||
//#region 切換頁簽判斷被選中的tab
|
||
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||
selected_tab = $(e.target).attr("href")
|
||
|
||
switch (selected_tab) {
|
||
case "#tab-user-manager":
|
||
userManagerTable.ajax.reload();
|
||
break;
|
||
case "#tab-role-manager":
|
||
roleManagerTable.ajax.reload();
|
||
break;
|
||
case "#tab-role-auth":
|
||
var url = "/UserInfo/RoleManagerList";
|
||
$.post(url, { post: 1 }, function (rel) {
|
||
if (rel.code != "0000") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
if (rel.data.length > 0) {
|
||
$('#select_roleId_roleAuth_tab').empty();
|
||
$.each(rel.data, function (index, val) {
|
||
$("#select_roleId_roleAuth_tab").append($("<option />").val(val.role_guid).text(val.full_name));
|
||
});
|
||
//預設查詢第一個
|
||
$("#select_roleId_roleAuth_tab").val($("#select_roleId_roleAuth_tab option:first").val());
|
||
|
||
roleAuthTable.ajax.reload();
|
||
|
||
} else {
|
||
$("#select_roleId_roleAuth_tab").empty();
|
||
$("#select_roleId_roleAuth_tab").append('<option value="0" disabled>請先新增角色</option>');
|
||
$("#select_roleId_roleAuth_tab").val($("#user_role_modal option:first").val());
|
||
}
|
||
}, 'json');
|
||
break;
|
||
}
|
||
});
|
||
//#endregion
|
||
|
||
|
||
//#region 人員基本資料 DataTable
|
||
userManagerTable = $("#user_table").DataTable({
|
||
"columns": [
|
||
{
|
||
"data": null,
|
||
"render": function (data, type, row, meta) {
|
||
return meta.row + 1;
|
||
}
|
||
},
|
||
{
|
||
"data": "full_name"
|
||
},
|
||
{
|
||
"data": "account"
|
||
},
|
||
{
|
||
"data": "role_full_name"
|
||
},
|
||
{
|
||
"data": "email"
|
||
},
|
||
{
|
||
"data": "phone"
|
||
},
|
||
{
|
||
"data": "created_at"
|
||
},
|
||
{
|
||
"data": "userinfo_guid",
|
||
"render": function (data, type, row, meta) {
|
||
if (data == "0") {
|
||
return "";
|
||
} else {
|
||
if (data != '@ViewBag.myUserInfo.Userinfo_guid') {
|
||
return '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>';
|
||
} else {
|
||
return '<button class="btn btn-primary edit-btn">修改</button>';
|
||
}
|
||
}
|
||
}
|
||
//"defaultContent": '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'
|
||
}
|
||
],
|
||
//"order": [[2, "desc"]],
|
||
'createdRow': function (row, data, dataIndex) {
|
||
$(row).attr('data-guid', data.userinfo_guid);
|
||
},
|
||
"ajax": {
|
||
"url": "/UserInfo/UserManagerList",
|
||
"type": "POST",
|
||
"dataSrc": function (rel) {
|
||
if (rel.code == "9999") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
|
||
data = rel.data;
|
||
|
||
if (data == null || data.length == 0) {
|
||
this.data = [];
|
||
}
|
||
if (@ViewBag.myUserInfo.Layer == 1) {
|
||
$.each(this.data, function (index, val) {
|
||
if (val.layer == 0) {
|
||
val.userinfo_guid = "0"
|
||
}
|
||
});
|
||
}
|
||
|
||
console.log(this.data);
|
||
return data;
|
||
}
|
||
}
|
||
});
|
||
//#endregion
|
||
});
|
||
|
||
//#region 新增使用者
|
||
function AddUser() {
|
||
selected_id = "0";
|
||
$("#user-modal .modal-title").html("人員基本資料 - 新增");
|
||
$("#user-form").trigger("reset");
|
||
$("#user_account_modal").prop("disabled", false);
|
||
$(".user_account_same_email_div").show();
|
||
$("#user_account_same_email").prop("disabled", false);
|
||
$(".user-password-div").show();
|
||
GetRoleDropDownList('', 1);
|
||
|
||
$("#user-modal").modal();
|
||
}
|
||
//#endregion
|
||
|
||
//#region 編輯使用者
|
||
$('#user_table').on("click", "button.edit-btn", function () {
|
||
|
||
$("#user-modal .modal-title").html("人員基本資料 - 編輯");
|
||
|
||
selected_id = $(this).parents('tr').attr('data-guid');
|
||
|
||
//取得單一使用者管理員
|
||
var url = "/UserInfo/GetOneUser/";
|
||
|
||
var send_data = {
|
||
guid: selected_id
|
||
}
|
||
|
||
$.post(url, send_data, function (rel) {
|
||
if (rel.code == "9999") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
else if (rel.code == "9998") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
$("#user_name_modal").val(rel.data.full_name);
|
||
$("#user_email_modal").val(rel.data.email);
|
||
$("#user_account_modal").val(rel.data.account);
|
||
$("#user_account_modal").prop("disabled", true);
|
||
$(".user_account_same_email_div").hide();
|
||
$("#user_account_same_email").prop("disabled", true);
|
||
$(".system_admin_password_form_row").hide();
|
||
$("#user_phone_modal").val(rel.data.phone);
|
||
|
||
GetRoleDropDownList(rel.data.role_guid, 1);
|
||
|
||
$(".user-password-div").hide();
|
||
|
||
$("#user-modal").modal();
|
||
}, 'json');
|
||
|
||
});
|
||
//#endregion
|
||
|
||
//#region 取得角色下拉選單
|
||
function GetRoleDropDownList(selectedVal, type) {
|
||
var url = "/UserInfo/RoleManagerList";
|
||
$.post(url, { post : 0 }, function (rel) {
|
||
if (rel.code != "0000") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
if (type == 1) {
|
||
if (rel.data.length > 0) {
|
||
$('#user_role_modal').empty();
|
||
$.each(rel.data, function (index, val) {
|
||
if (@ViewBag.myUserInfo.Layer == 1) {
|
||
if (val.layer == 0) {
|
||
$("#user_role_modal").append($("<option disabled style='background: #ccc;'/>").val(val.role_guid).text(val.full_name));
|
||
} else {
|
||
$("#user_role_modal").append($("<option />").val(val.role_guid).text(val.full_name));
|
||
}
|
||
|
||
} else {
|
||
$("#user_role_modal").append($("<option />").val(val.role_guid).text(val.full_name));
|
||
}
|
||
|
||
|
||
});
|
||
if (selectedVal != "") {
|
||
$("#user_role_modal").val(selectedVal);
|
||
}
|
||
else {
|
||
//預設查詢第一個
|
||
$("#user_role_modal").val($("#user_role_modal option:first").val()).trigger('change');
|
||
}
|
||
} else {
|
||
$("#user_role_modal").empty();
|
||
$("#user_role_modal").append('<option value="0" disabled>請先新增角色</option>');
|
||
$("#user_role_modal").val($("#user_role_modal option:first").val()).trigger('change');
|
||
}
|
||
}
|
||
else {
|
||
if (rel.data.length > 0) {
|
||
$('#select_roleId_roleAuth_tab').empty();
|
||
$.each(rel.data, function (index, val) {
|
||
$("#select_roleId_roleAuth_tab").append($("<option />").val(val.role_guid).text(val.full_name));
|
||
});
|
||
if (selectedVal != "") {
|
||
$("#select_roleId_roleAuth_tab").val(selectedVal);
|
||
}
|
||
else {
|
||
//預設查詢第一個
|
||
$("#select_roleId_roleAuth_tab").val($("#select_roleId_roleAuth_tab option:first").val()).trigger('change');
|
||
}
|
||
} else {
|
||
$("#select_roleId_roleAuth_tab").empty();
|
||
$("#select_roleId_roleAuth_tab").append('<option value="0" disabled>請先新增角色</option>');
|
||
$("#select_roleId_roleAuth_tab").val($("#user_role_modal option:first").val()).trigger('change');
|
||
}
|
||
}
|
||
//toast_ok(rel.msg);
|
||
}, 'json');
|
||
}
|
||
//#endregion
|
||
|
||
//#region 帳號是否等同Email
|
||
$('#user_account_same_email').change(function () {
|
||
var email = $("#user_email_modal").val();
|
||
if (email == undefined || email == null || email == "") {
|
||
toast_warning("請先填寫email");
|
||
$(this).prop("checked", false);
|
||
return;
|
||
}
|
||
if (this.checked && selected_id == 0) {
|
||
//只提供新增時,可透過email填入帳號欄位
|
||
$("#user_account_modal").val(email);
|
||
$("#user_account_modal").prop("disabled", true);
|
||
}
|
||
else {
|
||
$("#user_account_modal").prop("disabled", false);
|
||
}
|
||
});
|
||
//#endregion
|
||
|
||
//#region 使用者表單驗證
|
||
$("#user-form").validate({
|
||
rules: {
|
||
user_name_modal: {
|
||
required: true,
|
||
},
|
||
user_email_modal: {
|
||
required: true,
|
||
email: true,
|
||
},
|
||
user_account_modal: {
|
||
required: true,
|
||
}
|
||
},
|
||
});
|
||
//#endregion
|
||
|
||
//#region 儲存使用者
|
||
function SaveUser() {
|
||
if ($("#user-form").valid()) {
|
||
|
||
$("#save-user-btn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
|
||
|
||
var url = "/UserInfo/SaveUser";
|
||
var send_data = {
|
||
Id: selected_id,
|
||
Name: $("#user_name_modal").val(),
|
||
Password: $("#user_password_modal").val(),
|
||
Email: $("#user_email_modal").val(),
|
||
Account: $("#user_account_modal").val(),
|
||
Phone: $("#user_phone_modal").val(),
|
||
RoleId: $("#user_role_modal").val()
|
||
}
|
||
$.post(url, send_data, function (rel) {
|
||
$("#save-user-btn").html('確定').attr("disabled", false);
|
||
if (rel.code != "0000") {
|
||
if (rel.code == "9998") {
|
||
toast_warning(rel.msg);
|
||
return;
|
||
}
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
toast_ok(rel.msg);
|
||
$('#user-modal').modal('hide');
|
||
userManagerTable.ajax.reload();
|
||
}, 'json')
|
||
.fail(function (xhr, status, error) {
|
||
$("#save-user-btn").html('確定').attr("disabled", false);
|
||
});
|
||
}
|
||
}
|
||
//#endregion
|
||
|
||
//#region 刪除使用者
|
||
$('#user_table').on("click", "button.del-btn", function () {
|
||
selected_id = $(this).parents('tr').attr('data-guid');
|
||
Swal.fire(
|
||
{
|
||
title: "刪除",
|
||
text: "你確定是否刪除此筆資料?",
|
||
type: "warning",
|
||
icon: 'warning',
|
||
showCancelButton: true,
|
||
confirmButtonText: "是",
|
||
cancelButtonText: "否"
|
||
}).then(function (result) {
|
||
if (result.value) {
|
||
var url = "/UserInfo/DeleteOneUser";
|
||
var send_data = {
|
||
guid: selected_id
|
||
}
|
||
$.post(url, send_data, function (rel) {
|
||
if (rel.code != "0000") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
|
||
toast_ok(rel.msg);
|
||
|
||
userManagerTable.ajax.reload();
|
||
}, 'json');
|
||
}
|
||
});
|
||
});
|
||
//#endregion
|
||
</script>
|
||
<script>
|
||
var roleManagerTable;
|
||
var selected_roleGUID = "0";
|
||
$(function () {
|
||
//#region 角色資料 DataTable
|
||
roleManagerTable = $("#role_table").DataTable({
|
||
"columns": [
|
||
{
|
||
"data": null,
|
||
"render": function (data, type, row, meta) {
|
||
return meta.row + 1;
|
||
}
|
||
},
|
||
{
|
||
"data": "full_name"
|
||
},
|
||
{
|
||
"data": "created_at"
|
||
},
|
||
{
|
||
"data": "layer",
|
||
"render": function (data, type, row, meta) {
|
||
if (@ViewBag.myUserInfo.Layer == 0) {
|
||
if (data == 1) {
|
||
return '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>';
|
||
} else {
|
||
return '<button class="btn btn-primary edit-btn">修改</button>';
|
||
}
|
||
} else {
|
||
if (data == 1) {
|
||
return '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>';
|
||
} else {
|
||
return '';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
],
|
||
//"order": [[2, "desc"]],
|
||
'createdRow': function (row, data, dataIndex) {
|
||
$(row).attr('data-guid', data.role_guid);
|
||
},
|
||
"ajax": {
|
||
"url": "/UserInfo/RoleManagerList",
|
||
"type": "POST",
|
||
"data": function (d) {
|
||
d.post = 0;
|
||
},
|
||
"dataSrc": function (rel) {
|
||
if (rel.code == "9999") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
|
||
data = rel.data;
|
||
|
||
if (data == null || data.length == 0) {
|
||
this.data = [];
|
||
}
|
||
|
||
return data;
|
||
}
|
||
}
|
||
});
|
||
//#endregion
|
||
});
|
||
|
||
//#region 新增角色
|
||
function AddRole() {
|
||
selected_roleGUID = "0";
|
||
$("#role-modal .modal-title").html("角色資料 - 新增");
|
||
$("#role-form").trigger("reset");
|
||
|
||
$("#role-modal").modal();
|
||
}
|
||
//#endregion
|
||
|
||
//#region 編輯角色
|
||
$('#role_table').on("click", "button.edit-btn", function () {
|
||
|
||
$("#user-modal .modal-title").html("人員基本資料 - 編輯");
|
||
|
||
selected_roleGUID = $(this).parents('tr').attr('data-guid');
|
||
|
||
//取得單一使用者管理員
|
||
var url = "/UserInfo/GetOneRole/";
|
||
|
||
var send_data = {
|
||
guid: selected_roleGUID
|
||
}
|
||
|
||
$.post(url, send_data, function (rel) {
|
||
if (rel.code == "9999") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
else if (rel.code == "9998") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
$("#role_name_modal").val(rel.data.full_name);
|
||
|
||
$("#role-modal").modal();
|
||
}, 'json');
|
||
|
||
});
|
||
//#endregion
|
||
|
||
//#region 角色表單驗證
|
||
$("#role-form").validate({
|
||
rules: {
|
||
role_name_modal: {
|
||
required: true
|
||
}
|
||
},
|
||
});
|
||
//#endregion
|
||
|
||
//#region 儲存角色
|
||
function SaveRole() {
|
||
if ($("#role-form").valid()) {
|
||
|
||
$("#save-role-btn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
|
||
|
||
var url = "/UserInfo/SaveRole";
|
||
|
||
var send_data = {
|
||
Id: selected_roleGUID,
|
||
Name: $("#role_name_modal").val(),
|
||
}
|
||
|
||
$.post(url, send_data, function (rel) {
|
||
$("#save-role-btn").html('確定').attr("disabled", false);
|
||
|
||
if (rel.code != "0000") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
|
||
toast_ok(rel.msg);
|
||
$('#role-modal').modal('hide');
|
||
roleManagerTable.ajax.reload();
|
||
}, 'json')
|
||
.fail(function (xhr, status, error) {
|
||
$("#save-role-btn").html('確定').attr("disabled", false);
|
||
});
|
||
}
|
||
}
|
||
//#endregion
|
||
|
||
//#region 刪除角色
|
||
$('#role_table').on("click", "button.del-btn", function () {
|
||
selected_roleGUID = $(this).parents('tr').attr('data-guid');
|
||
Swal.fire(
|
||
{
|
||
title: "刪除",
|
||
text: "你確定是否刪除此筆資料?",
|
||
type: "warning",
|
||
icon: 'warning',
|
||
showCancelButton: true,
|
||
confirmButtonText: "是",
|
||
cancelButtonText: "否"
|
||
}).then(function (result) {
|
||
if (result.value) {
|
||
var url = "/UserInfo/DeleteOneRole";
|
||
var send_data = {
|
||
guid: selected_roleGUID
|
||
}
|
||
$.post(url, send_data, function (rel) {
|
||
if (rel.code != "0000") {
|
||
if (rel.code == "9999") {
|
||
toast_error(rel.msg);
|
||
}
|
||
else if (rel.code == "9997") {
|
||
var htnl = rel.msg + "<br>"
|
||
Swal.fire(
|
||
{
|
||
title: "刪除失敗",
|
||
icon: 'warning',
|
||
html: htnl,
|
||
});
|
||
}
|
||
else {
|
||
toast_warning(rel.msg);
|
||
}
|
||
return;
|
||
}
|
||
else {
|
||
toast_ok(rel.msg);
|
||
roleManagerTable.ajax.reload();
|
||
return;
|
||
}
|
||
}, 'json');
|
||
}
|
||
});
|
||
});
|
||
//#endregion
|
||
</script>
|
||
<script>
|
||
var roleAuthTable;
|
||
var roleAuthNotJoinTable;
|
||
var selected_roleAuthGUID = "0";
|
||
var selected_build = "0";
|
||
var saveCheckAuth = [];
|
||
//var CheckCount = 0;
|
||
var AllCount = 0;
|
||
//var frontEndCheckAuth = [];
|
||
//var backEndCheckAuth = [];
|
||
//var oddAuthType;
|
||
//var oddBuild;
|
||
|
||
$(function () {
|
||
var url = "/UserInfo/RoleManagerList";
|
||
$.post(url, { post: 1 }, function (rel) {
|
||
if (rel.code != "0000") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
if (rel.data.length > 0) {
|
||
$('#select_roleId_roleAuth_tab').empty();
|
||
$.each(rel.data, function (index, val) {
|
||
$("#select_roleId_roleAuth_tab").append($("<option />").val(val.role_guid).text(val.full_name));
|
||
});
|
||
//預設查詢第一個
|
||
$("#select_roleId_roleAuth_tab").val($("#select_roleId_roleAuth_tab option:first").val());
|
||
|
||
//#region 角色資料 DataTable
|
||
roleAuthTable = $("#roleAuth_table").DataTable({
|
||
"columns": [
|
||
{
|
||
"data": null,
|
||
"render": function (data, type, row, meta) {
|
||
return meta.row + 1;
|
||
}
|
||
},
|
||
{
|
||
"data": "role_full_name"
|
||
},
|
||
{
|
||
"data": "authTypeText"
|
||
},
|
||
{
|
||
"data": "building_full_name"
|
||
},
|
||
{
|
||
"data": "mainName"
|
||
},
|
||
{
|
||
"data": "subName"
|
||
},
|
||
{
|
||
"data": "created_at"
|
||
},
|
||
{
|
||
"data": null,
|
||
"defaultContent": '<button class="btn btn-danger del-btn">刪除</button>'
|
||
}
|
||
],
|
||
//"order": [[2, "desc"]],
|
||
'createdRow': function (row, data, dataIndex) {
|
||
$(row).attr('data-guid', data.role_guid);
|
||
$(row).attr('data-authCode', data.authCode);
|
||
},
|
||
"ajax": {
|
||
"url": "/UserInfo/RoleAuthList",
|
||
"type": "POST",
|
||
"data": function (d) {
|
||
d.SelectedRoleId = $('#select_roleId_roleAuth_tab').val();
|
||
},
|
||
"dataSrc": function (rel) {
|
||
if (rel.code == "9999") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
|
||
data = rel.data;
|
||
|
||
if (data == null || data.length == 0) {
|
||
this.data = [];
|
||
}
|
||
|
||
return data;
|
||
}
|
||
}
|
||
});
|
||
//#endregion
|
||
} else {
|
||
$("#select_roleId_roleAuth_tab").empty();
|
||
$("#select_roleId_roleAuth_tab").append('<option value="0" disabled>請先新增角色</option>');
|
||
$("#select_roleId_roleAuth_tab").val($("#user_role_modal option:first").val());
|
||
}
|
||
}, 'json');
|
||
|
||
//#region 角色未加入權限列表 DataTable
|
||
roleAuthNotJoinTable = $("#roleAuth_NotJoin_table").DataTable({
|
||
//"order": [[1, "desc"]],
|
||
"columns": [
|
||
{
|
||
"data": "authCode"
|
||
},
|
||
{
|
||
"data": "mainName"
|
||
},
|
||
{
|
||
"data": "subName"
|
||
}
|
||
],
|
||
"columnDefs": [{
|
||
'targets': 0,
|
||
'searchable': false,
|
||
'orderable': false,
|
||
'className': 'dt-body-center',
|
||
'render': function (data, type, full, meta) {
|
||
var check_html = "";
|
||
check_html += '<div class="custom-control custom-checkbox">';
|
||
//判斷是否要Check
|
||
var checkHtml = "";
|
||
if (saveCheckAuth.length > 0) {
|
||
var filterAuth = saveCheckAuth.filter(function (i, n) {
|
||
return i === data;
|
||
});
|
||
|
||
if (filterAuth.length > 0) {
|
||
checkHtml = "checked";
|
||
}
|
||
}
|
||
|
||
check_html += `<input type="checkbox" class="custom-control-input" name="selectedAuthPage[]" id="auth-page-${data}" value="${data}" ${checkHtml} /> `;
|
||
check_html += '<label class="custom-control-label" for="auth-page-' + data + '" />';
|
||
check_html += '</div>';
|
||
return check_html;
|
||
}
|
||
}],
|
||
'createdRow': function (row, data, dataIndex) {
|
||
$(row).attr('data-authCode', data.authCode);
|
||
},
|
||
"ajax": {
|
||
"url": "/UserInfo/GetRoleNotAuthPageList",
|
||
"type": "POST",
|
||
"data": function (d) {
|
||
d.SelectedRoleId = $('#select_roleId_roleAuth_tab').val();
|
||
d.SelectedAuthType = $("#select_authType").val();
|
||
d.SelectedBuild = selected_build;
|
||
},
|
||
"dataSrc": function (rel) {
|
||
if (rel.data.code == "9999") {
|
||
toast_error(rel.data.msg);
|
||
return;
|
||
}
|
||
|
||
data = rel.data;
|
||
AllCount = data.length;
|
||
console.log("AllCount", AllCount);
|
||
|
||
if (data == null || data.length == 0) {
|
||
this.data = [];
|
||
}
|
||
|
||
return data;
|
||
}
|
||
},
|
||
//"drawCallback": function (settings) {
|
||
|
||
// if (AllCount > 0) {
|
||
|
||
// var rows = roleAuthNotJoinTable.rows({ 'search': 'applied' }).nodes().length;
|
||
// var checkAuths = $("input[name='selectedAuthPage[]']:checked", rows).map(function () {
|
||
// return $(this).val();
|
||
// }).get();
|
||
// console.log("drawCallback", checkAuths.length);
|
||
// if (AllCount == CheckCount.length) {
|
||
// $("#select-all-role-auth").prop('checked', true);
|
||
// }
|
||
// else {
|
||
// $("#select-all-role-auth").prop('checked', false);
|
||
// }
|
||
// }
|
||
// else {
|
||
// $("#select-all-role-auth").prop('checked', false);
|
||
// }
|
||
// CheckCount = 0;
|
||
//}
|
||
});
|
||
//#endregion
|
||
});
|
||
|
||
//#region 角色權限全選
|
||
$("#select-all-role-auth").change(function () {
|
||
|
||
var rows = roleAuthNotJoinTable.rows({ 'search': 'applied' }).nodes();
|
||
|
||
$("input[name='selectedAuthPage[]']", rows).prop('checked', this.checked);
|
||
});
|
||
//#endregion
|
||
|
||
//#region 選擇角色下拉式選單select_option
|
||
$("#select_roleId_roleAuth_tab").change(function () {
|
||
roleAuthTable.ajax.reload();
|
||
});
|
||
//#endregion
|
||
|
||
//#region 新增角色權限
|
||
async function AddRoleAuth() {
|
||
$("#select_authType").val(1);
|
||
await authTypeChange();
|
||
//oddBuild = $("#select_building").val();
|
||
roleAuthNotJoinTable.ajax.reload();
|
||
saveCheckAuth = [];
|
||
$("#role-auth-modal").modal();
|
||
}
|
||
//#endregion
|
||
|
||
//#region 選擇角色類型下拉式選單select_option
|
||
function authTypeChange() {
|
||
return new Promise((resolve, reject) => {
|
||
if ($("#select_authType").val() == "1") {
|
||
$("#select_building").show();
|
||
var url = "/BuildInfo/BuildInfoList";
|
||
$.post(url, null, function (rel) {
|
||
if (rel.code != "0000") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
if (rel.data.length > 0) {
|
||
$('#select_building').empty();
|
||
$.each(rel.data, function (index, val) {
|
||
$("#select_building").append($("<option />").val(val.building_tag).text(val.full_name));
|
||
});
|
||
//預設查詢第一個
|
||
$("#select_building").val($("#select_building option:first").val());
|
||
selected_build = $("#select_building option:first").val();
|
||
roleAuthNotJoinTable.ajax.reload();
|
||
//#endregion
|
||
} else {
|
||
$("#select_building").empty();
|
||
$("#select_building").append('<option value="0" disabled>請先新增區域</option>');
|
||
$("#select_building").val($("#select_building option:first").val());
|
||
}
|
||
resolve();
|
||
}, 'json');
|
||
}
|
||
else {
|
||
selected_build = "0";
|
||
$("#select_building").hide();
|
||
roleAuthNotJoinTable.ajax.reload();
|
||
resolve();
|
||
}
|
||
|
||
});
|
||
}
|
||
|
||
$("#select_authType").change(function () {
|
||
$("#select-all-role-auth").prop('checked', false);
|
||
CheckAuthMain();
|
||
authTypeChange();
|
||
});
|
||
//#endregion
|
||
|
||
//#region 選擇區域下拉式選單select_option
|
||
$("#select_building").change(function () {
|
||
$("#select-all-role-auth").prop('checked', false);
|
||
CheckAuthMain();
|
||
|
||
selected_build = $("#select_building").val();
|
||
roleAuthNotJoinTable.ajax.reload();
|
||
});
|
||
//#endregion
|
||
|
||
//#region 儲存Check
|
||
async function CheckAuthMain() {
|
||
await CheckAuth();
|
||
}
|
||
|
||
function CheckAuth() {
|
||
return new Promise((resolve, reject) => {
|
||
var rows = roleAuthNotJoinTable.rows({ 'search': 'applied' }).nodes();
|
||
//取得被選擇的角色權限
|
||
var checkAuths = $("input[name='selectedAuthPage[]']:checked", rows).map(function () {
|
||
return $(this).val();
|
||
}).get();
|
||
|
||
var uncheckAuths = $("input[name='selectedAuthPage[]']:not(:checked)", rows).map(function () {
|
||
return $(this).val();
|
||
}).get();
|
||
|
||
//勾選
|
||
if (checkAuths.length > 0) {
|
||
$.each(checkAuths, function (index, val) {
|
||
var dbindex = saveCheckAuth.findIndex(x => x == val);
|
||
if (dbindex == -1) {
|
||
saveCheckAuth.push(val);
|
||
}
|
||
});
|
||
}
|
||
|
||
//未勾選
|
||
if (uncheckAuths.length > 0) {
|
||
$.each(uncheckAuths, function (index, val) {
|
||
var dbindex = saveCheckAuth.findIndex(x => x == val);
|
||
if (dbindex >= 0) {
|
||
saveCheckAuth.splice(dbindex, 1);
|
||
}
|
||
});
|
||
}
|
||
resolve();
|
||
});
|
||
}
|
||
//#endregion
|
||
|
||
//#region 刪除角色權限
|
||
$('#roleAuth_table').on("click", "button.del-btn", function () {
|
||
|
||
var row_guid = $(this).parents('tr').attr('data-guid');
|
||
var row_authCode = $(this).parents('tr').attr('data-authCode');
|
||
|
||
//var split_arr = row_id_authCode.split("_");
|
||
Swal.fire(
|
||
{
|
||
title: "刪除",
|
||
text: "你確定是否刪除此筆資料?",
|
||
type: "warning",
|
||
icon: 'warning',
|
||
showCancelButton: true,
|
||
confirmButtonText: "是",
|
||
cancelButtonText: "否"
|
||
}).then(function (result) {
|
||
if (result.value) {
|
||
//取得單一系統管理員
|
||
var url = "/UserInfo/DeleteOneRoleAuth/";
|
||
|
||
var send_data = {
|
||
RoleId: row_guid,
|
||
AuthCode: row_authCode
|
||
}
|
||
|
||
$.post(url, send_data, function (rel) {
|
||
if (rel.code != "0000") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
|
||
toast_ok(rel.msg);
|
||
roleAuthTable.ajax.reload();
|
||
}, 'json');
|
||
}
|
||
});
|
||
});
|
||
//#endregion
|
||
|
||
//#region 儲存角色權限
|
||
function SaveRoleAuth() {
|
||
CheckAuthMain();
|
||
|
||
$("#save-role-auth-btn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
|
||
|
||
var url = "/UserInfo/SaveRoleAuth";
|
||
|
||
var send_data = {
|
||
SelectedRoleId: $('#select_roleId_roleAuth_tab').val(),
|
||
SaveCheckAuth: saveCheckAuth
|
||
}
|
||
|
||
$.post(url, send_data, function (rel) {
|
||
$("#save-role-auth-btn").html('確定').attr("disabled", false);
|
||
if (rel.code != "0000") {
|
||
toast_error(rel.msg);
|
||
return;
|
||
}
|
||
|
||
toast_ok(rel.msg);
|
||
$("#role-auth-modal").modal('hide');
|
||
|
||
roleAuthTable.ajax.reload();
|
||
}, 'json')
|
||
.fail(function (xhr, status, error) {
|
||
$("#save-role-auth-btn").html('確定').attr("disabled", false);
|
||
});
|
||
}
|
||
//#endregion
|
||
</script>
|
||
} |