$(function() {
|
cheackForm("from");
|
$("title").text("角色管理 - " + systemTitle);
|
initRoleCatalogBox(roleId);
|
});
|
var respowers=[];
|
var vm = new Vue({
|
el: '#rapp',
|
data: {
|
title: null,
|
role: {}
|
},
|
methods: {
|
saveOrUpdate: function() {
|
vm.role.appId = $("#systemNames").val();
|
var resourceIds = this.getAuthValues();
|
var catalogIds = this.getResAuthValues();
|
if (vm.title == "新增") {
|
var url = "sys/role/save";
|
}
|
if (vm.title == "编辑") {
|
var url = "sys/role/update";
|
}
|
if($("#from").valid()) {
|
$.ajax({
|
type: "POST",
|
url: restServerBaseURL + url,
|
contentType: "application/json",
|
data: JSON.stringify({sysRole: vm.role, resourceIds: resourceIds,catalogIds: catalogIds}),
|
success: function (r) {
|
if (r.code === 0) {
|
alert('操作成功', function () {
|
if (vm.title == "新增") {
|
window.location.href = window.location.href + "?roleId=" + r.roleid;
|
} else {
|
window.location.reload();
|
}
|
if (parent.opener.vm && parent.opener.vm.reload) {
|
parent.opener.vm.reload();
|
}
|
});
|
} else {
|
alert(r.msg);
|
}
|
}
|
});
|
}
|
},
|
getInfo: function(roleId) {
|
|
$.get(restServerBaseURL + "sys/role/info?roleId=" + roleId, function(r) {
|
vm.role = r.role;
|
if (roleId == '') {//新增
|
initSysNames(r.systemNames,roleId);
|
updateWithSystemChange(1);
|
}else{//修改
|
initSysNames(r.systemNames,roleId);
|
$("#systemNames").find("option[value ='"+ vm.role.appId +"']").attr("selected","selected");
|
initPowerBox(r.sysResources);
|
initSelectBox(r.ownResources);
|
respowers=r.role.respowers;
|
|
}
|
});
|
},
|
getAuthValues: function(){
|
var arrId = [];
|
$("#authDiv input[type = 'checkbox']:checked").each(function(){
|
arrId.push($(this).val());
|
});
|
return arrId;
|
},
|
getResAuthValues: function(){
|
var arrId = [];
|
$("#resauthDiv input[type = 'checkbox']:checked").each(function(){
|
arrId.push($(this).val());
|
});
|
return arrId;
|
}
|
},
|
created: function(){
|
var search = window.location.search;
|
var roleId = "";
|
if(search.indexOf("?") > -1){
|
search = search.replace("?", "");
|
roleId = search.split('=')[1];
|
}
|
if(roleId == ""){
|
this.title = "新增";
|
this.role = {};
|
} else {
|
this.title = "编辑";
|
|
}
|
this.getInfo(roleId);
|
}
|
|
});
|
|
function initSysNames(systemNames,roleId){
|
if(systemNames != undefined && systemNames.length > 0) {
|
for (var i = 0; i < systemNames.length; i++) {
|
$("#systemNames").append("<option value=" + systemNames[i].id + ">" + systemNames[i].name + "</option>");
|
}
|
if ((roleId == null || roleId == '')&&getAppId()!=null) {
|
$("#systemNames").val(getAppId());
|
}
|
}
|
}
|
|
//add by zsx
|
function initRoleCatalogBox(roleId){
|
$.ajax({
|
type: 'get',
|
contentType: "application/json",
|
url: LanCatalogBaseURL + "api/catalog/getList/0",
|
success: function (data) {
|
debugger;
|
var catalogRes=data;
|
if(catalogRes != undefined && catalogRes.length > 0) {
|
for (var i = 0; i < catalogRes.length; i++) {
|
if (i != 0 && i % 4 === 0) $("#resauthDiv").append("<br/>");
|
$("#resauthDiv").append("<label class='control-checkbox' ><input type='checkbox' value='" + catalogRes[i].catlogid + "'>" + catalogRes[i].title + "</label>");
|
}
|
}
|
initResCatalogSelectBox(respowers.split(","));
|
},
|
error: function (data) {
|
debugger;
|
alert("未知错误");
|
}
|
})
|
}
|
|
function initResCatalogSelectBox(data){
|
if(data != undefined && data.length > 0) {
|
for (var i = 0; i < data.length; i++) {
|
$("#resauthDiv").find("input[value='" + data[i]+ "']").attr("checked", true);
|
}
|
}
|
}
|
|
function initPowerBox(sysResources){
|
if(sysResources != undefined && sysResources.length > 0) {
|
for (var i = 0; i < sysResources.length; i++) {
|
if (i != 0 && i % 4 === 0) $("#authDiv").append("<br/>");
|
$("#authDiv").append("<label class='control-checkbox' ><input type='checkbox' value='" + sysResources[i].id + "'>" + sysResources[i].name + "</label>");
|
}
|
}
|
}
|
|
|
|
function initSelectBox(ownResources){
|
if(ownResources != undefined && ownResources.length > 0) {
|
for (var i = 0; i < ownResources.length; i++) {
|
$("#authDiv").find("input[value='" + ownResources[i].id + "']").attr("checked", true);
|
}
|
}
|
}
|
|
//type=0为下拉框触动,=1为新增触动
|
function updateWithSystemChange(type){
|
if (type == 0) {
|
$("#authDiv").empty();
|
var roleId = $("#roleId").val();
|
var appId = $("#systemNames").val();
|
$.get(restServerBaseURL + "sys/role/systemChangeWithInit?roleId=" + roleId + "&appId=" + appId, function(data) {
|
initPowerBox(data.sysResources);
|
initSelectBox(data.ownResources)
|
})
|
}else{
|
if (getAppId() != null) {
|
$.get(restServerBaseURL + "sys/role/systemChangeWithInit?roleId=" + "&appId=" + getAppId(), function(data) {
|
initPowerBox(data.sysResources);
|
})
|
}
|
}
|
}
|