From 35129d7a07af3f2ac7509e9163db6e4fc8259efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E7=8E=AE?= Date: Tue, 29 Jun 2021 09:28:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/organization.js | 9 ++- .../jobmanagement/JobManagement.vue | 45 --------------- .../view/organization/jobmanagement/form.vue | 36 ------------ .../view/organization/jobmanagement/index.js | 3 - src/router/config.js | 9 ++- src/utils/index.js | 57 +++++++++++++++++++ 6 files changed, 72 insertions(+), 87 deletions(-) delete mode 100644 src/pages/system/view/organization/jobmanagement/JobManagement.vue delete mode 100644 src/pages/system/view/organization/jobmanagement/form.vue delete mode 100644 src/pages/system/view/organization/jobmanagement/index.js diff --git a/src/api/organization.js b/src/api/organization.js index a7ba9d7..be858d7 100644 --- a/src/api/organization.js +++ b/src/api/organization.js @@ -8,7 +8,12 @@ function updateJobsApi(data) { return putReq('/api/v1/jobs', data); } +function getOrganizationList(data) { + return getReq('/api/v1/organizations', data); +} + export default { - add: addJobsApi, - update: updateJobsApi, + addJobs: addJobsApi, + updateJobs: updateJobsApi, + getOrganizationList: getOrganizationList, }; diff --git a/src/pages/system/view/organization/jobmanagement/JobManagement.vue b/src/pages/system/view/organization/jobmanagement/JobManagement.vue deleted file mode 100644 index 4bd4e93..0000000 --- a/src/pages/system/view/organization/jobmanagement/JobManagement.vue +++ /dev/null @@ -1,45 +0,0 @@ - - \ No newline at end of file diff --git a/src/pages/system/view/organization/jobmanagement/form.vue b/src/pages/system/view/organization/jobmanagement/form.vue deleted file mode 100644 index fb91fd5..0000000 --- a/src/pages/system/view/organization/jobmanagement/form.vue +++ /dev/null @@ -1,36 +0,0 @@ - - - diff --git a/src/pages/system/view/organization/jobmanagement/index.js b/src/pages/system/view/organization/jobmanagement/index.js deleted file mode 100644 index 199f40f..0000000 --- a/src/pages/system/view/organization/jobmanagement/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import JobManagement from './JobManagement'; - -export default JobManagement; diff --git a/src/router/config.js b/src/router/config.js index 782ebb0..bc39b4d 100644 --- a/src/router/config.js +++ b/src/router/config.js @@ -78,7 +78,14 @@ const options = { { path: 'job_management', name: '岗位管理', - component: () => import('@/pages/system/view/organization/jobmanagement'), + component: () => + import('@/pages/system/view/organization/jobsmanagement'), + }, + { + path: 'user_management', + name: '用户管理', + component: () => + import('@/pages/system/view/organization/usermanagement'), }, ], }, diff --git a/src/utils/index.js b/src/utils/index.js index 2bb55c6..0df8d96 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -31,3 +31,60 @@ export function convertListToTree(menuList, filterMenu = false) { export function EMPTY_FUN() {} export const isFunction = val => typeof val === 'function'; +export function arrayToTree(options) { + options = JSON.parse(JSON.stringify(options)); + this.data = options.data || []; + this.parentKey = options.parentKey || 'parent_code'; + this.childrenKey = options.childrenKey || 'children'; + this.key = options.key || 'code'; + this.maping = options.maping || undefined; + this.rootValue = options.rootValue || '0'; + this.treeData = []; + this.indexStorage = {}; + this.getDataBykey = function(key) { + return this.indexStorage[key]; + }; + this.setMapping = function() { + for (let i = 0; i < this.data.length; i++) { + var item = this.data[i]; + for (const x in this.maping) { + item[this.maping[x]] = item[x]; + } + } + }; + if (this.maping) { + this.setMapping(); + } + this.setIndexStorage = function() { + for (let i = 0; i < this.data.length; i++) { + this.indexStorage[this.data[i][this.key]] = this.data[i]; // 以id作为索引存储元素,可以无需遍历直接定位元素 + } + }; + this.setIndexStorage(); + // 利用数组浅拷贝 + this.toTree = function() { + const THISDATA = JSON.parse(JSON.stringify(this.data)); + for (let i = 0; i < this.data.length; i++) { + let currentElement = this.data[i]; + let tempCurrentElementParent = this.indexStorage[currentElement[this.parentKey]]; // 临时变量里面的当前元素的父元素 + if (tempCurrentElementParent) { + // 如果存在父元素 + if (!tempCurrentElementParent[this.childrenKey]) { + // 如果父元素没有chindren键 + tempCurrentElementParent[this.childrenKey] = []; // 设上父元素的children键 + } + tempCurrentElementParent[this.childrenKey].push(currentElement); // 给父元素加上当前元素作为子元素 + } else { + // 不存在父元素,意味着当前元素是一级元素 + if (this.rootValue != undefined && currentElement[this.key] === this.rootValue) { + this.treeData.push(currentElement); + } else { + this.treeData.push(currentElement); + } + } + } + return this.treeData; + }; + this.toTree(); + return this; +} -- GitLab