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.

586 lines
16 KiB

1 year ago
<!-- @format -->
<template>
1 year ago
<div class="main">
<div class="left">
<div class="top">
<div class="ns-table-title">关联企业</div>
<div style="height: 100%; overflow-y: auto">
1 year ago
<a-input-search
v-model:value="searchValue"
style="margin-bottom: 8px"
placeholder="请输入关联企业"
@search="onSearch" />
<a-tree
v-if="treeData?.length"
:tree-data="treeData"
defaultExpandAll
@select="handleSelect">
<template #title="data">
{{ data.orgInfo?.orgName }}
1 year ago
</template>
</a-tree>
</div>
</div>
<div>
<div class="ns-table-title">关联部门</div>
1 year ago
<a-input-search
v-model:value="searchValue2"
style="margin-bottom: 8px"
placeholder="请输入关联部门"
@search="onSearch2" />
<a-tree
v-if="treeData2?.length"
:tree-data="treeData2"
defaultExpandAll
@select="handleSelect2">
<template #title="data">
{{ data.deptInfo?.deptName }}
1 year ago
</template>
</a-tree>
</div>
</div>
<div class="right">
1 year ago
<ns-view-list-table v-bind="tableConfig" :model="data" ref="mainRef" />
1 year ago
</div>
<a-drawer
:width="500"
:visible="visible"
:body-style="{ paddingBottom: '80px' }"
:footer-style="{ textAlign: 'right' }"
1 year ago
destroyOnClose
@close="onClose">
<ns-form
ref="formRef"
:schemas="formSchema"
:model="formData"
class="form"
:wrapperCol="{ span: 20 }"
formLayout="vertical" />
<span class="admin">用户权限</span>
<ns-view-list-table
v-bind="tableConfig2"
class="drawerTable"
:model="data"
:pagination="false"
ref="mainRef"
rowKey="uuid" />
<template #footer>
<a-button style="margin-right: 8px" @click="onClose">取消</a-button>
<a-button type="primary" @click="onEdit">确定</a-button>
</template>
</a-drawer>
1 year ago
<a-modal
title="用户信息"
:width="600"
:visible="addformvisible"
cancelText="取消"
@ok="handleOk"
@cancel="handleClose">
1 year ago
<ns-form :schemas="formSchema2" :model="formData2" formLayout="vertical" />
</a-modal>
</div>
1 year ago
</template>
<script lang="ts">
import { createVNode, defineComponent, reactive, ref } from 'vue';
import { http } from '/nerv-lib/util/http';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
1 year ago
import { cloneDeep } from 'lodash-es';
import { NsMessage, NsModal } from '/nerv-lib/component';
1 year ago
import { formConfig, formConfig2 } from './config';
import { origanizemanage, department } from '/@/api/origanizemanage';
1 year ago
1 year ago
export default defineComponent({
name: 'OrderListIndex',
setup() {
const mainRef = ref();
const data = reactive({});
1 year ago
let formData = ref({});
let formData2 = ref({ userRoleList: [1, 1, 3] });
1 year ago
const formRef = ref();
1 year ago
const visible = ref(false);
1 year ago
const addformvisible = ref(false);
1 year ago
const searchValue = ref<string>('');
const searchValue2 = ref<string>('');
1 year ago
const formSchema = formConfig;
const casData = ref([]);
const formSchema2 = formConfig2(casData);
const treeData = ref([]);
const treeData2 = ref([]);
const userAuthList = ref([]);
const orgId = JSON.parse(sessionStorage.getItem('userInfo')).orgId;
const fetch = (api, params = { orgId }) => {
return http.post(api, params);
};
// 企业树
fetch(origanizemanage.queryOrgTree).then((res) => {
treeData.value = res.data;
});
1 year ago
// 部门树
fetch(origanizemanage.queryDeptTree).then((res) => {
treeData2.value = res.data;
});
1 year ago
const opMap: any = {
type: 'add',
fuc: () => {},
record: {},
};
1 year ago
const onSearch = () => {
console.log(searchValue.value);
fetch(origanizemanage.queryOrgTree, { orgName: searchValue.value, orgId }).then((res) => {
treeData.value = res.data;
});
1 year ago
};
const onSearch2 = () => {
console.log(searchValue2.value);
fetch(origanizemanage.queryDeptTree, { deptName: searchValue2.value, orgId }).then(
(res) => {
treeData2.value = res.data;
},
);
};
const tableFetch = (params) => {
tableConfig.value.params = {
...tableConfig.value.params,
...params,
};
mainRef.value?.nsTableRef.reload();
1 year ago
};
const handleSelect = (selectedKeys: any, info: any) => {
fetch(origanizemanage.queryDeptTree, { orgId: info.node?.orgInfo.orgId }).then((res) => {
treeData2.value = res.data;
});
tableFetch({ orgId: info.node?.orgInfo.orgId });
1 year ago
};
1 year ago
const handleSelect2 = (selectedKeys: any, info: any) => {
tableFetch({ deptId: info.node?.deptInfo.deptId });
1 year ago
};
const onClose = () => {
visible.value = false;
};
1 year ago
1 year ago
const onEdit = () => {
1 year ago
formRef.value?.triggerSubmit().then(() => {
console.log(formData.value, 'formData.value');
if (!userAuthList.value.length) {
NsMessage.error('请添加用户权限');
return;
}
opMap.fuc && opMap.fuc({ ...formData.value, userRoleList: userAuthList.value, orgId });
1 year ago
visible.value = false;
});
1 year ago
};
const handleOk = () => {
1 year ago
console.log(formData2.value, 'formData2.value');
if (casData.value?.length !== 3) {
NsMessage.error('未选择角色');
1 year ago
}
userAuthList.value.push({
userAuthList: cloneDeep(casData.value),
roleId: casData.value[2].value,
roleName: casData.value[2].label,
});
1 year ago
addformvisible.value = false;
};
const handleClose = () => {
addformvisible.value = false;
};
const tableConfig = ref({
1 year ago
title: '用户管理',
api: origanizemanage.userList,
params: {
orgId,
1 year ago
},
1 year ago
headerActions: [
{
label: '新增',
name: 'RoleTypeAdd',
type: 'primary',
handle: () => {
1 year ago
opMap.type = 'add';
opMap.fuc = (formData: any) => {
console.log(formData, 'formData');
http.post(origanizemanage.addUser, formData).then(() => {
visible.value = false;
});
1 year ago
};
1 year ago
visible.value = true;
},
},
{
label: '导入',
type: 'primary',
name: 'RoleTypeAdd',
handle: () => {},
},
{
label: '模板下载',
type: 'primary',
name: 'RoleTypeAdd',
handle: () => {},
},
{
label: '导出',
type: 'primary',
1 year ago
name: 'exports',
1 year ago
},
{
label: '批量删除',
type: 'primary',
name: 'userBatchDel',
1 year ago
dynamicDisabled: (data: any) => {
return data.list.length === 0;
},
confirm: true,
isReload: true,
api: origanizemanage.batchDel,
dynamicParams: { userIds: 'userId[]' },
1 year ago
},
],
columns: [
{
title: '序号',
dataIndex: 'address',
customRender: (text: any) => {
return text.index + 1;
},
sorter: {
compare: (a, b) => a.address - b.address,
},
},
{
title: '账号',
1 year ago
dataIndex: 'accountNo',
1 year ago
sorter: {
1 year ago
compare: (a, b) => a.accountNo - b.accountNo,
1 year ago
},
},
{
title: '姓名',
1 year ago
dataIndex: 'realName',
1 year ago
sorter: {
1 year ago
compare: (a, b) => a.realName - b.realName,
1 year ago
},
},
{
title: '性别',
dataIndex: 'sex',
sorter: {
compare: (a, b) => a.name - b.name,
},
},
{
title: '手机号',
1 year ago
dataIndex: 'telephone',
1 year ago
},
{
title: '邮箱',
dataIndex: 'email',
},
{
title: '组织关系',
dataIndex: 'orgName',
1 year ago
},
{
1 year ago
title: '部门/角色',
dataIndex: 'deptRoleInfoList',
customRender: ({ value }) => {
if (!value) return '-';
return createVNode('div', {}, [
createVNode('span', {}, value[0]),
value.length > 1 &&
createVNode(
'a',
{
onClick: () =>
NsModal.info({
icon: null,
content: createVNode('div', { innerHTML: value.join('<br>') }),
}),
},
`+${value.length}`,
),
]);
1 year ago
},
1 year ago
},
{
title: '状态',
1 year ago
dataIndex: 'userStatus',
customRender: ({ value }) => ['正常', '冻结'][value],
1 year ago
},
],
columnActions: {
title: '操作',
actions: [
{
label: '编辑',
name: 'RoleTypeEdit',
// dynamicParams: 'uuid',
handle: (record: any) => {
console.log(record, 'record');
1 year ago
formData.value = record;
opMap.type = 'edit';
opMap.fuc = (formData: any) => {
Object.assign(
mockData.value.filter((item) => item.id === record.id)[0],
formData,
);
};
1 year ago
visible.value = true;
},
},
{
label: '冻结',
name: 'userFrozen',
confirm: true,
defaultParams: { userStatus: 1 },
dynamicParams: 'userId',
isReload: true,
api: origanizemanage.frozen,
1 year ago
},
{
label: '重置密码',
name: 'userCodeReset',
confirm: true,
handle: ({ userId }: any) => {
http
.post(origanizemanage.resetPwd, { userId })
.then(() => NsModal.success({ content: '密码重置成功,初始密码123456' }));
1 year ago
},
},
{
label: '删除',
name: 'userDelete',
dynamicParams: 'userId',
1 year ago
confirm: true,
isReload: true,
api: origanizemanage.del,
1 year ago
},
],
},
formConfig: {
schemas: [
{
1 year ago
field: 'accountNo',
1 year ago
label: '账号名',
component: 'NsInput',
componentProps: {
placeholder: '请输入账号名',
1 year ago
maxLength: 30,
1 year ago
},
},
{
1 year ago
field: 'realName',
1 year ago
label: '姓名',
component: 'NsInput',
componentProps: {
placeholder: '请输入姓名',
1 year ago
maxLength: 30,
1 year ago
},
},
{
1 year ago
field: 'telephone',
1 year ago
label: '手机号',
component: 'NsInput',
componentProps: {
placeholder: '请输入手机号',
1 year ago
maxLength: 11,
1 year ago
},
},
{
field: 'email',
label: '邮箱',
component: 'NsInput',
componentProps: {
placeholder: '请输入邮箱',
1 year ago
maxLength: 30,
1 year ago
},
},
{
1 year ago
field: 'userStatus',
1 year ago
label: '用户状态',
component: 'NsSelect',
componentProps: {
placeholder: '请选择',
allowClear: true,
1 year ago
options: [
{
label: '正常',
value: 0,
1 year ago
},
{
label: '冻结',
value: 1,
1 year ago
},
],
},
},
],
params: {},
},
// pagination: { defaultPageSize: 10 },
1 year ago
rowKey: 'id',
});
1 year ago
const tableConfig2 = {
1 year ago
// api: {
// url: '/carbon_emission/device/getGatewayList',
// method: 'post',
// },
value: userAuthList.value,
1 year ago
rowSelection: null,
headerActions: [
{
label: '新增',
name: 'RoleTypeAdd',
type: 'primary',
handle: () => {
// opMap.type = 'add';
// opMap.fuc = (formData2: any) => {
// console.log(formData2, 'formData2');
// userAuthList.value.push(cloneDeep(formData2));
// };
1 year ago
addformvisible.value = true;
},
},
],
columns: [
{
title: '角色信息',
dataIndex: 'userRoleList',
customRender: ({ record }) => {
if (record) {
const res = record.userAuthList.reduce((pre, cur) => {
pre.push(cur.label);
return pre;
}, []);
return res.join('/');
}
return '-';
},
1 year ago
},
],
columnActions: {
title: '操作',
actions: [
// {
// label: '编辑',
// name: 'RoleTypeEdit',
// // dynamicParams: 'uuid',
// handle: (record: any) => {
// console.log(record, 'record');
// formData2.value = record;
// opMap.type = 'edit';
// opMap.fuc = (formData2: any) => {
// Object.assign(
// mockData.value.filter((item) => item.id === record.id)[0],
// formData2,
// );
// };
// addformvisible.value = true;
// },
// },
1 year ago
{
label: '删除',
name: 'RoleTypeEdit',
1 year ago
confirm: true,
1 year ago
handle: (record: any, name: any, reload: any) => {
const id = record.roleId;
console.log(userAuthList.value, id);
let idx = 0;
userAuthList.value?.some((item, index) => {
idx = index;
if (item.roleId === id) return true;
});
userAuthList.value.splice(idx, 1);
1 year ago
},
},
],
},
};
return {
1 year ago
formRef,
1 year ago
tableConfig,
tableConfig2,
data,
mainRef,
visible,
1 year ago
addformvisible,
1 year ago
formSchema,
1 year ago
formSchema2,
1 year ago
formData,
1 year ago
formData2,
1 year ago
treeData,
treeData2,
searchValue,
searchValue2,
1 year ago
handleSelect,
handleSelect2,
onClose,
onEdit,
1 year ago
onSearch,
onSearch2,
handleOk,
handleClose,
};
},
});
</script>
1 year ago
<style lang="less" scoped>
1 year ago
.main {
display: flex;
}
.left {
width: 350px;
1 year ago
border-right: 5px solid rgb(229, 235, 240);
1 year ago
min-width: fit-content;
1 year ago
}
.right {
flex: 1;
min-width: 0;
}
1 year ago
.top {
height: 50%;
1 year ago
border-bottom: 5px solid rgb(229, 235, 240);
}
1 year ago
.ns-table-title {
1 year ago
text-align: left;
1 year ago
// height: 46px;
1 year ago
line-height: 46px;
font-size: 18px;
font-weight: bold;
padding-left: 16px;
}
.admin {
text-align: left;
height: 42px;
line-height: 42px;
font-size: 16px;
font-weight: bold;
user-select: text;
width: calc(100% + 32px);
}
.drawerTable {
:deep(.ns-table-container),
:deep(.ns-table-main) {
border-top: 0;
padding: 0;
}
1 year ago
}
</style>