| | |
| | | header: false |
| | | }, |
| | | pgId: '', // 保存角色编码 |
| | | privilegeData: [] // 保存权限数据 |
| | | privilegeData: [], // 保存权限数据 |
| | | pName: '全部', // 保存权限名称,默认为"全部" |
| | | buttonPrivileges: [], // 保存按钮权限 |
| | | labelPrivileges: [], // 保存标签权限 |
| | | dataPrivileges: [], // 保存数据权限 |
| | | }, |
| | | _initMethod: function () { |
| | | // 获取URL参数 |
| | |
| | | let pgId = ''; |
| | | let communityId = ''; |
| | | let type = ''; |
| | | let pName = '全部'; // 默认值为"全部" |
| | | |
| | | // 优先从 hash 中获取参数(单页应用使用 hash 路由) |
| | | const hash = location.hash; |
| | |
| | | communityId = value; |
| | | } else if (key === 'type') { |
| | | type = value; |
| | | } else if (key === 'pName') { |
| | | pName = value; |
| | | } |
| | | } |
| | | } |
| | |
| | | if (!type) { |
| | | type = vc.getParam('type') || ''; |
| | | } |
| | | if (pName === '全部') { |
| | | pName = vc.getParam('pName') || '全部'; |
| | | } |
| | | |
| | | // 如果缺少必要参数,使用默认值或从当前社区获取 |
| | | if (!communityId) { |
| | | communityId = vc.getCurrentCommunity().communityId; |
| | | } |
| | | |
| | | // 保存 pgId 到 data 中 |
| | | // 保存 pgId、pId 和 pName 到 data 中 |
| | | vc.component.pgId = pgId; |
| | | vc.component.pId = pId; |
| | | vc.component.pName = pName; |
| | | |
| | | // 更新页面标题 |
| | | const titleElement = document.querySelector('.role-a-container h3'); |
| | | if (titleElement) { |
| | | titleElement.textContent = pName; |
| | | } |
| | | |
| | | // 调用接口 |
| | | if (pgId && communityId) { |
| | |
| | | // 判断 json 的类型,如果已经是对象则直接使用,否则进行解析 |
| | | let data = typeof json === 'string' ? JSON.parse(json) : json; |
| | | vc.component.privilegeData = data; |
| | | vc.component.buttonPrivileges = data.filter(item => item.type === '按钮'); |
| | | vc.component.labelPrivileges = data.filter(item => item.type === '标签'); |
| | | vc.component.dataPrivileges = data.filter(item => item.type === '数据'); |
| | | vc.component.renderPrivileges(data); |
| | | vc.component.initCheckboxEvents(); |
| | | } catch (e) { |
| | |
| | | // 渲染权限复选框 |
| | | renderPrivileges: function (data) { |
| | | const buttonContainer = document.getElementById('button-container'); |
| | | const labelContainer = document.getElementById('label-container'); |
| | | const dataContainer = document.getElementById('data-container'); |
| | | |
| | | // 清空容器 |
| | | if (buttonContainer) buttonContainer.innerHTML = ''; |
| | | if (labelContainer) labelContainer.innerHTML = ''; |
| | | if (dataContainer) dataContainer.innerHTML = ''; |
| | | |
| | | // 遍历数据,根据 type 创建对应的复选框 |
| | |
| | | |
| | | const label = document.createElement('label'); |
| | | label.textContent = item.pName; |
| | | label.style.paddingTop = '8px'; |
| | | |
| | | const checkbox = document.createElement('input'); |
| | | checkbox.type = 'checkbox'; |
| | |
| | | checkbox.value = item.pId; |
| | | checkbox.setAttribute('data-pid', item.pId); |
| | | checkbox.setAttribute('data-type', item.type); |
| | | checkbox.checked = true; |
| | | |
| | | checkboxDiv.appendChild(label); |
| | | checkboxDiv.appendChild(checkbox); |
| | | checkboxDiv.appendChild(label); |
| | | |
| | | // 根据 type 添加到对应容器 |
| | | if (item.type === '按钮') { |
| | | if (buttonContainer) { |
| | | buttonContainer.appendChild(checkboxDiv); |
| | | } |
| | | } else if (item.type === '标签') { |
| | | if (labelContainer) { |
| | | labelContainer.appendChild(checkboxDiv); |
| | | } |
| | | } else if (item.type === '数据') { |
| | | if (dataContainer) { |
| | |
| | | }); |
| | | // 同时更新按钮和数据区域的"全部"复选框 |
| | | const buttonAll = document.getElementById('button-all'); |
| | | const labelAll = document.getElementById('label-all'); |
| | | const dataAll = document.getElementById('data-all'); |
| | | if (buttonAll) buttonAll.checked = isChecked; |
| | | if (labelAll) labelAll.checked = isChecked; |
| | | if (dataAll) dataAll.checked = isChecked; |
| | | }); |
| | | } |
| | |
| | | // 选中按钮区域所有复选框 |
| | | const buttonCheckboxes = document.querySelectorAll('#button-container input[type="checkbox"][name="privilege"]'); |
| | | buttonCheckboxes.forEach(function (cb) { |
| | | cb.checked = isChecked; |
| | | }); |
| | | // 检查是否需要更新"全部"复选框 |
| | | self.updateAllCheckbox(); |
| | | }); |
| | | } |
| | | |
| | | // 标签区域全部复选框 |
| | | const labelAllCheckbox = document.getElementById('label-all'); |
| | | if (labelAllCheckbox) { |
| | | labelAllCheckbox.addEventListener('change', function () { |
| | | const isChecked = this.checked; |
| | | // 选中标签区域所有复选框 |
| | | const labelCheckboxes = document.querySelectorAll('#label-container input[type="checkbox"][name="privilege"]'); |
| | | labelCheckboxes.forEach(function (cb) { |
| | | cb.checked = isChecked; |
| | | }); |
| | | // 检查是否需要更新"全部"复选框 |
| | |
| | | self.savePrivileges(); |
| | | }); |
| | | } |
| | | |
| | | // 重置按钮事件 |
| | | const resetButton = document.getElementById('reset'); |
| | | if (resetButton) { |
| | | resetButton.addEventListener('click', function () { |
| | | // 选中所有权限复选框 |
| | | const allCheckboxes = document.querySelectorAll('input[type="checkbox"][name="privilege"]'); |
| | | allCheckboxes.forEach(function (cb) { |
| | | cb.checked = true; |
| | | }); |
| | | // 选中所有"全部"复选框 |
| | | const allCheckbox = document.getElementById('all'); |
| | | const buttonAll = document.getElementById('button-all'); |
| | | const labelAll = document.getElementById('label-all'); |
| | | const dataAll = document.getElementById('data-all'); |
| | | if (allCheckbox) allCheckbox.checked = true; |
| | | if (buttonAll) buttonAll.checked = true; |
| | | if (labelAll) labelAll.checked = true; |
| | | if (dataAll) dataAll.checked = true; |
| | | }); |
| | | } |
| | | }, |
| | | // 更新"全部"复选框状态 |
| | | updateAllCheckbox: function () { |
| | |
| | | const buttonAll = document.getElementById('button-all'); |
| | | if (buttonAll) { |
| | | buttonAll.checked = buttonAllChecked; |
| | | } |
| | | |
| | | // 更新标签区域 |
| | | const labelCheckboxes = document.querySelectorAll('#label-container input[type="checkbox"][name="privilege"]'); |
| | | const labelAllChecked = labelCheckboxes.length > 0 && Array.from(labelCheckboxes).every(function (cb) { |
| | | return cb.checked; |
| | | }); |
| | | const labelAll = document.getElementById('label-all'); |
| | | if (labelAll) { |
| | | labelAll.checked = labelAllChecked; |
| | | } |
| | | |
| | | // 更新数据区域 |
| | |
| | | |
| | | const requestData = { |
| | | pgId: vc.component.pgId, |
| | | parentId: vc.component.pId, |
| | | pIds: pIds |
| | | }; |
| | | |