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 } }