You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

539 lines
23 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

define(function (require, exports, module) {
var Window = require('system/views/pages/window');
var tpl = require('text!apps/edp/frs/frs002/ActRightWin.tpl');
var menuData = [];
var roleFunData = [];
var roleActRightData = [];
var comBoxData = [];
//用于标识是否为初始化时进行操作权的选中初始化用于在初始化时避开onSelectedRowsChangde方法
var isOpenInitActRight = true;
//用于判断是否treeonCheck事件中的操作权选中初始化用于在初始化时避开onSelectedRowsChangde方法
var isTreeCheck = true;
var treeCheckRow = null;
/**
* [操作权弹框]
* @param {[type]} dsRole 角色表数据源用于对角色ComBox进行赋值
* @param {[type]} dsActRight 操作权数据源,用于操作权的显示
* @param {[type]} dsRoleFun 角色功能菜单操作权数据源,用于树菜单初始化勾选的显示
* @param {[type]} dsRoleActRight 角色对应功能的操作权数据源
* @param {[type]} menuRows 功能菜单行数据,用于初始加载树菜单
* @param {[type]} roleFunRows 角色功能表的功能菜单,用于树菜单的选中加载
* @param {[type]} roleID 当前选中行的角色ID用于tree中ID的赋值
* @param {[type]} roleCode 当前选中行的角色编码用于角色ComBox初始值赋值
*/
function ActRightWin(dsRole, dsActRight, dsRoleFun, dsRoleActRight, menuRows, roleFunRows, roleID, roleCode) {
this.options = {
title: Store.MSG.FRS002_11,//操作权
content: tpl,
width: 600,
height: 450,
modal: true,
closed: true,
closable: true,
draggable: false,
data: null
}
this.dsRole = dsRole;
this.dsRoleFun = dsRoleFun;
this.dsActRight = dsActRight;
this.dsRoleActRight = dsRoleActRight;
this.dsRoleActRight.search();
this.roleID = roleID;
this.roleCode = roleCode;
this.roleFunRows = roleFunRows;
this.menuRows = menuRows;
// 获取当前角色对应的功能编码
roleFunData = getRoleFunData(this.roleFunRows, this.roleID);
//查询出功能菜单数据
menuData = parseMenuData(this.menuRows, this.roleID, this.roleCode);
Window.call(this, this.options);
}
inherits(ActRightWin, Window);
ActRightWin.prototype.init = function () {
this._nowDate = Store.bizDao.getSysDate(); //当前日期
var self = this;
//操作权菜单树数据
var ztreeFuncMenu = {
opts: {
showLine: true,
checkEnable: true
},
data: menuData,
actions: {
onClick: function (e, treeNode) {
treeCheckRow = treeNode;
isOpenInitActRight = false;
//按照功能编码获取对应的操作权,只有功能节点时,进行操作权的赋值
if (!treeNode.isParent) {
self.dsActRight.fixQuery['FuncCode'] = treeNode.funcCode;
self.dsActRight.search(function (isOK) {
if (isOK) {
var selectIndex = [];
var $gridAct = self.vm.gridAct.vmodel.$grid;
// 获取角色对应的所有的操作权按钮编码,并进行选中状态的初始化
roleActRightData = getRoleActionRight(self.dsRoleActRight.rows, treeNode.roleID, treeNode.funcCode);
var actRightRows = self.dsActRight.rows;
for (var i = 0; i < actRightRows.length; i++) {
var rowOpCode = actRightRows[i]['OpCode'];
var index = _.findLastIndex(roleActRightData, {
roleActRight: rowOpCode
});
if (index > -1) {
selectIndex.push(i);
}
}
$gridAct.setSelectedRows(selectIndex);
//设置checkbox是否可以选择
if (!treeNode.checked) {
self.vm.gridAct.setSelectboxDisable(true);
} else {
self.vm.gridAct.setSelectboxDisable(false);
}
isOpenInitActRight = true;
}
});
} else {
self.dsActRight.clear();
}
},
onCheck: function (event, treeNode) {
treeCheckRow = treeNode;
isTreeCheck = false;
var roleID = treeNode.roleID;
var isChecked = treeNode.checked;
if (!treeNode.isParent) {
var funcCode = treeNode.funcCode;
setFuncAndActRight(self, roleID, funcCode, isChecked, false);
} else {
var treeIdChildren = self.vm.treeMenu.getAllChildrenNodes(treeNode);
for (var k = 0; k < treeIdChildren.length; k++) {
if (!treeIdChildren[k].isParent) {
var funcCode = treeIdChildren[k].funcCode;
setFuncAndActRight(self, roleID, funcCode, isChecked, true);
}
}
}
}
}
}
//操作权界面功能对应操作权数据
var gridActRight = {
opts: {
showCheckColumn: true,
editable: false,
enablePager: false,
pageSize: -1
},
data: self.dsActRight,
actions: {
onKeyDown: function (e, args) {
// if (!treeCheckRow.checked) {
// Store.messager.warn('当前功能未选中,不能修改操作权,请先选中当前功能');
// return;
// }
},
onSelectedRowsChanged: function (e, args) {
if (isOpenInitActRight && isTreeCheck && treeCheckRow) {
let selectedRows = args.selectedRows;
//删除功能下的权限
for (let i = self.dsRoleActRight.rows.length - 1; i >= 0; i--) {
let row = self.dsRoleActRight.rows[i]
if (row['FunCode'] === treeCheckRow.funcCode && row['RoleID'] === self.roleID) {
row.delete()
}
}
for (let i = 0; i < selectedRows.length; i++) {
// 获取当前修改行
let selectedRow = selectedRows[i];
let curFuncCode = selectedRow['FuncCode'];
let curOpCode = selectedRow['OpCode'];
let newRoleActRightRow = self.dsRoleActRight.addRow();
newRoleActRightRow['RoleID'] = self.roleID;
newRoleActRightRow['FunCode'] = curFuncCode;
newRoleActRightRow['ActRightCode'] = curOpCode;
newRoleActRightRow['CrtUserID'] = Store.logOn.userId;
newRoleActRightRow['CrtTime'] = self._nowDate;
}
}
}
}
}
this.register('tree', 'treeMenu', ztreeFuncMenu);
this.register('grid', 'gridAct', gridActRight);
}
ActRightWin.prototype.open = function () {
Window.prototype.open.call(this);
}
/**
* [执行windows窗体上自定义按钮事件]
*/
ActRightWin.prototype.customerize = function () {
var self = this;
var treeObj = self.vm.treeMenu;
//用于默认初始化树菜单选中的节点时,子节点全部选中时,将父节点也进行选中
var treeNodes = treeObj.getCheckedNodes();
for (var i = 0, l = treeNodes.length; i < l; i++) {
treeObj.checkNode(treeNodes[i], true, true);
}
comBoxData = [];
//为角色combox增加下拉数据过滤掉角色类型为数据权角色的用户
var rows = this.dsRole.rows;
for (var i = 0; i < rows.length; i++) {
var rowRoleID = rows[i]["RoleID"];
var rowRoleCode = rows[i]["RoleCode"];
var rowRoleName = rows[i]["RoleName"];
var rowRoleType = rows[i]["RoleType"];
if (rowRoleType === '0') {
comBoxData.push({
roleID: rowRoleID,
roleCode: rowRoleCode,
roleName: rowRoleCode + '-' + rowRoleName
});
}
}
//角色编码Combox属性及事件处理
var $roleSelect = this.getElement('.roleSelect');
//角色Combox选中时的事件处理用于加载不同角色编码下树菜单的选中状态
//这个事件要放到下面的"loadData"以及"setValue"前面这样就不会出现onSelect事件导致搜索失效的现象出现了。
$roleSelect.combobox({
onSelect: function (nv, ov) {
//'确定要切换角色吗?注意:如果当前角色已进行修改,请先进行保存。'
if (nv.roleCode != self.roleCode || (!self.roleCode)) {
Store.messager.confirm(Store.MSG.FRS002_12, function (confirmIsOk) {
if (confirmIsOk) {
var selectRoleCode = $roleSelect.combobox('getValue');
reSetActRight(selectRoleCode, self, treeObj);
self.dsActRight.clear();
} else {
$roleSelect.combobox('select', self.roleCode);
}
});
}
}
});
$roleSelect.combobox('loadData', comBoxData);
$roleSelect.combobox('select', this.roleCode);
//保存按钮事件
this.getElement('.btnSave').on('click', function (event) {
//判断哪些进行树菜单进行了修改,对角色功能表进行对应的处理
var treeNodes = treeObj.getAllNodes();
var deleteRow = []; //要删除的功能树菜单集合
for (var i = 0, l = treeNodes.length; i < l; i++) {
//初始化时为非选中状态,修改为选中状态时,进行增加行
if (!treeNodes[i].isParent && !treeNodes[i].checkedOld && treeNodes[i].checked) {
var newRoleFunRow = self.dsRoleFun.addRow();
newRoleFunRow['RoleID'] = treeNodes[i].roleID;
newRoleFunRow['RoleCode'] = treeNodes[i].roleCode;
newRoleFunRow['FunCode'] = treeNodes[i].funcCode;
newRoleFunRow['CrtUserID'] = Store.logOn.userId;;
newRoleFunRow['CrtTime'] = self._nowDate;
}
//初始化时为选中状态,修改为非选中状态时,进行删除行
if (!treeNodes[i].isParent && treeNodes[i].checkedOld && !treeNodes[i].checked) {
//找到角色功能表数据源的要删除的行,进行删除
var roleFunRows = self.roleFunRows;
var treeRoleID = treeNodes[i].roleID;
var treeFuncCode = treeNodes[i].funcCode;
_.each(roleFunRows, function (item, index) {
var rowRoleID = item["RoleID"];
var rowFunCode = item["FunCode"];
if (treeRoleID === rowRoleID && treeFuncCode === rowFunCode) {
deleteRow.push(item);
}
});
}
}
_.each(deleteRow, function (itemDelete, indexDelete) {
self.dsRoleFun.deleteRow(itemDelete);
});
var needDeleteFunRows = self.dsRoleFun.rows.filter(function (item) {
return item.FunCode === '';
});
for (var i = 0; i < needDeleteFunRows.length; i++) {
self.dsRoleFun.deleteRow(needDeleteFunRows[i]);
}
var needDeleteActRows = self.dsRoleActRight.rows.filter(function (item) {
return item.FunCode === '';
});
for (var i = 0; i < needDeleteActRows.length; i++) {
self.dsRoleActRight.deleteRow(needDeleteActRows[i]);
}
//角色功能表保存处理
self.dsRoleFun.save(function (isRoleFunOk) {
if (isRoleFunOk) {
//角色操作表保存处理
self.dsRoleActRight.save(function (isRoleActRightOk) {
if (!isRoleActRightOk) {
self.dsRoleFun.rejectChanges();
self.dsRoleActRight.rejectChanges();
Store.messager.err(Store.MSG.FRS002_13);//角色操作权设置失败,请重试。
return;
}
Store.messager.tip(Store.MSG.FRS002_14); //操作权设置成功。
self.close();
});
return;
} else {
//用于回滚数据
self.dsRoleFun.rejectChanges();
self.dsRoleActRight.rejectChanges();
Store.messager.err(Store.MSG.FRS002_15); //角色功能菜单设置失败,请重试。
return;
}
});
});
//取消按钮事件,恢复到刚打开界面的初始状态
this.getElement('.btnSel').on('click', function (event) {
//确定要取消设置的操作权吗?
Store.messager.confirm(Store.MSG.FRS002_16, function (confirmIsOk) {
if (confirmIsOk) {
var selectRoleCode = $roleSelect.combobox('getValue');
reSetActRight(selectRoleCode, self, treeObj);
self.dsRoleActRight.rejectChanges();
self.dsActRight.clear();
}
});
});
//关闭按钮事件
this.getElement('.btnClose').on('click', function (event) {
//确定要关闭操作权窗体吗?
Store.messager.confirm(Store.MSG.FRS002_17, function (confirmIsOk) {
if (confirmIsOk) {
self.close();
}
});
});
//全部展开按钮事件
this.getElement('.btnAllExpand').on('click', function (event) {
if (self.vm.treeMenu) {
treeObj.expandAll(true);
}
});
//全部合拢按钮事件
this.getElement('.btnAllShut').on('click', function (event) {
if (self.vm.treeMenu) {
treeObj.expandAll(false);
}
});
}
//强制转换为树结构数据
/**
* [强制转换为树结构数据]
* @param {[type]} data [要转换树菜单结构的数据,此处为功能菜单数据]
* @return {[type]} roleID [当前选中的角色ID]
* @return {[type]} roleCode [当前选中的角色I]
*/
function parseMenuData(data, roleID, roleCode) {
var nodes = [];
$.each(data, function (index, item) {
var node = {
icon: 'themes/default/images/icons/node.png'
}
node.id = item.MenuCode;
var idLen = item.MenuCode.length;
node.pId = idLen > 2 ? item.MenuCode.substring(0, idLen - 2) : item.MenuCode;
node.name = item.MenuCaption;
node.funcCode = item.FuncCode || '';
node.roleID = roleID || '';
node.roleCode = roleCode || '';
//TODO 当前登录人编码;当前日期
if (_.indexOf(roleFunData, node.funcCode) !== -1) {
node.checked = true;
}
if (idLen > 4) {
node.icon = 'themes/default/images/icons/node2.png';
}
nodes.push(node);
});
return nodes;
}
/**
* [获取当前角色编码tFrsRoleFun表中有权限的功能编码]
* @param {[type]} rows [当前所有角色设置的功能权限]
* @param {[type]} roleID [当前选中的角色ID]
* @return {[type]} [返回当前角色编码对应的功能权限]
*/
function getRoleFunData(rows, roleID) {
var FuncCodes = [];
for (var i = 0; i < rows.length; i++) {
var rowRoleID = rows[i]["RoleID"];
var rowFunCode = rows[i]["FunCode"];
if (rowRoleID === roleID) {
FuncCodes.push(rowFunCode);
}
}
return FuncCodes;
}
/**
* [获取当前角色编码角色操作权表tFrsRoleActionRight中的数据用于初始化需要勾选的操作权数据]
* @param {[type]} rows [当前所有角色设置的操作权数据]
* @param {[type]} roleID [当前选中的角色编码]
* @param {[type]} funcCode [当前选中的树功能编码]
* @return {[type]} [返回当前角色编码对应的功能权限]
*/
function getRoleActionRight(rows, roleID, funcCode) {
var roleActionRight = [];
for (var i = 0; i < rows.length; i++) {
var rowRoleID = rows[i]["RoleID"];
var rowFunCode = rows[i]["FunCode"];
var rowRoleActRight = rows[i]["ActRightCode"];
if (rowRoleID === roleID && rowFunCode === funcCode) {
roleActionRight.push({
funcCode: rowFunCode,
roleActRight: rowRoleActRight
});
}
}
return roleActionRight;
}
/**
* [选择角色或者点击取消按钮时,重新加载数据]
* @param {[type]} selectRoleCode [当前选中的角色编码]
* @param {[type]} self [弹框本身]
* @param {[type]} treeObj [当前tree控件Obj]
*/
function reSetActRight(selectRoleCode, self, treeObj) {
var index = _.findLastIndex(comBoxData, {
roleCode: selectRoleCode
});
var selectRoleID = comBoxData[index].roleID;
roleFunData = getRoleFunData(self.roleFunRows, selectRoleID);
menuData = parseMenuData(self.menuRows, selectRoleID, selectRoleCode);
self.vm.treeMenu.vmodel.$reset(menuData);
//用于默认初始化树菜单选中的节点时,子节点全部选中时,将父节点也进行选中
var treeNodes = treeObj.getCheckedNodes();
for (var i = 0, l = treeNodes.length; i < l; i++) {
treeObj.checkNode(treeNodes[i], true, true);
}
self.roleID = selectRoleID
self.roleCode = selectRoleCode
}
/**
* [用于在树菜单勾选菜单时,对操作权的控制,如果选中,那么该菜单下所有操作权默认选中,如果不选中,那么该菜单下所有操作权默认不选中]
* @param {[type]} self [弹框]
* @param {[type]} roleID [当前要处理的角色ID]
* @param {[type]} funcCode [当前要处理的功能编码]
* @param {Boolean} isChecked [当前树菜单的操作状态]
* @param {Boolean} isParent [是否为父节点]
*/
function setFuncAndActRight(self, roleID, funcCode, isChecked, isParent) {
self.dsActRight.fixQuery['FuncCode'] = funcCode;
self.dsActRight.search(function (isOK) {
if (isOK) {
var selectIndex = [];
var deleteRow = []; // 功能对应操作权待删除的行
var addRow = []; //需要增加的行的集合
var roleActRightRow = self.dsRoleActRight.rows;
var actRightRow = self.dsActRight.rows;
var $gridAct = self.vm.gridAct.vmodel.$grid;
if (!isChecked) {
$gridAct.setSelectedRows([]);
_.each(roleActRightRow, function (item, index) {
var rowRoleID = item["RoleID"];
var rowFunCode = item["FunCode"];
if (rowRoleID === roleID && rowFunCode === funcCode) {
deleteRow.push(item);
}
});
_.each(deleteRow, function (itemDelete, indexDelete) {
self.dsRoleActRight.deleteRow(itemDelete);
});
//设置checkbox为不可点击
self.vm.gridAct.setSelectboxDisable(true);
} else {
self.vm.gridAct.selectAll();
_.each(actRightRow, function (item, index) {
var count = 0; //记录角色操作权表是否存在该行数据
var rowFunCode = item["FuncCode"];
var rowOpCode = item['OpCode'];
_.each(roleActRightRow, function (roleActItem, roleActIndex) {
var rowRoleRoleID = roleActItem["RoleID"];
var rowRoleFunCode = roleActItem["FunCode"];
var rowRoleActRightCode = roleActItem["ActRightCode"];
if (rowRoleRoleID === roleID && rowRoleFunCode === rowFunCode && rowRoleActRightCode === rowOpCode) {
count++;
}
});
if (count === 0) {
addRow.push(item);
}
});
_.each(addRow, function (itemAdd, indexAdd) {
var newRoleActRightRow = self.dsRoleActRight.addRow();
newRoleActRightRow['RoleID'] = roleID;
newRoleActRightRow['FunCode'] = funcCode;
newRoleActRightRow['ActRightCode'] = itemAdd['OpCode'];
newRoleActRightRow['CrtUserID'] = Store.logOn.userId;
newRoleActRightRow['CrtTime'] = self._nowDate;
});
//设置checkbox为可点击
self.vm.gridAct.setSelectboxDisable(false);
}
//当点击的是Parents时需将操作权Grid进行清空
if (isParent) {
self.dsActRight.clear();
}
if (!isTreeCheck) {
isTreeCheck = true;
}
}
});
}
return ActRightWin;
})