完善部门管理
This commit is contained in:
@@ -31,6 +31,14 @@ export function userlist(data: any) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function userselect(data: any) {
|
||||||
|
return request({
|
||||||
|
url: '/user/list',
|
||||||
|
method: 'get',
|
||||||
|
params: data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function userbyid(id: string | number) {
|
export function userbyid(id: string | number) {
|
||||||
return request({
|
return request({
|
||||||
url: `/user/getById/${id}`,
|
url: `/user/getById/${id}`,
|
||||||
|
|||||||
@@ -88,10 +88,10 @@
|
|||||||
:formatter="formatCell"
|
:formatter="formatCell"
|
||||||
/>
|
/>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
prop="leaderName"
|
prop="leaderId"
|
||||||
label="部门领导"
|
label="部门领导"
|
||||||
min-width="150"
|
min-width="150"
|
||||||
:formatter="formatCell"
|
:formatter="formatLeaderCell"
|
||||||
/>
|
/>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
prop="remark"
|
prop="remark"
|
||||||
@@ -150,7 +150,7 @@
|
|||||||
:data="treeOptions"
|
:data="treeOptions"
|
||||||
:props="{ value: 'id', label: 'deptName', children: 'children' }"
|
:props="{ value: 'id', label: 'deptName', children: 'children' }"
|
||||||
check-strictly
|
check-strictly
|
||||||
placeholder="请选择上级部门(可选)"
|
placeholder="请选择上级部门"
|
||||||
clearable
|
clearable
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
/>
|
/>
|
||||||
@@ -160,13 +160,13 @@
|
|||||||
v-model="form.leaderId"
|
v-model="form.leaderId"
|
||||||
filterable
|
filterable
|
||||||
clearable
|
clearable
|
||||||
placeholder="请选择部门领导(可选)"
|
placeholder="请选择部门领导"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in userOptions"
|
v-for="item in userOptions"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:label="item.realName || item.nickName || item.username || item.name"
|
:label="item.nicke || item.realName || item.nickName || item.username || item.name || ''"
|
||||||
:value="item.id"
|
:value="item.id"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
@@ -206,6 +206,7 @@ import {
|
|||||||
departmentdel,
|
departmentdel,
|
||||||
departtree,
|
departtree,
|
||||||
} from '@/api/department'
|
} from '@/api/department'
|
||||||
|
import { userselect } from '@/api/user'
|
||||||
|
|
||||||
interface DeptItem {
|
interface DeptItem {
|
||||||
id?: number | string
|
id?: number | string
|
||||||
@@ -227,6 +228,7 @@ interface UserItem {
|
|||||||
username?: string
|
username?: string
|
||||||
realName?: string
|
realName?: string
|
||||||
nickName?: string
|
nickName?: string
|
||||||
|
nicke?: string
|
||||||
name?: string
|
name?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,6 +287,18 @@ const formatCell = (_row: any, _column: any, value: any) => {
|
|||||||
return value === undefined || value === null || value === '' ? '暂无' : value
|
return value === undefined || value === null || value === '' ? '暂无' : value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据leaderId获取用户的nicke字段
|
||||||
|
const getLeaderNicke = (leaderId: number | string | null | undefined): string => {
|
||||||
|
if (!leaderId) return '暂无'
|
||||||
|
const user = userOptions.value.find(u => u.id == leaderId)
|
||||||
|
return user?.nicke || user?.realName || user?.nickName || user?.username || user?.name || '暂无'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 部门领导列的formatter
|
||||||
|
const formatLeaderCell = (_row: any, _column: any, _value: any) => {
|
||||||
|
return getLeaderNicke(_row.leaderId)
|
||||||
|
}
|
||||||
|
|
||||||
// 构建树形选择器的选项
|
// 构建树形选择器的选项
|
||||||
const treeOptions = computed(() => {
|
const treeOptions = computed(() => {
|
||||||
const buildOptions = (nodes: DeptItem[], excludeId?: number | string): any[] => {
|
const buildOptions = (nodes: DeptItem[], excludeId?: number | string): any[] => {
|
||||||
@@ -347,15 +361,14 @@ const handleTreeReset = () => {
|
|||||||
// 加载用户列表(用于选择部门领导)
|
// 加载用户列表(用于选择部门领导)
|
||||||
const loadUsers = async () => {
|
const loadUsers = async () => {
|
||||||
try {
|
try {
|
||||||
// 这里需要根据实际API调整,暂时使用空数组
|
const res: any = await userselect({})
|
||||||
// 如果有用户列表API,可以在这里调用
|
// 兼容多种返回格式:res.data 或 res 本身
|
||||||
// const res: any = await userlist({ pageNum: 1, pageSize: 9999 })
|
const data = Array.isArray(res?.data) ? res.data : Array.isArray(res) ? res : []
|
||||||
// const data = res?.data ?? res ?? {}
|
userOptions.value = data
|
||||||
// const records = data.records || data.list || data.rows || data.items || []
|
|
||||||
// userOptions.value = Array.isArray(records) ? records : []
|
|
||||||
userOptions.value = []
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('load user list error', error)
|
console.error('load user list error', error)
|
||||||
|
ElMessage.error('加载用户列表失败')
|
||||||
|
userOptions.value = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,6 +376,11 @@ const loadUsers = async () => {
|
|||||||
const loadList = async () => {
|
const loadList = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
|
// 确保用户列表已加载(用于显示部门领导名称)
|
||||||
|
if (userOptions.value.length === 0) {
|
||||||
|
await loadUsers()
|
||||||
|
}
|
||||||
|
|
||||||
// 构建查询参数,过滤空字符串
|
// 构建查询参数,过滤空字符串
|
||||||
const params: any = {
|
const params: any = {
|
||||||
pageNum: pagination.pageNum,
|
pageNum: pagination.pageNum,
|
||||||
@@ -652,3 +670,4 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<el-form-item label="用户名">
|
<el-form-item label="用户名">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="queryForm.userName"
|
v-model="queryForm.userName"
|
||||||
placeholder="输入用户名(模糊查询)"
|
placeholder="输入用户名"
|
||||||
clearable
|
clearable
|
||||||
style="width: 200px"
|
style="width: 200px"
|
||||||
/>
|
/>
|
||||||
@@ -172,7 +172,7 @@
|
|||||||
:data="deptTreeOptions"
|
:data="deptTreeOptions"
|
||||||
:props="{ value: 'id', label: 'deptName', children: 'children' }"
|
:props="{ value: 'id', label: 'deptName', children: 'children' }"
|
||||||
check-strictly
|
check-strictly
|
||||||
placeholder="请选择部门(可选)"
|
placeholder="请选择部门"
|
||||||
clearable
|
clearable
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
/>
|
/>
|
||||||
@@ -182,7 +182,7 @@
|
|||||||
v-model="form.posId"
|
v-model="form.posId"
|
||||||
filterable
|
filterable
|
||||||
clearable
|
clearable
|
||||||
placeholder="请选择职位(可选)"
|
placeholder="请选择职位"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
|
|||||||
Reference in New Issue
Block a user