From cb3386d12248f9b7dd0918b24c277e30ba56f942 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 27 Jan 2022 15:26:33 +0800 Subject: [PATCH] fix: moving menu team causes submenus to be lost (halo-dev/console#422) * fix: moving menu team causes submenus to be lost Signed-off-by: Ryan Wang * fix: moving menu team causes submenus to be lost Signed-off-by: Ryan Wang --- .../interface/components/MenuTreeNode.vue | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/views/interface/components/MenuTreeNode.vue b/src/views/interface/components/MenuTreeNode.vue index feec0d5d8c..80a7519866 100644 --- a/src/views/interface/components/MenuTreeNode.vue +++ b/src/views/interface/components/MenuTreeNode.vue @@ -46,11 +46,6 @@ >{{ team === '' ? '未分组' : team }} - - {{ team === '' ? '未分组' : team }} - - @@ -147,24 +142,32 @@ export default { handleCloseCreateMenuForm(item) { this.$set(item, 'formVisible', false) }, - handleCopyMenu(item, team) { - const menu = deepClone(item) - menu.team = team - menu.parentId = 0 - menu.priority = 0 - menu.id = null - apiClient.menu.create(menu).then(() => { - this.$emit('reload') - }) - }, - handleMoveMenu(item, team) { + async handleMoveMenu(item, team) { const menu = deepClone(item) menu.team = team menu.parentId = 0 menu.priority = 0 - apiClient.menu.update(menu.id, menu).then(() => { + + const toFlatList = data => { + if (!data || data.length === 0) return [] + + return data.reduce((prev, current) => { + const children = current.children.length > 0 ? toFlatList(current.children) : [] + current.team = team + return [...prev, current, ...children] + }, []) + } + + const flatList = [menu, ...toFlatList(menu.children)] + + this.$log.debug('menu list as flat list:', flatList) + + try { + await apiClient.menu.updateInBatch(flatList) this.$emit('reload') - }) + } catch (e) { + this.$log.error('Fail to update menu in batch', e) + } }, onReloadEmit() { this.$emit('reload')