Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

fix: moving menu team causes submenus to be lost #422

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions src/views/interface/components/MenuTreeNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
>{{ team === '' ? '未分组' : team }}
</a-menu-item>
</a-sub-menu>
<a-sub-menu title="复制到分组">
<a-menu-item v-for="(team, index) in excludedTeams" :key="index" @click="handleCopyMenu(item, team)"
>{{ team === '' ? '未分组' : team }}
</a-menu-item>
</a-sub-menu>
</a-menu>
</a-dropdown>
</template>
Expand Down Expand Up @@ -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')
Expand Down