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

Commit

Permalink
fix: moving menu team causes submenus to be lost (#422)
Browse files Browse the repository at this point in the history
* fix: moving menu team causes submenus to be lost

Signed-off-by: Ryan Wang <i@ryanc.cc>

* fix: moving menu team causes submenus to be lost

Signed-off-by: Ryan Wang <i@ryanc.cc>
  • Loading branch information
ruibaby authored Jan 27, 2022
1 parent 70c95b3 commit dc1866d
Showing 1 changed file with 21 additions and 18 deletions.
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

0 comments on commit dc1866d

Please sign in to comment.