Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
JINRUN-PERPOSITION
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xinzhedeai
JINRUN-PERPOSITION
Commits
56c18dcf
Commit
56c18dcf
authored
Nov 27, 2025
by
xinzhedeai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add:所属部门树状数据下拉
parent
ebf3942b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
82 deletions
+16
-82
yuangong.vue
src/views/person/yuangong.vue
+16
-82
No files found.
src/views/person/yuangong.vue
View file @
56c18dcf
...
...
@@ -144,14 +144,12 @@
</el-col>
<el-col
:span=
"12"
>
<el-form-item
label=
"所在部门"
prop=
"deptId"
>
<
el-cascader
v-model=
"form.dept
Path
"
<
treeselect
v-model=
"form.dept
Ids
"
:options=
"deptOptions"
:props=
"cascaderProps"
placeholder=
"请选择所在部门"
clearable
@
change=
"handleDeptChange"
></el-cascader>
placeholder=
"请选择部门"
:normalizer=
"normalizer"
></treeselect>
</el-form-item>
</el-col>
<el-col
:span=
"12"
>
...
...
@@ -298,8 +296,12 @@ import {
import
{
getDict
}
from
"
@/api/jinrun/common
"
;
import
{
getDept
,
getPosition
}
from
"
@/api/jinrun/zhongkong
"
;
import
Treeselect
from
"
@riophae/vue-treeselect
"
;
import
"
@riophae/vue-treeselect/dist/vue-treeselect.css
"
;
export
default
{
name
:
"
Info
"
,
components
:
{
Treeselect
},
data
()
{
return
{
// 级联选择器配置
...
...
@@ -395,94 +397,26 @@ export default {
},
methods
:
{
/** 递归处理部门树,转换为级联选择器需要的格式 */
processDepartmentTreeForCascader
(
departments
)
{
// 直接返回处理后的部门树,不需要扁平化
return
departments
.
map
((
dept
)
=>
{
const
processedDept
=
{
index
:
dept
.
index
,
name
:
dept
.
name
,
children
:
[],
normalizer
(
node
)
{
return
{
id
:
node
.
index
,
// 用index作为唯一标识
label
:
node
.
name
,
// 用name作为显示文本
children
:
node
.
children
||
[],
// 子节点(如果为null则转为空数组)
};
// 如果有子部门,递归处理
if
(
dept
.
children
&&
dept
.
children
.
length
>
0
)
{
processedDept
.
children
=
this
.
processDepartmentTreeForCascader
(
dept
.
children
);
}
else
{
// 如果没有子部门,设置为null
processedDept
.
children
=
null
;
}
return
processedDept
;
});
},
/** 获取部门列表 */
getDeptList
()
{
getDept
({})
.
then
((
response
)
=>
{
console
.
log
(
response
.
data
,
"
部门数据
"
);
// 检查数据格式是否正确
if
(
response
.
data
&&
Array
.
isArray
(
response
.
data
)
&&
response
.
data
.
length
>
0
)
{
// 获取根节点的子部门并处理为级联格式
const
rootChildren
=
response
.
data
[
0
].
children
||
[];
this
.
deptOptions
=
this
.
processDepartmentTreeForCascader
(
rootChildren
);
}
else
{
this
.
deptOptions
=
[];
console
.
error
(
"
部门数据格式不正确
"
);
}
this
.
deptOptions
=
response
.
data
.
data
;
})
.
catch
((
error
)
=>
{
console
.
error
(
"
获取部门列表失败:
"
,
error
);
this
.
deptOptions
=
[];
});
},
/** 处理部门选择变化 */
handleDeptChange
(
value
)
{
if
(
value
&&
value
.
length
>
0
)
{
// 保存最后一级的部门ID作为deptId
this
.
form
.
deptId
=
value
[
value
.
length
-
1
];
// 查找选择的部门对象,获取部门名称
if
(
this
.
deptOptions
&&
this
.
deptOptions
.
length
>
0
)
{
let
selectedDept
=
this
.
findDeptById
(
this
.
deptOptions
,
this
.
form
.
deptId
);
if
(
selectedDept
)
{
this
.
form
.
deptName
=
selectedDept
.
name
;
}
}
}
else
{
this
.
form
.
deptId
=
null
;
this
.
form
.
deptName
=
null
;
}
},
/** 根据ID查找部门对象 */
findDeptById
(
departments
,
targetId
)
{
for
(
const
dept
of
departments
)
{
if
(
dept
.
index
===
targetId
)
{
return
dept
;
}
if
(
dept
.
children
&&
dept
.
children
.
length
>
0
)
{
const
found
=
this
.
findDeptById
(
dept
.
children
,
targetId
);
if
(
found
)
{
return
found
;
}
}
}
return
null
;
},
/** 获取岗位列表 */
getPositionList
()
{
getPosition
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment