diff --git a/snowy-admin-web/src/api/biz/bizOrgApi.js b/snowy-admin-web/src/api/biz/bizOrgApi.js
index 736b65a4..d77444c5 100644
--- a/snowy-admin-web/src/api/biz/bizOrgApi.js
+++ b/snowy-admin-web/src/api/biz/bizOrgApi.js
@@ -30,6 +30,10 @@ export default {
orgTree(data) {
return request('tree', data, 'get')
},
+ // 获取机构树(懒加载)
+ orgTreeLazy(data) {
+ return request('treeLazy', data, 'get')
+ },
// 提交表单 edit为true时为编辑,默认为新增
submitForm(data, edit = false) {
return request(edit ? 'edit' : 'add', data)
@@ -46,6 +50,10 @@ export default {
orgTreeSelector(data) {
return request('orgTreeSelector', data, 'get')
},
+ // 获取机构树选择器(懒加载)
+ orgTreeLazySelector(data) {
+ return request('orgTreeLazySelector', data, 'get')
+ },
// 获取人员选择器
orgUserSelector(data) {
return request('userSelector', data, 'get')
diff --git a/snowy-admin-web/src/api/biz/bizPositionApi.js b/snowy-admin-web/src/api/biz/bizPositionApi.js
index bf785325..2cbc2761 100644
--- a/snowy-admin-web/src/api/biz/bizPositionApi.js
+++ b/snowy-admin-web/src/api/biz/bizPositionApi.js
@@ -42,6 +42,10 @@ export default {
positionOrgTreeSelector(data) {
return request('orgTreeSelector', data, 'get')
},
+ // 获取机构树选择器(懒加载)
+ positionOrgTreeLazySelector(data) {
+ return request('orgTreeLazySelector', data, 'get')
+ },
// 获取岗位选择器
positionPositionSelector(data) {
return request('positionSelector', data, 'get')
diff --git a/snowy-admin-web/src/api/biz/bizUserApi.js b/snowy-admin-web/src/api/biz/bizUserApi.js
index afc81d84..02ad02b5 100644
--- a/snowy-admin-web/src/api/biz/bizUserApi.js
+++ b/snowy-admin-web/src/api/biz/bizUserApi.js
@@ -50,6 +50,10 @@ export default {
userOrgTreeSelector(data) {
return request('orgTreeSelector', data, 'get')
},
+ // 获取组织选择器(懒加载)
+ userOrgTreeLazySelector(data) {
+ return request('orgTreeLazySelector', data, 'get')
+ },
// 获取职位选择器
userPositionSelector(data) {
return request('positionSelector', data, 'get')
diff --git a/snowy-admin-web/src/api/dev/configApi.js b/snowy-admin-web/src/api/dev/configApi.js
index 4d21cc01..431e8e66 100644
--- a/snowy-admin-web/src/api/dev/configApi.js
+++ b/snowy-admin-web/src/api/dev/configApi.js
@@ -54,6 +54,10 @@ export default {
configOrgTree(data) {
return request('orgTree', data, 'get')
},
+ // 获取机构树(懒加载)
+ configOrgTreeLazy(data) {
+ return request('orgTreeLazy', data, 'get')
+ },
// 获取机构选择器
configOrgSelector(data) {
return request('orgSelector', data, 'get')
diff --git a/snowy-admin-web/src/api/sys/orgApi.js b/snowy-admin-web/src/api/sys/orgApi.js
index bead72e2..bf3d2823 100644
--- a/snowy-admin-web/src/api/sys/orgApi.js
+++ b/snowy-admin-web/src/api/sys/orgApi.js
@@ -26,6 +26,10 @@ export default {
orgTree(data) {
return request('tree', data, 'get')
},
+ // 获取组织树(懒加载)
+ orgTreeLazy(data) {
+ return request('treeLazy', data, 'get')
+ },
// 提交表单 edit为true时为编辑,默认为新增
submitForm(data, edit = false) {
return request(edit ? 'edit' : 'add', data)
@@ -42,6 +46,10 @@ export default {
orgOrgTreeSelector(data) {
return request('orgTreeSelector', data, 'get')
},
+ // 获取组织树选择器(懒加载)
+ orgOrgTreeLazySelector(data) {
+ return request('orgTreeLazySelector', data, 'get')
+ },
// 获取用户选择器
orgUserSelector(data) {
return request('userSelector', data, 'get')
diff --git a/snowy-admin-web/src/api/sys/positionApi.js b/snowy-admin-web/src/api/sys/positionApi.js
index f15b5350..686fff3f 100644
--- a/snowy-admin-web/src/api/sys/positionApi.js
+++ b/snowy-admin-web/src/api/sys/positionApi.js
@@ -42,6 +42,10 @@ export default {
positionOrgTreeSelector(data) {
return request('orgTreeSelector', data, 'get')
},
+ // 获取组织树选择器(懒加载)
+ positionOrgTreeLazySelector(data) {
+ return request('orgTreeLazySelector', data, 'get')
+ },
// 获取职位选择器
positionPositionSelector(data) {
return request('positionSelector', data, 'get')
diff --git a/snowy-admin-web/src/api/sys/roleApi.js b/snowy-admin-web/src/api/sys/roleApi.js
index 8f1f1167..836234a2 100644
--- a/snowy-admin-web/src/api/sys/roleApi.js
+++ b/snowy-admin-web/src/api/sys/roleApi.js
@@ -70,6 +70,10 @@ export default {
roleOrgTreeSelector(data) {
return request('orgTreeSelector', data, 'get')
},
+ // 获取机构树(懒加载)
+ roleOrgTreeLazySelector(data) {
+ return request('orgTreeLazySelector', data, 'get')
+ },
// 获取资源授权树
roleResourceTreeSelector(data) {
return request('resourceTreeSelector', data, 'get')
diff --git a/snowy-admin-web/src/api/sys/userApi.js b/snowy-admin-web/src/api/sys/userApi.js
index eefea016..7fc7dfc9 100644
--- a/snowy-admin-web/src/api/sys/userApi.js
+++ b/snowy-admin-web/src/api/sys/userApi.js
@@ -50,6 +50,10 @@ export default {
userOrgTreeSelector(data) {
return request('orgTreeSelector', data, 'get')
},
+ // 获取组织选择器(懒加载)
+ userOrgTreeLazySelector(data) {
+ return request('orgTreeLazySelector', data, 'get')
+ },
// 获取职位选择器
userPositionSelector(data) {
return request('positionSelector', data, 'get')
diff --git a/snowy-admin-web/src/components/XnOrgSelector/index.vue b/snowy-admin-web/src/components/XnOrgSelector/index.vue
index 2edafec4..a916b6e3 100644
--- a/snowy-admin-web/src/components/XnOrgSelector/index.vue
+++ b/snowy-admin-web/src/components/XnOrgSelector/index.vue
@@ -35,6 +35,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
>
@@ -201,6 +202,9 @@
orgTreeApi: {
type: Function
},
+ orgTreeLazyApi: {
+ type: Function
+ },
orgPageApi: {
type: Function
},
@@ -248,6 +252,31 @@
const current = ref(0) // 当前页数
const pageSize = ref(10) // 每页条数
const total = ref(0) // 数据总数
+
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (typeof props.orgTreeLazyApi !== 'function' || treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ props
+ .orgTreeLazyApi({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
+
const hasContent = (slotName) => {
return !!(slots[slotName] && slots[slotName]().length > 0)
}
@@ -293,28 +322,50 @@
}
visible.value = true
// 获取机构树
- orgTree()
- .then((data) => {
- if (!isEmpty(data)) {
- treeData.value = data
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
+ if (typeof props.orgTreeLazyApi === 'function') {
+ props
+ .orgTreeLazyApi()
+ .then((data) => {
+ if (!isEmpty(data)) {
+ treeData.value = data.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
}
+ })
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ defaultExpandedKeys.value.push(treeData.value[0].id)
}
- })
- }
- })
- .finally(() => {
- cardLoading.value = false
- })
+ }
+ })
+ .finally(() => {
+ cardLoading.value = false
+ })
+ } else {
+ orgTree()
+ .then((data) => {
+ if (!isEmpty(data)) {
+ treeData.value = data
+ // 默认展开2级
+ treeData.value.forEach((item) => {
+ // 因为0的顶级
+ if (item.parentId === '0') {
+ defaultExpandedKeys.value.push(item.id)
+ // 取到下级ID
+ if (item.children) {
+ item.children.forEach((items) => {
+ defaultExpandedKeys.value.push(items.id)
+ })
+ }
+ }
+ })
+ }
+ })
+ .finally(() => {
+ cardLoading.value = false
+ })
+ }
searchFormState.value.size = pageSize.value
loadData()
if (isEmpty(recordIds.value)) {
diff --git a/snowy-admin-web/src/components/XnPositionSelector/index.vue b/snowy-admin-web/src/components/XnPositionSelector/index.vue
index 8422b200..a22a26d6 100644
--- a/snowy-admin-web/src/components/XnPositionSelector/index.vue
+++ b/snowy-admin-web/src/components/XnPositionSelector/index.vue
@@ -35,6 +35,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
>
@@ -197,6 +198,9 @@
orgTreeApi: {
type: Function
},
+ orgTreeLazyApi: {
+ type: Function
+ },
positionPageApi: {
type: Function
},
@@ -244,6 +248,31 @@
const current = ref(0) // 当前页数
const pageSize = ref(10) // 每页条数
const total = ref(0) // 数据总数
+
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (typeof props.orgTreeLazyApi !== 'function' || treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ props
+ .orgTreeLazyApi({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
+
const hasContent = (slotName) => {
return !!(slots[slotName] && slots[slotName]().length > 0)
}
@@ -289,28 +318,50 @@
}
visible.value = true
// 获取机构树
- orgTree()
- .then((data) => {
- if (!isEmpty(data)) {
- treeData.value = data
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
+ if (typeof props.orgTreeLazyApi === 'function') {
+ props
+ .orgTreeLazyApi()
+ .then((data) => {
+ if (!isEmpty(data)) {
+ treeData.value = data.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
}
+ })
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ defaultExpandedKeys.value.push(treeData.value[0].id)
}
- })
- }
- })
- .finally(() => {
- cardLoading.value = false
- })
+ }
+ })
+ .finally(() => {
+ cardLoading.value = false
+ })
+ } else {
+ orgTree()
+ .then((data) => {
+ if (!isEmpty(data)) {
+ treeData.value = data
+ // 默认展开2级
+ treeData.value.forEach((item) => {
+ // 因为0的顶级
+ if (item.parentId === '0') {
+ defaultExpandedKeys.value.push(item.id)
+ // 取到下级ID
+ if (item.children) {
+ item.children.forEach((items) => {
+ defaultExpandedKeys.value.push(items.id)
+ })
+ }
+ }
+ })
+ }
+ })
+ .finally(() => {
+ cardLoading.value = false
+ })
+ }
searchFormState.value.size = pageSize.value
loadData()
if (isEmpty(recordIds.value)) {
diff --git a/snowy-admin-web/src/components/XnRoleSelector/index.vue b/snowy-admin-web/src/components/XnRoleSelector/index.vue
index 7daed065..c2a42179 100644
--- a/snowy-admin-web/src/components/XnRoleSelector/index.vue
+++ b/snowy-admin-web/src/components/XnRoleSelector/index.vue
@@ -35,6 +35,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
>
@@ -198,6 +199,9 @@
orgTreeApi: {
type: Function
},
+ orgTreeLazyApi: {
+ type: Function
+ },
rolePageApi: {
type: Function
},
@@ -251,6 +255,31 @@
const current = ref(0) // 当前页数
const pageSize = ref(10) // 每页条数
const total = ref(0) // 数据总数
+
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (typeof props.orgTreeLazyApi !== 'function' || treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ props
+ .orgTreeLazyApi({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
+
const hasContent = (slotName) => {
return !!(slots[slotName] && slots[slotName]().length > 0)
}
@@ -296,39 +325,61 @@
}
visible.value = true
// 获取机构树
- orgTree()
- .then((data) => {
- if (!isEmpty(data)) {
- treeData.value = data
- // 树中插入全局角色类型
- if (props.roleGlobal) {
- const globalRoleType = [
- {
- id: 'GLOBAL',
- parentId: '-1',
- name: '全局'
- }
- ]
- treeData.value = globalRoleType.concat(data)
- }
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
+ if (typeof props.orgTreeLazyApi === 'function') {
+ props
+ .orgTreeLazyApi()
+ .then((data) => {
+ if (!isEmpty(data)) {
+ treeData.value = data.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
}
+ })
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ defaultExpandedKeys.value.push(treeData.value[0].id)
}
- })
- }
- })
- .finally(() => {
- cardLoading.value = false
- })
+ }
+ })
+ .finally(() => {
+ cardLoading.value = false
+ })
+ } else {
+ orgTree()
+ .then((data) => {
+ if (!isEmpty(data)) {
+ treeData.value = data
+ // 树中插入全局角色类型
+ if (props.roleGlobal) {
+ const globalRoleType = [
+ {
+ id: 'GLOBAL',
+ parentId: '-1',
+ name: '全局'
+ }
+ ]
+ treeData.value = globalRoleType.concat(data)
+ }
+ // 默认展开2级
+ treeData.value.forEach((item) => {
+ // 因为0的顶级
+ if (item.parentId === '0') {
+ defaultExpandedKeys.value.push(item.id)
+ // 取到下级ID
+ if (item.children) {
+ item.children.forEach((items) => {
+ defaultExpandedKeys.value.push(items.id)
+ })
+ }
+ }
+ })
+ }
+ })
+ .finally(() => {
+ cardLoading.value = false
+ })
+ }
searchFormState.value.size = pageSize.value
loadData()
if (isEmpty(recordIds.value)) {
diff --git a/snowy-admin-web/src/components/XnUserSelector/index.vue b/snowy-admin-web/src/components/XnUserSelector/index.vue
index 5e1354d8..797b19b3 100644
--- a/snowy-admin-web/src/components/XnUserSelector/index.vue
+++ b/snowy-admin-web/src/components/XnUserSelector/index.vue
@@ -42,6 +42,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
>
@@ -211,6 +212,9 @@
orgTreeApi: {
type: Function
},
+ orgTreeLazyApi: {
+ type: Function
+ },
userPageApi: {
type: Function
},
@@ -255,7 +259,7 @@
const recordIds = ref([])
// 分页相关
const current = ref(0) // 当前页数
- const pageSize = ref(20) // 每页条数
+ const pageSize = ref(10) // 每页条数
const total = ref(0) // 数据总数
// 获取选中列表的api
const userListByIdList = (param) => {
@@ -280,40 +284,83 @@
const onMouseLeave = (index) => {
deleteShow.value = ''
}
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (typeof props.orgTreeLazyApi !== 'function' || treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ props
+ .orgTreeLazyApi({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
+
+ // 打开弹框
const openModal = () => {
- if (typeof props.orgTreeApi !== 'function') {
- message.warning('未配置选择器需要的orgTreeApi接口')
- return
- }
- if (typeof props.userPageApi !== 'function') {
- message.warning('未配置选择器需要的userPageApi接口')
+ if (typeof props.orgTreeApi !== 'function' || typeof props.userPageApi !== 'function') {
+ message.warning('未配置用户选择器API')
return
}
visible.value = true
// 获取机构树
- props
- .orgTreeApi()
- .then((data) => {
- if (data !== null) {
- treeData.value = data
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
+ if (typeof props.orgTreeLazyApi === 'function') {
+ props
+ .orgTreeLazyApi()
+ .then((data) => {
+ if (!isEmpty(data)) {
+ treeData.value = data.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
}
+ })
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ defaultExpandedKeys.value.push(treeData.value[0].id)
}
- })
- }
- })
- .finally(() => {
- cardLoading.value = false
- })
+ }
+ })
+ .finally(() => {
+ cardLoading.value = false
+ })
+ } else {
+ props
+ .orgTreeApi()
+ .then((data) => {
+ if (data !== null) {
+ treeData.value = data
+ // 默认展开2级
+ treeData.value.forEach((item) => {
+ // 因为0的顶级
+ if (item.parentId === '0') {
+ defaultExpandedKeys.value.push(item.id)
+ // 取到下级ID
+ if (item.children) {
+ item.children.forEach((items) => {
+ defaultExpandedKeys.value.push(items.id)
+ })
+ }
+ }
+ })
+ }
+ })
+ .finally(() => {
+ cardLoading.value = false
+ })
+ }
searchFormState.value.size = pageSize.value
loadData()
if (isEmpty(recordIds.value)) {
@@ -326,6 +373,7 @@
userListByIdList(param)
.then((data) => {
selectedData.value = data
+ userObj.value = data
})
.finally(() => {
selectedTableListLoading.value = false
diff --git a/snowy-admin-web/src/views/biz/org/form.vue b/snowy-admin-web/src/views/biz/org/form.vue
index 6673071c..701f8720 100644
--- a/snowy-admin-web/src/views/biz/org/form.vue
+++ b/snowy-admin-web/src/views/biz/org/form.vue
@@ -14,15 +14,14 @@
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
placeholder="请选择上级机构"
allow-clear
- tree-default-expand-all
:tree-data="treeData"
:field-names="{
children: 'children',
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
/>
@@ -42,6 +41,7 @@
{
+ bizOrgApi.orgTreeLazySelector().then((res) => {
treeData.value = [
{
- id: 0,
+ id: '0',
parentId: '-1',
name: '顶级',
- children: res
+ children: res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ }),
+ isLeaf: false
}
]
})
}
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ bizOrgApi
+ .orgTreeLazySelector({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
// 关闭抽屉
const onClose = () => {
visible.value = false
@@ -139,6 +168,11 @@
return Promise.resolve(data)
})
},
+ orgTreeLazyApi: (param) => {
+ return bizOrgApi.orgTreeLazySelector(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ },
userPageApi: (param) => {
return bizOrgApi.orgUserSelector(param).then((data) => {
return Promise.resolve(data)
diff --git a/snowy-admin-web/src/views/biz/org/index.vue b/snowy-admin-web/src/views/biz/org/index.vue
index 4ccdcc37..0d533833 100644
--- a/snowy-admin-web/src/views/biz/org/index.vue
+++ b/snowy-admin-web/src/views/biz/org/index.vue
@@ -6,6 +6,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
/>
@@ -27,8 +28,8 @@
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
/>
@@ -182,27 +183,46 @@
}
// 加载左侧的树
const loadTreeData = () => {
- bizOrgApi.orgTree().then((res) => {
+ bizOrgApi.orgTreeLazy().then((res) => {
if (res !== null) {
- treeData.value = res
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
if (isEmpty(defaultExpandedKeys.value)) {
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
- }
- }
- })
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ defaultExpandedKeys.value.push(treeData.value[0].id)
+ }
}
}
})
}
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ bizOrgApi
+ .orgTreeLazy({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
// 点击树查询
const treeSelect = (selectedKeys) => {
if (selectedKeys.length > 0) {
diff --git a/snowy-admin-web/src/views/biz/position/form.vue b/snowy-admin-web/src/views/biz/position/form.vue
index 90c870b6..4ac91ce4 100644
--- a/snowy-admin-web/src/views/biz/position/form.vue
+++ b/snowy-admin-web/src/views/biz/position/form.vue
@@ -14,15 +14,14 @@
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
placeholder="请选择组织"
allow-clear
- tree-default-expand-all
:tree-data="treeData"
:field-names="{
children: 'children',
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
>
@@ -77,8 +76,36 @@
formData.value = Object.assign({}, record)
}
// 获取机构树
- bizPositionApi.positionOrgTreeSelector().then((res) => {
- treeData.value = res
+ bizPositionApi.positionOrgTreeLazySelector().then((res) => {
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ })
+ }
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ bizPositionApi
+ .positionOrgTreeLazySelector({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
})
}
// 关闭抽屉
diff --git a/snowy-admin-web/src/views/biz/position/index.vue b/snowy-admin-web/src/views/biz/position/index.vue
index 9aef5df7..3e8ba942 100644
--- a/snowy-admin-web/src/views/biz/position/index.vue
+++ b/snowy-admin-web/src/views/biz/position/index.vue
@@ -6,6 +6,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
/>
@@ -27,8 +28,8 @@
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
/>
@@ -171,26 +172,52 @@
tableRef.value.refresh(true)
}
// 加载左侧的树
- bizOrgApi.orgTree().then((res) => {
- if (res !== null) {
- treeData.value = res
- if (isEmpty(defaultExpandedKeys.value)) {
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
- }
+ const loadTreeData = () => {
+ bizOrgApi.orgTreeLazy().then((res) => {
+ if (res !== null) {
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
}
})
+ if (isEmpty(defaultExpandedKeys.value)) {
+ // 默认展开顶级
+ treeData.value.forEach((item) => {
+ // 因为0的顶级
+ if (item.parentId === '0') {
+ defaultExpandedKeys.value.push(item.id)
+ }
+ })
+ }
}
- }
- })
+ })
+ }
+ loadTreeData()
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children || treeNode.dataRef.isLeaf) {
+ resolve()
+ return
+ }
+ bizOrgApi
+ .orgTreeLazy({ parentId: treeNode.dataRef.id })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ .catch(() => {
+ resolve()
+ })
+ })
+ }
// 点击树查询
const treeSelect = (selectedKeys) => {
if (selectedKeys.length > 0) {
diff --git a/snowy-admin-web/src/views/biz/user/form.vue b/snowy-admin-web/src/views/biz/user/form.vue
index d4abbd59..1fb3ca6b 100644
--- a/snowy-admin-web/src/views/biz/user/form.vue
+++ b/snowy-admin-web/src/views/biz/user/form.vue
@@ -51,7 +51,6 @@
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
placeholder="请选择机构"
allow-clear
- tree-default-expand-all
:tree-data="treeData"
:tree-default-expanded-keys="treeDefaultExpandedKeys"
:field-names="{
@@ -59,6 +58,7 @@
label: 'name',
value: 'id'
}"
+ :load-data="onLoadData"
@change="selePositionData(formData.orgId, 0)"
/>
@@ -135,6 +135,7 @@
:tree-data="treeData"
:tree-default-expanded-keys="treeDefaultExpandedKeys"
:field-names="{ children: 'children', label: 'name', value: 'id' }"
+ :load-data="onLoadData"
@select="childOrgSelect(positionInfo, 0, index)"
/>
@@ -340,26 +341,45 @@
}
nextTick(() => {
// 机构选择器数据
- bizUserApi.userOrgTreeSelector().then((res) => {
+ bizUserApi.userOrgTreeLazySelector().then((res) => {
if (res !== null) {
- treeData.value = res
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- treeDefaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- treeDefaultExpandedKeys.value.push(items.id)
- })
- }
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
}
})
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ treeDefaultExpandedKeys.value.push(treeData.value[0].id)
+ }
}
})
})
}
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ bizUserApi
+ .userOrgTreeLazySelector({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
// 关闭抽屉
const onClose = () => {
treeData.value = []
diff --git a/snowy-admin-web/src/views/biz/user/index.vue b/snowy-admin-web/src/views/biz/user/index.vue
index 03d49088..eaa21ddc 100644
--- a/snowy-admin-web/src/views/biz/user/index.vue
+++ b/snowy-admin-web/src/views/biz/user/index.vue
@@ -6,6 +6,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
/>
@@ -27,8 +28,8 @@
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
/>
@@ -158,6 +159,7 @@
{
- if (res !== null) {
- treeData.value = res
- if (isEmpty(defaultExpandedKeys.value)) {
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
- }
+ // 加载左侧树
+ const loadTreeData = () => {
+ bizOrgApi.orgTreeLazy().then((res) => {
+ if (res !== null) {
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
}
})
+ if (isEmpty(defaultExpandedKeys.value)) {
+ // 默认展开顶级
+ treeData.value.forEach((item) => {
+ // 因为0的顶级
+ if (item.parentId === '0') {
+ defaultExpandedKeys.value.push(item.id)
+ }
+ })
+ }
}
- }
- })
+ })
+ }
+ loadTreeData()
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children || treeNode.dataRef.isLeaf) {
+ resolve()
+ return
+ }
+ bizOrgApi
+ .orgTreeLazy({ parentId: treeNode.dataRef.id })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ .catch(() => {
+ resolve()
+ })
+ })
+ }
// 列表选择配置
const options = {
alert: {
@@ -279,7 +307,7 @@
}
}
}
- // 点击树查询
+ // 左侧树查询
const treeSelect = (selectedKeys) => {
if (selectedKeys.length > 0) {
searchFormState.value.orgId = selectedKeys.toString()
@@ -403,6 +431,11 @@
return Promise.resolve(orgTree)
})
},
+ orgTreeLazyApi: (param) => {
+ return bizUserApi.userOrgTreeLazySelector(param).then((orgTree) => {
+ return Promise.resolve(orgTree)
+ })
+ },
rolePageApi: (param) => {
return bizUserApi.userRoleSelector(param).then((data) => {
return Promise.resolve(data)
diff --git a/snowy-admin-web/src/views/dev/config/registerConfig/bForm.vue b/snowy-admin-web/src/views/dev/config/registerConfig/bForm.vue
index 9ad9d379..125385ad 100644
--- a/snowy-admin-web/src/views/dev/config/registerConfig/bForm.vue
+++ b/snowy-admin-web/src/views/dev/config/registerConfig/bForm.vue
@@ -55,6 +55,7 @@
>
{
+ return configApi.configOrgTreeLazy(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ },
orgPageApi: (param) => {
return configApi.configOrgSelector(param).then((data) => {
return Promise.resolve(data)
diff --git a/snowy-admin-web/src/views/sys/org/form.vue b/snowy-admin-web/src/views/sys/org/form.vue
index c98fe299..5528590d 100644
--- a/snowy-admin-web/src/views/sys/org/form.vue
+++ b/snowy-admin-web/src/views/sys/org/form.vue
@@ -14,15 +14,14 @@
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
placeholder="请选择上级组织"
allow-clear
- tree-default-expand-all
:tree-data="treeData"
:field-names="{
children: 'children',
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
/>
@@ -42,6 +41,7 @@
{
+ orgApi.orgOrgTreeLazySelector().then((res) => {
treeData.value = [
{
- id: 0,
+ id: '0',
parentId: '-1',
name: '顶级',
- children: res
+ children: res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ }),
+ isLeaf: false
}
]
})
}
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ orgApi
+ .orgOrgTreeLazySelector({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
// 关闭抽屉
const onClose = () => {
visible.value = false
@@ -138,6 +167,11 @@
return Promise.resolve(data)
})
},
+ orgTreeLazyApi: (param) => {
+ return orgApi.orgOrgTreeLazySelector(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ },
userPageApi: (param) => {
return orgApi.orgUserSelector(param).then((data) => {
return Promise.resolve(data)
diff --git a/snowy-admin-web/src/views/sys/org/index.vue b/snowy-admin-web/src/views/sys/org/index.vue
index b6b026a2..9f25ca95 100644
--- a/snowy-admin-web/src/views/sys/org/index.vue
+++ b/snowy-admin-web/src/views/sys/org/index.vue
@@ -6,6 +6,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
/>
@@ -27,8 +28,8 @@
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
/>
@@ -179,27 +180,46 @@
}
// 加载左侧的树
const loadTreeData = () => {
- orgApi.orgTree().then((res) => {
+ orgApi.orgTreeLazy().then((res) => {
if (res !== null) {
- treeData.value = res
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
if (isEmpty(defaultExpandedKeys.value)) {
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
- }
- }
- })
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ defaultExpandedKeys.value.push(treeData.value[0].id)
+ }
}
}
})
}
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ orgApi
+ .orgTreeLazy({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
// 点击树查询
const treeSelect = (selectedKeys) => {
if (selectedKeys.length > 0) {
diff --git a/snowy-admin-web/src/views/sys/position/form.vue b/snowy-admin-web/src/views/sys/position/form.vue
index 3014661c..3830dadd 100644
--- a/snowy-admin-web/src/views/sys/position/form.vue
+++ b/snowy-admin-web/src/views/sys/position/form.vue
@@ -14,15 +14,14 @@
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
placeholder="请选择组织"
allow-clear
- tree-default-expand-all
:tree-data="treeData"
:field-names="{
children: 'children',
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
>
@@ -76,8 +75,36 @@
formData.value = Object.assign({}, record)
}
// 获取机构树
- positionApi.positionOrgTreeSelector().then((res) => {
- treeData.value = res
+ positionApi.positionOrgTreeLazySelector().then((res) => {
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ })
+ }
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ positionApi
+ .positionOrgTreeLazySelector({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
})
}
// 关闭抽屉
diff --git a/snowy-admin-web/src/views/sys/position/index.vue b/snowy-admin-web/src/views/sys/position/index.vue
index ed380370..9e2372d3 100644
--- a/snowy-admin-web/src/views/sys/position/index.vue
+++ b/snowy-admin-web/src/views/sys/position/index.vue
@@ -6,6 +6,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
/>
@@ -27,8 +28,8 @@
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
/>
@@ -168,26 +169,45 @@
tableRef.value.refresh(true)
}
// 加载左侧的树
- orgApi.orgTree().then((res) => {
+ orgApi.orgTreeLazy().then((res) => {
if (res !== null) {
- treeData.value = res
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
if (isEmpty(defaultExpandedKeys.value)) {
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
- }
- }
- })
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ defaultExpandedKeys.value.push(treeData.value[0].id)
+ }
}
}
})
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ orgApi
+ .orgTreeLazy({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
// 点击树查询
const treeSelect = (selectedKeys) => {
if (selectedKeys.length > 0) {
diff --git a/snowy-admin-web/src/views/sys/role/index.vue b/snowy-admin-web/src/views/sys/role/index.vue
index e5fb6fdb..b2f94b00 100644
--- a/snowy-admin-web/src/views/sys/role/index.vue
+++ b/snowy-admin-web/src/views/sys/role/index.vue
@@ -6,6 +6,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
/>
@@ -27,8 +28,8 @@
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
@change="onCategoryOrOrgIdSelect"
/>
@@ -132,6 +133,7 @@
{
- if (res !== null) {
- // 树中插入全局角色类型
- const globalRoleType = [
- {
- id: 'GLOBAL',
- parentId: '-1',
- name: '全局'
- }
- ]
- treeData.value = globalRoleType.concat(res)
- if (isEmpty(defaultExpandedKeys.value)) {
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
- }
+ const loadTreeData = () => {
+ orgApi.orgTreeLazy().then((res) => {
+ if (res !== null) {
+ // 树中插入全局角色类型
+ const globalRoleType = [
+ {
+ id: 'GLOBAL',
+ parentId: '-1',
+ name: '全局',
+ isLeaf: true
}
- })
+ ]
+ treeData.value = globalRoleType.concat(
+ res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ )
+ if (isEmpty(defaultExpandedKeys.value)) {
+ // 默认展开顶级
+ treeData.value.forEach((item) => {
+ // 因为0的顶级
+ if (item.parentId === '0') {
+ defaultExpandedKeys.value.push(item.id)
+ }
+ })
+ }
}
- }
- })
+ })
+ }
+ loadTreeData()
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children || treeNode.dataRef.isLeaf) {
+ resolve()
+ return
+ }
+ orgApi
+ .orgTreeLazy({ parentId: treeNode.dataRef.id })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ .catch(() => {
+ resolve()
+ })
+ })
+ }
// 点击树查询
const treeSelect = (selectedKeys) => {
if (selectedKeys.length > 0) {
@@ -316,6 +347,11 @@
return Promise.resolve(data)
})
},
+ orgTreeLazyApi: (param) => {
+ return orgApi.orgOrgTreeLazySelector(param).then((data) => {
+ return Promise.resolve(data)
+ })
+ },
userPageApi: (param) => {
return roleApi.roleUserSelector(param).then((data) => {
return Promise.resolve(data)
diff --git a/snowy-admin-web/src/views/sys/role/scopeDefineOrg.vue b/snowy-admin-web/src/views/sys/role/scopeDefineOrg.vue
index dfa12720..68cd8ebc 100644
--- a/snowy-admin-web/src/views/sys/role/scopeDefineOrg.vue
+++ b/snowy-admin-web/src/views/sys/role/scopeDefineOrg.vue
@@ -23,6 +23,7 @@
checkable
check-strictly
:selectable="false"
+ :load-data="onLoadData"
@check="treeCheck"
>
@@ -65,9 +66,14 @@
visible.value = true
resultDataModel.dataScopeId = id
// const treeData = data.data;
- roleApi.roleOrgTreeSelector().then((res) => {
+ roleApi.roleOrgTreeLazySelector().then((res) => {
if (res !== null) {
- treeData.value = res
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
// 赋值选中项
echoOrgSelectKeys(checkKeys)
// 默认展开2级
@@ -75,17 +81,34 @@
// 因为0的顶级
if (item.parentId === '0') {
defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
- }
}
})
}
})
}
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ roleApi
+ .roleOrgTreeLazySelector({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
const onClose = () => {
visible.value = false
}
diff --git a/snowy-admin-web/src/views/sys/user/form.vue b/snowy-admin-web/src/views/sys/user/form.vue
index a777100c..9709e83c 100644
--- a/snowy-admin-web/src/views/sys/user/form.vue
+++ b/snowy-admin-web/src/views/sys/user/form.vue
@@ -51,7 +51,6 @@
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
placeholder="请选择组织"
allow-clear
- tree-default-expand-all
:tree-data="treeData"
:tree-default-expanded-keys="treeDefaultExpandedKeys"
:field-names="{
@@ -59,6 +58,7 @@
label: 'name',
value: 'id'
}"
+ :load-data="onLoadData"
@change="selePositionData(formData.orgId, 0)"
/>
@@ -135,6 +135,7 @@
:tree-data="treeData"
:tree-default-expanded-keys="treeDefaultExpandedKeys"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="childOrgSelect(positionInfo, 0, index)"
/>
@@ -340,26 +341,45 @@
}
nextTick(() => {
// 机构选择器数据
- userApi.userOrgTreeSelector().then((res) => {
+ userApi.userOrgTreeLazySelector().then((res) => {
if (res !== null) {
- treeData.value = res
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- treeDefaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- treeDefaultExpandedKeys.value.push(items.id)
- })
- }
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
}
})
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ treeDefaultExpandedKeys.value.push(treeData.value[0].id)
+ }
}
})
})
}
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ userApi
+ .userOrgTreeLazySelector({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
// 关闭抽屉
const onClose = () => {
treeData.value = []
diff --git a/snowy-admin-web/src/views/sys/user/index.vue b/snowy-admin-web/src/views/sys/user/index.vue
index 7aaa66b2..50c839ae 100644
--- a/snowy-admin-web/src/views/sys/user/index.vue
+++ b/snowy-admin-web/src/views/sys/user/index.vue
@@ -6,6 +6,7 @@
v-model:expandedKeys="defaultExpandedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
+ :load-data="onLoadData"
@select="treeSelect"
/>
@@ -27,8 +28,8 @@
label: 'name',
value: 'id'
}"
- selectable="false"
tree-line
+ :load-data="onLoadData"
/>
@@ -262,26 +263,45 @@
})
}
// 左侧树查询
- orgApi.orgTree().then((res) => {
+ orgApi.orgTreeLazy().then((res) => {
if (res !== null) {
- treeData.value = res
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
if (isEmpty(defaultExpandedKeys.value)) {
- // 默认展开2级
- treeData.value.forEach((item) => {
- // 因为0的顶级
- if (item.parentId === '0') {
- defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
- }
- }
- })
+ // 默认展开第一级
+ if (treeData.value.length > 0) {
+ defaultExpandedKeys.value.push(treeData.value[0].id)
+ }
}
}
})
+ // 懒加载子节点
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ orgApi
+ .orgTreeLazy({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
// 列表选择配置
const options = {
alert: {
diff --git a/snowy-admin-web/src/views/sys/user/scopeDefineOrg.vue b/snowy-admin-web/src/views/sys/user/scopeDefineOrg.vue
index bbcafc5c..effd2d5a 100644
--- a/snowy-admin-web/src/views/sys/user/scopeDefineOrg.vue
+++ b/snowy-admin-web/src/views/sys/user/scopeDefineOrg.vue
@@ -23,6 +23,7 @@
checkable
check-strictly
:selectable="false"
+ :load-data="onLoadData"
@check="treeCheck"
>
@@ -65,9 +66,14 @@
visible.value = true
resultDataModel.dataScopeId = id
// const treeData = data.data;
- userApi.userOrgTreeSelector().then((res) => {
+ userApi.userOrgTreeLazySelector().then((res) => {
if (res !== null) {
- treeData.value = res
+ treeData.value = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
// 赋值选中项
echoOrgSelectKeys(checkKeys)
// 默认展开2级
@@ -75,17 +81,33 @@
// 因为0的顶级
if (item.parentId === '0') {
defaultExpandedKeys.value.push(item.id)
- // 取到下级ID
- if (item.children) {
- item.children.forEach((items) => {
- defaultExpandedKeys.value.push(items.id)
- })
- }
}
})
}
})
}
+ const onLoadData = (treeNode) => {
+ return new Promise((resolve) => {
+ if (treeNode.dataRef.children) {
+ resolve()
+ return
+ }
+ userApi
+ .userOrgTreeLazySelector({
+ parentId: treeNode.dataRef.id
+ })
+ .then((res) => {
+ treeNode.dataRef.children = res.map((item) => {
+ return {
+ ...item,
+ isLeaf: item.isLeaf === undefined ? false : item.isLeaf
+ }
+ })
+ treeData.value = [...treeData.value]
+ resolve()
+ })
+ })
+ }
const onClose = () => {
visible.value = false
}
diff --git a/snowy-plugin-api/snowy-plugin-biz-api/src/main/java/vip/xiaonuo/biz/api/BizOrgApi.java b/snowy-plugin-api/snowy-plugin-biz-api/src/main/java/vip/xiaonuo/biz/api/BizOrgApi.java
index 7b0f46b1..11f725d2 100644
--- a/snowy-plugin-api/snowy-plugin-biz-api/src/main/java/vip/xiaonuo/biz/api/BizOrgApi.java
+++ b/snowy-plugin-api/snowy-plugin-biz-api/src/main/java/vip/xiaonuo/biz/api/BizOrgApi.java
@@ -34,6 +34,14 @@ public interface BizOrgApi {
**/
List> orgTreeSelector();
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author yubaoshan
+ * @date 2024/11/1 18:27:51
+ **/
+ List orgTreeLazySelector(String parentId);
+
/**
* 获取组织列表选择器
*
diff --git a/snowy-plugin-api/snowy-plugin-sys-api/src/main/java/vip/xiaonuo/sys/api/SysOrgApi.java b/snowy-plugin-api/snowy-plugin-sys-api/src/main/java/vip/xiaonuo/sys/api/SysOrgApi.java
index 40b9adae..df2e9421 100644
--- a/snowy-plugin-api/snowy-plugin-sys-api/src/main/java/vip/xiaonuo/sys/api/SysOrgApi.java
+++ b/snowy-plugin-api/snowy-plugin-sys-api/src/main/java/vip/xiaonuo/sys/api/SysOrgApi.java
@@ -50,6 +50,14 @@ public interface SysOrgApi {
**/
List> orgTreeSelector();
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/7/22 14:46
+ **/
+ List orgTreeLazySelector(String parentId);
+
/**
* 获取组织列表选择器
*
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/controller/BizOrgController.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/controller/BizOrgController.java
index 809770d3..5b3abbaf 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/controller/BizOrgController.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/controller/BizOrgController.java
@@ -14,6 +14,7 @@ package vip.xiaonuo.biz.modular.org.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
import com.github.xingfudeshi.knife4j.annotations.ApiSupport;
@@ -80,6 +81,20 @@ public class BizOrgController {
return CommonResult.data(bizOrgService.tree());
}
+ /**
+ * 获取机构树(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ @ApiOperationSupport(order = 2)
+ @Operation(summary = "获取机构树(懒加载)")
+ @SaCheckPermission("/biz/org/treeLazy")
+ @GetMapping("/biz/org/treeLazy")
+ public CommonResult> treeLazy(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
+ return CommonResult.data(bizOrgService.treeLazy(bizOrgTreeLazyParam));
+ }
+
/**
* 添加机构
*
@@ -175,6 +190,20 @@ public class BizOrgController {
return CommonResult.data(bizOrgService.orgTreeSelector());
}
+ /**
+ * 获取机构树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ @ApiOperationSupport(order = 8)
+ @Operation(summary = "获取机构树选择器(懒加载)")
+ @SaCheckPermission("/biz/org/orgTreeLazySelector")
+ @GetMapping("/biz/org/orgTreeLazySelector")
+ public CommonResult> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
+ return CommonResult.data(bizOrgService.treeLazy(bizOrgTreeLazyParam));
+ }
+
/**
* 获取人员选择器
*
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/param/BizOrgTreeLazyParam.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/param/BizOrgTreeLazyParam.java
new file mode 100644
index 00000000..42f520fc
--- /dev/null
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/param/BizOrgTreeLazyParam.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright [2022] [https://www.xiaonuo.vip]
+ *
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
+ *
+ * 1.请不要删除和修改根目录下的LICENSE文件.
+ * 2.请不要删除和修改Snowy源码头部的版权声明.
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等.
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作.
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
+ */
+package vip.xiaonuo.biz.modular.org.param;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 机构树懒加载参数
+ *
+ * @author xuyuxiang
+ * @date 2022/4/21 16:13
+ **/
+@Getter
+@Setter
+public class BizOrgTreeLazyParam {
+
+ /** 父id */
+ @Schema(description = "父id")
+ private String parentId;
+}
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/provider/BizOrgApiProvider.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/provider/BizOrgApiProvider.java
index 58e89954..dd2ada71 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/provider/BizOrgApiProvider.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/provider/BizOrgApiProvider.java
@@ -20,6 +20,7 @@ import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import vip.xiaonuo.biz.api.BizOrgApi;
import vip.xiaonuo.biz.modular.org.param.BizOrgSelectorOrgListParam;
+import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
import vip.xiaonuo.biz.modular.org.service.BizOrgService;
import java.util.List;
@@ -41,6 +42,13 @@ public class BizOrgApiProvider implements BizOrgApi {
return bizOrgService.orgTreeSelector();
}
+ @Override
+ public List orgTreeLazySelector(String parentId) {
+ BizOrgTreeLazyParam bizOrgTreeLazyParam = new BizOrgTreeLazyParam();
+ bizOrgTreeLazyParam.setParentId(parentId);
+ return bizOrgService.treeLazy(bizOrgTreeLazyParam);
+ }
+
@SuppressWarnings("ALL")
@Override
public Page orgListSelector(String parentId) {
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/BizOrgService.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/BizOrgService.java
index 70171c2a..592cd630 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/BizOrgService.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/BizOrgService.java
@@ -13,6 +13,7 @@
package vip.xiaonuo.biz.modular.org.service;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
@@ -45,6 +46,14 @@ public interface BizOrgService extends IService {
*/
List> tree();
+ /**
+ * 获取机构树(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:08
+ */
+ List treeLazy(BizOrgTreeLazyParam bizOrgTreeLazyParam);
+
/**
* 添加机构
*
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/impl/BizOrgServiceImpl.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/impl/BizOrgServiceImpl.java
index 652edef5..d0741f7d 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/impl/BizOrgServiceImpl.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/impl/BizOrgServiceImpl.java
@@ -43,6 +43,7 @@ import vip.xiaonuo.biz.modular.position.entity.BizPosition;
import vip.xiaonuo.biz.modular.position.service.BizPositionService;
import vip.xiaonuo.biz.modular.user.entity.BizUser;
import vip.xiaonuo.biz.modular.user.service.BizUserService;
+import vip.xiaonuo.common.cache.CommonCacheOperator;
import vip.xiaonuo.common.enums.CommonSortOrderEnum;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
@@ -61,6 +62,11 @@ import java.util.stream.Collectors;
@Service
public class BizOrgServiceImpl extends ServiceImpl implements BizOrgService {
+ private static final String ORG_ALL_LIST_CACHE_KEY = "biz-org:all-list";
+
+ @Resource
+ private CommonCacheOperator commonCacheOperator;
+
@Resource
private SysRoleApi sysRoleApi;
@@ -105,7 +111,7 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
@Override
public List> tree() {
// 获取所有机构
- List allOrgList = this.list();
+ List allOrgList = this.getAllOrgList();
// 定义机构集合
Set bizOrgSet = CollectionUtil.newHashSet();
// 校验数据范围
@@ -130,6 +136,58 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
return TreeUtil.build(treeNodeList, "0");
}
+ @Override
+ public List treeLazy(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
+ String parentId = ObjectUtil.isNotEmpty(bizOrgTreeLazyParam.getParentId()) ? bizOrgTreeLazyParam.getParentId() : "0";
+ List loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
+
+ // 获取所有机构
+ List allOrgList = this.getAllOrgList();
+ Set visibleOrgIds = null;
+
+ // 如果数据范围不为空,则计算可见机构ID集合(包含自身及其所有父级)
+ if (ObjectUtil.isNotEmpty(loginUserDataScope)) {
+ Set bizOrgSet = CollectionUtil.newHashSet();
+ loginUserDataScope.forEach(orgId -> bizOrgSet.addAll(this.getParentListById(allOrgList, orgId, true)));
+ visibleOrgIds = bizOrgSet.stream().map(BizOrg::getId).collect(Collectors.toSet());
+ }
+
+ // 过滤出当前父级下的可见子级
+ final Set finalVisibleOrgIds = visibleOrgIds;
+ List sysOrgList = allOrgList.stream()
+ .filter(bizOrg -> bizOrg.getParentId().equals(parentId))
+ .filter(bizOrg -> finalVisibleOrgIds == null || finalVisibleOrgIds.contains(bizOrg.getId()))
+ .sorted(Comparator.comparingInt(BizOrg::getSortCode).thenComparing(BizOrg::getId))
+ .collect(Collectors.toList());
+
+ if (ObjectUtil.isEmpty(sysOrgList)) {
+ return CollectionUtil.newArrayList();
+ }
+
+ // 判断这些机构是否还有可见子机构
+ return sysOrgList.stream().map(bizOrg -> {
+ JSONObject jsonObject = JSONUtil.parseObj(bizOrg);
+ // 计算是否有可见的子节点
+ boolean hasChildren = allOrgList.stream()
+ .anyMatch(item -> item.getParentId().equals(bizOrg.getId()) && (finalVisibleOrgIds == null || finalVisibleOrgIds.contains(item.getId())));
+
+ jsonObject.set("isLeaf", !hasChildren);
+ return jsonObject;
+ }).collect(Collectors.toList());
+ }
+
+ /**
+ * 获取机构树(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:08
+ */
+ public List treeLazy(String parentId) {
+ BizOrgTreeLazyParam bizOrgTreeLazyParam = new BizOrgTreeLazyParam();
+ bizOrgTreeLazyParam.setParentId(parentId);
+ return this.treeLazy(bizOrgTreeLazyParam);
+ }
+
@Transactional(rollbackFor = Exception.class)
@Override
public void add(BizOrgAddParam bizOrgAddParam, String sourceFromType) {
@@ -158,6 +216,8 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
bizOrgExtService.createExtInfo(bizOrg.getId(), sourceFromType);
// 发布增加事件
CommonDataChangeEventCenter.doAddWithData(BizDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(bizOrg));
+ // 清除缓存
+ commonCacheOperator.remove(ORG_ALL_LIST_CACHE_KEY);
}
@Transactional(rollbackFor = Exception.class)
@@ -183,7 +243,7 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
if(repeatName) {
throw new CommonException("存在重复的同级机构,名称为:{}", bizOrg.getName());
}
- List originDataList = this.list();
+ List originDataList = this.getAllOrgList();
boolean errorLevel = this.getChildListById(originDataList, bizOrg.getId(), true).stream()
.map(BizOrg::getId).collect(Collectors.toList()).contains(bizOrg.getParentId());
if(errorLevel) {
@@ -193,6 +253,8 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
this.updateById(bizOrg);
// 发布更新事件
CommonDataChangeEventCenter.doUpdateWithData(BizDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(bizOrg));
+ // 清除缓存
+ commonCacheOperator.remove(ORG_ALL_LIST_CACHE_KEY);
}
@Transactional(rollbackFor = Exception.class)
@@ -209,7 +271,7 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
} else {
throw new CommonException("您没有权限删除这些机构,机构id:{}", orgIdList);
}
- List allOrgList = this.list();
+ List allOrgList = this.getAllOrgList();
// 获取所有子机构
List toDeleteOrgIdList = CollectionUtil.newArrayList();
orgIdList.forEach(orgId -> toDeleteOrgIdList.addAll(this.getChildListById(allOrgList, orgId, true).stream()
@@ -246,6 +308,8 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
// 发布删除事件
CommonDataChangeEventCenter.doDeleteWithDataIdList(BizDataTypeEnum.ORG.getValue(), toDeleteOrgIdList);
+ // 清除缓存
+ commonCacheOperator.remove(ORG_ALL_LIST_CACHE_KEY);
}
}
@@ -265,7 +329,13 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
@Override
public List getAllOrgList() {
- return this.list(new LambdaQueryWrapper().orderByAsc(BizOrg::getSortCode));
+ Object cached = commonCacheOperator.get(ORG_ALL_LIST_CACHE_KEY);
+ if (cached != null) {
+ return JSONUtil.toList(JSONUtil.parseArray(cached), BizOrg.class);
+ }
+ List list = this.list(new LambdaQueryWrapper().orderByAsc(BizOrg::getSortCode));
+ commonCacheOperator.put(ORG_ALL_LIST_CACHE_KEY, list);
+ return list;
}
@Override
@@ -314,6 +384,8 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
this.save(bizOrg);
// 发布增加事件
CommonDataChangeEventCenter.doAddWithData(BizDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(bizOrg));
+ // 清除缓存
+ commonCacheOperator.remove(ORG_ALL_LIST_CACHE_KEY);
return bizOrg.getId();
}
@@ -328,7 +400,7 @@ public class BizOrgServiceImpl extends ServiceImpl impleme
Set bizOrgSet = CollectionUtil.newHashSet();
if(ObjectUtil.isNotEmpty(loginUserDataScope)) {
// 获取所有机构
- List allOrgList = this.list();
+ List allOrgList = this.getAllOrgList();
loginUserDataScope.forEach(orgId -> bizOrgSet.addAll(this.getParentListById(allOrgList, orgId, true)));
List loginUserDataScopeFullList = bizOrgSet.stream().map(BizOrg::getId).collect(Collectors.toList());
lambdaQueryWrapper.in(BizOrg::getId, loginUserDataScopeFullList);
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/controller/BizPositionController.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/controller/BizPositionController.java
index 706691e6..002f2eaa 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/controller/BizPositionController.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/controller/BizPositionController.java
@@ -14,6 +14,7 @@ package vip.xiaonuo.biz.modular.position.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
import com.github.xingfudeshi.knife4j.annotations.ApiSupport;
@@ -31,6 +32,7 @@ import vip.xiaonuo.biz.modular.position.param.*;
import vip.xiaonuo.biz.modular.position.service.BizPositionService;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
+import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
import javax.validation.Valid;
import java.util.List;
@@ -143,6 +145,20 @@ public class BizPositionController {
return CommonResult.data(bizPositionService.orgTreeSelector());
}
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ @ApiOperationSupport(order = 6)
+ @Operation(summary = "获取组织树选择器(懒加载)")
+ @SaCheckPermission("/biz/position/orgTreeLazySelector")
+ @GetMapping("/biz/position/orgTreeLazySelector")
+ public CommonResult> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
+ return CommonResult.data(bizPositionService.orgTreeLazySelector(bizOrgTreeLazyParam));
+ }
+
/**
* 获取岗位选择器
*
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/service/BizPositionService.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/service/BizPositionService.java
index 60e5fa6c..1ec9dc4c 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/service/BizPositionService.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/service/BizPositionService.java
@@ -13,10 +13,12 @@
package vip.xiaonuo.biz.modular.position.service;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
import vip.xiaonuo.biz.modular.position.param.*;
+import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
import java.util.List;
@@ -94,6 +96,14 @@ public interface BizPositionService extends IService {
*/
List> orgTreeSelector();
+ /**
+ * 获取机构树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:08
+ */
+ List orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam);
+
/**
* 获取岗位选择器
*
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/service/impl/BizPositionServiceImpl.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/service/impl/BizPositionServiceImpl.java
index 95233c60..57492600 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/service/impl/BizPositionServiceImpl.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/position/service/impl/BizPositionServiceImpl.java
@@ -32,8 +32,8 @@ import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
-import vip.xiaonuo.biz.core.enums.BizDataTypeEnum;
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
+import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
import vip.xiaonuo.biz.modular.org.service.BizOrgService;
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
import vip.xiaonuo.biz.modular.position.enums.BizPositionCategoryEnum;
@@ -42,6 +42,7 @@ import vip.xiaonuo.biz.modular.position.param.*;
import vip.xiaonuo.biz.modular.position.service.BizPositionService;
import vip.xiaonuo.biz.modular.user.entity.BizUser;
import vip.xiaonuo.biz.modular.user.service.BizUserService;
+import vip.xiaonuo.biz.core.enums.BizDataTypeEnum;
import vip.xiaonuo.common.enums.CommonSortOrderEnum;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
@@ -239,6 +240,11 @@ public class BizPositionServiceImpl extends ServiceImpl orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
+ return bizOrgService.treeLazy(bizOrgTreeLazyParam);
+ }
+
@Override
public Page positionSelector(BizPositionSelectorPositionParam bizPositionSelectorPositionParam) {
QueryWrapper queryWrapper = new QueryWrapper();
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/controller/BizUserController.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/controller/BizUserController.java
index d47fb0ac..d735900b 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/controller/BizUserController.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/controller/BizUserController.java
@@ -14,6 +14,7 @@ package vip.xiaonuo.biz.modular.user.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
import com.github.xingfudeshi.knife4j.annotations.ApiSupport;
@@ -30,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
+import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
import vip.xiaonuo.biz.modular.user.entity.BizUser;
import vip.xiaonuo.biz.modular.user.enums.BizUserSourceFromTypeEnum;
import vip.xiaonuo.biz.modular.user.param.*;
@@ -258,6 +260,20 @@ public class BizUserController {
return CommonResult.data(bizUserService.orgTreeSelector());
}
+ /**
+ * 获取机构树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ @ApiOperationSupport(order = 13)
+ @Operation(summary = "获取机构树选择器(懒加载)")
+ @SaCheckPermission("/biz/user/orgTreeLazySelector")
+ @GetMapping("/biz/user/orgTreeLazySelector")
+ public CommonResult> orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
+ return CommonResult.data(bizUserService.orgTreeLazySelector(bizOrgTreeLazyParam));
+ }
+
/**
* 获取机构列表选择器
*
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/service/BizUserService.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/service/BizUserService.java
index 7c3906fc..bae15f7d 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/service/BizUserService.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/service/BizUserService.java
@@ -13,10 +13,12 @@
package vip.xiaonuo.biz.modular.user.service;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import jakarta.servlet.http.HttpServletResponse;
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
+import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
import vip.xiaonuo.biz.modular.user.entity.BizUser;
import vip.xiaonuo.biz.modular.user.param.*;
@@ -147,6 +149,14 @@ public interface BizUserService extends IService {
*/
List> orgTreeSelector();
+ /**
+ * 获取机构树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/5/13 21:00
+ */
+ List orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam);
+
/**
* 获取机构列表选择器
*
diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/service/impl/BizUserServiceImpl.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/service/impl/BizUserServiceImpl.java
index eab508ea..b65a9b34 100644
--- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/service/impl/BizUserServiceImpl.java
+++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/user/service/impl/BizUserServiceImpl.java
@@ -57,6 +57,7 @@ import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
import vip.xiaonuo.biz.core.enums.BizBuildInEnum;
import vip.xiaonuo.biz.core.enums.BizDataTypeEnum;
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
+import vip.xiaonuo.biz.modular.org.param.BizOrgTreeLazyParam;
import vip.xiaonuo.biz.modular.org.service.BizOrgService;
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
import vip.xiaonuo.biz.modular.position.service.BizPositionService;
@@ -640,6 +641,11 @@ public class BizUserServiceImpl extends ServiceImpl impl
return TreeUtil.build(treeNodeList, "0");
}
+ @Override
+ public List orgTreeLazySelector(BizOrgTreeLazyParam bizOrgTreeLazyParam) {
+ return bizOrgService.treeLazy(bizOrgTreeLazyParam);
+ }
+
@Override
public Page orgListSelector(BizUserSelectorOrgListParam bizUserSelectorOrgListParam) {
QueryWrapper queryWrapper = new QueryWrapper().checkSqlInjection();
diff --git a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/config/controller/DevConfigController.java b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/config/controller/DevConfigController.java
index 5fc0f1de..ceec4896 100644
--- a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/config/controller/DevConfigController.java
+++ b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/config/controller/DevConfigController.java
@@ -201,6 +201,18 @@ public class DevConfigController {
return CommonResult.data(sysOrgApi.orgTreeSelector());
}
+ /**
+ * 获取机构选树(懒加载)
+ *
+ * @author yubaoshan
+ * @date 2025/4/23 20:00
+ */
+ @Operation(summary = "获取机构选树(懒加载)")
+ @GetMapping("/dev/config/orgTreeLazy")
+ public CommonResult> orgTreeLazy(String parentId) {
+ return CommonResult.data(sysOrgApi.orgTreeLazySelector(parentId));
+ }
+
/**
* 获取角色选择器
*
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/controller/SysOrgController.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/controller/SysOrgController.java
index b7871cdb..ca115b28 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/controller/SysOrgController.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/controller/SysOrgController.java
@@ -13,6 +13,7 @@
package vip.xiaonuo.sys.modular.org.controller;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
import com.github.xingfudeshi.knife4j.annotations.ApiSupport;
@@ -77,6 +78,19 @@ public class SysOrgController {
return CommonResult.data(sysOrgService.tree());
}
+ /**
+ * 获取组织树(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ @ApiOperationSupport(order = 2)
+ @Operation(summary = "获取组织树(懒加载)")
+ @GetMapping("/sys/org/treeLazy")
+ public CommonResult> treeLazy(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
+ return CommonResult.data(sysOrgService.treeLazy(sysOrgTreeLazyParam));
+ }
+
/**
* 添加组织
*
@@ -166,6 +180,19 @@ public class SysOrgController {
return CommonResult.data(sysOrgService.orgTreeSelector());
}
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ @ApiOperationSupport(order = 8)
+ @Operation(summary = "获取组织树选择器(懒加载)")
+ @GetMapping("/sys/org/orgTreeLazySelector")
+ public CommonResult> orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
+ return CommonResult.data(sysOrgService.treeLazy(sysOrgTreeLazyParam));
+ }
+
/**
* 获取用户选择器
*
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/param/SysOrgTreeLazyParam.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/param/SysOrgTreeLazyParam.java
new file mode 100644
index 00000000..6055637e
--- /dev/null
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/param/SysOrgTreeLazyParam.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright [2022] [https://www.xiaonuo.vip]
+ *
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
+ *
+ * 1.请不要删除和修改根目录下的LICENSE文件.
+ * 2.请不要删除和修改Snowy源码头部的版权声明.
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等.
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作.
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
+ */
+package vip.xiaonuo.sys.modular.org.param;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 组织树懒加载参数
+ *
+ * @author xuyuxiang
+ * @date 2022/4/21 16:13
+ **/
+@Getter
+@Setter
+public class SysOrgTreeLazyParam {
+
+ /** 父id */
+ @Schema(description = "父id")
+ private String parentId;
+}
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/provider/SysOrgApiProvider.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/provider/SysOrgApiProvider.java
index ef21bfde..2cf7e631 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/provider/SysOrgApiProvider.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/provider/SysOrgApiProvider.java
@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
import vip.xiaonuo.sys.api.SysOrgApi;
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
import vip.xiaonuo.sys.modular.org.param.SysOrgSelectorOrgListParam;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
import java.util.List;
@@ -59,6 +60,13 @@ public class SysOrgApiProvider implements SysOrgApi {
return sysOrgService.orgTreeSelector();
}
+ @Override
+ public List orgTreeLazySelector(String parentId) {
+ SysOrgTreeLazyParam sysOrgTreeLazyParam = new SysOrgTreeLazyParam();
+ sysOrgTreeLazyParam.setParentId(parentId);
+ return sysOrgService.treeLazy(sysOrgTreeLazyParam);
+ }
+
@SuppressWarnings("ALL")
@Override
public Page orgListSelector(String parentId) {
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/service/SysOrgService.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/service/SysOrgService.java
index 7374f002..94333813 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/service/SysOrgService.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/service/SysOrgService.java
@@ -13,6 +13,7 @@
package vip.xiaonuo.sys.modular.org.service;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
@@ -45,6 +46,14 @@ public interface SysOrgService extends IService {
*/
List> tree();
+ /**
+ * 获取机构树(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/21 16:13
+ **/
+ List treeLazy(SysOrgTreeLazyParam sysOrgTreeLazyParam);
+
/**
* 添加组织
*
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/service/impl/SysOrgServiceImpl.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/service/impl/SysOrgServiceImpl.java
index c5112818..fb0dbad1 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/service/impl/SysOrgServiceImpl.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/org/service/impl/SysOrgServiceImpl.java
@@ -30,6 +30,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
+import vip.xiaonuo.common.cache.CommonCacheOperator;
import vip.xiaonuo.common.enums.CommonSortOrderEnum;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
@@ -53,6 +55,7 @@ import vip.xiaonuo.sys.modular.user.service.SysUserService;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -64,6 +67,11 @@ import java.util.stream.Collectors;
@Service
public class SysOrgServiceImpl extends ServiceImpl implements SysOrgService {
+ private static final String ORG_ALL_LIST_CACHE_KEY = "sys-org:all-list";
+
+ @Resource
+ private CommonCacheOperator commonCacheOperator;
+
@Resource
private SysOrgExtService sysOrgExtService;
@@ -111,6 +119,58 @@ public class SysOrgServiceImpl extends ServiceImpl impleme
return TreeUtil.build(treeNodeList, "0");
}
+ @Override
+ public List treeLazy(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
+ String parentId = ObjectUtil.isNotEmpty(sysOrgTreeLazyParam.getParentId()) ? sysOrgTreeLazyParam.getParentId() : "0";
+ List loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
+
+ // 获取所有机构
+ List allOrgList = this.getAllOrgList();
+ Set visibleOrgIds = null;
+
+ // 如果数据范围不为空,则计算可见机构ID集合(包含自身及其所有父级)
+ if (ObjectUtil.isNotEmpty(loginUserDataScope)) {
+ Set sysOrgSet = CollectionUtil.newHashSet();
+ loginUserDataScope.forEach(orgId -> sysOrgSet.addAll(this.getParentListById(allOrgList, orgId, true)));
+ visibleOrgIds = sysOrgSet.stream().map(SysOrg::getId).collect(Collectors.toSet());
+ }
+
+ // 过滤出当前父级下的可见子级
+ final Set finalVisibleOrgIds = visibleOrgIds;
+ List sysOrgList = allOrgList.stream()
+ .filter(sysOrg -> sysOrg.getParentId().equals(parentId))
+ .filter(sysOrg -> finalVisibleOrgIds == null || finalVisibleOrgIds.contains(sysOrg.getId()))
+ .sorted(Comparator.comparingInt(SysOrg::getSortCode).thenComparing(SysOrg::getId))
+ .collect(Collectors.toList());
+
+ if (CollectionUtil.isEmpty(sysOrgList)) {
+ return CollectionUtil.newArrayList();
+ }
+
+ // 判断这些机构是否还有可见子机构
+ return sysOrgList.stream().map(sysOrg -> {
+ JSONObject jsonObject = JSONUtil.parseObj(sysOrg);
+ // 计算是否有可见的子节点
+ boolean hasChildren = allOrgList.stream()
+ .anyMatch(item -> item.getParentId().equals(sysOrg.getId()) && (finalVisibleOrgIds == null || finalVisibleOrgIds.contains(item.getId())));
+
+ jsonObject.set("isLeaf", !hasChildren);
+ return jsonObject;
+ }).collect(Collectors.toList());
+ }
+
+ /**
+ * 获取机构树(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/21 16:13
+ **/
+ public List treeLazy(String parentId) {
+ SysOrgTreeLazyParam sysOrgTreeLazyParam = new SysOrgTreeLazyParam();
+ sysOrgTreeLazyParam.setParentId(parentId);
+ return this.treeLazy(sysOrgTreeLazyParam);
+ }
+
@Transactional(rollbackFor = Exception.class)
@Override
public void add(SysOrgAddParam sysOrgAddParam, String sourceFromType) {
@@ -129,6 +189,8 @@ public class SysOrgServiceImpl extends ServiceImpl impleme
sysOrgExtService.createExtInfo(sysOrg.getId(), sourceFromType);
// 发布增加事件
CommonDataChangeEventCenter.doAddWithData(SysDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(sysOrg));
+ // 清除缓存
+ commonCacheOperator.remove(ORG_ALL_LIST_CACHE_KEY);
}
@Transactional(rollbackFor = Exception.class)
@@ -152,6 +214,8 @@ public class SysOrgServiceImpl extends ServiceImpl impleme
this.updateById(sysOrg);
// 发布更新事件
CommonDataChangeEventCenter.doUpdateWithData(SysDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(sysOrg));
+ // 清除缓存
+ commonCacheOperator.remove(ORG_ALL_LIST_CACHE_KEY);
}
@Transactional(rollbackFor = Exception.class)
@@ -197,6 +261,8 @@ public class SysOrgServiceImpl extends ServiceImpl impleme
// 发布删除事件
CommonDataChangeEventCenter.doDeleteWithDataIdList(SysDataTypeEnum.ORG.getValue(), toDeleteOrgIdList);
+ // 清除缓存
+ commonCacheOperator.remove(ORG_ALL_LIST_CACHE_KEY);
}
}
@@ -245,6 +311,8 @@ public class SysOrgServiceImpl extends ServiceImpl impleme
}
}
});
+ // 清除缓存
+ commonCacheOperator.remove(ORG_ALL_LIST_CACHE_KEY);
}
}
@@ -259,7 +327,13 @@ public class SysOrgServiceImpl extends ServiceImpl impleme
@Override
public List getAllOrgList() {
- return this.list(new LambdaQueryWrapper().orderByAsc(SysOrg::getSortCode));
+ Object cached = commonCacheOperator.get(ORG_ALL_LIST_CACHE_KEY);
+ if (cached != null) {
+ return JSONUtil.toList(JSONUtil.parseArray(cached), SysOrg.class);
+ }
+ List list = this.list(new LambdaQueryWrapper().orderByAsc(SysOrg::getSortCode));
+ commonCacheOperator.put(ORG_ALL_LIST_CACHE_KEY, list);
+ return list;
}
@Override
@@ -311,6 +385,8 @@ public class SysOrgServiceImpl extends ServiceImpl impleme
sysOrgExtService.createExtInfo(sysOrg.getId(), SysOrgSourceFromTypeEnum.SYSTEM_ADD.getValue());
// 发布增加事件
CommonDataChangeEventCenter.doAddWithData(SysDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(sysOrg));
+ // 清除缓存
+ commonCacheOperator.remove(ORG_ALL_LIST_CACHE_KEY);
return sysOrg.getId();
}
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/controller/SysPositionController.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/controller/SysPositionController.java
index c21b24c0..692b7c3d 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/controller/SysPositionController.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/controller/SysPositionController.java
@@ -13,6 +13,7 @@
package vip.xiaonuo.sys.modular.position.controller;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
import com.github.xingfudeshi.knife4j.annotations.ApiSupport;
@@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
import vip.xiaonuo.sys.modular.position.param.*;
import vip.xiaonuo.sys.modular.position.service.SysPositionService;
@@ -136,6 +138,19 @@ public class SysPositionController {
return CommonResult.data(sysPositionService.orgTreeSelector());
}
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ @ApiOperationSupport(order = 6)
+ @Operation(summary = "获取组织树选择器(懒加载)")
+ @GetMapping("/sys/position/orgTreeLazySelector")
+ public CommonResult> orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
+ return CommonResult.data(sysPositionService.orgTreeLazySelector(sysOrgTreeLazyParam));
+ }
+
/**
* 获取职位选择器
*
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/service/SysPositionService.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/service/SysPositionService.java
index 02a6e9bf..a01b9fc6 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/service/SysPositionService.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/service/SysPositionService.java
@@ -13,8 +13,10 @@
package vip.xiaonuo.sys.modular.position.service;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
import vip.xiaonuo.sys.modular.position.param.*;
@@ -102,6 +104,14 @@ public interface SysPositionService extends IService {
*/
List> orgTreeSelector();
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/22 15:53
+ **/
+ List orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam);
+
/**
* 获取职位选择器
*
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/service/impl/SysPositionServiceImpl.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/service/impl/SysPositionServiceImpl.java
index 503922ff..e635199d 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/service/impl/SysPositionServiceImpl.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/position/service/impl/SysPositionServiceImpl.java
@@ -36,6 +36,7 @@ import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
import vip.xiaonuo.common.page.CommonPageRequest;
import vip.xiaonuo.sys.core.enums.SysDataTypeEnum;
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
import vip.xiaonuo.sys.modular.position.enums.SysPositionCategoryEnum;
@@ -200,6 +201,11 @@ public class SysPositionServiceImpl extends ServiceImpl orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
+ return sysOrgService.treeLazy(sysOrgTreeLazyParam);
+ }
+
@Override
public Page positionSelector(SysPositionSelectorPositionParam sysPositionSelectorPositionParam) {
QueryWrapper queryWrapper = new QueryWrapper().checkSqlInjection();
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/controller/SysRoleController.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/controller/SysRoleController.java
index c37f6749..3f8c48de 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/controller/SysRoleController.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/controller/SysRoleController.java
@@ -13,6 +13,7 @@
package vip.xiaonuo.sys.modular.role.controller;
import cn.hutool.core.lang.tree.Tree;
+import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xingfudeshi.knife4j.annotations.ApiOperationSupport;
import com.github.xingfudeshi.knife4j.annotations.ApiSupport;
@@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.role.entity.SysRole;
import vip.xiaonuo.sys.modular.role.param.*;
import vip.xiaonuo.sys.modular.role.result.*;
@@ -251,6 +253,19 @@ public class SysRoleController {
return CommonResult.data(sysRoleService.orgTreeSelector());
}
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ @ApiOperationSupport(order = 15)
+ @Operation(summary = "获取组织树选择器(懒加载)")
+ @GetMapping("/sys/role/orgTreeLazySelector")
+ public CommonResult> orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
+ return CommonResult.data(sysRoleService.orgTreeLazySelector(sysOrgTreeLazyParam));
+ }
+
/**
* 获取资源授权树
*
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/service/SysRoleService.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/service/SysRoleService.java
index 36b5d416..9beafa9c 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/service/SysRoleService.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/service/SysRoleService.java
@@ -16,6 +16,7 @@ import cn.hutool.core.lang.tree.Tree;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.resource.entity.SysMenu;
import vip.xiaonuo.sys.modular.role.entity.SysRole;
import vip.xiaonuo.sys.modular.role.param.*;
@@ -154,6 +155,14 @@ public interface SysRoleService extends IService {
*/
List> orgTreeSelector();
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ List orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam);
+
/**
* 获取资源授权树
*
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/service/impl/SysRoleServiceImpl.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/service/impl/SysRoleServiceImpl.java
index 8556ad14..5c65ff24 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/service/impl/SysRoleServiceImpl.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/role/service/impl/SysRoleServiceImpl.java
@@ -41,6 +41,7 @@ import vip.xiaonuo.mobile.api.MobileMenuApi;
import vip.xiaonuo.sys.core.enums.SysBuildInEnum;
import vip.xiaonuo.sys.core.enums.SysDataTypeEnum;
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
import vip.xiaonuo.sys.modular.relation.entity.SysRelation;
import vip.xiaonuo.sys.modular.relation.enums.SysRelationCategoryEnum;
@@ -357,6 +358,11 @@ public class SysRoleServiceImpl extends ServiceImpl impl
return TreeUtil.build(treeNodeList, "0");
}
+ @Override
+ public List orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
+ return sysOrgService.treeLazy(sysOrgTreeLazyParam);
+ }
+
@Override
public List resourceTreeSelector(boolean containsTen) {
LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>();
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/controller/SysUserController.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/controller/SysUserController.java
index 237251e0..9b8050cc 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/controller/SysUserController.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/controller/SysUserController.java
@@ -31,6 +31,7 @@ import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
import vip.xiaonuo.sys.modular.role.entity.SysRole;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.user.entity.SysUser;
import vip.xiaonuo.sys.modular.user.enums.SysUserSourceFromTypeEnum;
import vip.xiaonuo.sys.modular.user.param.*;
@@ -329,6 +330,19 @@ public class SysUserController {
return CommonResult.data(sysUserService.orgTreeSelector());
}
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/4/24 20:00
+ */
+ @ApiOperationSupport(order = 19)
+ @Operation(summary = "获取组织树选择器(懒加载)")
+ @GetMapping("/sys/user/orgTreeLazySelector")
+ public CommonResult> orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
+ return CommonResult.data(sysUserService.orgTreeLazySelector(sysOrgTreeLazyParam));
+ }
+
/**
* 获取组织列表选择器
*
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/SysUserService.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/SysUserService.java
index 3b87cd97..2332868e 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/SysUserService.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/SysUserService.java
@@ -22,6 +22,7 @@ import vip.xiaonuo.sys.modular.group.entity.SysGroup;
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
import vip.xiaonuo.sys.modular.role.entity.SysRole;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.user.entity.SysUser;
import vip.xiaonuo.sys.modular.user.entity.SysUserExt;
import vip.xiaonuo.sys.modular.user.param.*;
@@ -480,6 +481,14 @@ public interface SysUserService extends IService {
*/
List> orgTreeSelector();
+ /**
+ * 获取组织树选择器(懒加载)
+ *
+ * @author xuyuxiang
+ * @date 2022/5/13 21:00
+ */
+ List orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam);
+
/**
* 获取组织列表选择器
*
diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java
index ab926a6a..0d7fa39e 100644
--- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java
+++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java
@@ -88,6 +88,7 @@ import vip.xiaonuo.sys.core.util.SysPasswordUtl;
import vip.xiaonuo.sys.modular.group.entity.SysGroup;
import vip.xiaonuo.sys.modular.group.service.SysGroupService;
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
+import vip.xiaonuo.sys.modular.org.param.SysOrgTreeLazyParam;
import vip.xiaonuo.sys.modular.org.service.SysOrgService;
import vip.xiaonuo.sys.modular.position.entity.SysPosition;
import vip.xiaonuo.sys.modular.position.service.SysPositionService;
@@ -2004,6 +2005,11 @@ public class SysUserServiceImpl extends ServiceImpl impl
return TreeUtil.build(treeNodeList, "0");
}
+ @Override
+ public List orgTreeLazySelector(SysOrgTreeLazyParam sysOrgTreeLazyParam) {
+ return sysOrgService.treeLazy(sysOrgTreeLazyParam);
+ }
+
@Override
public Page orgListSelector(SysUserSelectorOrgListParam sysUserSelectorOrgListParam) {
QueryWrapper queryWrapper = new QueryWrapper().checkSqlInjection();