Files
SaaS-lib/hx-ai-intelligent/src/view/organizationManage/departmentManage/index.vue

501 lines
14 KiB
Vue
Raw Normal View History

2024-05-22 11:23:13 +08:00
<!-- @format -->
<template>
<div class="main">
<div class="left">
<div class="ns-table-title">部门管理</div>
<a-row>
<a-col :span="12" class="tree">
2024-06-04 19:22:11 +08:00
<ns-button :disabled="disabled" style="margin: 10px" type="primary" @click="addApartment"
>新增部门</ns-button
>
<ns-button :disabled="disabled" type="primary" @click="addApartmentSon"
>新增子部门</ns-button
>
<ns-button
:disabled="disabled"
style="margin: 10px"
type="primary"
@click="deleteApartment"
>删除</ns-button
>
2024-06-04 10:54:02 +08:00
<a-tree
v-if="apartmentTreeData?.length"
:tree-data="apartmentTreeData"
defaultExpandAll
@select="SelectApartmentTree">
<template #title="data">
2024-06-04 19:22:11 +08:00
{{ data.deptInfo?.deptName }}
2024-05-22 11:23:13 +08:00
</template>
</a-tree>
</a-col>
<a-col :span="12" class="list">
<a-tabs v-model:activeKey="activeKey">
<a-tab-pane key="1" tab="部门信息">
2024-05-28 11:08:57 +08:00
<ns-form
ref="formRef"
:schemas="formSchema"
:model="formData"
formLayout="vertical"
class="form" />
2024-05-22 17:43:25 +08:00
</a-tab-pane>
<a-tab-pane key="2" tab="部门权限">
<a-tree
:tree-data="apartmentAdminTreeData"
v-model:checkedKeys="ApartcheckedKeys"
checkable
2024-05-28 11:08:57 +08:00
defaultExpandAll
2024-05-22 17:43:25 +08:00
@select="ApartmentSelect">
<template #title="{ title }">
{{ title }}
</template>
</a-tree>
2024-05-22 11:23:13 +08:00
</a-tab-pane>
</a-tabs>
2024-05-22 17:43:25 +08:00
<ns-button style="margin: 20px" type="primary" @click="CancelApartment">取消</ns-button>
2024-06-04 10:54:02 +08:00
<ns-button type="primary" @click="ApartmentSure">确定</ns-button>
2024-05-22 16:31:55 +08:00
</a-col>
</a-row>
</div>
<div class="right">
<div class="ns-table-title">角色管理</div>
<a-row>
<a-col :span="12" class="tree">
2024-06-04 19:22:11 +08:00
<ns-button :disabled="disabled2" style="margin: 10px" type="primary" @click="addUser"
>新增角色</ns-button
>
<ns-button :disabled="disabled2" type="primary" @click="addUserSon">新增子角色</ns-button>
<ns-button :disabled="disabled2" style="margin: 10px" type="primary" @click="deleteUser"
>删除</ns-button
>
<a-tree
v-if="userTreeData.length"
:tree-data="userTreeData"
defaultExpandAll
@select="SelectUserTree">
2024-06-04 10:54:02 +08:00
<template #title="data">
2024-06-04 19:22:11 +08:00
{{ data.zhName }}
2024-05-22 16:31:55 +08:00
</template>
</a-tree>
</a-col>
<a-col :span="12" class="list">
<a-tabs v-model:activeKey="activeKey2">
<a-tab-pane key="1" tab="角色信息">
2024-05-22 17:43:25 +08:00
<ns-form
:schemas="formSchema2"
:model="formData2"
formLayout="vertical"
class="form" />
</a-tab-pane>
<a-tab-pane key="2" tab="角色权限">
<a-tree
:tree-data="userAdminTreeData"
v-model:checkedKeys="UsercheckedKeys"
2024-05-28 11:08:57 +08:00
defaultExpandAll
2024-05-22 17:43:25 +08:00
checkable
@select="UserSelect">
<template #title="{ title }">
{{ title }}
</template>
</a-tree>
2024-05-22 16:31:55 +08:00
</a-tab-pane>
</a-tabs>
2024-05-22 17:43:25 +08:00
<ns-button style="margin: 20px" type="primary" @click="CancelUser">取消</ns-button>
2024-06-06 16:56:34 +08:00
<ns-button type="primary" @click="UserSure"> 确定</ns-button>
2024-05-22 11:23:13 +08:00
</a-col>
</a-row>
</div>
</div>
</template>
<script lang="ts">
2024-06-06 16:56:34 +08:00
import { createVNode, defineComponent, reactive, ref, watch, watchEffect } from 'vue';
2024-05-22 16:31:55 +08:00
import { Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
2024-05-22 11:23:13 +08:00
import { http } from '/nerv-lib/util/http';
2024-05-28 11:08:57 +08:00
import { cloneDeep } from 'lodash-es';
import { formConfig, formConfig2 } from './config';
2024-06-04 10:54:02 +08:00
import { department } from '/@/api/origanizemanage';
2024-06-04 19:22:11 +08:00
import { permission } from '/@/api/origanizemanage';
import { NsMessage } from '/nerv-lib/component';
2024-06-04 10:54:02 +08:00
2024-05-22 11:23:13 +08:00
export default defineComponent({
2024-05-24 09:44:08 +08:00
name: 'AuthorityManageIndex',
2024-05-22 11:23:13 +08:00
setup() {
2024-05-28 11:08:57 +08:00
const formRef = ref();
2024-05-24 09:44:08 +08:00
let formData = ref({});
let formData2 = ref({});
const activeKey = ref('1');
const activeKey2 = ref('1');
const disabled = ref(true);
const disabled2 = ref(true);
2024-05-22 17:43:25 +08:00
const ApartcheckedKeys = ref<string[]>([]);
const UsercheckedKeys = ref<string[]>([]);
2024-05-28 11:08:57 +08:00
const selectKey = ref();
const selectRef = ref();
const selectKey2 = ref();
const selectRef2 = ref();
const formSchema = formConfig(disabled as any);
const formSchema2 = formConfig2(disabled2 as any);
2024-06-04 10:54:02 +08:00
const orgId = JSON.parse(sessionStorage.getItem('userInfo')).orgId;
const projectId = JSON.parse(sessionStorage.getItem('userInfo')).projectId;
2024-06-04 19:22:11 +08:00
const userAdminTreeData = ref([]);
2024-06-04 10:54:02 +08:00
const apartmentTreeData = ref([]);
2024-05-24 09:44:08 +08:00
2024-06-04 19:22:11 +08:00
const userTreeData = ref([]);
2024-06-06 16:56:34 +08:00
const getPermissionTree = (params) => {
return http.post(permission.permissionTree, params);
};
getPermissionTree({ projectId });
2024-05-24 09:44:08 +08:00
const apartmentAdminTreeData = [
{
title: '首页',
key: '0-0',
children: [
{
title: '控制台',
key: '0-0-0',
children: [
{ title: 'leaf', key: '0-0-0-0' },
{ title: 'leaf', key: '0-0-0-1' },
],
},
{
title: '用户管理',
key: '0-0-1',
children: [{ key: '0-0-1-0', title: 'sss' }],
},
],
},
];
2024-06-04 19:22:11 +08:00
watch(ApartcheckedKeys, () => {
console.log('checkedKeys', ApartcheckedKeys.value);
});
watch(UsercheckedKeys, () => {
console.log('checkedKeys', UsercheckedKeys.value);
});
2024-05-24 09:44:08 +08:00
2024-06-04 19:22:11 +08:00
// 部门树
const getDepartList = (params) => {
return http.post(department.dartList, params);
};
getDepartList({ orgId }).then((res) => {
apartmentTreeData.value = res.data;
});
const getTree = () => {
getDepartList({ orgId }).then((res) => {
apartmentTreeData.value = res.data;
NsMessage.success('操作成功');
});
};
2024-06-06 16:56:34 +08:00
const getUserTree = (params = { deptId: selectRef.value.deptInfo.deptId }) => {
2024-06-04 19:22:11 +08:00
http.post(department.queryRoleTree, params).then((res) => {
userTreeData.value = res.data;
});
};
2024-06-06 16:56:34 +08:00
// 根据依赖刷新角色树
watchEffect(() => {
if (selectRef.value) getUserTree();
});
2024-06-04 19:22:11 +08:00
const opMap: any = {
type: 'add',
fuc: () => {},
record: {},
callback: null,
};
2024-05-22 16:31:55 +08:00
2024-06-04 10:54:02 +08:00
function fetch(api, params) {
return http.post(api, params);
}
2024-05-22 16:31:55 +08:00
const addApartment = () => {
disabled.value = false;
2024-06-04 19:22:11 +08:00
opMap.type = 'addDept';
formData.value = {};
2024-06-04 10:54:02 +08:00
opMap.fuc = (params) => {
2024-06-04 19:22:11 +08:00
return http.post(department.deptSave, {
...params,
orgId,
projectId,
});
2024-06-04 10:54:02 +08:00
};
return;
2024-05-22 16:31:55 +08:00
};
const addApartmentSon = () => {
disabled.value = false;
2024-05-24 13:13:24 +08:00
opMap.type = 'addson';
2024-06-04 10:54:02 +08:00
formData.value = {};
opMap.fuc = (params) => {
2024-06-04 19:22:11 +08:00
return http.post(department.deptSave, {
2024-06-04 10:54:02 +08:00
...params,
orgId,
projectId,
pdeptId: selectRef.value.deptInfo.deptId,
});
};
2024-05-22 16:31:55 +08:00
};
2024-05-24 09:44:08 +08:00
const addUser = () => {
disabled2.value = false;
2024-06-04 19:22:11 +08:00
opMap.type = 'addUser';
2024-06-06 16:56:34 +08:00
formData2.value = {};
2024-06-04 19:22:11 +08:00
opMap.fuc = (params) => {
delete params.roleId;
return http.post(department.addRole, {
...params,
orgId,
projectId,
2024-06-06 16:56:34 +08:00
deptId: selectRef.value.deptInfo.deptId,
2024-06-04 19:22:11 +08:00
});
};
2024-05-24 09:44:08 +08:00
};
const addUserSon = () => {
disabled.value = false;
2024-06-04 19:22:11 +08:00
opMap.type = 'addUserSon';
2024-06-06 16:56:34 +08:00
formData2.value = {};
2024-06-04 19:22:11 +08:00
opMap.fuc = (params) => {
delete params.roleId;
return http.post(department.addRole, {
...params,
orgId,
projectId,
2024-06-06 16:56:34 +08:00
proleId: selectRef2.value.roleId,
deptId: selectRef.value.deptInfo.deptId,
2024-06-04 19:22:11 +08:00
});
};
2024-05-24 09:44:08 +08:00
};
2024-05-22 16:31:55 +08:00
const deleteApartment = () => {
2024-06-04 19:22:11 +08:00
// 删除逻辑
// opMap.type = 'deptDelete';
// opMap.fuc = (params) => {
// return http.post(department.deptDel, params).then(() => {
// NsMessage.success('删除成功');
// });
// };
2024-05-22 16:31:55 +08:00
Modal.confirm({
title: '是否确认删除',
icon: createVNode(ExclamationCircleOutlined),
content: createVNode('div', { style: 'color:red;' }, ''),
2024-05-28 11:08:57 +08:00
onOk() {
2024-06-04 19:22:11 +08:00
http.post(department.deptDel, { deptId: selectRef.value.deptInfo.deptId }).then(() => {
getTree();
clearData();
});
2024-05-28 11:08:57 +08:00
},
2024-05-22 16:31:55 +08:00
onCancel() {
console.log('Cancel');
},
});
};
const deleteUser = () => {
Modal.confirm({
title: '是否确认删除',
icon: createVNode(ExclamationCircleOutlined),
content: createVNode('div', { style: 'color:red;' }, ''),
2024-05-28 11:08:57 +08:00
onOk() {
2024-06-04 19:22:11 +08:00
http.post(department.delRole, { roleId: selectRef2.value.roleId }).then(() => {
2024-06-06 16:56:34 +08:00
getUserTree({ deptId: selectRef.value.deptInfo.deptId });
2024-06-04 19:22:11 +08:00
});
2024-05-22 16:31:55 +08:00
},
2024-06-04 19:22:11 +08:00
2024-05-22 16:31:55 +08:00
class: 'test',
});
};
2024-06-04 19:22:11 +08:00
const clearData = () => {
selectRef.value = {};
formData.value = {};
opMap.type = '';
opMap.fuc = '';
selectKey.value = '';
};
// 部门选择
2024-05-22 17:43:25 +08:00
const SelectApartmentTree = (selectedKeys: any, info: any) => {
2024-06-04 19:22:11 +08:00
const { selected } = info;
disabled.value = !selected;
console.log(info, 'info');
2024-05-28 11:08:57 +08:00
selectKey.value = selectedKeys[0];
selectRef.value = info.node.dataRef;
2024-06-04 19:22:11 +08:00
formData.value = cloneDeep(info.node.dataRef.deptInfo);
opMap.type = 'editDpet';
opMap.fuc = (params) => {
return http.post(department.deptEdit, params);
};
2024-06-06 16:56:34 +08:00
// getUserTree({ deptId: selectRef.value.deptInfo.deptId });
2024-05-22 16:31:55 +08:00
};
2024-06-04 19:22:11 +08:00
// 角色选择
2024-05-22 17:43:25 +08:00
const SelectUserTree = (selectedKeys: any, info: any) => {
2024-06-04 19:22:11 +08:00
const { selected } = info;
disabled2.value = !selected;
2024-05-22 17:43:25 +08:00
console.log(selectedKeys, 'selectedKeys');
2024-06-04 19:22:11 +08:00
console.log(info, 'info');
2024-05-28 11:08:57 +08:00
selectKey2.value = selectedKeys[0];
selectRef2.value = info.node.dataRef;
2024-06-04 19:22:11 +08:00
formData2.value = cloneDeep(info.node.dataRef);
2024-06-06 16:56:34 +08:00
opMap.type = 'editRole';
opMap.fuc = (params) => {
return http.post(department.editRole, params);
};
2024-05-22 17:43:25 +08:00
};
2024-05-24 09:44:08 +08:00
const CancelApartment = () => {
disabled.value = true;
};
const CancelUser = () => {
disabled2.value = true;
};
2024-05-22 17:43:25 +08:00
const ApartmentSelect = (selectedKeys: any, info: any) => {
console.log(selectedKeys, 'selectedKeys');
console.log(info, 'info');
};
const UserSelect = (selectedKeys: any, info: any) => {
console.log(selectedKeys, 'selectedKeys');
console.log(info, 'info');
};
2024-05-22 16:31:55 +08:00
const ApartmentSure = () => {
2024-05-28 11:08:57 +08:00
// formRef.value?.triggerSubmit().then(() => {});
2024-06-04 10:54:02 +08:00
// disabled.value = !disabled.value;
2024-05-24 13:13:24 +08:00
// console.log(formData.value.name, 'formData');
2024-06-04 19:22:11 +08:00
console.log(opMap.type, 'ApartmentSure');
const opArr = ['addDept', 'editDpet'];
if (opArr.includes(opMap.type)) {
2024-06-04 10:54:02 +08:00
console.log(formRef.value, formData);
2024-06-04 19:22:11 +08:00
opMap.fuc &&
opMap.fuc(formData.value).then(() => {
getTree();
});
2024-05-28 11:08:57 +08:00
} else if (selectRef.value && opMap.type === 'addson')
2024-06-04 10:54:02 +08:00
opMap.fuc && opMap.fuc(formData.value);
2024-06-04 19:22:11 +08:00
else if (opMap.type === 'deptDelete') {
opMap.fuc && opMap.fuc({ ...formData.value, selectRef: selectRef.value });
2024-05-24 13:13:24 +08:00
}
2024-05-22 16:31:55 +08:00
};
2024-05-22 17:43:25 +08:00
const UserSure = () => {
disabled2.value = !disabled2.value;
2024-05-24 09:44:08 +08:00
console.log(formData2.value, 'formData2');
2024-05-28 11:08:57 +08:00
console.log(opMap.type, 'opMap.type');
2024-06-06 16:56:34 +08:00
const typeArr = ['addUserSon', 'addUser', 'editRole'];
2024-06-04 19:22:11 +08:00
if (typeArr.includes(opMap.type)) {
2024-06-06 16:56:34 +08:00
opMap.fuc &&
opMap.fuc(formData2.value).then(() => {
getUserTree();
});
2024-05-28 11:08:57 +08:00
} else if (selectRef2.value && opMap.type === 'addson')
selectRef2.value['children'] = [
{
key: '123',
title: formData2.value.departname,
info: { ...cloneDeep(formData2.value) },
},
];
else {
console.log('ss');
}
formData2.value = {};
2024-05-22 17:43:25 +08:00
};
2024-05-22 11:23:13 +08:00
return {
2024-05-22 16:31:55 +08:00
disabled,
2024-05-22 17:43:25 +08:00
disabled2,
2024-05-22 11:23:13 +08:00
formSchema,
2024-05-22 17:43:25 +08:00
formSchema2,
2024-05-22 11:23:13 +08:00
formData,
2024-05-22 17:43:25 +08:00
formData2,
apartmentTreeData,
userTreeData,
SelectApartmentTree,
SelectUserTree,
2024-05-22 11:23:13 +08:00
activeKey,
2024-05-22 16:31:55 +08:00
activeKey2,
ApartmentSure,
2024-05-22 17:43:25 +08:00
UserSure,
2024-05-22 16:31:55 +08:00
addApartment,
addApartmentSon,
deleteApartment,
deleteUser,
addUser,
addUserSon,
2024-05-22 17:43:25 +08:00
CancelApartment,
CancelUser,
apartmentAdminTreeData,
ApartmentSelect,
ApartcheckedKeys,
userAdminTreeData,
UsercheckedKeys,
UserSelect,
2024-05-28 11:08:57 +08:00
formRef,
2024-05-22 11:23:13 +08:00
};
},
});
</script>
<style scoped>
.main {
display: flex;
flex: 1;
}
2024-06-04 19:22:11 +08:00
2024-05-22 11:23:13 +08:00
.left {
width: 50%;
height: calc(100vh-50px);
border-right: 5px solid rgb(229, 235, 240);
}
2024-06-04 19:22:11 +08:00
2024-05-22 16:31:55 +08:00
.tree {
2024-05-22 11:23:13 +08:00
width: 400px;
height: 89vh;
border-right: 2px solid rgb(229, 235, 240);
}
2024-06-04 19:22:11 +08:00
2024-05-22 11:23:13 +08:00
.right {
width: 50%;
}
.top {
height: 50vh;
border-bottom: 5px solid rgb(229, 235, 240);
}
2024-06-04 19:22:11 +08:00
2024-05-22 11:23:13 +08:00
.ns-table-title {
text-align: left;
height: 46px;
line-height: 46px;
font-size: 18px;
font-weight: bold;
user-select: text;
padding-left: 16px;
width: 100%;
border-bottom: 2px solid rgb(229, 235, 240);
}
2024-06-04 19:22:11 +08:00
2024-05-22 11:23:13 +08:00
.table {
width: 2000px;
}
2024-06-04 19:22:11 +08:00
2024-05-22 11:23:13 +08:00
.admin {
text-align: left;
height: 42px;
line-height: 42px;
font-size: 16px;
font-weight: bold;
user-select: text;
padding-left: 16px;
width: calc(100% + 32px);
}
2024-06-04 19:22:11 +08:00
2024-05-22 11:23:13 +08:00
.form {
2024-05-22 17:43:25 +08:00
margin: 20px;
2024-05-22 11:23:13 +08:00
}
</style>