Explorar o código

feat: 添加用户权限选择标记同步功能

caipin hai 1 día
pai
achega
f080a072e2
Modificáronse 1 ficheiros con 38 adicións e 2 borrados
  1. 38 2
      app/public/js/file_detail.js

+ 38 - 2
app/public/js/file_detail.js

@@ -1455,7 +1455,7 @@ $(document).ready(function() {
                 return false;
             });
             $('dl').on('click', 'dd', function (e) {
-                e.stopPropagation();
+                
                 const type = $(this).data('type');
                 if (type === 'all') {
                     const cid = parseInt($(this).data('id'));
@@ -1469,6 +1469,7 @@ $(document).ready(function() {
                     if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
                 }
                 self.loadCurFiling();
+                e.stopPropagation();
             });
             $('#sync-filing').click(function() {
                 const selectFilingId = [];
@@ -1519,6 +1520,7 @@ $(document).ready(function() {
                 const id = this.getAttribute('uid');
                 self.delFiling(self.curFiling, id);
                 self.loadCurFiling();
+                this.syncPermissionUserSelectedMarks();
             });
             $('#user-select-all').click(function(){
                 $('input[uid]').attr('checked', this.checked);
@@ -1558,6 +1560,7 @@ $(document).ready(function() {
             }
             $(this.setting.list).html(html.join(''));
             $('#user-select-all')[0].checked = false;
+            this.syncPermissionUserSelectedMarks(); 
         }
         refreshBtn() {
             const self = this;
@@ -1581,13 +1584,22 @@ $(document).ready(function() {
         }
         loadPermissionUser() {
             const html = [];
+            const currentFilingUserIds = new Set();
+            if (this.permissionUser && Array.isArray(this.permissionUser)) {
+                for (const f of this.permissionUser) {
+                    if (f.filing_type && f.filing_type.indexOf(this.curFiling) >= 0) {
+                        currentFilingUserIds.add(f.id); 
+                    }
+                }
+            }
             for (const c of this.company) {
                 html.push(`<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${c.id}" data-type="hide"><i class="fa fa-plus-square"></i></a> ${c.company}</dt>`);
                 html.push(`<div class="dd-content" data-toggleid="${c.id}">`);
                 html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${c.id}" data-type="all"><p class="mb-0 d-flex"><span class="text-primary">添加单位下全部用户</span></p></dd>`);
                 for (const u of c.users) {
+                    const initialDisplayStyle = currentFilingUserIds.has(u.id) ? 'display:inline-block;' : 'display:none;';
                     html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${u.id}" >`);
-                    html.push(`<p class="mb-0 d-flex"><span class="text-primary">${u.name}</span><span class="ml-auto">${u.mobile}</span></p>`);
+                    html.push(`<p class="mb-0 d-flex"><span class="text-primary">${u.name}</span><span class="ml-auto">${u.mobile}</span><span class="selected-mark text-success ml-2" style="${initialDisplayStyle}"><i class="fa fa-check"></i></span></p>`);
                     html.push(`<span class="text-muted">${u.role}</span>`);
                     html.push(`</dd>`);
                 }
@@ -1595,6 +1607,29 @@ $(document).ready(function() {
             }
             $('#puList').html(html.join(''));
         }
+        syncPermissionUserSelectedMarks() {
+            const tableUserIds = new Set(); 
+            $(this.setting.list + ' tr').each(function() { 
+                const $firstInput = $(this).find('input[name="ftu-check"]').first();
+                if ($firstInput.length) {
+                    const uid = parseInt($firstInput.attr('uid'), 10); 
+                    if (!isNaN(uid)) {
+                        tableUserIds.add(uid);
+                    }
+                }
+            });
+            $('#puList dd[data-id]').each(function() {
+                const userId = parseInt($(this).data('id'), 10); 
+                const $mark = $(this).find('.selected-mark'); 
+                if (!isNaN(userId) && $mark.length > 0 && $(this).data('type') !== 'all') {
+                    if (tableUserIds.has(userId)) {
+                        $mark.show();
+                    } else {
+                        $mark.hide();
+                    }
+                }
+            });
+        }
         _convertData(sourceTree) {
             const data = [];
             for (const node of sourceTree.nodes) {
@@ -1633,6 +1668,7 @@ $(document).ready(function() {
                 }
                 self.loadPermissionUser();
             });
+            
         }
         syncFiling(sourceId, targetIds) {
             for (const pu of this.permissionUser) {