feat:增加 user 用户的部门筛选
parent
8fa52f0d30
commit
8fee76a84b
|
@ -1,15 +1,18 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { SystemUserApi } from '#/api/system/user';
|
import type { SystemUserApi } from '#/api/system/user';
|
||||||
|
import type { SystemDeptApi } from '#/api/system/dept';
|
||||||
|
|
||||||
import { Page, useVbenModal } from '@vben/common-ui';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { Button, message, Modal } from 'ant-design-vue';
|
import { Button, message, Modal, Row, Col } from 'ant-design-vue';
|
||||||
import { Plus, Download } from '@vben/icons';
|
import { Plus, Download } from '@vben/icons';
|
||||||
import Form from './modules/form.vue';
|
import Form from './modules/form.vue';
|
||||||
import ResetPasswordForm from './modules/reset-password-form.vue';
|
import ResetPasswordForm from './modules/reset-password-form.vue';
|
||||||
import AssignRoleForm from './modules/assign-role-form.vue';
|
import AssignRoleForm from './modules/assign-role-form.vue';
|
||||||
|
import DeptTree from './modules/dept-tree.vue';
|
||||||
|
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
import { ref } from 'vue';
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { getUserPage, deleteUser, exportUser, updateUserStatus } from '#/api/system/user';
|
import { getUserPage, deleteUser, exportUser, updateUserStatus } from '#/api/system/user';
|
||||||
import { downloadByData } from '#/utils/download';
|
import { downloadByData } from '#/utils/download';
|
||||||
|
@ -43,6 +46,13 @@ async function onExport() {
|
||||||
downloadByData(data, '用户.xls');
|
downloadByData(data, '用户.xls');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 选择部门 */
|
||||||
|
const searchDeptId = ref<number | undefined>(undefined);
|
||||||
|
async function onDeptSelect (dept: SystemDeptApi.SystemDept) {
|
||||||
|
searchDeptId.value = dept.id;
|
||||||
|
onRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
/** 创建用户 */
|
/** 创建用户 */
|
||||||
function onCreate() {
|
function onCreate() {
|
||||||
formModalApi.setData(null).open();
|
formModalApi.setData(null).open();
|
||||||
|
@ -94,18 +104,16 @@ async function onStatusChange(newStatus: number, row: SystemUserApi.SystemUser):
|
||||||
},
|
},
|
||||||
onOk() {
|
onOk() {
|
||||||
// 更新用户状态
|
// 更新用户状态
|
||||||
updateUserStatus(row.id as number, newStatus)
|
updateUserStatus(row.id as number, newStatus).then(() => {
|
||||||
.then(() => {
|
// 提示并返回成功
|
||||||
// 提示并返回成功
|
message.success({
|
||||||
message.success({
|
content: $t('ui.actionMessage.operationSuccess'),
|
||||||
content: $t('ui.actionMessage.operationSuccess'),
|
key: 'action_process_msg',
|
||||||
key: 'action_process_msg',
|
|
||||||
});
|
|
||||||
resolve(true);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
});
|
||||||
|
resolve(true);
|
||||||
|
}).catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -151,6 +159,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
pageNo: page.currentPage,
|
pageNo: page.currentPage,
|
||||||
pageSize: page.pageSize,
|
pageSize: page.pageSize,
|
||||||
...formValues,
|
...formValues,
|
||||||
|
deptId: searchDeptId.value,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -171,17 +180,27 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
<FormModal @success="onRefresh" />
|
<FormModal @success="onRefresh" />
|
||||||
<ResetPasswordModal @success="onRefresh" />
|
<ResetPasswordModal @success="onRefresh" />
|
||||||
<AssignRoleModal @success="onRefresh" />
|
<AssignRoleModal @success="onRefresh" />
|
||||||
<Grid table-title="用户列表">
|
|
||||||
<template #toolbar-tools>
|
<div class="flex h-full">
|
||||||
<Button type="primary" @click="onCreate">
|
<!-- 左侧部门树 -->
|
||||||
<Plus class="size-5" />
|
<div class="w-4/24 pr-3">
|
||||||
{{ $t('ui.actionTitle.create', ['用户']) }}
|
<DeptTree @select="onDeptSelect" />
|
||||||
</Button>
|
</div>
|
||||||
<Button type="primary" class="ml-2" @click="onExport">
|
<!-- 右侧用户列表 -->
|
||||||
<Download class="size-5" />
|
<div class="w-18/24">
|
||||||
{{ $t('ui.actionTitle.export') }}
|
<Grid table-title="用户列表">
|
||||||
</Button>
|
<template #toolbar-tools>
|
||||||
</template>
|
<Button type="primary" @click="onCreate">
|
||||||
</Grid>
|
<Plus class="size-5" />
|
||||||
|
{{ $t('ui.actionTitle.create', ['用户']) }}
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" class="ml-2" @click="onExport">
|
||||||
|
<Download class="size-5" />
|
||||||
|
{{ $t('ui.actionTitle.export') }}
|
||||||
|
</Button>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { SystemDeptApi } from '#/api/system/dept';
|
||||||
|
|
||||||
|
import { Tree, Input, Spin } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { ref, onMounted } from 'vue';
|
||||||
|
import { Search } from '@vben/icons';
|
||||||
|
import { getDeptList } from '#/api/system/dept';
|
||||||
|
import { handleTree } from '#/utils/tree';
|
||||||
|
|
||||||
|
const emit = defineEmits(['select']);
|
||||||
|
const deptList = ref<SystemDeptApi.SystemDept[]>([]); // 部门列表
|
||||||
|
const deptTree = ref<any[]>([]); // 部门树
|
||||||
|
const expandedKeys = ref<number[]>([]); // 展开的节点
|
||||||
|
const loading = ref(false); // 加载状态
|
||||||
|
const searchValue = ref(''); // 搜索值
|
||||||
|
|
||||||
|
/** 处理搜索逻辑 */
|
||||||
|
function handleSearch(e: any) {
|
||||||
|
const value = e.target.value;
|
||||||
|
searchValue.value = value;
|
||||||
|
const filteredList = value ? deptList.value.filter(item =>
|
||||||
|
item.name.toLowerCase().includes(value.toLowerCase())
|
||||||
|
) : deptList.value;
|
||||||
|
deptTree.value = handleTree(filteredList);
|
||||||
|
// 展开所有节点
|
||||||
|
expandedKeys.value = deptTree.value.map(node => node.id as number);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 选中部门 */
|
||||||
|
const handleSelect = (_selectedKeys: any[], info: any) => {
|
||||||
|
emit('select', info.node.dataRef);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
const data = await getDeptList();
|
||||||
|
deptList.value = data;
|
||||||
|
deptTree.value = handleTree(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取部门数据失败', error);
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<Input
|
||||||
|
placeholder="搜索部门"
|
||||||
|
allowClear
|
||||||
|
v-model:value="searchValue"
|
||||||
|
@change="handleSearch"
|
||||||
|
class="w-full"
|
||||||
|
>
|
||||||
|
<template #prefix>
|
||||||
|
<Search class="size-4" />
|
||||||
|
</template>
|
||||||
|
</Input>
|
||||||
|
</div>
|
||||||
|
<Spin :spinning="loading">
|
||||||
|
<Tree
|
||||||
|
class="pt-2"
|
||||||
|
v-if="deptTree.length > 0"
|
||||||
|
:tree-data="deptTree"
|
||||||
|
:fieldNames="{ title: 'name', key: 'id', children: 'children' }"
|
||||||
|
@select="handleSelect"
|
||||||
|
:defaultExpandAll="true"
|
||||||
|
/>
|
||||||
|
<div v-else-if="!loading" class="text-center text-gray-500 py-4">
|
||||||
|
暂无数据
|
||||||
|
</div>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Reference in New Issue