vxe-table 樹結構單元格選取與複製貼上

可不简单發表於2024-11-30

vxe-table 樹結構單元格選取與複製貼上,透過 tree-config.transform 使用樹形表格

<template>
  <div>
    <vxe-table
      border
      show-overflow
      keep-source
      height="600"
      :column-config="columnConfig"
      :tree-config="treeConfig"
      :mouse-config="mouseConfig"
      :area-config="areaConfig"
      :edit-config="editConfig"
      :clip-config="clipConfig"
      :keyboard-config="keyboardConfig"
      :data="tableData">
      <vxe-column type="seq" width="80"></vxe-column>
      <vxe-column field="name" title="名稱" min-width="300" tree-node :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="size" title="大小" width="140" :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="type" title="型別" width="140" :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="createBy" title="建立人" width="200" :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="updateDate" title="修改時間" width="200" :edit-render="{ name: 'input' }"></vxe-column>
      <vxe-column field="createDate" title="建立時間" width="200" :edit-render="{ name: 'input' }"></vxe-column>
    </vxe-table>
  </div>
</template>

<script>
export default {
  data () {
    const tableData = [
      { id: 10000, parentId: null, name: '檔案1.xlsx', type: 'xlsx', size: 1024, createBy: '王五', updateDate: '2020-09-11', createDate: '2020-08-01' },
      { id: 10050, parentId: null, name: '部署目錄', type: '', size: 0, createBy: '老六', updateDate: '2020-08-01', createDate: '2021-04-01' },
      { id: 24300, parentId: 10050, name: '選單配置.avi', type: 'avi', size: 1024, createBy: '小芳', updateDate: '2020-10-24', createDate: '2020-03-01' },
      { id: 20045, parentId: 24300, name: '角色說明.html', type: 'html', size: 600, createBy: '老徐', updateDate: '2020-08-01', createDate: '2021-04-01' },
      { id: 10053, parentId: 24300, name: '許可權配置.avi', type: 'avi', size: 0, createBy: '老胡', updateDate: '', createDate: '2021-04-01' },
      { id: 24330, parentId: 10053, name: '部署秘鑰.txt', type: 'txt', size: 25, createBy: '張三', updateDate: '2020-09-11', createDate: '2021-10-01' },
      { id: 21011, parentId: 10053, name: '流程文件。pdf', type: 'pdf', size: 512, createBy: '老張', updateDate: '2020-08-01', createDate: '2020-01-01' },
      { id: 22200, parentId: 10053, name: '解決 bug 檔案.js', type: 'js', size: 1024, createBy: '小劉', updateDate: '2020-10-24', createDate: '2021-06-01' },
      { id: 23666, parentId: null, name: '發版目錄', type: '', size: 2048, createBy: '老劉', updateDate: '2020-02-18', createDate: '2020-11-01' },
      { id: 23677, parentId: 23666, name: '替換問題檔案.js', type: 'js', size: 1024, createBy: '老馮', updateDate: '2020-09-11', createDate: '2021-06-01' },
      { id: 23671, parentId: 23677, name: '釋出流程.avi', type: 'avi', size: 1024, createBy: '小牛', updateDate: '2020-08-01', createDate: '2021-06-01' },
      { id: 23672, parentId: 23677, name: '配置流程.mp4', type: 'mp4', size: 1024, createBy: '李四', updateDate: '2020-02-09', createDate: '2021-06-01' },
      { id: 23688, parentId: 23666, name: '測試流程.mp4', type: 'mp4', size: 1024, createBy: '小三', updateDate: '2020-10-24', createDate: '2021-06-01' },
      { id: 23681, parentId: 23688, name: '問題記錄.txt', type: 'txt', size: 1024, createBy: '小李', updateDate: '2020-08-01', createDate: '2021-06-01' },
      { id: 23682, parentId: 23688, name: '釋出說明.html', type: 'html', size: 1024, createBy: '小徐', updateDate: '2020-02-18', createDate: '2021-06-01' },
      { id: 24555, parentId: null, name: '資源目錄', type: '', size: 224, createBy: '小小', updateDate: '2020-08-01', createDate: '2020-10-01' },
      { id: 24566, parentId: 24555, name: '鈴聲檔案.mp3', type: 'mp3', size: 1024, createBy: '老八', updateDate: '2020-02-29', createDate: '2021-06-01' },
      { id: 24577, parentId: 24555, name: '上線人員列表.xlsx', type: 'xlsx', size: 1024, createBy: '小紅', updateDate: '2020-08-01', createDate: '2021-06-01' }
    ]

    const columnConfig = {
      resizable: true
    }

    const treeConfig = {
      transform: true,
      rowField: 'id',
      parentField: 'parentId'
    }

    const mouseConfig = {
      area: true // 是否開啟區域選取
    }

    const areaConfig = {
      multiple: true // 是否啟用多區域選取功能
    }

    const editConfig = {
      mode: 'cell',
      trigger: 'dblclick',
      showStatus: true
    }

    const clipConfig = {
      isDeepPaste: true // 是否深層貼上,用於樹結構,啟用後貼上時會覆蓋到子級資料進行貼上
    }

    const keyboardConfig = {
      isClip: true,
      isArrow: true,
      isShift: true,
      isTab: true,
      isEnter: true,
      isEdit: true,
      isDel: true,
      isEsc: true,
      isFNR: true // 是否開啟查詢與替換
    }

    return {
      tableData,
      columnConfig,
      treeConfig,
      mouseConfig,
      areaConfig,
      editConfig,
      clipConfig,
      keyboardConfig
    }
  }
}
</script>

相關文章