|
|
@@ -313,31 +313,37 @@ export function getDepartments () {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+let departmentCache = null
|
|
|
+export function resetDepartmentCache () {
|
|
|
+ departmentCache = null
|
|
|
+}
|
|
|
+
|
|
|
export function getDepartmentTree () {
|
|
|
+ if (departmentCache) {
|
|
|
+ return Promise.resolve({ data: departmentCache })
|
|
|
+ }
|
|
|
if (store.getters.isTenantAdmin) {
|
|
|
return getDepartments().then(({ data }) => {
|
|
|
- return {
|
|
|
- data: [{
|
|
|
- path: store.getters.tenant,
|
|
|
- name: store.getters.tenantName || '我的部门',
|
|
|
- children: data
|
|
|
- }]
|
|
|
- }
|
|
|
+ departmentCache = [{
|
|
|
+ path: store.getters.tenant,
|
|
|
+ name: store.getters.tenantName || '我的部门',
|
|
|
+ children: data
|
|
|
+ }]
|
|
|
+ return { data: departmentCache }
|
|
|
})
|
|
|
}
|
|
|
return request({
|
|
|
url: '/keycloak/oneself/tree',
|
|
|
method: 'GET'
|
|
|
}).then(({ data }) => {
|
|
|
- return {
|
|
|
- data: Array.isArray(data)
|
|
|
- ? [{
|
|
|
- path: store.getters.org,
|
|
|
- name: '我的部门',
|
|
|
- children: data
|
|
|
- }]
|
|
|
- : [data]
|
|
|
- }
|
|
|
+ departmentCache = Array.isArray(data)
|
|
|
+ ? [{
|
|
|
+ path: store.getters.org,
|
|
|
+ name: '我的部门',
|
|
|
+ children: data
|
|
|
+ }]
|
|
|
+ : [data]
|
|
|
+ return { data: departmentCache }
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -346,7 +352,7 @@ export function addDepartment (data) {
|
|
|
url: '/admin/department',
|
|
|
method: 'POST',
|
|
|
data: addTenantKey(data)
|
|
|
- }, tenantRequest)
|
|
|
+ }, tenantRequest).finally(resetDepartmentCache)
|
|
|
}
|
|
|
|
|
|
export function updateDepartmentName (data) {
|
|
|
@@ -354,14 +360,14 @@ export function updateDepartmentName (data) {
|
|
|
url: '/admin/department',
|
|
|
method: 'PUT',
|
|
|
data
|
|
|
- })
|
|
|
+ }).finally(resetDepartmentCache)
|
|
|
}
|
|
|
|
|
|
export function deleteDepartment ({ id }) {
|
|
|
return messageSend({
|
|
|
url: `/admin/department/${id}`,
|
|
|
method: 'DELETE'
|
|
|
- }, '删除')
|
|
|
+ }, '删除').finally(resetDepartmentCache)
|
|
|
}
|
|
|
|
|
|
export function getUsersByDepartment (query) {
|