diff --git a/src/views/modules/sys/menu-add-or-update.vue b/src/views/modules/sys/menu-add-or-update.vue index c66207c..ed04724 100644 --- a/src/views/modules/sys/menu-add-or-update.vue +++ b/src/views/modules/sys/menu-add-or-update.vue @@ -11,12 +11,6 @@ {{ type }} - - - - - - + + + + + + @@ -119,6 +119,10 @@ typeName:'名称' }, dataRule: { + menuId: [ + { required: true, message: '目录编号不能为空', trigger: 'blur' }, + { pattern: /^\d+$/, message: '目录编号必须是纯数字', trigger: 'blur' } + ], name: [ { required: true, message: '菜单名称不能为空', trigger: 'blur' } ], @@ -154,6 +158,7 @@ code:'编号' }, menuList: [], + flatMenuList: [], menuListTreeProps: { label: 'name', children: 'children' @@ -172,6 +177,7 @@ method: 'get', params: this.$http.adornParams() }).then(({data}) => { + this.flatMenuList = data.menuList || [] this.menuList = treeDataTranslate(data.menuList, 'menuId') }).then(() => { this.visible = true @@ -224,6 +230,17 @@ this.dataForm.parentId = data.menuId this.dataForm.parentName = data.name this.treeVisible = false + + // 在添加时,根据用户选的上级菜单的menuId作为parentId去查最大的menuId+1,赋值给目录编码 + if (!this.dataForm.id) { + let children = this.flatMenuList.filter(item => item.parentId === data.menuId) + if (children.length > 0) { + let maxId = Math.max(...children.map(item => Number(item.menuId))) + this.dataForm.menuId = String(maxId + 1) + } else { + this.dataForm.menuId = String(data.menuId) + '01' + } + } }, // 菜单树设置当前选中节点 menuListTreeSetCurrentNode () {