feat: 新增需求
This commit is contained in:
@@ -65,22 +65,22 @@
|
||||
<view class="jnpf-tree-select-tree">
|
||||
<scroll-view :scroll-y="true" style="height: 100%" :scroll-top="scrollTop" @scroll="handleScroll"
|
||||
v-show="(!hasPage && !currStep) && selectType === 'all' && activeKey!=='current'">
|
||||
<ly-tree ref="tree" :props="realProps" :node-key="realProps.value" :load="getGroupList" lazy
|
||||
:tree-data="lazyOptions" show-node-icon :defaultExpandAll='false'
|
||||
@node-click="handleTreeNodeClick" :expandOnClickNode="false" :checkOnClickNode="false"
|
||||
v-if="activeKey==='position'" />
|
||||
<block v-else>
|
||||
<view class="jnpf-selcet-list" v-if="list.length">
|
||||
<view class="jnpf-selcet-cell" v-for="item in list" :key="item.id"
|
||||
@click.stop="handleNodeClick(item)">
|
||||
<view class="jnpf-selcet-cell-icon" :class='item.icon'></view>
|
||||
<view class="jnpf-selcet-cell-name">
|
||||
{{item.deptName}}
|
||||
<ly-tree v-show="activeKey == 'user'" ref="tree" :props="realProps" :node-key="realProps.value"
|
||||
:load="loadNode" lazy :tree-data="lazyOptions" show-node-icon :defaultExpandAll='false'
|
||||
@node-click="handleTreeNodeClick" :show-checkbox="multiple" :show-radio="!multiple"
|
||||
:expandOnClickNode="false" :checkOnClickNode="true" :expandOnCheckNode="false" checkStrictly />
|
||||
<block v-if="activeKey == 'role'">
|
||||
<view class="jnpf-selcet-list" v-if="list.length">
|
||||
<view class="jnpf-selcet-cell" v-for="item in list" :key="item.id"
|
||||
@click.stop="handleNodeClick(item)">
|
||||
<view class="jnpf-selcet-cell-icon" :class='item.icon'></view>
|
||||
<view class="jnpf-selcet-cell-name">
|
||||
{{item.deptName}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<Empty class="h-full" v-else />
|
||||
</block>
|
||||
<Empty class="h-full" v-else />
|
||||
</block>
|
||||
</scroll-view>
|
||||
<scroll-view :scroll-y="true" style="height: 100%" :refresher-enabled="false" :refresher-threshold="100"
|
||||
:scroll-with-animation='true' :refresher-triggered="triggered" @scrolltolower="handleScrollToLower"
|
||||
@@ -129,7 +129,7 @@
|
||||
const baseStore = useBaseStore()
|
||||
const defaultProps = {
|
||||
label: 'deptName',
|
||||
value: 'id',
|
||||
value: 'deptId',
|
||||
icon: 'icon',
|
||||
children: 'children'
|
||||
}
|
||||
@@ -168,7 +168,7 @@
|
||||
type: Object,
|
||||
default: () => ({
|
||||
label: 'deptName',
|
||||
value: 'id',
|
||||
value: 'deptId',
|
||||
icon: 'icon',
|
||||
children: 'children',
|
||||
isLeaf: 'isLeaf'
|
||||
@@ -190,7 +190,7 @@
|
||||
selectedIds: [],
|
||||
keyword: '',
|
||||
showPopup: false,
|
||||
lazyOptions: [],
|
||||
lazyOptions: [{}],
|
||||
activeKey: 'user',
|
||||
hasPage: false,
|
||||
pagination: {
|
||||
@@ -284,7 +284,7 @@
|
||||
getConditionOptions() {
|
||||
if (!this.ableIds.length) return
|
||||
const query = {
|
||||
keyword: this.keyword,
|
||||
nickName: this.keyword,
|
||||
ids: this.ableIds,
|
||||
...this.pagination
|
||||
}
|
||||
@@ -296,15 +296,30 @@
|
||||
})
|
||||
},
|
||||
loadNode(node, resolve) {
|
||||
const id = node.key || '0'
|
||||
const type = node?.data?.type || 'organize'
|
||||
const data = {
|
||||
id,
|
||||
type
|
||||
}
|
||||
getOrgAndPosSelector(data).then(res => {
|
||||
const list = res.data?.list || []
|
||||
resolve(list)
|
||||
const parentId = node.key || '0'
|
||||
const level = node.level || 0
|
||||
// 如果是根节点(level为0),直接使用已经构建好的options
|
||||
// if (level === 0 && this.options.length > 0) {
|
||||
// resolve(this.options)
|
||||
// return
|
||||
// }
|
||||
|
||||
getOrganizeSelector(this.selectType).then(res => {
|
||||
const list = res.data || []
|
||||
// 将返回的扁平数据转换为树形节点
|
||||
const treeData = this.buildTree(list, 'deptId', 'deptPid', parentId)
|
||||
console.log(treeData,'-treeData')
|
||||
// 设置节点的isLeaf属性(根据是否有子节点判断)
|
||||
treeData.forEach(item => {
|
||||
// 判断该节点是否还有子节点(根据实际情况调整)
|
||||
// 如果知道接口返回是否有子节点的字段,可以替换这个判断
|
||||
item.isLeaf = !item.children || item.children.length === 0
|
||||
})
|
||||
|
||||
console.log(`加载父节点 ${parentId} 的子节点:`, treeData)
|
||||
resolve(treeData)
|
||||
}).catch(() => {
|
||||
resolve([]) // 异常时返回空数组,避免组件报错
|
||||
})
|
||||
},
|
||||
handleScroll(e) {
|
||||
@@ -322,7 +337,7 @@
|
||||
},
|
||||
getUserList() {
|
||||
let data = {
|
||||
// keyword: this.keyword,
|
||||
nickName: this.keyword,
|
||||
// ...this.pagination,
|
||||
...this.userQuery
|
||||
}
|
||||
@@ -338,13 +353,10 @@
|
||||
this.handleNodeClick(data)
|
||||
},
|
||||
handleNodeClick(data) {
|
||||
console.log(data,'data--------')
|
||||
// let key = `${this.activeKey==='position'?(data.type||'position'):this.activeKey}Id`;
|
||||
// if (this.activeKey === 'user') key = 'groupId'
|
||||
const key = this.activeKey == 'user' ? 'deptId' : 'roleId'
|
||||
this.hasPage = 1
|
||||
this.userQuery = {
|
||||
// ...defaultUserQuery,
|
||||
deptId: data.deptId,
|
||||
[key]: data[key],
|
||||
fieldList: ["userId","nickName","sex","post","deptName"],
|
||||
pageNo: this.hasPage,
|
||||
pageSize: 10
|
||||
@@ -376,6 +388,7 @@
|
||||
toggloActive(key) {
|
||||
if (this.activeKey === key) return
|
||||
this.currStep = 0
|
||||
this.hasPage = false
|
||||
this.keyword = ''
|
||||
this.resetQuery()
|
||||
this.$nextTick(async () => {
|
||||
@@ -387,34 +400,52 @@
|
||||
})
|
||||
},
|
||||
async getGroupList() {
|
||||
// const list = await baseStore.getGroupList()
|
||||
const res = await getOrganizeSelector(this.selectType)
|
||||
const list = this.formatDeptData(res.data) || []
|
||||
console.log(list,'list-------')
|
||||
this.list = [{
|
||||
deptName: '全部用户',
|
||||
icon: 'icon-ym icon-ym-generator-group1',
|
||||
id: ''
|
||||
}, ...list]
|
||||
},
|
||||
async getRoleList() {
|
||||
// const list = await baseStore.getGroupList()
|
||||
const res = await getAdapterRoleList()
|
||||
const list = this.formatDeptData(res.data) || []
|
||||
console.log(list,'list-------role')
|
||||
const list = res.data || []
|
||||
const treeData = this.buildTree(list, 'deptId', 'deptPid', '0')
|
||||
treeData.forEach(item => {
|
||||
item.isLeaf = !item.children || item.children.length === 0
|
||||
})
|
||||
// this.list = treeData
|
||||
this.lazyOptions = treeData
|
||||
console.log(this.list,'list---')
|
||||
// const list = this.formatDeptData(res.data) || []
|
||||
// this.list = [{
|
||||
// deptName: '全部用户',
|
||||
// icon: 'icon-ym icon-ym-generator-group1',
|
||||
// id: ''
|
||||
// }, ...list]
|
||||
},
|
||||
async getRoleList() {
|
||||
const res = await getAdapterRoleList()
|
||||
const list = this.formatDeptData(res.data) || []
|
||||
this.list = list
|
||||
},
|
||||
buildTree(data, idKey, pidKey, rootPid) {
|
||||
const result = []
|
||||
const map = {}
|
||||
// 先构建ID映射
|
||||
data.forEach(item => {
|
||||
map[item[idKey]] = { ...item, children: [] }
|
||||
})
|
||||
// 组装父子关系
|
||||
data.forEach(item => {
|
||||
const parent = map[item[pidKey]]
|
||||
if (item[pidKey] === rootPid) {
|
||||
result.push(map[item[idKey]])
|
||||
} else if (parent) {
|
||||
parent.children.push(map[item[idKey]])
|
||||
}
|
||||
})
|
||||
return result
|
||||
},
|
||||
formatDeptData(data) {
|
||||
const result = [];
|
||||
|
||||
const formatItem = (item) => {
|
||||
// 优先使用 depthd 字段(根据打印结果)
|
||||
let deptId = item.depthd || item.id || item.deptId;
|
||||
let deptName = item.depthName || item.deptName || item.fullName || item.name || item.orgNameTree;
|
||||
// 优先使用 deptId 字段(根据打印结果)
|
||||
let deptId = item.deptId || item.roleId;
|
||||
let deptName = item.deptName || item.roleName;
|
||||
|
||||
// 确保ID是字符串
|
||||
deptId = String(deptId || '');
|
||||
|
||||
Reference in New Issue
Block a user