|
@@ -65,7 +65,10 @@
|
|
|
<td><%= account.name %></td>
|
|
|
<td><%= account.company %></td>
|
|
|
<td><%= account.role %></td>
|
|
|
- <td>台帐管理(创建标段)<a href="#permission-form" data-toggle="modal" data-target="#permission-form" class="btn btn-sm">编辑</a></td>
|
|
|
+ <td>
|
|
|
+ <span class="permission-string"></span>
|
|
|
+ <a href="#permission-form" data-toggle="modal" data-target="#permission-form" class="btn btn-sm permission" data-permission="<%= account.permission %>" data-id="<%= account.id %>">编辑</a>
|
|
|
+ </td>
|
|
|
</tr>
|
|
|
<% }) %>
|
|
|
<% } %>
|
|
@@ -80,7 +83,28 @@
|
|
|
let permissionList = '<%- permissionList %>';
|
|
|
permissionList = JSON.parse(permissionList);
|
|
|
|
|
|
+let permissionString = '<%- permissionString %>';
|
|
|
+permissionString = JSON.parse(permissionString);
|
|
|
$(document).ready(function() {
|
|
|
+
|
|
|
+ // 页面载入时显示权限中文
|
|
|
+ $(".permission").each(function() {
|
|
|
+ const permission = $(this).data('permission');
|
|
|
+ const permissionShowString = getPermissionString(permission);
|
|
|
+ $(this).prev(".permission-string").html(permissionShowString);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 点击编辑权限按钮
|
|
|
+ let currentPermission = [];
|
|
|
+ let currentId = 0;
|
|
|
+ let currentTarget = null;
|
|
|
+ $(".permission").click(function() {
|
|
|
+ const permission = $(this).data('permission');
|
|
|
+ currentPermission = permission.split(',');
|
|
|
+ currentId = $(this).data('id');
|
|
|
+ currentTarget = $(this);
|
|
|
+ });
|
|
|
+
|
|
|
// 初始化弹窗数据
|
|
|
$("#permission-form").on("show.bs.modal", function() {
|
|
|
let html = '';
|
|
@@ -89,8 +113,9 @@ $(document).ready(function() {
|
|
|
'<label><i class="fa '+ permissionList[index].icon +'"></i> '+ permissionList[index].name +'</label>' +
|
|
|
'<div>';
|
|
|
for (const child of permissionList[index].permission) {
|
|
|
+ const checkedString = currentPermission.indexOf(child.value + '') >= 0 ? 'checked="checked"' : '';
|
|
|
html += '<div class="form-check form-check-inline">' +
|
|
|
- '<input class="form-check-input" type="checkbox" name="permission" value="'+ child.value +'">' +
|
|
|
+ '<input class="form-check-input" type="checkbox" name="permission" value="'+ child.value +'" '+ checkedString +'>' +
|
|
|
'<label class="form-check-label">'+ child.name +'</label>' +
|
|
|
'</div>';
|
|
|
}
|
|
@@ -98,6 +123,66 @@ $(document).ready(function() {
|
|
|
}
|
|
|
$(this).find('.modal-body').html(html);
|
|
|
});
|
|
|
+
|
|
|
+ // 修改数据
|
|
|
+ let isChanging = false;
|
|
|
+ $("#modify-permission").click(function() {
|
|
|
+ currentId = parseInt(currentId);
|
|
|
+ if (isNaN(currentId) || currentId <= 0 || isChanging) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const selectPermission = [];
|
|
|
+ $("input[name='permission']").each(function() {
|
|
|
+ if ($(this).is(":checked")) {
|
|
|
+ selectPermission.push($(this).val());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (selectPermission.length <= 0) {
|
|
|
+ alert('请选择权限!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ url: '/project/account/permission/' + currentId + "?_csrf=<%= ctx.csrf %>",
|
|
|
+ type: 'post',
|
|
|
+ data: { permission: selectPermission.join(',') },
|
|
|
+ error: function() {
|
|
|
+ alert('通信错误');
|
|
|
+ isChanging = false;
|
|
|
+ },
|
|
|
+ beforeSend: function() {
|
|
|
+ isChanging = true;
|
|
|
+ },
|
|
|
+ success: function(response) {
|
|
|
+ isChanging = false;
|
|
|
+ if (response.err !== 0) {
|
|
|
+ alert(response.msg);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const permissionShowString = getPermissionString(selectPermission);
|
|
|
+ currentTarget.prev(".permission-string").html(permissionShowString);
|
|
|
+
|
|
|
+ $("#permission-form").modal('hide');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
+function getPermissionString(permission) {
|
|
|
+ let result = '';
|
|
|
+ permission = permission instanceof Array ? permission : permission.split(",");
|
|
|
+ if (permission.length <= 0) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ const permissionArr = [];
|
|
|
+ for (const tmp of permission) {
|
|
|
+ if (permissionString[tmp] !== undefined) {
|
|
|
+ permissionArr.push(permissionString[tmp]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return permissionArr.join(',');
|
|
|
+}
|
|
|
</script>
|