From 990970181a69fa8c10f5fc312ecc447b41e988e3 Mon Sep 17 00:00:00 2001 From: ZhengJie <201507802@qq.com> Date: Mon, 22 Jun 2020 08:15:28 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=BC=BA=E9=99=B7=E4=BF=AE=E5=A4=8D](v2.5):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E8=A7=92=E8=89=B2=E5=88=86=E9=85=8D?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E4=B8=89=E7=BA=A7=E8=8A=82=E7=82=B9=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=A2=E5=A4=B1=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close https://github.com/elunez/eladmin/issues/413 --- package.json | 2 +- src/api/system/menu.js | 1 - src/views/system/role/index.vue | 31 ++++++++++++++++++------------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 42c47c1..d90f327 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "echarts": "^4.2.1", "echarts-gl": "^1.1.1", "echarts-wordcloud": "^1.1.3", - "element-ui": "^2.12.0", + "element-ui": "^2.13.2", "file-saver": "1.3.8", "fuse.js": "3.4.4", "js-beautify": "^1.10.2", diff --git a/src/api/system/menu.js b/src/api/system/menu.js index 7f9d84e..d601323 100644 --- a/src/api/system/menu.js +++ b/src/api/system/menu.js @@ -16,7 +16,6 @@ export function getMenus(params) { } export function getMenuSuperior(ids) { - console.log(ids.length) const data = ids.length || ids.length === 0 ? ids : Array.of(ids) return request({ url: 'api/menus/superior', diff --git a/src/views/system/role/index.vue b/src/views/system/role/index.vue index dd9f2dc..b3cf2ed 100644 --- a/src/views/system/role/index.vue +++ b/src/views/system/role/index.vue @@ -109,6 +109,7 @@ accordion show-checkbox node-key="id" + @check="menuChange" /> @@ -185,7 +186,7 @@ export default { } } const depts = [] - form.depts.forEach(function(dept, index) { + form.depts.forEach(function(dept) { depts.push(dept.id) }) form.depts = depts @@ -200,7 +201,7 @@ export default { return false } else if (crud.form.dataScope === '自定义') { const depts = [] - crud.form.depts.forEach(function(data, index) { + crud.form.depts.forEach(function(data) { const dept = { id: data } depts.push(dept) }) @@ -218,7 +219,7 @@ export default { }, afterErrorMethod(crud) { const depts = [] - crud.form.depts.forEach(function(dept, index) { + crud.form.depts.forEach(function(dept) { depts.push(dept.id) }) crud.form.depts = depts @@ -236,7 +237,7 @@ export default { // 初始化 this.menuIds = [] // 菜单数据需要特殊处理 - val.menus.forEach(function(data, index) { + val.menus.forEach(function(data) { _this.menuIds.push(data.id) }) getMenuSuperior(this.menuIds).then(res => { @@ -246,21 +247,25 @@ export default { }) } }, + menuChange(menu) { + // 判断是否在 menuIds 中,如果存在则删除,否则添加 + const index = this.menuIds.indexOf(menu.id) + if (index !== -1) { + this.menuIds.splice(index, 1) + } else { + this.menuIds.push(menu.id) + } + }, // 保存菜单 saveMenu() { this.menuLoading = true const role = { id: this.currentId, menus: [] } - // 得到半选的父节点数据,保存起来 - this.$refs.menu.getHalfCheckedNodes().forEach(function(data, index) { - const menu = { id: data.id } - role.menus.push(menu) - }) // 得到已选中的 key 值 - this.$refs.menu.getCheckedKeys().forEach(function(data, index) { - const menu = { id: data } + this.menuIds.forEach(function(id) { + const menu = { id: id } role.menus.push(menu) }) - crudRoles.editMenu(role).then(res => { + crudRoles.editMenu(role).then(() => { this.crud.notify('保存成功', CRUD.NOTIFICATION_TYPE.SUCCESS) this.menuLoading = false this.update() @@ -328,7 +333,7 @@ export default { this.getDepts() } }, - checkboxT(row, rowIndex) { + checkboxT(row) { return row.level >= this.level } }