vxe-table 樹表格單元格選擇複製貼上

可不简单發表於2024-12-05

vxe-table 樹表格單元格選擇複製貼上,樹結構預設是平級貼上,可以透過 clip-config.isDeepPaste 啟用深層資料結構的貼上;需要注意只支援 tree-config.transform 模式

<template>
  <div>
    <vxe-table
      border
      show-overflow
      keep-source
      height="500"
      :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: 3200, createBy: '王五', updateDate: '2020-09-11', createDate: '2020-08-01' },
      { id: 10050, parentId: null, name: '部署目錄', type: '', size: null, 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: '2021-08-01', createDate: '201-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: null, createBy: '老劉', updateDate: '2020-02-18', createDate: '2020-11-01' },
      { id: 23677, parentId: 23666, name: '替換問題檔案.js', type: 'js', size: 1024, createBy: '老馮', updateDate: '2019-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: '2019-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: '2021-02-18', createDate: '2021-06-01' },
      { id: 24555, parentId: null, name: '資源目錄', type: '', size: null, 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' },
      { id: 30000, parentId: null, name: '評審目錄', type: '', size: null, createBy: '小何', updateDate: '2020-01-26', createDate: '2020-09-05' },
      { id: 30001, parentId: 30000, name: '評審檔案.xlsx', type: 'xlsx', size: 36522, createBy: '張三', updateDate: '2021-02-22', createDate: '2020-08-09' },
      { id: 30010, parentId: 30000, name: '更多檔案', type: '', size: null, createBy: '小徐', updateDate: '2021-02-22', createDate: '2020-08-09' },
      { id: 30011, parentId: 30010, name: '評審檔案.xlsx', type: 'xlsx', size: 36522, createBy: '李四', updateDate: '2021-02-22', createDate: '2020-08-09' },
      { id: 30012, parentId: 30010, name: '其他目錄', type: '', size: null, createBy: '老劉', updateDate: '2021-02-22', createDate: '2020-08-09' },
      { id: 30102, parentId: 30012, name: '評審檔案.xlsx', type: 'xlsx', size: 36522, createBy: '小康', updateDate: '2021-02-22', createDate: '2020-08-09' },
      { id: 40000, parentId: null, name: '檔案4.xlsx', type: 'ppt', size: 2048, createBy: '王五', updateDate: '2020-10-04', createDate: '2020-11-07' },
      { id: 50000, parentId: null, name: '檔案5.xlsx', type: 'pdf', size: 3652, createBy: '小張', updateDate: '2020-12-08', createDate: '2020-04-08' }
    ]

    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,
      isBack: true,
      isDel: true,
      isEsc: true,
      isFNR: true // 是否開啟查詢與替換
    }

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

相關文章