博客 / 詳情

返回

如何實現 vxe-tree 樹組件拖拽節點後進行二次確認提示

如何實現 vxe-tree 樹組件拖拽節點後進行二次確認提示,參數 drag-config.dragStartMethod 可以自定義處理拖拽開始時的拖動,可以自定義是否允許拖拽

官網:https://vxeui.com
github:https://github.com/x-extends/vxe-pc-ui
gitee:https://gitee.com/x-extends/vxe-pc-ui

tree_drag_drag_method

需要提示操作時,通過 drag-config.dragEndMethod 可以自定義處理拖拽結束時的拖動

<template>
  <div>
    <vxe-tree v-bind="treeOptions"></vxe-tree>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import { VxeUI } from 'vxe-pc-ui'

const treeOptions = reactive({
  transform: true,
  drag: true,
  dragConfig: {
    isCrossDrag: true,
    isSelfToChildDrag: true,
    showGuidesStatus: true,
    async dragEndMethod () {
      const type = await VxeUI.modal.confirm({
        content: '請是否確認調整順序?'
      })
      if (type === 'confirm') {
        return true
      }
      VxeUI.modal.message({
        content: '操作已取消',
        status: 'warning'
      })
      return false
    }
  },
  data: [
    { title: '節點2', id: '2', parentId: null },
    { title: '節點3', id: '3', parentId: null },
    { title: '節點3-1', id: '31', parentId: '3' },
    { title: '節點3-2', id: '32', parentId: '3' },
    { title: '節點3-2-1', id: '321', parentId: '32' },
    { title: '節點3-2-2', id: '322', parentId: '32' },
    { title: '節點3-3', id: '33', parentId: '3' },
    { title: '節點3-3-1', id: '331', parentId: '33' },
    { title: '節點3-3-2', id: '332', parentId: '33' },
    { title: '節點3-3-3', id: '333', parentId: '33' },
    { title: '節點3-4', id: '34', parentId: '3' },
    { title: '節點4', id: '4', parentId: null },
    { title: '節點4-1', id: '41', parentId: '4' },
    { title: '節點4-1-1', id: '411', parentId: '42' },
    { title: '節點4-1-2', id: '412', parentId: '42' },
    { title: '節點4-2', id: '42', parentId: '4' },
    { title: '節點4-3', id: '43', parentId: '4' },
    { title: '節點4-3-1', id: '431', parentId: '43' },
    { title: '節點4-3-2', id: '432', parentId: '43' },
    { title: '節點5', id: '5', parentId: null }
  ]
})
</script>

https://gitee.com/x-extends/vxe-pc-ui

user avatar
0 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.