From fe5fc3c9f9e7ee346425fc5752469f48f37858fa Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 27 Jan 2022 13:01:13 +0800 Subject: [PATCH 1/2] fix: moving menu team causes submenus to be lost Signed-off-by: Ryan Wang --- .../interface/components/MenuTreeNode.vue | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/views/interface/components/MenuTreeNode.vue b/src/views/interface/components/MenuTreeNode.vue index feec0d5d8..1b38b4b30 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,34 @@ 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) { + console.log(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') From d8ffec51aa60d8552b89cb05c4c08f7d0e0cc39d Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 27 Jan 2022 13:01:44 +0800 Subject: [PATCH 2/2] fix: moving menu team causes submenus to be lost Signed-off-by: Ryan Wang --- src/views/interface/components/MenuTreeNode.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/views/interface/components/MenuTreeNode.vue b/src/views/interface/components/MenuTreeNode.vue index 1b38b4b30..80a751986 100644 --- a/src/views/interface/components/MenuTreeNode.vue +++ b/src/views/interface/components/MenuTreeNode.vue @@ -143,8 +143,6 @@ export default { this.$set(item, 'formVisible', false) }, async handleMoveMenu(item, team) { - console.log(item, team) - const menu = deepClone(item) menu.team = team menu.parentId = 0