vue-apps/com.actionsoft.apps.coe.pal/views/portal/UserGroup.vue

748 lines
34 KiB
Vue
Raw Normal View History

2022-06-28 01:29:37 +08:00
<template>
<el-container id="userGroup">
<el-header :height="headerHeight">
<el-col :span="24" style="position: relative;top: 10px;">
<div style="display:inline-block;float:left;">
<awsui-button style="width: 100px;" class="button-general-color" type="primary" @click="addUserGroup()">新建用户组</awsui-button>
</div>
<div style="display:inline-block;float:right;width:320px;padding-right: 20px;">
<el-input
placeholder="搜索"
prefix-icon="el-icon-search"
v-model="searchInput"
@input="searchUserGroup"
size="small"
clearable>
</el-input>
</div>
</el-col>
<el-dialog
v-loading="dlgLoading"
:title="dialog.title"
:visible.sync="dialog.visible"
:modal-append-to-body=false
:close-on-click-modal=false
:close-on-press-escape=true
:before-close="handleCloseDlg"
@close="clearDlgData"
destroy-on-close
width="700px">
<div v-loading="loading">
<el-steps :active="dialog.active" align-center>
<el-step title="基本信息"></el-step>
<el-step title="关联角色"></el-step>
<el-step title="数据权限"></el-step>
</el-steps>
<div style="padding:10px;border:1px solid #e9e9e9">
<div style="height: 300px;" v-show="dialog.active == 1">
<awsui-form ref="infoForm" :model="dialog.basicInfo.infoForm" :rules="dialog.basicInfo.rules" label-width="100px" label-position="top">
<awsui-form-item label="分类" prop="category">
<awsui-select
:validate-event=false
filterable
allow-create
default-first-option
placeholder="请选择/输入分类"
v-model="dialog.basicInfo.infoForm.category.value"
:options="dialog.basicInfo.infoForm.category.options"
@change="changeType"
>
</awsui-select>
</awsui-form-item>
<awsui-form-item label="名称" prop="name">
<awsui-input placeholder="请输入名称" :validate-event=false v-model="dialog.basicInfo.infoForm.name"></awsui-input>
</awsui-form-item>
<awsui-form-item label="简介" prop="desc">
<!-- <el-input type="textarea" v-model="dialog.basicInfo.infoForm.desc" maxlength="255" show-word-limit rows="5"></el-input>-->
<awsui-input v-model="dialog.basicInfo.infoForm.desc" type="textarea" placeholder="请输入简介"></awsui-input>
</awsui-form-item>
</awsui-form>
</div>
<div style="height: 300px;" v-show="dialog.active == 2">
<el-tree
ref="roleTree"
style="height: 100%;overflow: auto;"
:props="dialog.roleConfig.props"
:default-checked-keys="dialog.roleConfig.value"
:expand-on-click-node=false
:highlight-current=true
@node-expand="expandRoleNode"
@node-collapse="closeRoleNode"
@check-change="checkedRoleNode"
check-strictly
:load="loadRoleNode"
lazy
show-checkbox
:default-expand-all=false
node-key="id">
<span slot-scope="{node, data}">
<i class="awsui-iconfont tree-content-icon tree-content-icon-padding" :style="{'color': data.iconFont.color, 'position': 'relative', 'top': '-1px'}" v-html="data.iconFont.code"></i>
<span>{{data.label}}</span>
</span>
</el-tree>
</div>
<div style="height: 300px;" v-show="dialog.active == 3">
<el-select
style="width: 100%;"
v-model="dialog.repositoryPerm.ws.value"
filterable
default-first-option
size="small"
placeholder="请选择资产库"
@change="changeWs">
<el-option
v-for="item in dialog.repositoryPerm.ws.options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<div style="height: 268px;overflow: auto;">
<el-tree v-if="dialog.repositoryPerm.ws.value != ''"
ref="repositoryTree"
:props="dialog.repositoryPerm.tree.props"
:default-checked-keys="dialog.repositoryPerm.tree.value"
:expand-on-click-node=false
:highlight-current=true
@node-click="openNode"
@node-expand="expandNode"
@node-collapse="closeNode"
@check-change="checkedNode"
check-strictly
show-checkbox
node-key="versionId"
lazy
:load="loadNode">
<span slot-scope="{node, data}">
<i class="awsui-iconfont tree-content-icon tree-content-icon-padding" :style="{'color': node.data.icon.color}" v-html="node.data.icon.icon"></i>
<span>{{node.data.name}}</span>
</span>
</el-tree>
</div>
</div>
</div>
</div>
<span slot="footer" class="dialog-footer">
<!-- <awsui-button @click="closeDlg">取消</awsui-button>-->
<awsui-button v-show="dialog.active == 2 || dialog.active == 3" class="button-general-color-reverse" @click="function(){dialog.active--}">上一步</awsui-button>
<awsui-button v-show="dialog.active == 1 || dialog.active == 2" class="button-general-color" type="primary" @click="next">下一步</awsui-button>
<awsui-button v-show="dialog.active == 3" class="button-general-color" type="primary" @click="saveUserGroup(dialog.updateId)">确定</awsui-button>
</span>
</el-dialog>
</el-header>
<el-main>
<div id="main" :style="{'height': mainHeight, 'width': '100%'}">
<el-table
:height="mainHeight"
:data="data"
style="width: 100%">
<el-table-column
prop="no"
label="序号"
align="center"
width="50">
</el-table-column>
<el-table-column
prop="name"
label="名称"
:show-overflow-tooltip=true
width="250">
</el-table-column>
<el-table-column
prop="category"
label="分类"
width="150">
</el-table-column>
<el-table-column
prop="wsName"
label="关联资产库"
:show-overflow-tooltip=true
width="200">
</el-table-column>
<el-table-column
prop="desc"
label="说明">
</el-table-column>
<el-table-column
prop="opt"
label="操作"
align="center"
width="80">
<template slot-scope="scope">
<div class="operate-icon-display">
<p class="text-second-color">
<i style="display: inline-block;cursor: pointer;margin-right: 15px;" class="awsui-iconfont" @click="addUserGroup(scope.row.id)">&#58914;</i>
<i style="display: inline-block;cursor: pointer;" class="awsui-iconfont" @click="deleteUserGroup(scope.row.id, scope.row.name)">&#58918;</i>
</p>
</div>
</template>
</el-table-column>
</el-table>
</div>
</el-main>
</el-container>
</template>
<script>
import awsuiAxios from "../../awsuiAxios";
export default {
name: "userGroup",
data() {
return {
headerHeight: '50px',
mainHeight: (parseInt(this.$store.getters.getTopMainHeightFn) - 52) + 'px',
loading: false,
dlgLoading: false,
searchInput: '',
data: [],
dataTemp: [],
dialog:{
active: 1,
visible: false,
title: '新建用户组',
updateId: '',// 更新信息id若新建则为空
basicInfo: {
infoForm: {
name: '',
category: {
value: '',
options: []
},
desc: '',
groupCode: ''
},
rules: {
category: [
{ required: true, message: '[分类]不允许为空', trigger: 'blur' },
],
name: [
{ required: true, message: '[名称]不允许为空', trigger: 'blur' },
]
}
},
roleConfig: {
data: [],
props: {
label: 'label',
isLeaf: 'leaf'
},
value: []
},
repositoryPerm: {
ws: {
value: '',
options: []
},
tree: {
props: {
children: 'children',
label: 'label',
isLeaf: 'leaf'
},
value: []
}
}
}
}
},
mounted() {
// 火狐浏览器拖拽问题
document.body.ondrop = function (event) {
event.preventDefault();
event.stopPropagation();
}
this.initData();
},
methods: {
initData() {// 初始化数据查询
const that = this;
const params = {
url:'jd',
data:{
cmd: 'com.actionsoft.apps.coe.pal_publish_publishgroup_list'
}
};
// 查询数据
awsuiAxios.post(params).then(function (ro) {
if(ro.result == 'ok') {
let data = ro.data;
that.data = that.handleDataNo(data);
that.dataTemp = JSON.parse(JSON.stringify(that.data));
} else {
this.$message({message: ro.msg,type: 'warning'});
}
}).catch(error=>{
console.log(error);
})
},
handleDataNo(data) {// 处理数据的序号
for (let i = 0; i < data.length; i++) {
data[i].no = i+1;
}
return data;
},
searchUserGroup() {// 搜索
if (this.searchInput && this.searchInput.trim() != '') {// 根据条件搜索
const data = [];
for (let i = 0; i < this.dataTemp.length; i++) {
if (this.dataTemp[i].name.indexOf(this.searchInput) > -1
|| this.dataTemp[i].category.indexOf(this.searchInput) > -1
|| this.dataTemp[i].wsName.indexOf(this.searchInput) > -1
|| this.dataTemp[i].desc.indexOf(this.searchInput) > -1) {
data.push(this.dataTemp[i]);
}
}
this.data = this.handleDataNo(data);
} else {// 显示全部
this.data = this.handleDataNo(this.dataTemp);
}
},
addUserGroup(id) {// 新增用户组
this.dialog.updateId = '';
if (id) {
this.dialog.updateId = id;
this.dialog.title = '修改用户组';
} else {
this.dialog.title = '新建用户组';
}
this.dialog.visible = true;
this.loading = true;
const that = this;
const params = {
url:'jd',
data:{
cmd: 'com.actionsoft.apps.coe.pal_publish_publishgroup_create_data_query',
id: (id == undefined ? '' : id)
}
};
// 查询数据
awsuiAxios.post(params).then(function (ro) {
if(ro.result == 'ok') {
const data = ro.data;
that.dialog.basicInfo.infoForm.name = data.name;
that.dialog.basicInfo.infoForm.category.value = data.category;
that.dialog.basicInfo.infoForm.category.options = data.categoryArr;
that.dialog.basicInfo.infoForm.desc = data.desc;
that.dialog.basicInfo.infoForm.groupCode = data.groupCode;
that.dialog.roleConfig.value = data.roles;
that.dialog.repositoryPerm.ws.value = data.wsId;
that.dialog.repositoryPerm.ws.options = data.wsArr;
that.dialog.repositoryPerm.tree.value = data.repositorys;
} else {
that.$message(ro.msg);
}
that.loading = false;
}).catch(error=>{
console.log(error);
that.loading = false;
})
},
changeType(val) {
this.dialog.basicInfo.infoForm.category.value = val;
},
deleteUserGroup(id, name) {// 删除用户组
const that = this;
that.$confirm('确定要删除吗?', '提示', {
confirmButtonText: '确定',
confirmButtonClass: 'button-general-color',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const params = {
url:'jd',
data:{
cmd: 'com.actionsoft.apps.coe.pal_publish_publishgroup_delete',
id: id
}
};
awsuiAxios.post(params).then(function (ro) {
if(ro.result == 'ok') {
that.$message({
message: '删除成功',
type: 'success'
});
that.initData();
} else {
that.$message(ro.msg);
}
}).catch(error=>{
console.log(error);
})
}).catch(() => {
});
},
clearDlgData() {// 清除dialog数据
this.dialog.active = 1;
this.dialog.updateId = '';
this.dialog.basicInfo.infoForm.name = '';
this.dialog.basicInfo.infoForm.category.value = '';
this.dialog.basicInfo.infoForm.category.options = [];
this.dialog.basicInfo.infoForm.desc = '';
this.dialog.basicInfo.infoForm.groupCode = '';
this.$refs.infoForm.resetFields();
this.dialog.roleConfig.data = [];
this.dialog.roleConfig.value = [];
this.dialog.repositoryPerm.ws.value = '';
this.dialog.repositoryPerm.ws.options = [];
this.dialog.repositoryPerm.tree.data = [];
this.dialog.repositoryPerm.tree.value = [];
},
closeDlg() {// 关闭新建/修改窗口
this.dialog.visible = false;
},
handleCloseDlg(done) {
this.closeDlg();
done();
},
handleTabClick(tab, event) {
// console.log(tab, event);
},
next() {
const that = this;
if (this.dialog.active == 1) {
// 基本信息
const groupName = that.dialog.basicInfo.infoForm.name;
const category = that.dialog.basicInfo.infoForm.category.value;
const groupDesc = that.dialog.basicInfo.infoForm.desc;
const groupCode = that.dialog.basicInfo.infoForm.groupCode;
if (groupCode == "") {
that.$message({message: '[代码]不允许为空',type: 'warning'});
return;
}
if (groupCode.length > 36) {
that.$message({message: '[代码]不允许超过36个字符',type: 'warning'});
return;
}
if (category == "") {
that.$message({message: '[分类]不允许为空',type: 'warning'});
return;
}
if (category.length > 64) {
that.$message({message: '[分类]不允许超过64个字符',type: 'warning'});
return;
}
if (!category.match("^[a-zA-Z0-9_\u4e00-\u9fa5]+$")) {
that.$message({message: '[分类]只能输入字母、数字、汉字或下划线',type: 'warning'});
return;
}
if (groupName == "") {
that.$message({message: '[名称]不允许为空',type: 'warning'});
return;
}
if (groupName.length > 128) {
that.$message({message: '[名称]不允许超过128个字符',type: 'warning'});
return;
}
if (groupDesc.length > 255) {
that.$message({message: '[简介]不允许超过255个字符',type: 'warning'});
return;
}
}
this.dialog.active++;
},
saveUserGroup(updateId) {
const that = this;
const groupName = that.dialog.basicInfo.infoForm.name;
const category = that.dialog.basicInfo.infoForm.category.value;
const groupDesc = that.dialog.basicInfo.infoForm.desc;
const groupCode = that.dialog.basicInfo.infoForm.groupCode;
// 角色权限信息
const roles = that.dialog.roleConfig.value;
// 数据权限
const wsId = that.dialog.repositoryPerm.ws.value;
const repositorys = that.dialog.repositoryPerm.tree.value;
// 保存
that.dlgLoading = true;
const params = {
url:'jd',
data:{
cmd: 'com.actionsoft.apps.coe.pal_publish_publishgroup_create_save',
id: updateId == undefined ? '' : updateId,
groupName: groupName,
groupCode: groupCode,
groupDesc: groupDesc,
category: category,
wsId: wsId,
roleIds: roles.join(","),
resourceIds: repositorys.join(",")
}
};
awsuiAxios.post(params).then(function (ro) {
if(ro.result == 'ok') {
that.dlgLoading = false;
that.clearDlgData();
that.closeDlg();
that.$message({
message: '保存成功',
type: 'success'
});
that.initData();
} else {
that.$message.error('保存失败');
that.dlgLoading = false;
}
}).catch(error=>{
console.log(error);
that.dlgLoading = false;
})
},
/*****数据权限*******/
changeWs(targetWsId) {// 变更资产库
const that = this;
that.dialog.repositoryPerm.ws.value = '';
that.dialog.repositoryPerm.tree.value = [];
that.$nextTick(function () {
that.dialog.repositoryPerm.ws.value = targetWsId;
})
},
openNode(obj, node, tree) {// 点击数
},
loadNode(node, resolve) {
const that = this;
const data = {
url:'jd',
data:{
}
};
data.data.wsId = that.dialog.repositoryPerm.ws.value;
data.data.teamId = '';
data.data.cmd = 'com.actionsoft.apps.coe.pal_processlevel_tree_data';
if (node.level === 0) {
// 获取根目录
data.data.pid = '';
} else {
// 获取其他目录
data.data.pid = node.data.id;
}
// 查询数据
awsuiAxios.post(data).then(function (ro) {
resolve(ro.data);
if (node.level == 0 && ro.data.length > 0) {
const tree = that.$refs.repositoryTree;
tree.getNode(ro.data[0].id).expand();
setTimeout(function(){
const childNode = tree.getNode(ro.data[0].id).childNodes[0];
if (childNode != null) {
childNode.expand();
}
}, 500);
}
}).catch(error=>{
console.log(error);
})
},
expandNode(obj, node, tree) {// 展开节点
},
closeNode(obj, node, tree) {// 关闭时清空,下次展开重新请求动态加载
node.childNodes = [];
node.loaded = false;
},
checkedNode(data, checked, subChecked) {// 节点选中事件
// 获取所有子节点
const that = this;
const params = {
url:'jd',
data:{
cmd: 'com.actionsoft.apps.coe.pal_publish_publishgroup_repository_data_query',
wsId: that.dialog.repositoryPerm.ws.value,
pid: data.id,
}
};
awsuiAxios.post(params).then(function (ro) {
const childVerIds = ro.data;
const currVerId = data.versionId;
if (checked) {// 选中
const checkedVerIds = that.dialog.repositoryPerm.tree.value;
if (checkedVerIds.indexOf(currVerId) == -1) {
checkedVerIds.push(currVerId);
}
for (let i = 0; i < childVerIds.length; i++) {
if (checkedVerIds.indexOf(childVerIds[i]) == -1) {
checkedVerIds.push(childVerIds[i]);
}
}
that.$refs.repositoryTree.setCheckedKeys(checkedVerIds);
} else {// 取消选中
const checkedVerIds = that.dialog.repositoryPerm.tree.value;
const tempArr = [];
for (let i = 0; i < checkedVerIds.length; i++) {
if (checkedVerIds[i] != currVerId && childVerIds.indexOf(checkedVerIds[i]) == -1) {
tempArr.push(checkedVerIds[i]);
}
}
that.dialog.repositoryPerm.tree.value = tempArr;
that.$refs.repositoryTree.setCheckedKeys([]);
}
}).catch(error=>{
console.log(error);
})
},
/*********数据权限************/
/*********角色权限***********/
loadRoleNode(node, resolve) {
const that = this;
const data = {
url: 'jd',
data: {}
};
data.data.cmd = 'com.actionsoft.apps.coe.pal_publish_publishgroup_role_tree_data_query';
if (node.level === 0) {
// 获取根目录
data.data.pid = '';
} else {
// 获取其他目录
data.data.pid = node.data.id;
}
// 查询数据
awsuiAxios.post(data).then(function (ro) {
resolve(ro.data);
}).catch(error => {
console.log(error);
that.tableLoading = false;
})
},
expandRoleNode(obj, node, tree) {// 展开节点
},
closeRoleNode(obj, node, tree) {// 关闭时清空,下次展开重新请求动态加载
node.childNodes = [];
node.loaded = false;
},
checkedRoleNode(data, checked, subChecked) {// 角色岗位节点选中事件
debugger;
// 获取所有子节点
const that = this;
if (data.type == 'roleGroup') {// 选中角色组,异步查询
// 查询子节点
const params = {
url:'jd',
data:{
cmd: 'com.actionsoft.apps.coe.pal_publish_publishgroup_role_tree_data_query',
pid: data.id
}
};
awsuiAxios.post(params).then(function (ro) {
const roleArr = ro.data;
let roleIdArr = [];
for (let i = 0; i < roleArr.length; i++) {
roleIdArr.push(roleArr[i].id);
}
const currId = data.id;
const checkIds = that.dialog.roleConfig.value;
if (checked) {// 选中
if (checkIds.indexOf(currId) == -1) {
checkIds.push(currId);
}
for (let i = 0; i < roleIdArr.length; i++) {
if (checkIds.indexOf(roleIdArr[i]) == -1) {
checkIds.push(roleIdArr[i]);
}
}
} else {// 取消选中
const tempArr = [];
for (let i = 0; i < checkIds.length; i++) {
if (checkIds[i] != currId && roleIdArr.indexOf(checkIds[i]) == -1) {
tempArr.push(checkIds[i]);
}
}
that.dialog.roleConfig.value = tempArr;
}
that.$refs.roleTree.setCheckedKeys(that.dialog.roleConfig.value);
}).catch(error=>{
console.log(error);
})
} else if (data.type == 'role') {// 选中角色,无子级,直接设置选中值
const checkIds = that.dialog.roleConfig.value;
if (checked) {// 选中
if (checkIds.indexOf(data.id) == -1) {
checkIds.push(data.id);
}
} else {// 取消选中
const tempArr = [];
for (let i = 0; i < checkIds.length; i++) {
if (checkIds[i] != data.id) {
tempArr.push(checkIds[i]);
}
}
that.dialog.roleConfig.value = tempArr;
}
that.$refs.roleTree.setCheckedKeys(that.dialog.roleConfig.value);
}
}
/*********角色权限***********/
},
computed: {
listenTopMainHeight() {
return this.$store.getters.getTopMainHeightFn;
}
},
watch: {
listenTopMainHeight: function (newd, old) {
this.mainHeight = (parseInt(this.$store.getters.getTopMainHeightFn) - parseInt(this.headerHeight)) -2 + 'px';
}
}
}
</script>
<style scoped>
#userGroup >>> .el-main {
padding: 0px 20px;
}
#userGroup >>> .el-table__row .operate-icon-display{
display: none;
}
#userGroup >>> .el-table__row:hover .operate-icon-display{
display: inline-block;
}
#userGroup >>> .el-dialog__body {
padding: 0px 20px;
}
#userGroup >>> .el-tabs__nav-wrap:after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 1px;
background-color: #F2F2F2;
z-index: 1;
}
#userGroup >>> .el-tabs__active-bar {
height: 1px;
background-color: #4E7FF9;
}
#userGroup >>> .el-tabs__item.is-active {
color: #4E7FF9;
}
#userGroup >>> .el-tabs__item {
color: #606266;
}
#userGroup >>> .el-form-item__label {
padding: 0;
line-height: 0;
}
#userGroup >>> .el-form-item {
margin-bottom: 16px;
}
#userGroup >>> .el-tree {
min-width: 100%;
display:inline-block !important;
}
#userGroup >>> .el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content {
background-color: #F5F7FA;
color: #4E7FF9;
}
#userGroup >>> .el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content .awsui-iconfont {
color: #4E7FF9 !important;
}
#userGroup >>> .el-step__title {
font-size: 12px;
}
#userGroup >>> textarea.awsui-input {
height: 130px;
}
</style>