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.

308 lines
9.7 KiB

4 years ago
define(function (require, exports, module) {
let Window = require('system/views/pages/window');
let tpl = require('text!./right-win.tpl');
function RoleRightWin(curRole, funcCode) {
this.options = {
title: Store.MSG.FRS002_11,//操作权
content: tpl,
width: 900,
height: 600,
modal: true,
closed: true,
closable: true,
draggable: false,
data: null
}
this.curRole = curRole
this.dsMenuRight = new DataSource({
funcCode: funcCode,
funcObjCode: '2012',
isMultiPage: false
})
this.dsMenuRight.fixQuery = {
role_id: curRole.UGrpCode
}
this.dsOpRight = new DataSource({
funcCode: funcCode,
funcObjCode: '2013',
isMultiPage: false
})
this.dsOpRight.fixQuery = {
role_id: curRole.UGrpCode
}
this.dsMenu = new DataSource({
funcCode: funcCode,
funcObjCode: 'tFrmFuncMenu',
isMultiPage: false
})
this.dsFuncOp = new DataSource({
funcCode: funcCode,
funcObjCode: '2014',
isMultiPage: false
})
Window.call(this, this.options);
}
inherits(RoleRightWin, Window);
function parseMenuData(self) {
let data = self.dsMenu.rows
let nodes = [];
data.forEach(function (item, index) {
let idLen = item.MenuCode.length;
let node = {
id: item.MenuCode,
pId: idLen > 2 ? item.MenuCode.substring(0, idLen - 2) : '',
name: item.MenuCaption,
value: item.FuncCode || '',
menuCode: item.MenuCode,
checked: !!self.menuSelection[item.MenuCode]
}
nodes.push(node);
});
return nodes;
}
RoleRightWin.prototype.init = function () {
let self = this;
//操作权菜单树数据
let ztreeFuncMenu = {
opts: {
showLine: true,
checkEnable: true
},
data: parseMenuData(self),
actions: {
onClick: function (e, treeNode) {
self.selectedMenu = treeNode;
if (!treeNode || !treeNode.value || treeNode.value === '*') {
self.dsFuncOp.clear()
return
}
self.dsFuncOp.fixQuery['FuncCode'] = treeNode.value
self.dsFuncOp.search((isOk) => {
syncOpSelection(self)
})
},
onCheck: function (event, treeNode) {
let isChecked = treeNode.checked;
if (isChecked) {
checkTreeNode(treeNode, self)
} else {
notCheckTreeNode(treeNode, self)
}
}
}
}
//操作权界面功能对应操作权数据
let gridActRight = {
opts: {
showCheckColumn: true,
editable: false,
enablePager: false,
pageSize: -1
},
data: self.dsFuncOp,
actions: {
onKeyDown: function (e, args) {
// if (!treeCheckRow.checked) {
// Store.messager.warn('当前功能未选中,不能修改操作权,请先选中当前功能');
// return;
// }
},
onSelectedRowsChanged: function (e, args) {
if (self.dsFuncOp.rows.length <= 0) {
return
}
let selectedRows = args.selectedRows;
//删除组织下部门
for (let i = self.dsOpRight.rows.length - 1; i >= 0; i--) {
let row = self.dsOpRight.rows[i]
if (row['menu_code'] === self.selectedMenu.menuCode) {
let key = getKey(row)
self.opSelection[key]['$is_sel'] = false
}
}
for (let i = 0; i < selectedRows.length; i++) {
// 获取当前修改行
let selectedRow = selectedRows[i];
let opCode = selectedRow['OpCode']
let key = self.selectedMenu.menuCode + '-' + opCode
if (!self.opSelection[key]) {
let newRow = self.dsOpRight.addRow();
newRow.setColumnText('role_id', self.curRole.UGrpCode)
newRow.setColumnText('menu_code', self.selectedMenu.menuCode)
newRow.setColumnText('op_code', opCode)
newRow['$is_sel'] = true
self.opSelection[key] = newRow
} else {
self.opSelection[key]['$is_sel'] = true
}
}
}
}
}
this.register('tree', 'treeMenu', ztreeFuncMenu);
this.register('grid', 'gridOp', gridActRight);
}
function checkTreeNode(node, self) {
let menuCode = node.id
if (self.menuSelection[menuCode]) {
self.menuSelection[menuCode]['$is_sel'] = true
} else {
const newRow = self.dsMenuRight.addRow()
newRow['$is_sel'] = true
newRow.setColumnText('menu_code', menuCode)
newRow.setColumnText('role_id', self.curRole.UGrpCode)
self.menuSelection[menuCode] = newRow
}
recurseParent(node, self)
}
function recurseParent(node, self) {
let parent = node.getParentNode()
if (!parent) {
return
}
if (parent.checked) {
checkTreeNode(parent, self)
} else {
notCheckTreeNode(parent, self)
}
}
function notCheckTreeNode(node, self) {
let menuCode = node.id
if (self.menuSelection[menuCode]) {
self.menuSelection[menuCode]['$is_sel'] = false
}
recurseParent(node, self)
}
function getKey(row) {
return row.menu_code + '-' + row.op_code
}
function syncOpSelection(self) {
self.dsFuncOp.rows.forEach(r => {
//r.OpCode
let key = self.selectedMenu.menuCode + '-' + r.OpCode
r['$is_sel'] = !!self.opSelection[key]
})
self.vm.gridOp.updateSelection()
}
RoleRightWin.prototype.open = function () {
const self = this
let params = {
uiObjCodes: '2012;2013;tFrmFuncMenu;2014'
}
Store.services.getUiObjSchema(params, function (isOk, data) {
if (isOk) {
self.dsMenuRight.initUIObj(data['2012']);
self.dsOpRight.initUIObj(data['2013']);
self.dsMenu.initUIObj(data['tFrmFuncMenu']);
self.dsFuncOp.initUIObj(data['2014']);
Store.bizDao.getDataSet([self.dsMenuRight, self.dsOpRight, self.dsMenu], (isSuccess) => {
if (isSuccess) {
updateMenuSelection(self)
updateOpSelection(self)
Window.prototype.open.call(self);
} else {
Store.messager.err('获取权限数据失败');
}
})
}
});
}
function updateMenuSelection(self) {
self.menuSelection = {}
self.dsMenuRight.rows.forEach(r => {
r['$is_sel'] = true
self.menuSelection[r.menu_code] = r
})
}
function updateOpSelection(self) {
self.opSelection = {}
self.dsOpRight.rows.forEach(r => {
r['$is_sel'] = true
self.opSelection[getKey(r)] = r
})
}
RoleRightWin.prototype.customerize = function ($container) {
let self = this;
let treeObj = self.vm.treeMenu
this.getElement('.cur-role').text(self.curRole.UGrpCode + '-' + self.curRole.UGrpName)
this.getElement('.btn-save').on('click', function (event) {
for (let i = self.dsMenuRight.rows.length - 1; i >= 0; i--) {
let row = self.dsMenuRight.rows[i]
if (!row['$is_sel']) {
row.delete()
}
}
for (let i = self.dsOpRight.rows.length - 1; i >= 0; i--) {
let row = self.dsOpRight.rows[i]
if (!row['$is_sel']) {
row.delete()
}
}
Store.bizDao.saveDataSet([self.dsMenuRight, self.dsOpRight], (isOk) => {
if (isOk) {
Store.messager.tip('保存成功')
self.close()
}
})
});
this.getElement('.btnClose').on('click', function (event) {
Store.messager.confirm('确定要关闭操作权窗体吗?', function (confirmIsOk) {
if (confirmIsOk) {
self.close();
}
});
});
//全部展开按钮事件
this.getElement('.btn-all-expand').on('click', function (event) {
if (treeObj) {
treeObj.expandAll(true);
}
});
//全部合拢按钮事件
this.getElement('.btn-all-pack').on('click', function (event) {
if (treeObj) {
treeObj.expandAll(false);
}
});
}
return RoleRightWin;
})